org.moremotion.security
Class SecurityContext

java.lang.Object
  extended by org.moremotion.security.SecurityContext

public class SecurityContext
extends java.lang.Object

Represents a Security Context that is the gateway for user related security operations. The object of this class is created by the SecurityManager.getSecurityContext(org.moremotion.servlet.MoreMotionRequest, java.lang.String, java.lang.String, java.lang.String) method. The operations that update the security information are reflected to the persistency through the security broker interface that is defined by the SecurityBrokerConfig.

Version:
$Id: SecurityContext.java 72 2008-03-18 14:12:35Z erkan $

Method Summary
 boolean authenticateUser(User user, java.lang.String password)
          Authenticates the given user ubject and the specified password (plain) and returns true if user is found and its password mathes.
 void deleteCheckPoint(java.lang.String checkPointName)
          Deletes an check point.
 void deleteRole(java.lang.String roleName)
          Deletes a role by its name.
 void deleteUser(java.lang.String userName)
          Deletes the given user.
 java.lang.String encryptPassword(java.lang.String password)
          Encryptes the specified plain password.
 int flaTries(java.lang.String userName, long suspendPeriod)
           
 void forcedLogout()
           
 int getActiveUserCount(java.lang.String subDomainName)
          Returns the number of the active users
 java.util.ArrayList getActiveUsers(java.lang.String subDomainName, int from, int amount)
          Returns the specified portion of the active users
 java.lang.String getAdminRoleName()
          Returns the name of the role name of the system administrator.
 CheckPoint getCheckPoint(java.lang.String checkPointName)
          Gets an CheckPoint by its name.
 CheckPoint[] getCheckPoints()
          Lists all check points.
 User getCurrentUser()
          Returns the user object that currently logged-in.
 User getCurrentUser(boolean refresh)
           
 RememberUser getRememberUser()
           
 MoreMotionRequest getRequest()
          Returns the request associated with this context.
 Role getRole(java.lang.String roleName)
          Finds a role by its name.
 Role[] getRoles()
          Lists all roles.
 java.lang.String getRootUserName()
          Returns the name of the root user.
 SecurityBrokerConfig getSecurityBrokerDefinition()
          Returns the security broker definition associated with this context.
 java.lang.String getSecurityDomain()
          Returns the name of the security domain associated with this context.
 SignedUser getSignerUser()
           
 java.lang.String getSubdomain()
          Returns the subdomain associated with this context
 User getUser(java.lang.String username)
          Returns a User object by its username.
 User getUserByEmail(java.lang.String email)
          Returns a User object by its email.
 User[] getUsers()
          Returns a list of all the users.
 User[] getUsers(int from, int amount, MutableInt nou)
          Returns a sublist of the users.
 boolean hasAuthority(User user, java.lang.String checkPoint)
          Returns true if the given user object has the authority for the specified checkpoint.
 void login(User user)
          Logs in the given user.
 void login(User user, boolean multipleLoginAllowed)
          Logs in the given user.
 void logout()
          Logs out the current user
 void logout(java.lang.String userName)
          Logs out the specified user.
 User newUser(java.lang.String name, java.lang.String password, java.lang.String email, java.lang.String fullname, boolean accDsbld)
          Creates a new user in this context.
 void prepareBroker()
           
 int registerFailedLoginAttempt(java.lang.String userName, long suspendPeriod)
           
 void saveCheckPoint(CheckPoint checkPoint)
          Saves a check point.
 void saveRole(Role role)
          Saves a role.
 void saveUser(User user)
          Saves given user.
 User[] searchUsers(java.lang.String searchCriteria, int from, int amount, MutableInt nou)
          Returns a sublist of users that match with search criteria
 void setSubdomain(java.lang.String subdomain)
          Sets the subdomain of this context
 void setVar(java.lang.String name, java.lang.String value)
          Sets a security broker variable.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

prepareBroker

public void prepareBroker()

getRequest

public MoreMotionRequest getRequest()
Returns the request associated with this context.


setSubdomain

public void setSubdomain(java.lang.String subdomain)
Sets the subdomain of this context


getSubdomain

public java.lang.String getSubdomain()
Returns the subdomain associated with this context


getSecurityDomain

public java.lang.String getSecurityDomain()
Returns the name of the security domain associated with this context.


getRememberUser

public RememberUser getRememberUser()

getActiveUsers

public java.util.ArrayList getActiveUsers(java.lang.String subDomainName,
                                          int from,
                                          int amount)
Returns the specified portion of the active users

Parameters:
subDomainName -

getActiveUserCount

public int getActiveUserCount(java.lang.String subDomainName)
Returns the number of the active users


getSecurityBrokerDefinition

public SecurityBrokerConfig getSecurityBrokerDefinition()
Returns the security broker definition associated with this context.


newUser

public User newUser(java.lang.String name,
                    java.lang.String password,
                    java.lang.String email,
                    java.lang.String fullname,
                    boolean accDsbld)
Creates a new user in this context.

Parameters:
name - The user name
password - The plain password
email - The email of the user
fullname - The full name of the user
accDsbld - true to create the new user as disabled
Returns:
The user object created.

authenticateUser

public boolean authenticateUser(User user,
                                java.lang.String password)
Authenticates the given user ubject and the specified password (plain) and returns true if user is found and its password mathes.


hasAuthority

public boolean hasAuthority(User user,
                            java.lang.String checkPoint)
Returns true if the given user object has the authority for the specified checkpoint.


getRootUserName

