com.atlassian.crowd.service.cache
Class CachingUserManager

java.lang.Object
  extended by com.atlassian.crowd.service.cache.CachingUserManager
All Implemented Interfaces:
UserManager

public class CachingUserManager
extends java.lang.Object
implements UserManager


Constructor Summary
CachingUserManager(SecurityServerClient securityServerClient, BasicCache basicCache)
           
 
Method Summary
 void addAllUsers(java.util.Collection<SOAPPrincipalWithCredential> users)
          Adds all users to Crowd.
 SOAPPrincipal addUser(SOAPPrincipal user, PasswordCredential credential)
          Adds a user to Crowd.
 java.util.List getAllUserNames()
          This optimises the background getAllUserNames() call.
 SOAPPrincipal getUser(java.lang.String userName)
          Given a userName, fetches the user's details, either from cache or from the Crowd server.
 SOAPPrincipal getUserFromToken(java.lang.String token)
          Note: the lookup is not currently cached - it will always hit the server.
 SOAPPrincipal getUserWithAttributes(java.lang.String userName)
          Given a userName, fetches the user's details and their associated attributes, either from cache or from the Crowd server.
 boolean isUser(java.lang.String userName)
          With JIRA we're guaranteed that if there are any names in the user list, all the names are in the user list.
 void removeUser(java.lang.String userName)
          Removes a user from Crowd.
 java.util.List searchUsers(SearchRestriction[] restrictions)
          Searches the list of all available users based on the passed-in restrictions and returns a list of users that match.
 void updatePassword(java.lang.String userName, PasswordCredential credential)
          Changes the password for the user specified by userName.
 void updateUser(SOAPPrincipal user)
          Updates a user's details in Crowd.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingUserManager

public CachingUserManager(SecurityServerClient securityServerClient,
                          BasicCache basicCache)
Method Detail

getUser

public SOAPPrincipal getUser(java.lang.String userName)
                      throws java.rmi.RemoteException,
                             InvalidAuthorizationTokenException
Description copied from interface: UserManager
Given a userName, fetches the user's details, either from cache or from the Crowd server.

Specified by:
getUser in interface UserManager
Parameters:
userName - The user's identifer
Returns:
An object representing the user
Throws:
java.rmi.RemoteException - A communication error occurred - the Crowd server may not be available.
InvalidAuthorizationTokenException - The application (not the user) was not authenticated correctly.

getUserWithAttributes

public SOAPPrincipal getUserWithAttributes(java.lang.String userName)
                                    throws java.rmi.RemoteException,
                                           InvalidAuthorizationTokenException,
                                           ObjectNotFoundException
Description copied from interface: UserManager
Given a userName, fetches the user's details and their associated attributes, either from cache or from the Crowd server.

Specified by:
getUserWithAttributes in interface UserManager
Parameters:
userName - The user's identifer
Returns:
An object representing the user and their attributes
Throws:
java.rmi.RemoteException - A communication error occurred - the Crowd server may not be available.
InvalidAuthorizationTokenException - The application (not the user) was not authenticated correctly.
ObjectNotFoundException

getUserFromToken

public SOAPPrincipal getUserFromToken(java.lang.String token)
                               throws java.rmi.RemoteException,
                                      InvalidAuthorizationTokenException,
                                      InvalidTokenException
Note: the lookup is not currently cached - it will always hit the server. The returned user is cached and will by found by a call to getUser()

Specified by:
getUserFromToken in interface UserManager
Parameters:
token -
Returns:
Throws:
java.rmi.RemoteException
InvalidAuthorizationTokenException
com.atlassian.crowd.embedded.api.UserNotFoundException
InvalidTokenException - The token presented was not a valid Crowd token.

searchUsers

public java.util.List searchUsers(SearchRestriction[] restrictions)
                           throws java.rmi.RemoteException,
                                  InvalidAuthorizationTokenException
Description copied from interface: UserManager
Searches the list of all available users based on the passed-in restrictions and returns a list of users that match.

Specified by:
searchUsers in interface UserManager
Returns:
A List of SOAPPrincipals that match the criteria.
Throws:
java.rmi.RemoteException - A communication error occurred - the Crowd server may not be available.
InvalidAuthorizationTokenException - The application (not the user) was not authenticated correctly.

addUser

public SOAPPrincipal addUser(SOAPPrincipal user,
                             PasswordCredential credential)
                      throws java.rmi.RemoteException,
                             ApplicationPermissionException,
                             InvalidCredentialException,
                             InvalidUserException,
                             InvalidAuthorizationTokenException
