com.esri.adf.security.store
Class DBStore

java.lang.Object
  extended by com.esri.adf.security.store.DBStore
All Implemented Interfaces:
SecurityStore

public class DBStore
extends java.lang.Object
implements SecurityStore

This class implements the SecurityStore interface and provides access methods to a relational database. You can use this class as an underlying implementation for the ArcGISSecurityStore when users or role are maintained in a database as tabular information.


Field Summary
protected  java.sql.Connection dbConnection
           
protected  DBConnectParams dbConnectParams
           
protected  java.util.Map<java.lang.String,java.lang.String> dbParamsMap
           
protected  java.lang.String ROLE_ATTR_DESCRIPTION
           
protected  java.lang.String ROLE_ATTR_ROLENAME
           
protected  java.lang.String ROLE_TABLE
           
protected  java.lang.String USER_ATTR_EMAIL
           
protected  java.lang.String USER_ATTR_FULLNAME
           
protected  java.lang.String USER_ATTR_MD5PASSWORD
           
protected  java.lang.String USER_ATTR_SECRETANSWER
           
protected  java.lang.String USER_ATTR_SECRETQUESTION
           
protected  java.lang.String USER_ATTR_SHAPASSWORD
           
protected  java.lang.String USER_ATTR_USERNAME
           
protected  java.lang.String USER_ROLE_TABLE
           
protected  java.lang.String USER_TABLE
           
 
Constructor Summary
DBStore()
           
 
Method Summary
 void addRole(ArcGISSecurityRole role)
          Add a new role to the security store database.
 void addRolesToUser(java.lang.String username, java.util.List<ArcGISSecurityRole> roleList)
          Assign list of roles to a user.
 void addRolesToUser(java.lang.String username, java.lang.String[] roleList)
          Assign list of roles to a user.
 void addUser(ArcGISSecurityUser user)
          Add a user to the security store database.
 void addUsersToRole(java.lang.String rolename, java.lang.String[] userList)
          Assign a role to a bunch of users.
 void close()
          Close all connections to the security store.
 void createTables(boolean bUsersInDb, boolean bRolesInDb)
          Creates tables within a database that are required by the security store.
protected  void deleteAllRolesFromUser(java.lang.String userName)
          Delete all the roles that have been assigned to a user.
protected  void deleteAllUsersForRole(java.lang.String roleName)
          Delete a particular role from a bunch of users.
 void deleteRole(java.lang.String rolename)
          Delete a role from the security store database.
 void deleteRolesFromUser(java.lang.String username, java.lang.String[] roleList)
          Delete list of roles that are assigned to a user.
 void deleteUser(java.lang.String userName)
          Delete a user from the security store database.
 void deleteUsersFromRole(java.lang.String rolename, java.lang.String[] userList)
          Delete a particular role from a bunch of users.
 java.lang.String forgotUserPassword(java.lang.String userName, java.lang.String secretQuest, java.lang.String secretAns)
          Method that will reset the user password to some random string, by checking the answer provided to the secret question provided by the user when adding user to the security store.
 java.util.List<ArcGISSecurityRole> getAllRoles()
          Return list of roles that are present in the security store.
 java.util.List<ArcGISSecurityUser> getAllUsers()
          Returns a list of ArcGISSecurityUser objects that represent all the users currently in the security store.
 ArcGISSecurityRole getRole(java.lang.String rolename)
          Call this method to get information regarding a particular role in the security store database.
 java.util.List<ArcGISSecurityRole> getRolesForUser(java.lang.String username)
          Return a list of roles that are assigned to a particular user.
 ArcGISSecurityUser getUser(java.lang.String username)
          Call this method to get information regarding a particular user in the security store.
 java.lang.String getUserSecretQuestion(java.lang.String userName)
          Returns the secret question that has been set for a user.
 java.util.List<ArcGISSecurityUser> getUsersForRole(java.lang.String rolename)
          Return list of user who are assigned a particular role.
 void init(java.util.Map<java.lang.String,java.lang.String> paramsMap)
          Initialize the database connection.
 boolean isReadOnly()
          For the current implementation, we can write to a DB so this method will always return false.
 void modifyRole(ArcGISSecurityRole role)
          Modify the information for a role in the security store.
 void modifyUser(ArcGISSecurityUser user)
          Modify the information for a user in the security store.
 void reinitialize()
          Reinitialize the connection to data stores.
 boolean testConnection(java.util.Map<java.lang.String,java.lang.String> paramsMap)
          Test the connection to the data store
 boolean validateUser(java.lang.String username, java.lang.String password)
          Check the user credentials with the information available in the security store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dbConnectParams

