Class AliasingAwareTokenAuthenticationManager
- All Implemented Interfaces:
TokenAuthenticationManager
-
Constructor Summary
ConstructorsConstructorDescriptionAliasingAwareTokenAuthenticationManager(TokenAuthenticationManager tokenAuthenticationManager, ApplicationManager applicationManager, AliasManager aliasManager) -
Method Summary
Modifier and TypeMethodDescriptionauthenticateApplication(Application application, ApplicationAuthenticationContext authenticationContext, TokenLifetime tokenLifetime) Authenticates an application and generates an authentication token.authenticateApplicationWithoutValidatingPassword(Application application, ApplicationAuthenticationContext authenticationContext, TokenLifetime tokenLifetime) Authenticates an application and generates an authentication token, ignoring the credentials.authenticateUser(Application application, UserAuthenticationContext authenticateContext, TokenLifetime tokenLifetime) Authenticates a user and and generates an authentication token.authenticateUserWithoutValidatingPassword(Application application, UserAuthenticationContext authenticateContext) Feigns the authentication process for a user and creates a token for the authentication without validating the password.findAuthorisedApplications(User user, String applicationName) Returns a list of applications a user is authorised to authenticate with.findUserByToken(Token token, Application application) Will find a user via the passed in token.findUserTokenByKey(String tokenKey, Application application) Returns the token matching a given keygetTokenExpiryTime(Token token) Returns the expiry time of a token.voidInvalidates all user and application tokens.invalidateToken(String token) Attempts to invalidate a Token based on the passed in Token key (random hash).voidinvalidateTokensForUser(String username, String exclusionToken, String applicationName) Invalidates all sessions for a user, possibly excluding a specific one.voidRemoves all tokens that have exceeded their expiry time.validateApplicationToken(String tokenKey, ValidationFactor[] validationFactors) Validates an application token key given validation factors.validateUserToken(Application application, String userTokenKey, ValidationFactor[] validationFactors) Validates a user token key given validation factors and checks that the user is allowed to authenticate with the specified application
-
Constructor Details
-
AliasingAwareTokenAuthenticationManager
public AliasingAwareTokenAuthenticationManager(TokenAuthenticationManager tokenAuthenticationManager, ApplicationManager applicationManager, AliasManager aliasManager)
-
-
Method Details
-
authenticateApplication
public Token authenticateApplication(Application application, ApplicationAuthenticationContext authenticationContext, TokenLifetime tokenLifetime) throws InvalidAuthenticationException Description copied from interface:TokenAuthenticationManagerAuthenticates an application and generates an authentication token.- Specified by:
authenticateApplicationin interfaceTokenAuthenticationManager- Parameters:
application- the application being authenticatedauthenticationContext- application authentication credentials.tokenLifetime- Requested lifetime of the token- Returns:
- generated authentication token.
- Throws:
InvalidAuthenticationException- authentication was not successful because either the application does not exist, the password is incorrect, the application is inactive or there was a problem generating the authentication token.
-
authenticateApplicationWithoutValidatingPassword
public Token authenticateApplicationWithoutValidatingPassword(Application application, ApplicationAuthenticationContext authenticationContext, TokenLifetime tokenLifetime) throws InvalidAuthenticationException Description copied from interface:TokenAuthenticationManagerAuthenticates an application and generates an authentication token, ignoring the credentials.This method should only be used to generate a token for an application that has already authenticated via some other means (eg. TLS client certificates) as this method bypasses any password checks.
- Specified by:
authenticateApplicationWithoutValidatingPasswordin interfaceTokenAuthenticationManager- Parameters:
application- the application being authenticatedauthenticationContext- application authentication credentials.tokenLifetime- Requested lifetime of the token- Returns:
- generated authentication token.
- Throws:
InvalidAuthenticationException- authentication was not successful because either the application does not exist, the application is inactive or there was a problem generating the authentication token.
-
authenticateUser
public Token authenticateUser(Application application, UserAuthenticationContext authenticateContext, TokenLifetime tokenLifetime) throws InvalidAuthenticationException, OperationFailedException, InactiveAccountException, ApplicationAccessDeniedException, ExpiredCredentialException Description copied from interface:TokenAuthenticationManagerAuthenticates a user and and generates an authentication token. The password of the user is validated before generating a token.The
RemoteDirectory.authenticate(String, com.atlassian.crowd.embedded.api.PasswordCredential)method is iteratively called for each assigned directory. If the user does not exist in one directory, the directory is skipped and the next one is examined. If the user does not exist in any of the assigned directories then anInvalidAuthenticationExceptionis thrown.- Specified by:
authenticateUserin interfaceTokenAuthenticationManagerauthenticateContext- The authentication details for the user.tokenLifetime- Requested lifetime of the token- Returns:
- The authenticated token for the user.
- Throws:
InvalidAuthenticationException- The authentication was not successful.OperationFailedException- error thrown by directory implementation when attempting to find or authenticate the user.InactiveAccountException- user account is inactive.ApplicationAccessDeniedException- user does not have access to authenticate with application.ExpiredCredentialException- the user's credentials have expired. The user must change their credentials in order to successfully authenticate.
-
authenticateUserWithoutValidatingPassword
public Token authenticateUserWithoutValidatingPassword(Application application, UserAuthenticationContext authenticateContext) throws InvalidAuthenticationException, OperationFailedException, InactiveAccountException, ApplicationAccessDeniedException Description copied from interface:TokenAuthenticationManagerFeigns the authentication process for a user and creates a token for the authentication without validating the password.This method should only be used to generate a token for a user that has already authenticated credentials via some other means (eg. SharePoint NTLM connector) as this method bypasses any password checks.
If you want actual password authentication, use the
TokenAuthenticationManager.authenticateUser(Application, UserAuthenticationContext, TokenLifetime)method.- Specified by:
authenticateUserWithoutValidatingPasswordin interfaceTokenAuthenticationManagerauthenticateContext- The authentication details for the user.- Returns:
- The authenticated token for the user.
- Throws:
InvalidAuthenticationException- if the authentication was not successful.OperationFailedException- if the error was thrown by directory implementation when attempting to find or authenticate the user.InactiveAccountException- if the user account is inactive.ApplicationAccessDeniedException- if the user does not have access to authenticate with application.
-
validateApplicationToken
public Token validateApplicationToken(String tokenKey, ValidationFactor[] validationFactors) throws InvalidTokenException Description copied from interface:TokenAuthenticationManagerValidates an application token key given validation factors.- Specified by:
validateApplicationTokenin interfaceTokenAuthenticationManager- Parameters:
tokenKey- returns a valid token corresponding to the tokenKey.validationFactors- validation factors for generating the token hash.- Returns:
- validated token.
- Throws:
InvalidTokenException- if the tokenKey or corresponding client validation factors do not represent a valid application token.
-
validateUserToken
public Token validateUserToken(Application application, String userTokenKey, ValidationFactor[] validationFactors) throws InvalidTokenException, ApplicationAccessDeniedException, OperationFailedException Description copied from interface:TokenAuthenticationManagerValidates a user token key given validation factors and checks that the user is allowed to authenticate with the specified application- Specified by:
validateUserTokenin interfaceTokenAuthenticationManager- Parameters:
application- the application performing the authenticationuserTokenKey- returns a valid token corresponding to the tokenKey.validationFactors- validation factors for generating the token hash.- Returns:
- validated authentication token.
- Throws:
InvalidTokenException- if the userTokenKey or corresponding validationFactors do not represent a valid SSO token.ApplicationAccessDeniedException- the user is not allowed to authenticate with the application.OperationFailedException- there was an error communicating with an underlying directory when determining if a user is allowed to authenticate with the application (eg. if a user has the appropriate group memberships).
-
invalidateToken
Description copied from interface:TokenAuthenticationManagerAttempts to invalidate a Token based on the passed in Token key (random hash).If the token does not exist (ie. already invalidated) this method returns
Optional.empty(). If an existing token is successfully invalidated, a TokenInvalidatedEvent is fired, and the invalidated token is returned- Specified by:
invalidateTokenin interfaceTokenAuthenticationManager- Parameters:
token- the token key (random hash) to invalidate.
-
invalidateAllTokens
public void invalidateAllTokens()Description copied from interface:TokenAuthenticationManagerInvalidates all user and application tokens. This means it will also invalidate the token of the calling application.- Specified by:
invalidateAllTokensin interfaceTokenAuthenticationManager
-
removeExpiredTokens
public void removeExpiredTokens()Description copied from interface:TokenAuthenticationManagerRemoves all tokens that have exceeded their expiry time.NOTE: Do not call this method from the web layer, as this is wrapped in a Spring managed transaction.
- Specified by:
removeExpiredTokensin interfaceTokenAuthenticationManager
-
findUserByToken
public User findUserByToken(Token token, Application application) throws OperationFailedException, InvalidTokenException Description copied from interface:TokenAuthenticationManagerWill find a user via the passed in token.- Specified by:
findUserByTokenin interfaceTokenAuthenticationManager- Parameters:
token- the tokenapplication- the application to do the lookup for- Returns:
- the User associated to the given token
- Throws:
OperationFailedException- if there was an issue accessing the user from the underlying directoryInvalidTokenException- if the User or Directory cannot be found that relates to the given token, or the token is associated to an Application and not a User
-
findUserTokenByKey
public Token findUserTokenByKey(String tokenKey, Application application) throws InvalidTokenException, ApplicationAccessDeniedException, OperationFailedException Description copied from interface:TokenAuthenticationManagerReturns the token matching a given key- Specified by:
findUserTokenByKeyin interfaceTokenAuthenticationManager- Parameters:
tokenKey- the token keyapplication- the application to do the lookup for- Returns:
- the Token with the given token key
- Throws:
InvalidTokenException- if the token cannot be found by the give key, or the token is associated to an Application and not a UserApplicationAccessDeniedException- the user is not allowed to authenticate with the application.OperationFailedException- if there was an issue accessing the user from the underlying directory
-
findAuthorisedApplications
public List<Application> findAuthorisedApplications(User user, String applicationName) throws OperationFailedException, DirectoryNotFoundException, ApplicationNotFoundException Description copied from interface:TokenAuthenticationManagerReturns a list of applications a user is authorised to authenticate with.NOTE: this is a potentially expensive call, iterating all applications and all group mappings for each application and determining group membership, ie. expense = number of applications * number of group mappings per application.
- Specified by:
findAuthorisedApplicationsin interfaceTokenAuthenticationManager- Parameters:
user- user to search for.applicationName- name of the current application- Returns:
- list of applications.
- Throws:
OperationFailedException- if there was an error querying directory.DirectoryNotFoundException- if the directory could not be found.ApplicationNotFoundException- if the application could not be found
-
invalidateTokensForUser
public void invalidateTokensForUser(String username, String exclusionToken, String applicationName) throws UserNotFoundException, ApplicationNotFoundException Description copied from interface:TokenAuthenticationManagerInvalidates all sessions for a user, possibly excluding a specific one.- Specified by:
invalidateTokensForUserin interfaceTokenAuthenticationManagerexclusionToken- the random hash of a token to leave validapplicationName- name of the current application- Throws:
UserNotFoundExceptionApplicationNotFoundException
-
getTokenExpiryTime
Description copied from interface:TokenAuthenticationManagerReturns the expiry time of a token.- Specified by:
getTokenExpiryTimein interfaceTokenAuthenticationManager- Parameters:
token- a token- Returns:
- the expiry time for the given token
-