com.lightdev.app.trec.server.sam
Class JDBCStoreAdministrator

java.lang.Object
  extended by com.lightdev.app.trec.server.sam.JDBCStoreAdministrator
All Implemented Interfaces:
UserDataStoreAdministrator

public class JDBCStoreAdministrator
extends Object
implements UserDataStoreAdministrator

An implementation of interface UserDataStoreAdministrator for use with databases through JDBC.

Version:
2, 25.12.2005
Author:
Ulrich Hilger, Light Development, http://www.lightdev.com, info@lightdev.com, published under the terms and conditions of the BSD License, for details see file license.txt in the distribution package of this software

Constructor Summary
JDBCStoreAdministrator(JDBCAdapter adapter)
          create a new instance of a JDBCStoreAdministrator object
 
Method Summary
 boolean backupSAM(String backupDirectory)
          Create a backup of the SAM data store to file to a given backup directory.
 void changeRole(Role role)
          change an existing role
 void changeUser(User user)
          change a user in the UserDataStore this adapter maps to
 void createRole(Role role)
          create a new role
 void createUser(User user, String pw)
          create a user in the UserDataStore this adapter maps to
 void deleteRole(Role role)
          delete an existing role
 void deleteUser(User user)
          delete a user from the UserDataStore this adapter maps to
 JDBCAdapter getAdapter()
          get the JDBCAdapter of this data store
 Vector getAvailableBackups()
          get the names of all SAM backups currently available on the server
 Role getRoleForId(String roleId)
          get the role with the given id
 Role[] getRolesForName(String namePart)
          get all roles whose name contains a given string
 Role[] getRolesForUser(User user)
          get the roles that are granted to a given user
 User[] getUsersForName(String namePart)
          get all users whose last name contains a given string
 User[] getUsersForRole(Role role)
          get the users that are granted a given role
 void grantRole(String userId, String roleId)
          grant the given user a given role
 void newPw(String userId, String newPw)
          set a given password for a given user
 boolean restoreSAM(String backupDirectory)
          Restore the SAM data store from a given directory.
 void revokeRole(String roleId)
          revoke a given role from all users
 void revokeRole(String userId, String roleId)
          revoke a given role from a given user
 void revokeRoles(String userId)
          revoke all roles of a user with a given user id
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCStoreAdministrator

public JDBCStoreAdministrator(JDBCAdapter adapter)
create a new instance of a JDBCStoreAdministrator object

Parameters:
adapter - the database adapter to use
Method Detail

backupSAM

public boolean backupSAM(String backupDirectory)
                  throws Exception

Create a backup of the SAM data store to file to a given backup directory.

This method is not part of interface UserDataStoreAdministrator as the interface does not necessarily require a database as the data store. It is implemented here individually for the Light Development implementation of a SAM database in Derby. I.e., other implementations of a JDBCStoreAdministrator will need to override this method or otherwise re-implement a backup strategy.

Parameters:
backupDirectory - directory to backup to
Returns:
true, when ooperation was successful, otherwise an Exception will be thrown
Throws:
Exception

restoreSAM

public boolean restoreSAM(String backupDirectory)
                   throws Exception

Restore the SAM data store from a given directory.

As the SAM user data store not necessarily needs to be a database, this method is implemented only for the case that the standard Light Development implementation of a JDBCStoreAdministrator using an EmbeddedDerbyAdapter is running.

Parameters:
backupDirectory - the directory to restore from; the EmbeddedDerbyAdapter automatically restores from the base directory it was constructed with and looks for the backup to restore inside a subdirectory named as the given backupDirectory
Returns:
true when restore operation was successful, false, when restore did not commence because of an adapter other than EmbeddedDerbyAdapter is used or an Exception is thrown, when something else goes wrong
Throws:
Exception

getAvailableBackups

public Vector getAvailableBackups()
get the names of all SAM backups currently available on the server

Returns:
the backup names
Throws:
Exception

getRoleForId

public Role getRoleForId(String roleId)
                  throws Exception
get the role with the given id

Specified by:
getRoleForId in interface UserDataStoreAdministrator
Parameters:
roleId - the id to get the role for
Returns:
the role object with the given id or null if none was found
Throws:
Exception