protected DBConnectParams dbConnectParams

dbConnection

protected java.sql.Connection dbConnection

dbParamsMap

protected java.util.Map<java.lang.String,java.lang.String> dbParamsMap

USER_TABLE

protected java.lang.String USER_TABLE

ROLE_TABLE

protected java.lang.String ROLE_TABLE

USER_ROLE_TABLE

protected java.lang.String USER_ROLE_TABLE

USER_ATTR_USERNAME

protected java.lang.String USER_ATTR_USERNAME

USER_ATTR_FULLNAME

protected java.lang.String USER_ATTR_FULLNAME

USER_ATTR_MD5PASSWORD

protected java.lang.String USER_ATTR_MD5PASSWORD

USER_ATTR_SHAPASSWORD

protected java.lang.String USER_ATTR_SHAPASSWORD

USER_ATTR_SECRETQUESTION

protected java.lang.String USER_ATTR_SECRETQUESTION

USER_ATTR_SECRETANSWER

protected java.lang.String USER_ATTR_SECRETANSWER

USER_ATTR_EMAIL

protected java.lang.String USER_ATTR_EMAIL

ROLE_ATTR_ROLENAME

protected java.lang.String ROLE_ATTR_ROLENAME

ROLE_ATTR_DESCRIPTION

protected java.lang.String ROLE_ATTR_DESCRIPTION
Constructor Detail

DBStore

public DBStore()
Method Detail

init

public void init(java.util.Map<java.lang.String,java.lang.String> paramsMap)
          throws ArcGISSecurityException
Initialize the database connection.

Specified by:
init in interface SecurityStore
Parameters:
paramsMap - - HashMap generated from a DBConnectParams object. It contains information that the ArcGISSecurityStore uses to connect to an database.
Throws:
ArcGISSecurityException - - if connection to a database cannot be made

reinitialize

public void reinitialize()
                  throws ArcGISSecurityException
Reinitialize the connection to data stores. Sometimes, the connections timeout, there needs to be a hook so that clients can call the object to reinitialize without having to create a new one.

Specified by:
reinitialize in interface SecurityStore
Throws:
ArcGISSecurityException - - if connection cannot be initialized

isReadOnly

public boolean isReadOnly()
For the current implementation, we can write to a DB so this method will always return false.

Specified by:
isReadOnly in interface SecurityStore
Returns:
false

testConnection

public boolean testConnection(java.util.Map<java.lang.String,java.lang.String> paramsMap)
                       throws ArcGISSecurityException
Test the connection to the data store

Specified by:
testConnection in interface SecurityStore
Parameters:
paramsMap - - HashMap generated from a DBConnectParams object. It contains information that the ArcGISSecurityStore uses to connect to an database.
Returns:
true if the method can successfully connect to he security store false otherwise
Throws:
ArcGISSecurityException - - if there is an error while connecting to the security data store

addUser

public void addUser(ArcGISSecurityUser user)
             throws ArcGISSecurityException
Add a user to the security store database.

Specified by:
addUser in interface SecurityStore
Parameters:
user - - reference to ArcGISSecurityUser object that contains user information.
Throws:
ArcGISSecurityException - - if user cannot be added

deleteUser

public void deleteUser(java.lang.String userName)
                throws ArcGISSecurityException
Delete a user from the security store database.

Specified by:
deleteUser in interface SecurityStore
Parameters:
userName - - String identifier that uniquely identifies a user.
Throws:
ArcGISSecurityException - - if the user cannot be deleted from the store.

modifyUser

public void modifyUser(ArcGISSecurityUser user)
                throws ArcGISSecurityException
Modify the information for a user in the security store. When modifying user information, a particular user is identified by its userName. You cannot modify the userName for this user. Only those properties on the user object will be modified which are not null.

Specified by:
modifyUser in interface SecurityStore
Parameters:
user - - reference to ArcGISSecurityUser object thats contains modified user information.
Throws:
ArcGISSecurityException

