public interface Account
extends java.util.Map
SecurityProvider.getAccount(java.lang.String, java.lang.String[])
method however with some SecurityProviders, an Account may be constructed directly such as for creating an account in the SecurityProvider authority.
See the API documentation of the concrete SecurityProvider and Account implementations being used.
The names and corresponding values of attributes that constitute the account depend greatly on the Account implementation. For example, an Active Directory based SecurityProvider may have attributes like sAMAccountName mapped to a String value representing the account name or objectSid mapped to a byte[] array containing the binary representation of the account's SID. An SQL based SecurityProvider would probably have attributes based on database table field names like user_login with a String value representing the account name.
The getProperty and setProperty methods should be favored over the get and set methods of the Map interface. The getProperty and setProperty methods may modify and validate data, perform additional work and throw exceptions whereas the get and set methods may not.
HttpSecurityServletRequest.getSecurityProvider()
.
The following example demonstrates how to retrieve Account information from Active Directory using the LdapSecurityProvider from within a JSP. This example assumes that the HttpSecurityService used the NtlmSecurityProvider to authenticate the client as it copies many properties from the NtlmSecurityProvider instance to construct the LdapSecurityProvider.
<%@ page import="jespa.http.HttpSecurityServletRequest" %> <%@ page import="jespa.security.SecurityProvider" %> <%@ page import="jespa.security.Account" %> <%@ page import="jespa.ldap.LdapSecurityProvider" %> <% // Get the NtlmSecurityProvider HttpSecurityServletRequest req = (HttpSecurityServletRequest)request; NtlmSecurityProvider nsp = (NtlmSecurityProvider)req.getSecurityProvider(); // Create an LdapSecurityProvider based on the NtlmSecurityProvider properties // Many of the properties have the same meaning, so we can mostly copy them String[] pnames = new String[] { "dns.servers", "dns.records.path", "dns.cache.ttl", "service.acctname", "service.password", "domain.netbios.name", "domain.dns.name", }; LdapSecurityProvider lsp = new LdapSecurityProvider(nsp, pnames); // However, we want to 1) use the same domain controller against which the client was // authenticated and 2) add the LDAP base under which to search for accounts lsp.setProperty("bindstr", "ldap://" + nsp.getProperty("authority.dns.name") + "/DefaultNamingContext"); // We know the domain controller hostname is correct so we can disable SRV lookups lsp.setProperty("authority.dns.names.resolve", "false"); // Now we can retrieve any information about an account - in this case just the displayName attribute Account acct = lsp.getAccount(nsp.getIdentity(), new String[] { "displayName" }); out.println("displayName: " + acct.get("displayName")); %>
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
ALL_ATTRS
Used as a parameter with some methods to specify "all attributes".
|
Modifier and Type | Method and Description |
---|---|
void |
changePassword(char[] oldpassword,
char[] newpassword)
Change the password for this account in the SecurityProvider authority but only if the supplied old password is correct.
|
void |
create()
Create a new account in the SecurityProvider with all attribute values of this object.
|
void |
create(java.lang.String[] attrs)
Create a new account in the SecurityProvider authority with selected attribute values of this object.
|
void |
delete()
Delete an existing account in the SecurityProvider authority.
|
java.lang.Object |
getProperty(java.lang.String name)
Retrieve an account attribute or property or throw an exception if it has no value.
|
java.lang.Object |
getProperty(java.lang.String name,
java.lang.Object def)
Retrieve an account attribute or property.
|
boolean |
isMemberOf(java.lang.String group)
Return true only if this Account is a member of the named group.
|
void |
setPassword(char[] password)
Set the password for this account to the supplied value in the SecurityProvider authority.
|
void |
setProperty(java.lang.String name,
java.lang.Object obj)
Set an account attribute or property.
|
void |
update()
Update an existing account in the SecurityProvider authority with all attribute values of this object.
|
void |
update(java.lang.String[] attrs)
Update an existing account in the SecurityProvider authority with selected attribute values of this object.
|
static final java.lang.String[] ALL_ATTRS
SecurityProvider.getAccount(java.lang.String, java.lang.String[])
, create(java.lang.String[])
and update(java.lang.String[])
.
See the API documentation for these methods for the SecurityProvider and Account implementation being used.void setProperty(java.lang.String name, java.lang.Object obj) throws SecurityProviderException
name
- the name of the attribute or propertyobj
- the value of the attribute or property to setSecurityProviderException
- if an error occurs setting the attribute or property such as a validation failurejava.lang.Object getProperty(java.lang.String name, java.lang.Object def) throws SecurityProviderException
name
- the name of the attribute or property to be retrieveddef
- the default value to be returned of the named attribute or property has no valueSecurityProviderException
- if an error occurs retrieving the attribute or propertyjava.lang.Object getProperty(java.lang.String name) throws SecurityProviderException
name
- the name of the attribute or property to be retrievedSecurityProviderException
- if the named attribute or property is not mapped to a value or if an error occurs retrieving the valueboolean isMemberOf(java.lang.String group) throws SecurityProviderException
group
- the name of the group to check.SecurityProviderException
- if a catostrophic error occurs trying to check group membershipvoid create(java.lang.String[] attrs) throws SecurityProviderException
For specific implementation details, see the API documentation of the concrete Account class being used.
attrs
- an array of attribute names indicating the attributes of this object with which to create the account.
If this parameter is the special constant Account.ALL_ATTRS, the account will be created with all attributes of this object.
If this parameter is null, the account will be created with an implementation defined set of attributes of this object.
SecurityProviderException
- if an error occurs creating the account.
If an account with the same identity already exists, the implementation should throw a SecurityProviderException with an error code of SecurityProviderException.STATUS_ALREADY_EXISTS.void create() throws SecurityProviderException
create(Account.ALL_ATTRS)
.
See the create(String[])
method for additional details.SecurityProviderException
- if an error occurs creating the account.
If an account with the same identity already exists, the implementation should throw a SecurityProviderException with an error code of SecurityProviderException.STATUS_ALREADY_EXISTS.void update(java.lang.String[] attrs) throws SecurityProviderException
attrs
- a list of attribute names indicating the attributes of this object to be updated.SecurityProviderException
- if an error occurs updating the account.
If the account being updated is not found, the implementation should throw a SecurityProviderException with an error code of SecurityProviderException.STATUS_ACCOUNT_NOT_FOUND.void update() throws SecurityProviderException
update(Account.ALL_ATTRS)
.
See the update(String[])
method for additional details.SecurityProviderException
- if an error occurs updating the account.
If the account being updated is not found, the implementation should throw a SecurityProviderException with an error code of SecurityProviderException.STATUS_ACCOUNT_NOT_FOUND.void delete() throws SecurityProviderException
SecurityProviderException
- if an error occurs deleting the account.
If the account being deleted is not found, the implementation should throw a SecurityProviderException with an error code of SecurityProviderException.STATUS_ACCOUNT_NOT_FOUND.void setPassword(char[] password) throws SecurityProviderException
SecurityProviderException
- if an error occurs setting the account password.
If the account being updated is not found, the implementation should throw a SecurityProviderException with an error code of SecurityProviderException.STATUS_ACCOUNT_NOT_FOUND.void changePassword(char[] oldpassword, char[] newpassword) throws SecurityProviderException
oldpassword
- the current password for this account.newpassword
- the new password to be set on this account.SecurityProviderException
- if an error occurs validating the old or setting the new password for this account.
If the account being updated is not found, the implementation should throw a SecurityProviderException with an error code of SecurityProviderException.STATUS_ACCOUNT_NOT_FOUND.