Package edu.vt.middleware.ldap.ed
Class EdAuth
- java.lang.Object
-
- edu.vt.middleware.ldap.ed.EdAuth
-
- All Implemented Interfaces:
EdAuthService,EdOperation
public final class EdAuth extends Object
EdAuth provides methods to perform common authentication and authorization operations.- Author:
- Middleware Services
-
-
Constructor Summary
Constructors Constructor Description EdAuth()Creates a new instance of an ED client object that can perform operations on the production ED-Auth directory.EdAuth(DirectoryEnv env)Creates a new instance of an ED client object that can perform operations on an ED-Auth directory of the given environment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.ldaptive.LdapEntryauthenticate(String user, org.ldaptive.Credential credential, String... attributes)This will attempt to authenticate a user against ED-Auth.voidauthorize(org.ldaptive.LdapEntry entry, String authorizationExpression)This will attempt to authorize a user's givenLdapEntryvia the provided authorizationExpression.String[]getAffiliations(org.ldaptive.LdapEntry result)This returns all the affiliations for the supplied entry.org.ldaptive.ConnectionFactorygetConnectionFactory()Gets the underlying connection factory.DirectoryEnvgetEnvironment()Gets the environment this client operates on.String[]getGroupMembership(org.ldaptive.LdapEntry result)This returns all the group memberships for the supplied entry.DirectoryTypegetType()Gets the class of directory this client operates on.VirginiaTechPersongetVirginiaTechPerson(org.ldaptive.LdapEntry result)This will attempt to mapLdapEntryto aVirginiaTechPersonbean.protected voidinitialize()Initialize the EdAuth client for use.protected voidsetEnvironment(DirectoryEnv dirEnv)Sets the directory environment this ED client is configured to operate on.
-
-
-
Constructor Detail
-
EdAuth
public EdAuth()
Creates a new instance of an ED client object that can perform operations on the production ED-Auth directory.
-
EdAuth
public EdAuth(DirectoryEnv env)
Creates a new instance of an ED client object that can perform operations on an ED-Auth directory of the given environment.- Parameters:
env- Directory environment, e.g. LOCAL|DEV|PPRD|PROD.
-
-
Method Detail
-
getType
public DirectoryType getType()
Description copied from interface:EdOperationGets the class of directory this client operates on.- Returns:
- Directory type.
-
getEnvironment
public final DirectoryEnv getEnvironment()
Description copied from interface:EdOperationGets the environment this client operates on.- Specified by:
getEnvironmentin interfaceEdOperation- Returns:
- Directory environment.
-
getConnectionFactory
public org.ldaptive.ConnectionFactory getConnectionFactory()
Description copied from interface:EdOperationGets the underlying connection factory.- Specified by:
getConnectionFactoryin interfaceEdOperation- Returns:
- Connection factory implementation.
-
setEnvironment
protected void setEnvironment(DirectoryEnv dirEnv)
Sets the directory environment this ED client is configured to operate on.- Parameters:
dirEnv- Directory environment.
-
initialize
protected final void initialize()
Initialize the EdAuth client for use.This method must be called after the environment (
setEnvironment(DirectoryEnv)) is set and before any LDAP operations are performed. If the directory type and/or environment are changed, the search client must be re-initialized for the changes to take effect on the next LDAP operation.
-
authenticate
public final org.ldaptive.LdapEntry authenticate(String user, org.ldaptive.Credential credential, String... attributes) throws org.ldaptive.LdapException
Description copied from interface:EdAuthServiceThis will attempt to authenticate a user against ED-Auth. User should correspond to uupid. Once this method has been called the connection to the LDAP is closed.- Specified by:
authenticatein interfaceEdAuthService- Parameters:
user- username for bindcredential- credential for bindattributes- attributes to retrieve (ieEdContext.ALL_ATTR,EdContext.AFFILIATION_ATTR, ...)- Returns:
- Found
LdapEntry - Throws:
org.ldaptive.LdapException- if the authentication fails for any reason
-
authorize
public final void authorize(org.ldaptive.LdapEntry entry, String authorizationExpression) throws org.ldaptive.LdapException, EdAuthAuthorizationExceptionThis will attempt to authorize a user's givenLdapEntryvia the provided authorizationExpression. This method implements authorizationExpression viaSpelExpressionParser. Available methods are authorizationExpressions are:
hasAttributeValue(String attribute, String value) and hasAttribute(String attribute). If the entire expression evaluates to false authorization will fail with EdAuthAuthorizationException. The following is an example authorization expression: (hasAttributeValue('eduPersonAffiliation', 'VT-ACTIVE-MEMBER') && hasAttributeValue('eduPersonAffiliation', 'VT-EMPLOYEE')) || hasAttribute('eduPersonPrimaryAffiliation' )- Specified by:
authorizein interfaceEdAuthService- Parameters:
entry-LdapEntryreturned from authentication to authorize withauthorizationExpression- Expression to authorize with- Throws:
org.ldaptive.LdapException- if the authentication fails for any reasonEdAuthAuthorizationException- if the authorization fails for any reason
-
getVirginiaTechPerson
public final VirginiaTechPerson getVirginiaTechPerson(org.ldaptive.LdapEntry result)
Description copied from interface:EdAuthServiceThis will attempt to mapLdapEntryto aVirginiaTechPersonbean.- Specified by:
getVirginiaTechPersonin interfaceEdAuthService- Parameters:
result-LdapEntryreturned from authentication to parse- Returns:
VirginiaTechPersonPOJO representation of theLdapEntry.
-
getAffiliations
public final String[] getAffiliations(org.ldaptive.LdapEntry result)
Description copied from interface:EdAuthServiceThis returns all the affiliations for the supplied entry.- Specified by:
getAffiliationsin interfaceEdAuthService- Parameters:
result-LdapEntryto parse- Returns:
- user's affiliations
-
getGroupMembership
public final String[] getGroupMembership(org.ldaptive.LdapEntry result)
Description copied from interface:EdAuthServiceThis returns all the group memberships for the supplied entry.- Specified by:
getGroupMembershipin interfaceEdAuthService- Parameters:
result-LdapEntryto parse- Returns:
- user's group memberships
-
-