getUserSecretQuestion

public java.lang.String getUserSecretQuestion(java.lang.String userName)
                                       throws ArcGISSecurityException
Returns the secret question that has been set for a user.

Specified by:
getUserSecretQuestion in interface SecurityStore
Parameters:
userName - - String represnting the unique identifier for a user.
Returns:
String representing the secret question for a user
Throws:
ArcGISSecurityException - - if input parameter is null or cannot access security store

forgotUserPassword

public java.lang.String forgotUserPassword(java.lang.String userName,
                                           java.lang.String secretQuest,
                                           java.lang.String secretAns)
                                    throws ArcGISSecurityException
Method that will reset the user password to some random string, by checking the answer provided to the secret question provided by the user when adding user to the security store.

Specified by:
forgotUserPassword in interface SecurityStore
Parameters:
userName - - String represnting the unique identifier for a user.
secretQuest - - String represnting secret question set for a user
secretAns - - String represnting the answer to the secret question
Returns:
String representing the new password that has been set for the user.
Throws:
ArcGISSecurityException - - if the password cannot be reset

getAllUsers

public java.util.List<ArcGISSecurityUser> getAllUsers()
                                               throws ArcGISSecurityException
Returns a list of ArcGISSecurityUser objects that represent all the users currently in the security store.

Specified by:
getAllUsers in interface SecurityStore
Returns:
list of ArcGISSecurityUser objects
Throws:
ArcGISSecurityException - - if users cannot be retrieved from the security store

addRole

public void addRole(ArcGISSecurityRole role)
             throws ArcGISSecurityException
Add a new role to the security store database.

Specified by:
addRole in interface SecurityStore
Parameters:
role - - reference to ArcGISSecurityRole object that contains role information
Throws:
ArcGISSecurityException - - if role cannot be added to the security store

deleteRole

public void deleteRole(java.lang.String rolename)
                throws ArcGISSecurityException
Delete a role from the security store database.

Specified by:
deleteRole in interface SecurityStore
Parameters:
roleName - - name of the role to be deleted
Throws:
ArcGISSecurityException - - if the role cannot be deleted from the security store

modifyRole

public void modifyRole(ArcGISSecurityRole role)
                throws ArcGISSecurityException
Modify the information for a role in the security store. When modifying role information, a particular role is identified by its roleName. You cannot modify the roleName for this role.

Specified by:
modifyRole in interface SecurityStore
Parameters:
role - - reference to the ArcGISSecurityRole object that contains the modified role information.
Throws:
ArcGISSecurityException - - if role information cannot be modified.

getAllRoles

public java.util.List<ArcGISSecurityRole> getAllRoles()
                                               throws ArcGISSecurityException
Return list of roles that are present in the security store.

Specified by:
getAllRoles in interface SecurityStore
Returns:
list of ArcGISSecurityRole objects each representing a single role
Throws:
ArcGISSecurityException - - if a role cannot be retrieved from the security store

getUser

public ArcGISSecurityUser getUser(java.lang.String username)
                           throws ArcGISSecurityException
Call this method to get information regarding a particular user in the security store.

Specified by:
getUser in interface SecurityStore
Parameters:
userName - - unique name of the user for whom to retrieve information.
Returns:
ArcGISSecurityUser object that represents the user in security store.
Throws:
ArcGISSecurityException - - if user information cannot be retrieved from the security store.

getRole

public ArcGISSecurityRole getRole(java.lang.String rolename)
                           throws ArcGISSecurityException
Call this method to get information regarding a particular role in the security store database.

Specified by:
getRole in interface SecurityStore
Parameters:
roleName - - unique name of the role for whom to retrieve information.
Returns:
ArcGISSecurityRole object that represents the role in the security store.
Throws:
ArcGISSecurityException - - if role information cannot be retrieved from the security store

addRolesToUser

public void addRolesToUser(java.lang.String username,
                           java.util.List<ArcGISSecurityRole> roleList)
                    throws ArcGISSecurityException
Assign list of roles to a user.

Parameters:
userName - - unique name of user to whom the roles are to be assigned
roleList - - list of role objects that are to be assigned to the user
Throws:
ArcGISSecurityException - - if users cannot be assigned to roles

addRolesToUser

public void addRolesToUser(java.lang.String username,
                           java.lang.String[] roleList)
                    throws ArcGISSecurityException
