net.sf.jguard.authentication
Class AbstractAuthenticationManager

java.lang.Object
  extended by net.sf.jguard.authentication.AbstractAuthenticationManager
All Implemented Interfaces:
AuthenticationManager
Direct Known Subclasses:
JdbcAuthenticationManager, JNDIAuthenticationManager, XmlAuthenticationManager

public abstract class AbstractAuthenticationManager
extends java.lang.Object
implements AuthenticationManager

Abstract class which provides convenient methods for all the AuthenticationManager implementations.

Author:
Charles Gay

Field Summary
protected  java.lang.String applicationName
           
protected  boolean debug
           
protected static java.lang.String DEFAULT
           
protected  java.util.Map localPrincipals
           
protected  java.util.Set localPrincipalsSet
           
protected  SubjectTemplate subjectTemplate
           
 
Constructor Summary
AbstractAuthenticationManager()
           
 
Method Summary
 void addPrincipalToUser(javax.security.auth.Subject user, java.lang.String roleName)
          add a role present in the webapp to the registered user.
 java.security.Principal clonePrincipal(java.lang.String roleName)
          Clone a Principal with a random name
 java.security.Principal clonePrincipal(java.lang.String roleName, java.lang.String cloneName)
          Clone a Principal.
 void createPrincipal(java.security.Principal principal)
          verify the Subject and create a user in the backend.
 void createUser(javax.security.auth.Subject user)
          verify the Subject and create a user in the XML backend.
 javax.security.auth.Subject createUser(SubjectTemplate user)
          verify the Subject and create a user in the XML backend.
 javax.security.auth.Subject createUser(SubjectTemplate user, SubjectTemplate template)
          verify the Subject against the provided template and create a user in the XML backend.
protected  java.util.Set extractCredentials(java.util.Set credentialsSought, java.util.Set credentials)
          extract credentials sought
protected  java.util.Set extractCredentialsFromSubject(java.util.Set credentialsSought, javax.security.auth.Subject user)
           
protected  JGuardCredential extractIdentityCredentialFromUser(javax.security.auth.Subject user)
           
abstract  java.util.Set findUsers(java.util.Collection credentials)
          search the users which matches credentials criterions.
 SubjectTemplate getDefaultSubjectTemplate()
          return the default unmodifiable SubjectTemplate.
 java.security.Principal getLocalPrincipal(java.lang.String name)
          retrieve role from the principals set of the webapp.
 java.util.Set getLocalPrincipals()
          get the principals defined in the repository for all the applications.
abstract  java.util.Set getUsers()
           
 boolean hasPrincipal(java.security.Principal role)
          verify whether or not the role exists in the webapp.
 boolean hasPrincipal(java.lang.String ppalName)
          verify whether or not the role exists in the webapp.
 void importAuthenticationManager(AuthenticationManager authManager)
           
protected abstract  void persistPrincipal(java.security.Principal principal)
          persist role in the datasource backend.
protected abstract  void persistUser(javax.security.auth.Subject user)
          persist user in the datasource backend.
 boolean userAlreadyExists(javax.security.auth.Subject user)
          indicate wether the user exists in the webapp or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.jguard.authentication.AuthenticationManager
deletePrincipal, deleteUser, getAllPrincipalsSet, getSubjectTemplate, init, isEmpty, persistSubjectTemplate, updatePrincipal, updateUser
 

Field Detail

DEFAULT

protected static final java.lang.String DEFAULT
See Also:
Constant Field Values

subjectTemplate

protected SubjectTemplate subjectTemplate

debug

protected boolean debug

applicationName

protected java.lang.String applicationName

localPrincipalsSet

protected java.util.Set localPrincipalsSet

localPrincipals

protected java.util.Map localPrincipals
Constructor Detail

AbstractAuthenticationManager

public AbstractAuthenticationManager()
Method Detail

createUser

public javax.security.auth.Subject createUser(SubjectTemplate user)
                                       throws AuthenticationException
verify the Subject and create a user in the XML backend.

Specified by:
createUser in interface AuthenticationManager
Parameters:
user - Subject to create in the XML backend
Throws:
AuthenticationException
See Also:
AuthenticationManager.createUser(javax.security.auth.Subject)

createUser

public javax.security.auth.Subject createUser(SubjectTemplate user,
                                              SubjectTemplate template)
                                       throws AuthenticationException
verify the Subject against the provided template and create a user in the XML backend.

Specified by:
createUser in interface AuthenticationManager
Parameters:
user - Subject to create in the XML backend
template - we register user against this specific template
Throws:
AuthenticationException - if user already exists
See Also:
AuthenticationManager.createUser(javax.security.auth.Subject)

createUser

public void createUser(javax.security.auth.Subject user)
                throws AuthenticationException
verify the Subject and create a user in the XML backend.

Specified by:
createUser in interface AuthenticationManager
Parameters:
user - Subject to create in the XML backend
Throws:
AuthenticationException
See Also:
AuthenticationManager.createUser(javax.security.auth.Subject)

createPrincipal

public void createPrincipal(java.security.Principal principal)
                     throws AuthenticationException
verify the Subject and create a user in the backend.

Specified by:
createPrincipal in interface AuthenticationManager
Parameters:
user - Subject to create in the XML backend
Throws:
AuthenticationException
See Also:
net.sf.jguard.authentication.AuthenticationManager#createPrincipal(javax.security.auth.Subject)