getUsersForRole

public User[] getUsersForRole(Role role)
                       throws Exception
get the users that are granted a given role

Specified by:
getUsersForRole in interface UserDataStoreAdministrator
Parameters:
role - the role to get the users for
Returns:
an array of User objects having the given role
Throws:
Exception

getRolesForUser

public Role[] getRolesForUser(User user)
                       throws Exception
get the roles that are granted to a given user

Specified by:
getRolesForUser in interface UserDataStoreAdministrator
Parameters:
user - the user to get roles for
Returns:
an array of role objects granted to that user
Throws:
Exception

getUsersForName

public User[] getUsersForName(String namePart)
                       throws Exception
get all users whose last name contains a given string

Specified by:
getUsersForName in interface UserDataStoreAdministrator
Parameters:
namePart - the name part to contain
Returns:
an array of User objects having the given string in their last name
Throws:
Exception

getRolesForName

public Role[] getRolesForName(String namePart)
                       throws Exception
get all roles whose name contains a given string

Specified by:
getRolesForName in interface UserDataStoreAdministrator
Parameters:
namePart - the name part to contain
Returns:
an array of Role objects having the given string in their name
Throws:
Exception

createUser

public void createUser(User user,
                       String pw)
                throws Exception
create a user in the UserDataStore this adapter maps to

Specified by:
createUser in interface UserDataStoreAdministrator
Parameters:
user - the user to create
pw - the password of the user
Throws:
Exception - if something went wrong during user creation

changeUser

public void changeUser(User user)
                throws Exception
change a user in the UserDataStore this adapter maps to

Specified by:
changeUser in interface UserDataStoreAdministrator
Parameters:
user - the user to change
Throws:
Exception - if something went wrong

deleteUser

public void deleteUser(User user)
                throws Exception
delete a user from the UserDataStore this adapter maps to

Specified by:
deleteUser in interface UserDataStoreAdministrator
Parameters:
user - the user to delete
Throws:
Exception - if something went wrong

newPw

public void newPw(String userId,
                  String newPw)
           throws Exception
set a given password for a given user

Specified by:
newPw in interface UserDataStoreAdministrator
Parameters:
userId - id of the user to set the password for
newPw - password to set for the given user
Throws:
Exception - if something went wrong during password change

grantRole

public void grantRole(String userId,
                      String roleId)
               throws Exception
grant the given user a given role

Specified by:
grantRole in interface UserDataStoreAdministrator
Parameters:
userId - id of the user to grant a role
roleId - id of role to grant to given user
Throws:
Exception - if something went wrong

revokeRole

public void revokeRole(String userId,
                       String roleId)
                throws Exception
revoke a given role from a given user

Specified by:
revokeRole in interface UserDataStoreAdministrator
Parameters:
userId - id of user to revoke a role from
roleId - id of role to revoke from given user
Throws:
Exception - if something went wrong

revokeRole

public void revokeRole(String roleId)
                throws Exception
revoke a given role from all users

Specified by:
revokeRole in interface UserDataStoreAdministrator
Parameters:
roleId - id of role to revoke
Throws:
Exception - if something went wrong

revokeRoles

public void revokeRoles(String userId)
                 throws Exception
revoke all roles of a user with a given user id

Specified by:
revokeRoles in interface UserDataStoreAdministrator
Parameters:
userId - id of the user to revoke all roles of
Throws:
Exception - ifsomething went wrong

createRole

public void createRole(Role role)
                throws Exception
create a new role

Specified by:
createRole in interface UserDataStoreAdministrator
Parameters:
role - the role to create
Throws:
Exception - if something went wrong

changeRole

public void changeRole(Role role)
                throws Exception
change an existing role

Specified by:
changeRole in interface UserDataStoreAdministrator
Parameters:
role - the changes to apply
Throws:
Exception - if something went wrong

deleteRole

public void deleteRole(Role role)
                throws Exception
delete an existing role

Specified by:
deleteRole in interface UserDataStoreAdministrator
Parameters:
role - the role to delete
Throws:
Exception - if something went wrong

getAdapter

public JDBCAdapter getAdapter()
get the JDBCAdapter of this data store

Returns:
the adapter