Package edu.vt.middleware.ldap.ed
Class Login
- java.lang.Object
-
- edu.vt.middleware.ldap.ed.Login
-
- All Implemented Interfaces:
EdAuthService,EdOperation
public final class Login extends Object
Provides methods to perform common authentication and authorization operations using the 2FA directory. As per documentation, if noMultiFactoris provided auto configuration will be used.
See documentation.- Author:
- Middleware Services
-
-
Constructor Summary
Constructors Constructor Description Login()Creates a new instance of an ED client object that can perform operations on the production login directory.Login(DirectoryEnv env)Creates a new instance of an ED client object that can perform operations on login 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, MultiFactor secondFactor, String... attributes)Same asEdAuthService.authenticate(String, Credential, String...)with a second factor.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
-
Login
public Login()
Creates a new instance of an ED client object that can perform operations on the production login directory.
-
Login
public Login(DirectoryEnv env)
Creates a new instance of an ED client object that can perform operations on login 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.
-
authenticate
public org.ldaptive.LdapEntry authenticate(String user, org.ldaptive.Credential credential, MultiFactor secondFactor, String... attributes) throws org.ldaptive.LdapException
Same asEdAuthService.authenticate(String, Credential, String...)with a second factor.- Parameters:
user- username for bindcredential- credential for bindsecondFactor- second factor for bind (seeMultiFactor)attributes- attributes to retrieve (ieEdContext.ALL_ATTR,EdContext.AFFILIATION_ATTR, ...)- Returns:
- Found
LdapEntry - Throws:
org.ldaptive.LdapException- if the authentication fails for any reason- See Also:
EdAuthService.authenticate(String, Credential, String...)
-
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
-
-