persistUser

protected abstract void persistUser(javax.security.auth.Subject user)
                             throws AuthenticationException
persist user in the datasource backend.

Parameters:
user -
Throws:
AuthenticationException

persistPrincipal

protected abstract void persistPrincipal(java.security.Principal principal)
                                  throws AuthenticationException
persist role in the datasource backend.

Parameters:
principal - to persist
Throws:
AuthenticationException

getLocalPrincipals

public java.util.Set getLocalPrincipals()
get the principals defined in the repository for all the applications.

Specified by:
getLocalPrincipals in interface AuthenticationManager
Returns:
role's list.

getLocalPrincipal

public java.security.Principal getLocalPrincipal(java.lang.String name)
                                          throws AuthenticationException
retrieve role from the principals set of the webapp.

Specified by:
getLocalPrincipal in interface AuthenticationManager
Parameters:
name -
Returns:
role found or null if not found
Throws:
AuthenticationException
See Also:
net.sf.jguard.authentication.AuthenticationManager#getRole(java.lang.String)

userAlreadyExists

public boolean userAlreadyExists(javax.security.auth.Subject user)
                          throws AuthenticationException
indicate wether the user exists in the webapp or not.

Specified by:
userAlreadyExists in interface AuthenticationManager
Parameters:
user - we are looking for
Returns:
true if registered in the webapp, false otherwise
Throws:
AuthenticationException
See Also:
AuthenticationManager.userAlreadyExists(javax.security.auth.Subject)

addPrincipalToUser

public void addPrincipalToUser(javax.security.auth.Subject user,
                               java.lang.String roleName)
                        throws AuthenticationException
add a role present in the webapp to the registered user. you need to call refreshUsers of the HttpAuthenticationUtils to update connected users.

Specified by:
addPrincipalToUser in interface AuthenticationManager
Throws:
AuthenticationException
See Also:
AuthenticationManager.addPrincipalToUser(javax.security.auth.Subject, java.lang.String)

hasPrincipal

public boolean hasPrincipal(java.security.Principal role)
                     throws AuthenticationException
verify whether or not the role exists in the webapp.

Specified by:
hasPrincipal in interface AuthenticationManager
Parameters:
role -
Returns:
result
Throws:
AuthenticationException

hasPrincipal

public boolean hasPrincipal(java.lang.String ppalName)
                     throws AuthenticationException
verify whether or not the role exists in the webapp.

Specified by:
hasPrincipal in interface AuthenticationManager
Parameters:
ppalName - Principal's name
Returns:
result
Throws:
AuthenticationException

findUsers

public abstract java.util.Set findUsers(java.util.Collection credentials)
                                 throws AuthenticationException
search the users which matches credentials criterions.

Specified by:
findUsers in interface AuthenticationManager
Parameters:
credentials - crierions used to grab the users
Returns:
users found
Throws:
AuthenticationException

getDefaultSubjectTemplate

public SubjectTemplate getDefaultSubjectTemplate()
                                          throws AuthenticationException
return the default unmodifiable SubjectTemplate.

Specified by:
getDefaultSubjectTemplate in interface AuthenticationManager
Returns:
default unmodifiable SubjectTemplate
Throws:
AuthenticationException

getUsers

public abstract java.util.Set getUsers()
                                throws AuthenticationException
Specified by:
getUsers in interface AuthenticationManager
Throws:
AuthenticationException

importAuthenticationManager

public void importAuthenticationManager(AuthenticationManager authManager)

extractCredentials

protected java.util.Set extractCredentials(java.util.Set credentialsSought,
                                           java.util.Set credentials)
extract credentials sought

Parameters:
credentialsSought -
credentials -
Returns:

extractCredentialsFromSubject

protected java.util.Set extractCredentialsFromSubject(java.util.Set credentialsSought,
                                                      javax.security.auth.Subject user)

extractIdentityCredentialFromUser

protected JGuardCredential extractIdentityCredentialFromUser(javax.security.auth.Subject user)
                                                      throws AuthenticationException
Throws:
AuthenticationException

clonePrincipal

public java.security.Principal clonePrincipal(java.lang.String roleName)
                                       throws AuthenticationException
Description copied from interface: AuthenticationManager
Clone a Principal with a random name

Specified by:
clonePrincipal in interface AuthenticationManager
Parameters:
roleName - Principal name to clone
Returns:
cloned Principal with a different name: roleName + Random integer betweeen 0 and 99999
Throws:
AuthenticationException
See Also:
AuthenticationManager.clonePrincipal(String roleName)

clonePrincipal

public java.security.Principal clonePrincipal(java.lang.String roleName,
                                              java.lang.String cloneName)
                                       throws AuthenticationException
Description copied from interface: AuthenticationManager
Clone a Principal. If Principal is instance of JGuardPrincipal makes a call to the clone method leting the clone task to JGuardPrincipal

Specified by:
clonePrincipal in interface AuthenticationManager
Parameters:
roleName - Principal name to clone
cloneName - Principal cloned name
Returns:
cloned Principal with the given cloneName
Throws:
AuthenticationException
See Also:
AuthenticationManager.clonePrincipal(String roleName, String cloneName)