public java.lang.String getRootUserName()
Returns the name of the root user. Unless otherwise defined the name of the root user is 'sa'.


getAdminRoleName

public java.lang.String getAdminRoleName()
Returns the name of the role name of the system administrator. Unless otherwise defined the name of the system administrator role is 'SYS_ADM'.


getCurrentUser

public User getCurrentUser(boolean refresh)

getCurrentUser

public User getCurrentUser()
Returns the user object that currently logged-in. Returns null if no user is logged-in.


getSignerUser

public SignedUser getSignerUser()

login

public void login(User user)
           throws SecurityDomainException
Logs in the given user.

Parameters:
user - The user object to login
Throws:
SecurityDomainException - if login fails

login

public void login(User user,
                  boolean multipleLoginAllowed)
           throws SecurityDomainException
Logs in the given user.

Parameters:
user - The user object to login
multipleLoginAllowed - If false and is the user is already logged-in it fires MultipleLoginDisallowedException.
Throws:
SecurityDomainException - if login fails
MultipleLoginDisallowedException - if the user is already logged-in.

registerFailedLoginAttempt

public int registerFailedLoginAttempt(java.lang.String userName,
                                      long suspendPeriod)

flaTries

public int flaTries(java.lang.String userName,
                    long suspendPeriod)

logout

public void logout()
Logs out the current user


logout

public void logout(java.lang.String userName)
Logs out the specified user.


forcedLogout

public void forcedLogout()

encryptPassword

public java.lang.String encryptPassword(java.lang.String password)
Encryptes the specified plain password. Encryption is performed by the security broker attacted to the context.


getUser

public User getUser(java.lang.String username)
             throws MissingSecurityEntityException
Returns a User object by its username.

Parameters:
username - User name.
Returns:
User object.
Throws:
MissingSecurityEntityException - If user cannot be found.

getUserByEmail

public User getUserByEmail(java.lang.String email)
                    throws MissingSecurityEntityException
Returns a User object by its email.

Parameters:
email - Email of user.
Returns:
User object.
Throws:
MissingSecurityEntityException - If user cannot be found.

getUsers

public User[] getUsers()
                throws MissingSecurityEntityException
Returns a list of all the users.

Returns:
User objects array.
Throws:
MissingSecurityEntityException

getUsers

public User[] getUsers(int from,
                       int amount,
                       MutableInt nou)
                throws MissingSecurityEntityException
Returns a sublist of the users.

Parameters:
from - the start index.
amount - the number of the users to return.
nou - A return value: Total number of users found
Returns:
User objects array.
Throws:
MissingSecurityEntityException

searchUsers

public User[] searchUsers(java.lang.String searchCriteria,
                          int from,
                          int amount,
                          MutableInt nou)
                   throws MissingSecurityEntityException
Returns a sublist of users that match with search criteria

Parameters:
searchCriteria - the string that contains the search criteria
from - the start index.
amount - the number of the users to return.
nou - A return value: Total number of users found
Returns:
User objects array.
Throws:
MissingSecurityEntityException

saveUser

public void saveUser(User user)
              throws SaveSecurityEntityException
Saves given user. Makes it persistent through the associated security broker.

Parameters:
user - User object
Throws:
SaveSecurityEntityException - If user cannot be saved.

deleteUser

public void deleteUser(java.lang.String userName)
                throws DeleteSecurityEntityException
Deletes the given user.

Parameters:
userName - name of the user
Throws:
DeleteSecurityEntityException - If user cannot be deleted.

getRole

public Role getRole(java.lang.String roleName)
             throws MissingSecurityEntityException
Finds a role by its name.

Parameters:
roleName - Role name.
Returns:
Role object.
Throws:
MissingSecurityEntityException - If role cannot be found.

getRoles

public Role[] getRoles()
Lists all roles.

Returns:
Role objects array.

saveRole

public void saveRole(Role role)
              throws SaveSecurityEntityException
Saves a role.

Parameters:
role - Role object.
Throws:
SaveSecurityEntityException - If role cannot be saved.

deleteRole

public void deleteRole(java.lang.String roleName)
                throws DeleteSecurityEntityException
Deletes a role by its name.

Parameters:
roleName - Role name.
Throws:
DeleteSecurityEntityException - If role cannot be deleted.

getCheckPoints

public CheckPoint[] getCheckPoints()
Lists all check points.

Returns:
CheckPoint ojects array.

getCheckPoint

public CheckPoint getCheckPoint(java.lang.String checkPointName)
                         throws MissingSecurityEntityException
Gets an CheckPoint by its name.

Parameters:
checkPointName - Check point name.
Returns:
CheckPoint object.
Throws:
MissingSecurityEntityException - If check point cannot be found.

saveCheckPoint

public void saveCheckPoint(CheckPoint checkPoint)
                    throws SaveSecurityEntityException
Saves a check point.

Parameters:
checkPoint - CheckPoint object.
Throws:
SaveSecurityEntityException - If check point cannot be saved.

deleteCheckPoint

public void deleteCheckPoint(java.lang.String checkPointName)
                      throws DeleteSecurityEntityException
Deletes an check point.

Parameters:
checkPointName - Check point name.
Throws:
DeleteSecurityEntityException - If check point cannot be deleted.

setVar

public void setVar(java.lang.String name,
                   java.lang.String value)
            throws SaveSecurityEntityException
Sets a security broker variable.

Parameters:
name - variable name.
value - variavle value.
Throws:
SaveSecurityEntityException - If property value cannot be set.


Copyright © 2002-2008 MOR YAZILIM. All Rights Reserved.