public class ChainSecurityProvider extends SecurityProvider
The ChainSecurityProvider is most commonly used with the HttpSecurityService
to authenticate web clients against multiple independent security authorities.
A chain is defined entirely using properties. The chain.names property defines the list of chain element names. For each chain element name, the property chain.<name>.provider.classname indicates to ChainSecurityProvider the name of the SecurityProvider class to construct for that chain element. For all other properties that begin with chain.<name>., that prefix is removed and the property is inserted into the Map used to construct the SecurityProvider for that chain element. Consider the following list of properties:
chain.names = BUSICORP,OPENBOOK chain.BUSICORP.provider.classname = jespa.ntlm.NtlmSecurityProvider chain.BUSICORP.bindstr = busicorp.local chain.BUSICORP.service.acctname = jespa1$@busicorp.local chain.BUSICORP.service.password = opensaysme44 chain.BUSICORP.account.canonicalForm = 3 chain.OPENBOOK.provider.classname = jespa.ldap.LdapSecurityProvider chain.OPENBOOK.ldap.disposition = RFC chain.OPENBOOK.domain.netbios.name = OPENBOOK chain.OPENBOOK.domain.dns.name = openbook.edu chain.OPENBOOK.bindstr = ldap://192.168.2.119/OU=Engineering,DC=openbook,DC=edu chain.OPENBOOK.service.acctname = CN=jespa1,DC=openbook,DC=edu chain.OPENBOOK.service.password = moonbike55 chain.OPENBOOK.account.canonicalForm = 3
The above example shows two SecurityProviders in a chain called BUSICORP and OPENBOOK.
The BUSICORP chain uses the NtlmSecurityProvider whereas the OPENBOOK chain uses the LdapSecurityProvider configured for an RFC-based LDAP server like OpenLDAP.
identity, isComplete
Constructor and Description |
---|
ChainSecurityProvider(java.util.Map properties) |
Modifier and Type | Method and Description |
---|---|
byte[] |
acceptSecContext(byte[] token,
int off,
int len)
Call acceptSecContext on each SecurityProvider in the chain until the supplied token is successfully processed.
|
void |
authenticate(java.lang.Object credential)
Call authenticate on each SecurityProvider in the chain until the supplied credentials are successfully authenticated.
|
void |
dispose()
Dispose the currently selected SecurityProvider in the chain if any.
|
protected void |
encodeObject(ByteBuffer bb,
java.lang.Object obj)
Serialize this ChainSecurityProvider and underlying currently selected SecurityProvider into the supplied buffer.
|
java.lang.Object |
exportState()
Return a byte[] array representing the complete state of the currently selected SecurityProvider so that it can be reconstituted later (by possibly another thread) with the
importState(java.lang.Object) method. |
Account |
getAccount(java.lang.String acctname,
java.lang.String[] attrs)
Call getAccount on the currently selected SecurityProvider in the chain.
|
Domain |
getDomain(java.lang.String dname,
java.lang.String[] attrs)
Call getDomain on the currently selected SecurityProvider in the chain.
|
boolean |
getFlag(java.lang.String name)
Call getFlag on the currently selected SecurityProvider in the chain.
|
java.lang.String |
getIdentity()
Call getIdentity on the currently selected SecurityProvider in the chain.
|
java.lang.String |
getName()
Call getName on the currently selected SecurityProvider in the chain.
|
java.lang.Object |
getProperty(java.lang.String name,
java.lang.Object def)
Call getProperty on the currently selected SecurityProvider in the chain (unless the property is specific to the ChainSecurityProvider).
|
SecurityProvider |
getSecurityProvider()
Return the currently selected SecurityProvider.
|
void |
importState(java.lang.Object ostate)
Initialize and set as the currrently selected SecurityProvider to the SecurityProvider deserialized from the state Object returned by a previous call to
exportState() . |
boolean |
isComplete()
Call isComplete on the currently selected SecurityProvider in the chain.
|
void |
setFlag(java.lang.String name,
boolean value)
Call getFlag on the currently selected SecurityProvider in the chain.
|
void |
setProperty(java.lang.String name,
java.lang.Object obj)
Set a property such as a SecurityProvider specific option.
|
initSecContext, unwrap, wrap
decodeObject, getEncryptedProperty, getFilteredProperties, getFilteredProperties, getProperty, getPropertyAsBoolean, getPropertyAsLong, setEncryptedProperty
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
public void setProperty(java.lang.String name, java.lang.Object obj) throws SecurityProviderException
SecurityProvider
setProperty
in class SecurityProvider
name
- the name of the property to set.obj
- the value of the property to set (which may be null).SecurityProviderException
- if the property or it's value are invalid
or cannot be set.public java.lang.Object getProperty(java.lang.String name, java.lang.Object def) throws SecurityProviderException
For details, see the API documentation for the corresponding methods of the concrete SecurityProvider classes configured for this chain.
getProperty
in class SecurityProvider
name
- the name of the property to retrieve.def
- the default value to return of the named property is not set.SecurityProviderException
- if the name is invalid or it's value cannot
be retrieved.protected void encodeObject(ByteBuffer bb, java.lang.Object obj) throws EncodingException
encodeObject
in class jespa.security.Properties
EncodingException
public java.lang.Object exportState() throws SecurityProviderException
importState(java.lang.Object)
method.
This method allows multi-step authentication to occur with stateless protocols such as HTTP.
For example, the HttpSecurityService
uses this method to store authentication state or state about the authenticated principal into the HTTP session.exportState
in class SecurityProvider
SecurityProviderException
- if the state could not or cannot be
exported.public void importState(java.lang.Object ostate) throws SecurityProviderException
exportState()
.
This method allows multi-step authentication to occur with stateless protocols such as HTTP.
For example, the HttpSecurityService
uses this method to reconstitute authentication state and state about the authenticated principal from HTTP session data.importState
in class SecurityProvider
ostate
- an Object (or byte[] array) that represets the state
to be imported.SecurityProviderException
- if the state could not be imported such as
because the state being imported has been transferred beyond it's acceptable
boundries.public SecurityProvider getSecurityProvider() throws SecurityProviderException
For details, see the API documentation for the corresponding methods of the concrete SecurityProvider classes configured for this chain.
SecurityProviderException
public java.lang.String getName() throws SecurityProviderException
For details, see the API documentation for the corresponding methods of the concrete SecurityProvider classes configured for this chain.
getName
in class SecurityProvider
SecurityProviderException
public boolean getFlag(java.lang.String name) throws SecurityProviderException
For details, see the API documentation for the corresponding methods of the concrete SecurityProvider classes configured for this chain.
getFlag
in class SecurityProvider
name
- the name of the flag value to retrieve.SecurityProviderException
public void setFlag(java.lang.String name, boolean value) throws SecurityProviderException
For details, see the API documentation for the corresponding methods of the concrete SecurityProvider classes configured for this chain.
setFlag
in class SecurityProvider
name
- the name of the flag to set.value
- the new value of the flag.SecurityProviderException
public Domain getDomain(java.lang.String dname, java.lang.String[] attrs) throws SecurityProviderException
For details, see the API documentation for the corresponding methods of the concrete SecurityProvider classes configured for this chain.
getDomain
in class SecurityProvider
dname
- the name of the domain to retrieveattrs
- the list of attribute names to populate in the Domain object returnedSecurityProviderException
- if the named domain could not be found or if a catostrophic error occurs.public Account getAccount(java.lang.String acctname, java.lang.String[] attrs) throws SecurityProviderException
For details, see the API documentation for the corresponding methods of the concrete SecurityProvider classes configured for this chain.
getAccount
in class SecurityProvider
acctname
- the name of the account to retrieve or null to indicate that a default account should be retrievedattrs
- the names of the account attributes to retrieve or null to indicate that a default set of attriubutes should be retrieved or the special constant Account.ALL_ATTRS to indicate that "all attributes" should be retrieved.SecurityProviderException
- if the named account could not be found or if a catostrophic error occurs.public java.lang.String getIdentity() throws SecurityProviderException
For details, see the API documentation for the corresponding methods of the concrete SecurityProvider classes configured for this chain.
getIdentity
in class SecurityProvider
SecurityProviderException
- if an error occurs trying to retrieve
the identity value.public boolean isComplete()
For details, see the API documentation for the corresponding methods of the concrete SecurityProvider classes configured for this chain.
isComplete
in class SecurityProvider
public byte[] acceptSecContext(byte[] token, int off, int len) throws SecurityProviderException
For details, see the API documentation for the corresponding methods of the concrete SecurityProvider classes configured for this chain.
acceptSecContext
in class SecurityProvider
token
- the buffer containing the authentication token supplied by
the other peer.off
- the offset within token to the relevant data.len
- the length of the token within token at offset off.SecurityProviderException
- if a catostrophic error occured in processing. Note
that unlike initSecContext, this method should not throw an exception
to indicate that authentication has failed. Most errors will be encoded into a
final token so as to communicate the failure to the initiator.public void authenticate(java.lang.Object credential) throws SecurityProviderException
For details, see the API documentation for the corresponding methods of the concrete SecurityProvider classes configured for this chain.
authenticate
in class SecurityProvider
credential
- a credential to be validated. Providers should support the generic
PasswordCredential
class.SecurityProviderException
- if the validation fails. The exception code should be
SecurityProviderException.STATUS_ACCOUNT_NOT_FOUND
if the credential identity was not found by the provider authority or
SecurityProviderException.STATUS_INVALID_CREDENTIALS
if the credential was cryptographically incorrect.
If the authority only indicated that the authentication failed in general and does not
distinguish between the two cases, STATUS_INVALID_CREDENTIALS should be
favored.public void dispose() throws SecurityProviderException
For details, see the API documentation for the corresponding methods of the concrete SecurityProvider classes configured for this chain.
dispose
in class SecurityProvider
SecurityProviderException