Enhancements to detect errors and faciltiate easier testing.
This commit is contained in:
parent
d59a5da321
commit
adb1971873
|
@ -16,6 +16,7 @@
|
||||||
package net.sf.acegisecurity.providers.dao.memory;
|
package net.sf.acegisecurity.providers.dao.memory;
|
||||||
|
|
||||||
import net.sf.acegisecurity.providers.dao.User;
|
import net.sf.acegisecurity.providers.dao.User;
|
||||||
|
import net.sf.acegisecurity.providers.dao.UsernameNotFoundException;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -42,16 +43,48 @@ public class UserMap {
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
public User getUser(String username) {
|
/**
|
||||||
return (User) this.userMap.get(username.toLowerCase());
|
* Locates the specified user by performing a case insensitive search by
|
||||||
|
* username.
|
||||||
|
*
|
||||||
|
* @param username to find
|
||||||
|
*
|
||||||
|
* @return the located user
|
||||||
|
*
|
||||||
|
* @throws UsernameNotFoundException if the user could not be found
|
||||||
|
*/
|
||||||
|
public User getUser(String username) throws UsernameNotFoundException {
|
||||||
|
User result = (User) this.userMap.get(username.toLowerCase());
|
||||||
|
|
||||||
|
if (result == null) {
|
||||||
|
throw new UsernameNotFoundException("Could not find user: "
|
||||||
|
+ username);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates the size of the user map.
|
||||||
|
*
|
||||||
|
* @return the number of users in the map
|
||||||
|
*/
|
||||||
|
public int getUserCount() {
|
||||||
|
return this.userMap.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a user to the in-memory map.
|
* Adds a user to the in-memory map.
|
||||||
*
|
*
|
||||||
* @param user the user to be stored
|
* @param user the user to be stored
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException if a null User was passed
|
||||||
*/
|
*/
|
||||||
public void addUser(User user) {
|
public void addUser(User user) throws IllegalArgumentException {
|
||||||
|
if (user == null) {
|
||||||
|
throw new IllegalArgumentException("Must be a valid User");
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("Adding user [" + user + "]");
|
logger.info("Adding user [" + user + "]");
|
||||||
this.userMap.put(user.getUsername().toLowerCase(), user);
|
this.userMap.put(user.getUsername().toLowerCase(), user);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue