net.sf.jguard.ext.authentication.manager
Class AbstractAuthenticationManager

java.lang.Object
  extended by net.sf.jguard.ext.authentication.manager.AbstractAuthenticationManager
All Implemented Interfaces:
net.sf.jguard.core.authentication.manager.AuthenticationManager
Direct Known Subclasses:
HibernateAuthenticationManager, XmlAuthenticationManager

public abstract class AbstractAuthenticationManager
extends java.lang.Object
implements net.sf.jguard.core.authentication.manager.AuthenticationManager

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

Author:
Charles Gay, Maximiliano Batelli

Field Summary
protected  java.lang.String applicationName
           
protected  boolean debug
           
protected  net.sf.jguard.core.organization.Organization defaultOrganization
           
protected  java.util.Map localPrincipals
           
protected  java.util.Set localPrincipalsSet
           
protected  java.util.Set organizations
           
protected  net.sf.jguard.core.provisioning.OrganizationTemplate organizationTemplate
           
 
Constructor Summary
AbstractAuthenticationManager(java.util.Map options)
           
 
Method Summary
 void addPrincipalToUser(javax.security.auth.Subject user, java.lang.String roleName)
          add a role present in the webapp to the registered user.
 void addPrincipalToUser(javax.security.auth.Subject user, java.lang.String roleName, java.lang.String applicationName)
          add a role present in any webapp to the registered user.
 java.security.Principal clonePrincipal(java.lang.String roleName)
           
 java.security.Principal clonePrincipal(java.lang.String roleName, java.lang.String cloneName)
           
 net.sf.jguard.core.organization.Organization createOrganization(net.sf.jguard.core.provisioning.OrganizationTemplate organizationCandidate)
           
 net.sf.jguard.core.organization.Organization createOrganization(net.sf.jguard.core.provisioning.OrganizationTemplate organizationTemplate, net.sf.jguard.core.provisioning.OrganizationTemplate organizationCandidate)
          verify the organization against the provided template and create an organizationin the XML backend.
 void createPrincipal(java.security.Principal principal)
          create a Principal in the backend, only if it is not already present.
 javax.security.auth.Subject createUser(javax.security.auth.Subject user, net.sf.jguard.core.organization.Organization organization)
          verify the Subject and create a user in the backend.
 javax.security.auth.Subject createUser(net.sf.jguard.core.provisioning.SubjectTemplate user, net.sf.jguard.core.organization.Organization organization)
          verify the Subject against the provided template and create a user in the XML backend.
protected  java.util.Set extractCredentials(java.util.Set credentialsIdSought, java.util.Set credentials)
          extract credentials sought
protected  java.util.Set extractCredentialsFromSubject(java.util.Set credentialsSought, javax.security.auth.Subject user)
           
protected  net.sf.jguard.core.authentication.credentials.JGuardCredential extractIdentityCredentialFromUser(javax.security.auth.Subject user)
           
 javax.security.auth.Subject findUser(java.lang.String login)
          finds a user with a private Credential with name='login' and value= parameter of this method.
abstract  java.util.Set findUsers(java.util.Collection privateCredentials, java.util.Collection publicCredentials)
          search the users which matches credentials criterions.
 java.lang.String getApplicationName()
           
 java.lang.String getCredentialId()
           
 java.lang.String getCredentialPassword()
           
 net.sf.jguard.core.organization.Organization getDefaultOrganization()
           
 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.
 net.sf.jguard.core.provisioning.OrganizationTemplate getOrganizationTemplate()
           
 java.security.Principal getRole(javax.security.auth.Subject subject, java.lang.String roleName, java.lang.String applicationName)
           
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(net.sf.jguard.core.authentication.manager.AuthenticationManager authManager)
           
protected  void importXmlData(java.util.Map opts)
           
protected  boolean isRole(java.security.Principal principal)
           
protected  boolean isRoleAndLocal(java.security.Principal principal)
          return true if the principal is an instance of a class or subclass of RolePrincipal and if its applicationName is equals to the name of the running application.
 boolean organizationAlreadyExists(net.sf.jguard.core.organization.Organization organization)
          indicate wether the organization exists in the webapp or not.
protected abstract  void persistOrganization(net.sf.jguard.core.organization.Organization organization)
          persist role in the datasource backend.
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.
 void setActiveOnRolePrincipal(javax.security.auth.Subject subject, java.lang.String roleName, java.lang.String applicationName, boolean active)
          change 'active' property on the specified role for a user.
abstract  void setOrganizationTemplate(net.sf.jguard.core.provisioning.OrganizationTemplate organizationTemplate)
           
 void updateRoleDefinition(javax.security.auth.Subject subject, java.lang.String roleName, java.lang.String applicationName, java.lang.String definition)
           
 void updateUser(net.sf.jguard.core.authentication.credentials.JGuardCredential identityCred, javax.security.auth.Subject user)
           
protected abstract  void updateUserImpl(net.sf.jguard.core.authentication.credentials.JGuardCredential identityCred, javax.security.auth.Subject user)
           
 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.core.authentication.manager.AuthenticationManager
deleteOrganization, deletePrincipal, deleteUser, findOrganization, getAllPrincipalsSet, getOrganizations, isEmpty, persistUserLoginAttempt, persistUserLogoutAttempt, updateOrganization, updatePrincipal
 

Field Detail

organizationTemplate

protected net.sf.jguard.core.provisioning.OrganizationTemplate organizationTemplate

debug

protected boolean debug

defaultOrganization

protected net.sf.jguard.core.organization.Organization defaultOrganization

applicationName

protected java.lang.String applicationName

localPrincipalsSet

protected java.util.Set localPrincipalsSet

localPrincipals

protected java.util.Map localPrincipals

organizations

protected java.util.Set organizations
Constructor Detail

AbstractAuthenticationManager

public AbstractAuthenticationManager(java.util.Map options)
Method Detail

getApplicationName

public java.lang.String getApplicationName()
Specified by:
getApplicationName in interface net.sf.jguard.core.authentication.manager.AuthenticationManager

importXmlData

protected void importXmlData(java.util.Map opts)

getDefaultOrganization

public net.sf.jguard.core.organization.Organization getDefaultOrganization()
Specified by:
getDefaultOrganization in interface net.sf.jguard.core.authentication.manager.AuthenticationManager

setOrganizationTemplate

public abstract void setOrganizationTemplate(net.sf.jguard.core.provisioning.OrganizationTemplate organizationTemplate)
                                      throws net.sf.jguard.core.authentication.AuthenticationException
Specified by:
setOrganizationTemplate in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Throws:
net.sf.jguard.core.authentication.AuthenticationException

createUser

public javax.security.auth.Subject createUser(net.sf.jguard.core.provisioning.SubjectTemplate user,
                                              net.sf.jguard.core.organization.Organization organization)
                                       throws net.sf.jguard.core.provisioning.RegistrationException
verify the Subject against the provided template and create a user in the XML backend.

Specified by:
createUser in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Parameters:
user - Subject to create in the XML backend
Throws:
net.sf.jguard.core.authentication.AuthenticationException - if user already exists
net.sf.jguard.core.provisioning.RegistrationException
See Also:
net.sf.jguard.core.authentication.manager.AuthenticationManager#createUser(javax.security.auth.Subject)

createUser

public javax.security.auth.Subject createUser(javax.security.auth.Subject user,
                                              net.sf.jguard.core.organization.Organization organization)
                                       throws net.sf.jguard.core.authentication.AuthenticationException
verify the Subject and create a user in the backend.

Specified by:
createUser in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Parameters:
user - Subject to create in the backend
Returns:
a Subject containing only the principals owned by the current application.
Throws:
net.sf.jguard.core.authentication.AuthenticationException
See Also:
net.sf.jguard.core.authentication.manager.AuthenticationManager#createUser(javax.security.auth.Subject)

createOrganization

public net.sf.jguard.core.organization.Organization createOrganization(net.sf.jguard.core.provisioning.OrganizationTemplate organizationCandidate)
                                                                throws net.sf.jguard.core.provisioning.RegistrationException
Specified by:
createOrganization in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Throws:
net.sf.jguard.core.provisioning.RegistrationException

createOrganization

public net.sf.jguard.core.organization.Organization createOrganization(net.sf.jguard.core.provisioning.OrganizationTemplate organizationTemplate,
                                                                       net.sf.jguard.core.provisioning.OrganizationTemplate organizationCandidate)
                                                                throws net.sf.jguard.core.provisioning.RegistrationException
verify the organization against the provided template and create an organizationin the XML backend.

Parameters:
organizationCandidate -
organizationTemplate -
Throws:
net.sf.jguard.core.authentication.AuthenticationException - if user already exists
net.sf.jguard.core.provisioning.RegistrationException

createPrincipal

public void createPrincipal(java.security.Principal principal)
                     throws net.sf.jguard.core.authentication.AuthenticationException
create a Principal in the backend, only if it is not already present.

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

persistUser

protected abstract void persistUser(javax.security.auth.Subject user)
                             throws net.sf.jguard.core.authentication.AuthenticationException
persist user in the datasource backend.

Parameters:
user -
Throws:
net.sf.jguard.core.authentication.AuthenticationException

persistPrincipal

protected abstract void persistPrincipal(java.security.Principal principal)
                                  throws net.sf.jguard.core.authentication.AuthenticationException
persist role in the datasource backend.

Parameters:
principal - to persist
Throws:
net.sf.jguard.core.authentication.AuthenticationException

persistOrganization

protected abstract void persistOrganization(net.sf.jguard.core.organization.Organization organization)
                                     throws net.sf.jguard.core.authentication.AuthenticationException
persist role in the datasource backend.

Parameters:
principal - to persist
Throws:
net.sf.jguard.core.authentication.AuthenticationException

getLocalPrincipals

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

Specified by:
getLocalPrincipals in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Returns:
role's list.

getLocalPrincipal

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

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

userAlreadyExists

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

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

organizationAlreadyExists

public boolean organizationAlreadyExists(net.sf.jguard.core.organization.Organization organization)
                                  throws net.sf.jguard.core.authentication.AuthenticationException
indicate wether the organization exists in the webapp or not.

Parameters:
organization - we are looking for
Returns:
true if registered, false otherwise
Throws:
net.sf.jguard.core.authentication.AuthenticationException
See Also:
AuthenticationManager.userAlreadyExists(javax.security.auth.Subject)

addPrincipalToUser

public void addPrincipalToUser(javax.security.auth.Subject user,
                               java.lang.String roleName)
                        throws net.sf.jguard.core.authentication.AuthenticationException
add a role present in the webapp to the registered user.

Throws:
net.sf.jguard.core.authentication.AuthenticationException
See Also:
net.sf.jguard.core.authentication.manager.AuthenticationManager#addPrincipalToUser(javax.security.auth.Subject, java.lang.String)

addPrincipalToUser

public void addPrincipalToUser(javax.security.auth.Subject user,
                               java.lang.String roleName,
                               java.lang.String applicationName)
                        throws net.sf.jguard.core.authentication.AuthenticationException
add a role present in any webapp to the registered user.

Throws:
net.sf.jguard.core.authentication.AuthenticationException
See Also:
net.sf.jguard.core.authentication.manager.AuthenticationManager#addPrincipalToUser(javax.security.auth.Subject, java.lang.String)

hasPrincipal

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

Specified by:
hasPrincipal in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Parameters:
role -
Throws:
net.sf.jguard.core.authentication.AuthenticationException

hasPrincipal

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

Specified by:
hasPrincipal in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Parameters:
ppalName - Principal's name
Throws:
net.sf.jguard.core.authentication.AuthenticationException

updateUser

public void updateUser(net.sf.jguard.core.authentication.credentials.JGuardCredential identityCred,
                       javax.security.auth.Subject user)
                throws net.sf.jguard.core.authentication.AuthenticationException
Specified by:
updateUser in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Throws:
net.sf.jguard.core.authentication.AuthenticationException

updateUserImpl

protected abstract void updateUserImpl(net.sf.jguard.core.authentication.credentials.JGuardCredential identityCred,
                                       javax.security.auth.Subject user)
                                throws net.sf.jguard.core.authentication.AuthenticationException
Throws:
net.sf.jguard.core.authentication.AuthenticationException

findUsers

public abstract java.util.Set findUsers(java.util.Collection privateCredentials,
                                        java.util.Collection publicCredentials)
                                 throws net.sf.jguard.core.authentication.AuthenticationException
search the users which matches credentials criterions.