Description copied from interface: UserManager
Adds a user to Crowd.

Specified by:
addUser in interface UserManager
Parameters:
user - The user to add to Crowd
credential - The credential (eg. password) for the user. May be null.
Returns:
The SOAPPrincipal, as returned by the Crowd server.
Throws:
java.rmi.RemoteException - A communication error occurred - the Crowd server may not be available.
ApplicationPermissionException - The application, not the user, does not have rights to add users.
InvalidCredentialException - The credentials were malformed or did not meet directory complexity requirements.
InvalidUserException - The user was malformed or already exists.
InvalidAuthorizationTokenException - The application (not the user) was not authenticated correctly.

addAllUsers

public void addAllUsers(java.util.Collection<SOAPPrincipalWithCredential> users)
                 throws InvalidAuthorizationTokenException,
                        BulkAddFailedException,
                        java.rmi.RemoteException,
                        ApplicationPermissionException
Description copied from interface: UserManager
Adds all users to Crowd. N.B.: After adding the users the cache gets flushed.

Specified by:
addAllUsers in interface UserManager
Parameters:
users - The users to add to Crowd
Throws:
InvalidAuthorizationTokenException - The application (not the user) was not authenticated correctly.
BulkAddFailedException - Thrown when it failed to create a user in of the directories.
java.rmi.RemoteException - A communication error occurred - the Crowd server may not be available.
ApplicationPermissionException - The application, not the user, does not have rights to add users.

updateUser

public void updateUser(SOAPPrincipal user)
                throws java.rmi.RemoteException,
                       ApplicationPermissionException,
                       InvalidAuthorizationTokenException
Description copied from interface: UserManager
Updates a user's details in Crowd.

Specified by:
updateUser in interface UserManager
Parameters:
user - The user to update
Throws:
java.rmi.RemoteException - A communication error occurred - the Crowd server may not be available.
ApplicationPermissionException - This application does not have the rights to update the user. Sorry.
InvalidAuthorizationTokenException - The application (not the user) was not authenticated correctly.

updatePassword

public void updatePassword(java.lang.String userName,
                           PasswordCredential credential)
                    throws java.rmi.RemoteException,
                           InvalidAuthorizationTokenException,
                           InvalidCredentialException,
                           ApplicationPermissionException
Description copied from interface: UserManager
Changes the password for the user specified by userName.

Specified by:
updatePassword in interface UserManager
Parameters:
userName - The identifier of the user
credential - The new credentials for the user.
Throws:
java.rmi.RemoteException - A communication error occurred - the Crowd server may not be available.
InvalidAuthorizationTokenException - The application (not the user) was not authenticated correctly.
InvalidCredentialException - The credentials were malformed or did not meet directory complexity requirements.
ApplicationPermissionException - This application does not have the rights to update the user's password. Sorry.

removeUser

public void removeUser(java.lang.String userName)
                throws java.rmi.RemoteException,
                       InvalidAuthorizationTokenException,
                       ApplicationPermissionException
Description copied from interface: UserManager
Removes a user from Crowd.

Specified by:
removeUser in interface UserManager
Parameters:
userName - The name of the user to remove.
Throws:
java.rmi.RemoteException - A communication error occurred - the Crowd server may not be available.
InvalidAuthorizationTokenException - The application (not the user) was not authenticated correctly.
ApplicationPermissionException - This application is not allowed to remove this user.

getAllUserNames

public java.util.List getAllUserNames()
                               throws java.rmi.RemoteException,
                                      InvalidAuthorizationTokenException
This optimises the background getAllUserNames() call. JIRA goes "give me all the usernames", followed by "give me each user, individually". This is slow because we scan the directory once for the list of usernames, then once again for each user.

The optimisation reduces the number of directory scans to one. A huge benefit, particularly with Active Directory.

Specified by:
getAllUserNames in interface UserManager
Returns:
Throws:
java.rmi.RemoteException
InvalidAuthorizationTokenException

isUser

public boolean isUser(java.lang.String userName)
               throws java.rmi.RemoteException,
                      InvalidAuthorizationTokenException
With JIRA we're guaranteed that if there are any names in the user list, all the names are in the user list. We go to the user cache because a map lookup should be much faster than using contains() on a List, because it's implemented as a straight iterative search.

Specified by:
isUser in interface UserManager
Parameters:
userName -
Returns:
Throws:
java.rmi.RemoteException
InvalidAuthorizationTokenException


Copyright © 2010 Atlassian. All Rights Reserved.