Coverage report

  %line %branch
org.apache.fulcrum.security.memory.MemoryUserManagerImpl
95% 
93% 

 1  
 package org.apache.fulcrum.security.memory;
 2  
 /*
 3  
  *  Copyright 2001-2004 The Apache Software Foundation
 4  
  *
 5  
  *  Licensed under the Apache License, Version 2.0 (the "License");
 6  
  *  you may not use this file except in compliance with the License.
 7  
  *  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  *  Unless required by applicable law or agreed to in writing, software
 12  
  *  distributed under the License is distributed on an "AS IS" BASIS,
 13  
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  *  See the License for the specific language governing permissions and
 15  
  *  limitations under the License.
 16  
  */
 17  
 import java.util.ArrayList;
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.commons.logging.Log;
 21  
 import org.apache.commons.logging.LogFactory;
 22  
 import org.apache.fulcrum.security.entity.User;
 23  
 import org.apache.fulcrum.security.spi.AbstractUserManager;
 24  
 import org.apache.fulcrum.security.util.DataBackendException;
 25  
 import org.apache.fulcrum.security.util.EntityExistsException;
 26  
 import org.apache.fulcrum.security.util.UnknownEntityException;
 27  
 import org.apache.fulcrum.security.util.UserSet;
 28  
 
 29  
 /**
 30  
  * This implementation keeps all objects in memory.  This is mostly meant to help
 31  
  * with testing and prototyping of ideas.
 32  
  *
 33  
  * @todo Need to load up Crypto component and actually encrypt passwords!
 34  
  * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
 35  
  * @version $Id: MemoryUserManagerImpl.java 223067 2004-07-13 16:11:28Z epugh $
 36  
  */
 37  387
 public class MemoryUserManagerImpl
 38  
     extends AbstractUserManager
 39  
     
 40  
 {
 41  
     /** Logging */
 42  33
     private static Log log = LogFactory.getLog(MemoryUserManagerImpl.class);
 43  33
     private static List users = new ArrayList();
 44  
    
 45  
     /** Our Unique ID counter */
 46  33
     private static int uniqueId = 0;
 47  
 
 48  
     /**
 49  
      * Check whether a specified user's account exists.
 50  
      *
 51  
      * The login name is used for looking up the account.
 52  
      *
 53  
      * @param userName The name of the user to be checked.
 54  
      * @return true if the specified account exists
 55  
      * @throws DataBackendException if there was an error accessing
 56  
      *         the data backend.
 57  
      */
 58  
     public boolean checkExists(String userName) throws DataBackendException
 59  
     {
 60  297
         return MemoryHelper.checkExists(users,userName); 
 61  
        
 62  
     }
 63  
     
 64  
 	/**
 65  
 	 * Retrieves all users defined in the system.
 66  
 	 * 
 67  
 	 * @return the names of all users defined in the system.
 68  
 	 * @throws DataBackendException if there was an error accessing the data backend.
 69  
 	 */
 70  
 	public UserSet getAllUsers() throws DataBackendException
 71  
 	{
 72  87
 		return new UserSet(users);
 73  
 	}    
 74  
     /**
 75  
     	* Removes an user account from the system.
 76  
     	*
 77  
     	* @param user the object describing the account to be removed.
 78  
     	* @throws DataBackendException if there was an error accessing the data
 79  
     	*         backend.
 80  
     	* @throws UnknownEntityException if the user account is not present.
 81  
     	*/
 82  
     public void removeUser(User user)
 83  
         throws DataBackendException, UnknownEntityException
 84  
     {
 85  6
         users.remove(user);
 86  6
     }
 87  
     /**
 88  
        * Creates new user account with specified attributes.
 89  
        *
 90  
        * @param user the object describing account to be created.
 91  
        * @param password The password to use for the account.
 92  
        *
 93  
        * @throws DataBackendException if there was an error accessing the
 94  
        *         data backend.
 95  
        * @throws EntityExistsException if the user account already exists.
 96  
        */
 97  
     protected User persistNewUser(User user)
 98  
         throws DataBackendException
 99  
     {
 100  
        
 101  135
             users.remove(user);
 102  135
             user.setId(MemoryHelper.getUniqueId());
 103  135
             users.add(user);
 104  135
             return user;
 105  
         
 106  
     }
 107  
     /**
 108  
        * Stores User attributes. The User is required to exist in the system.
 109  
        *
 110  
        * @param role The User to be stored.
 111  
        * @throws DataBackendException if there was an error accessing the data
 112  
        *         backend.
 113  
        * @throws UnknownEntityException if the role does not exist.
 114  
        */
 115  
     public void saveUser(User user)
 116  
         throws DataBackendException, UnknownEntityException
 117  
     {
 118  18
         boolean userExists = false;
 119  18
         userExists = checkExists(user);
 120  18
         if (userExists)
 121  
         {
 122  18
             users.remove(user);
 123  18
             users.add(user);
 124  
         }
 125  
         else
 126  
         {
 127  0
             throw new UnknownEntityException("Unknown user '" + user + "'");
 128  
         }
 129  18
     }
 130  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.