Framework Professional Edition Package


com.prosyst.mbs.services.useradmin
Interface SimpleLogin


public interface SimpleLogin

This class provides a helper service for making an easy login and logout operations. The base algorithm for logging in any user is:

  1. Getting the SimpleLogin service from the framework.
  2. Call SimpleLogin.login(...) with the user's name and password for the given user.
  3. Call Authorization.hasRole(...) of the received Authorization object with parameter the name of the group that represents wanted rights for access.
  4. When the work is done, call Authorization.logout() to avoid any farther undesired check for such user.
The service uses a special system property named mbs.useradmin.anonymousConnect which, if set to true will allow anonymous login, if the UserAdmin service is not available.

Author:
Kalin Tsvetkov

Field Summary
static java.lang.String PASSWORD
          This keys stores the password credentials of the user in the authorization properties.
static java.lang.String SHA1_HASH
          This keys stores a SHA1 hash of the password credentials.
static java.lang.String USERNAME
          This keys stores the name of the user in the authorization properties.
 
Method Summary
 Authorization getAuthorization(java.lang.Object context)
          Retrieves the Authorization object that is associated with the specified context.
 Authorization login(java.lang.String username, java.lang.String password)
          This method is similar to calling: SimpleLogin.login(username, SimpleLogin.PASSWORD, password);
 Authorization login(java.lang.String username, java.lang.String algorithm, java.lang.Object credential)
          This method tries to authorize the user defined by it's name, password algorithm and credentials.
 Authorization setAuthorization(java.lang.Object context, Authorization auth)
          This method associates an Authorization with given context.
 

Field Detail

USERNAME

static final java.lang.String USERNAME
This keys stores the name of the user in the authorization properties. You can obtain if using the dictionary returned from Role.getProperties().

See Also:
Constant Field Values

PASSWORD

static final java.lang.String PASSWORD
This keys stores the password credentials of the user in the authorization properties. You can obtain if using the dictionary returned from User.getCredentials().

See Also:
Constant Field Values

SHA1_HASH

static final java.lang.String SHA1_HASH
This keys stores a SHA1 hash of the password credentials. You can obtain if using the dictionary returned from User.getCredentials().

See Also:
Constant Field Values
Method Detail

login

Authorization login(java.lang.String username,
                    java.lang.String password)
                    throws java.lang.Exception
This method is similar to calling: SimpleLogin.login(username, SimpleLogin.PASSWORD, password);

Parameters:
username - the name of the user
password - the plain password string.
Returns:
the Authorization object
Throws:
java.lang.Exception - on error
See Also:
login(String, String, Object)

login

Authorization login(java.lang.String username,
                    java.lang.String algorithm,
                    java.lang.Object credential)
                    throws java.lang.Exception
This method tries to authorize the user defined by it's name, password algorithm and credentials. If the system property mbs.useradmin.anonymousConnect is set true, the implementation should successfully login, even if the UserAdmin service is missing. Please not, that this method will automatically associate the authorization object with the current thread. If you want to associate it with another object, you should use setAuthorization(Object, Authorization). This feature allows you to obtain the currently logged user from the context.

Parameters:
username - the name of the user. If this parameter is given null value or empty string - anonymous login is considered.
algorithm - the name of the algorithm used for logging. See SHA1_HASH and PASSWORD
credential - the credentials - e.g. the password itself. If the algorithm is SHA1_HASH, the value of this argument should be byte[] containing the SHA1 hash. If PASSWORD algorithm is used, this arguments should be the plain password string.
Returns:
the Authorization object or null if UserAdmin service is not available and mbs.useradmin.anonymousConnect is set true.
Throws:
java.lang.Exception - if the authorization has failed because UserAdmin service not available and the property mbs.useradmin.anonymousConnect is not set true, or the user name and the password don't match.
java.lang.NullPointerException - if algorithm or credential parameter is null.
java.lang.IllegalArgumentException - is SHA1_HASH algorithm is used and credential is not byte[] containing valid SHA1 hash.

setAuthorization

Authorization setAuthorization(java.lang.Object context,
                               Authorization auth)
This method associates an Authorization with given context. The context can be any kind of object. The service automatically uses the current thread as context object, to which the Authorization object is automatically associated, when login(String, String, Object) method is called. Associates the authoObject with the given handle or removes it if the authoObject is null.

Parameters:
context - the association context. If it is null, the current thread is used by default.
auth - the Authorization object to associate with the context. If this is null, the association is removed.
Returns:
the previously associated to the context Authorization or null if the context was not associated.
Throws:
java.lang.IllegalArgumentException - if the Authorization object is no longer valid or already logged out.

getAuthorization

Authorization getAuthorization(java.lang.Object context)
Retrieves the Authorization object that is associated with the specified context.

Parameters:
context - the association context. If it is null, the current thread is used by default.
Returns:
the associated to the context Authorization, or null if the context was not associated.

Framework Professional Edition Package


Copyright © 1999-2007 ProSyst Software GmbH. All Rights Reserved