Assign list of roles to a user.

Specified by:
addRolesToUser in interface SecurityStore
Parameters:
userName - - unique name of user to whom the roles are to be assigned
roleList - - Array of strings containing the name of the roles that are to be assigned to the user.
Throws:
ArcGISSecurityException - - if users cannot be assigned to roles

deleteAllUsersForRole

protected void deleteAllUsersForRole(java.lang.String roleName)
                              throws ArcGISSecurityException
Delete a particular role from a bunch of users.

Parameters:
roleName - - name of the role that will be deleted from all users.
Throws:
ArcGISSecurityException - - if the particular role cannot be deleted from the list of users.

deleteAllRolesFromUser

protected void deleteAllRolesFromUser(java.lang.String userName)
                               throws ArcGISSecurityException
Delete all the roles that have been assigned to a user.

Parameters:
userName - - name of the user whose all roles will be delted
Throws:
ArcGISSecurityException - - if roles assigned to the user cannot be deleted

addUsersToRole

public void addUsersToRole(java.lang.String rolename,
                           java.lang.String[] userList)
                    throws ArcGISSecurityException
Assign a role to a bunch of users.

Specified by:
addUsersToRole in interface SecurityStore
Parameters:
roleName - - String representing the particular role that is to be assigned.
userList - - Array of strings containing the name of the user to whom this role is to be assigned
Throws:
ArcGISSecurityException - - if this role cannot be assigned to the users.

deleteRolesFromUser

public void deleteRolesFromUser(java.lang.String username,
                                java.lang.String[] roleList)
                         throws ArcGISSecurityException
Delete list of roles that are assigned to a user.

Specified by:
deleteRolesFromUser in interface SecurityStore
Parameters:
userName - - name of the user from whom the roles are to be deleted
roleList - - array of strings containing name of the roles that are to be deleted from this user.
Throws:
ArcGISSecurityException - - if the user or any role in the list does not exist in the security store.

deleteUsersFromRole

public void deleteUsersFromRole(java.lang.String rolename,
                                java.lang.String[] userList)
                         throws ArcGISSecurityException
Delete a particular role from a bunch of users.

Specified by:
deleteUsersFromRole in interface SecurityStore
Parameters:
roleName - - String representing the particular role thats is to be deleted.
userList - - Array of strings containing the name of the users from whom this role is to be deleted.
Throws:
ArcGISSecurityException - - if the role cannot be deleted from the list of users

getRolesForUser

public java.util.List<ArcGISSecurityRole> getRolesForUser(java.lang.String username)
                                                   throws ArcGISSecurityException
Return a list of roles that are assigned to a particular user.

Specified by:
getRolesForUser in interface SecurityStore
Parameters:
userName - - String representing the user whose roles are to be returned.
Returns:
List of ArcGISSecurityRole objects that are assigned to this user.
Throws:
ArcGISSecurityException - - if role list cannot be retrieved

getUsersForRole

public java.util.List<ArcGISSecurityUser> getUsersForRole(java.lang.String rolename)
                                                   throws ArcGISSecurityException
Return list of user who are assigned a particular role.

Specified by:
getUsersForRole in interface SecurityStore
Parameters:
roleName - - String representing the role that is assigned to the users.
Returns:
List of ArcGISSecurityUser objects that are assigned this particular role.
Throws:
ArcGISSecurityException - - if user list cannot be retrieved.

validateUser

public boolean validateUser(java.lang.String username,
                            java.lang.String password)
                     throws ArcGISSecurityException
Check the user credentials with the information available in the security store.

Specified by:
validateUser in interface SecurityStore
Parameters:
userName - - String representing a particular user
userPassword - - String representing the user's password
Returns:
true if the user credentials match with the ones in the security store.
Throws:
ArcGISSecurityException - - if user information cannot be retrieved.

close

public void close()
Close all connections to the security store.

Specified by:
close in interface SecurityStore

createTables

public void createTables(boolean bUsersInDb,
                         boolean bRolesInDb)
                  throws ArcGISSecurityException
Creates tables within a database that are required by the security store. If tables are already existing within a database in the same schema that is required by the security store, then new tables will not be created.

Throws:
ArcGISSecurityException - - if tables and keys cannot be created in the security store