Specified by:
findUsers in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Parameters:
credentials - crierions used to grab the users
Returns:
users found
Throws:
net.sf.jguard.core.authentication.AuthenticationException

getUsers

public abstract java.util.Set getUsers()
                                throws net.sf.jguard.core.authentication.AuthenticationException
Specified by:
getUsers in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Throws:
net.sf.jguard.core.authentication.AuthenticationException

importAuthenticationManager

public void importAuthenticationManager(net.sf.jguard.core.authentication.manager.AuthenticationManager authManager)
Specified by:
importAuthenticationManager in interface net.sf.jguard.core.authentication.manager.AuthenticationManager

extractCredentials

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

Parameters:
credentials - Ids Sought
credentials -
Returns:

extractCredentialsFromSubject

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

extractIdentityCredentialFromUser

protected net.sf.jguard.core.authentication.credentials.JGuardCredential extractIdentityCredentialFromUser(javax.security.auth.Subject user)
                                                                                                    throws net.sf.jguard.core.authentication.AuthenticationException
Throws:
net.sf.jguard.core.authentication.AuthenticationException

clonePrincipal

public java.security.Principal clonePrincipal(java.lang.String roleName)
                                       throws net.sf.jguard.core.authentication.AuthenticationException
Specified by:
clonePrincipal in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Throws:
net.sf.jguard.core.authentication.AuthenticationException
See Also:
AuthenticationManager.clonePrincipal(String roleName)

clonePrincipal

public java.security.Principal clonePrincipal(java.lang.String roleName,
                                              java.lang.String cloneName)
                                       throws net.sf.jguard.core.authentication.AuthenticationException
Specified by:
clonePrincipal in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Throws:
net.sf.jguard.core.authentication.AuthenticationException
See Also:
AuthenticationManager.clonePrincipal(String roleName, String cloneName)

setActiveOnRolePrincipal

public void setActiveOnRolePrincipal(javax.security.auth.Subject subject,
                                     java.lang.String roleName,
                                     java.lang.String applicationName,
                                     boolean active)
                              throws net.sf.jguard.core.authentication.AuthenticationException
change 'active' property on the specified role for a user. this change cannot be done on 'guest' user, or if it remains only one 'active=true' role.

Specified by:
setActiveOnRolePrincipal in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Parameters:
subject -
roleName -
applicationName -
active -
Throws:
net.sf.jguard.core.authentication.AuthenticationException

getRole

public java.security.Principal getRole(javax.security.auth.Subject subject,
                                       java.lang.String roleName,
                                       java.lang.String applicationName)
                                throws net.sf.jguard.core.authentication.AuthenticationException
Throws:
net.sf.jguard.core.authentication.AuthenticationException

findUser

public javax.security.auth.Subject findUser(java.lang.String login)
finds a user with a private Credential with name='login' and value= parameter of this method.

Specified by:
findUser in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Parameters:
login -
am -
Returns:
Subject

updateRoleDefinition

public void updateRoleDefinition(javax.security.auth.Subject subject,
                                 java.lang.String roleName,
                                 java.lang.String applicationName,
                                 java.lang.String definition)
                          throws net.sf.jguard.core.authentication.AuthenticationException
Specified by:
updateRoleDefinition in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Throws:
net.sf.jguard.core.authentication.AuthenticationException

getCredentialId

public java.lang.String getCredentialId()
Specified by:
getCredentialId in interface net.sf.jguard.core.authentication.manager.AuthenticationManager

getOrganizationTemplate

public net.sf.jguard.core.provisioning.OrganizationTemplate getOrganizationTemplate()
Specified by:
getOrganizationTemplate in interface net.sf.jguard.core.authentication.manager.AuthenticationManager
Returns:
a cloned version of the OrganizationTemplate.

isRoleAndLocal

protected boolean isRoleAndLocal(java.security.Principal principal)
return true if the principal is an instance of a class or subclass of RolePrincipal and if its applicationName is equals to the name of the running application.

Parameters:
principal -
Returns:

isRole

protected boolean isRole(java.security.Principal principal)

getCredentialPassword

public java.lang.String getCredentialPassword()
Specified by:
getCredentialPassword in interface net.sf.jguard.core.authentication.manager.AuthenticationManager


Copyright © 2004-2009. All Rights Reserved.