org.apache.turbine.services.security
Class TurbineSecurity

java.lang.Object
  |
  +--org.apache.turbine.services.security.TurbineSecurity

public abstract class TurbineSecurity
extends java.lang.Object

This is a Facade class for SecurityService. This class provides static methods that call related methods of the implementation of SecurityService used by the System, according to the settings in TurbineResources.

Certain Roles that the Users may have in the system may are not related to any specific resource nor entity. They are assigned within a special group named 'global' that can be referenced in the code as Group.GLOBAL_GROUP_NAME.

Version:
$Id$
Author:
Rafal Krzewski

Constructor Summary
TurbineSecurity()
           
 
Method Summary
static boolean accountExists(java.lang.String username)
          Check whether a specified user's account exists.
static boolean accountExists(User user)
          Check whether a specified user's account exists.
static void addGroup(Group group)
          Creates a new group with specified attributes.
static void addPermission(Permission permission)
          Creates a new permission with specified attributes.
static void addRole(Role role)
          Creates a new role with specified attributes.
static void addUser(User user, java.lang.String password)
          Creates new user account with specified attributes.
static void changePassword(User user, java.lang.String oldPassword, java.lang.String newPassword)
          Change the password for an User.
static Group createGroup(java.lang.String name)
          Creates a new Group in the system.
static Permission createPermission(java.lang.String name)
          Creates a new Permission in the system.
static java.lang.String encryptPassword(java.lang.String password)
           
static void forcePassword(User user, java.lang.String password)
          Forcibly sets new password for an User.
static AccessControlList getACL(User user)
          Constructs an AccessControlList for a specific user.
static GroupSet getAllGroups()
          Retrieves all groups defined in the system.
static PermissionSet getAllPermissions()
          Retrieves all permissions defined in the system.
static RoleSet getAllRoles()
          Retrieves all roles defined in the system.
static User getAnonymousUser()
          Constructs an User object to represent an anonymous user of the application.
static User getAuthenticatedUser(java.lang.String username, java.lang.String password)
          Authenticates an user, and constructs an User object to represent him/her.
static Group getGlobalGroup()
          Provides a reference to the Group object that represents the global group.
static Group getGroup(java.lang.String groupName)
          Retrieves a named Group.
static GroupSet getGroups(Criteria criteria)
          Retrieve a set of Groups that meet the specified Criteria.
static Group getNewGroup(java.lang.String groupName)
          Retrieves a named Group.
static Permission getNewPermission(java.lang.String permissionName)
          Retrieves a named Permission.
static Role getNewRole(java.lang.String roleName)
          Retrieves a named Permission.
static Permission getPermission(java.lang.String permissionName)
          Retrieves a named Permission.
static PermissionSet getPermissions(Criteria criteria)
          Retrieve a set of Permissions that meet the specified Criteria.
static PermissionSet getPermissions(Role role)
          Retrieves all permissions associated with a role.
static Role getRole(java.lang.String roleName)
          Retrieves a named Role.
static RoleSet getRoles(Criteria criteria)
          Retrieve a set of Roles that meet the specified Criteria.
static SecurityService getService()
          Retrieves an implementation of SecurityService, base on the settings in TurbineResources.
static User getUser(java.lang.String username)
          Constructs an User object to represent a registered user of the application.
static java.lang.Class getUserClass()
          Return a Class object representing the system's chosen implementation of of User interface.
static User getUserInstance()
          Construct a blank User object.
static User[] getUsers(Criteria criteria)
          Retrieve a set of users that meet the specified criteria.
static void grant(Role role, Permission permission)
          Grants a Role a Permission
static void grant(User user, Group group, Role role)
          Grant an User a Role in a Group.
static void removeGroup(Group group)
          Removes a Group from the system.
static void removePermission(Permission permission)
          Removes a Permission from the system.
static void removeRole(Role role)
          Removes a Role from the system.
static void removeUser(User user)
          Removes an user account from the system.
static void renameGroup(Group group, java.lang.String name)
          Renames an existing Group.
static void renamePermission(Permission permission, java.lang.String name)
          Renames an existing Permission.
static void renameRole(Role role, java.lang.String name)
          Renames an existing Role.
static void revoke(Role role, Permission permission)
          Revokes a Permission from a Role.
static void revoke(User user, Group group, Role role)
          Revoke a Role in a Group from an User.
static void revokeAll(Role role)
          Revokes all permissions from a Role.
static void revokeAll(User user)
          Revokes all roles from an User.
static void saveGroup(Group group)
          Stores Group's attributes.
static void savePermission(Permission permission)
          Stores Permission's attributes.
static void saveRole(Role role)
          Stores Role's attributes.
static void saveUser(User user)
          Saves User's data in the permanent storage.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

TurbineSecurity

public TurbineSecurity()
Method Detail

getService

public static SecurityService getService()
Retrieves an implementation of SecurityService, base on the settings in TurbineResources.
Returns:
an implementation of SecurityService.

encryptPassword

public static java.lang.String encryptPassword(java.lang.String password)

getUserClass

public static java.lang.Class getUserClass()
                                    throws UnknownEntityException
Return a Class object representing the system's chosen implementation of of User interface.
Returns:
systems's chosen implementation of User interface.
Throws:
UnknownEntityException - if the implementation of User interface could not be determined, or does not exist.

getUserInstance

public static User getUserInstance()
                            throws UnknownEntityException
Construct a blank User object. This method calls getUserClass, and then creates a new object using the default constructor.
Returns:
an object implementing User interface.
Throws:
UnknownEntityException - if the object could not be instantiated.

accountExists

public static boolean accountExists(User user)
                             throws DataBackendException
Check whether a specified user's account exists. The login name is used for looking up the account.
Parameters:
user - The user to be checked.
Returns:
true if the specified account exists
Throws:
DataBackendException - if there was an error accessing the data backend.

accountExists

public static boolean accountExists(java.lang.String username)
                             throws DataBackendException
Check whether a specified user's account exists. The login name is used for looking up the account.
Parameters:
usename - The name of the user to be checked.
Returns:
true if the specified account exists
Throws:
DataBackendException - if there was an error accessing the data backend.

getAuthenticatedUser

public static User getAuthenticatedUser(java.lang.String username,
                                        java.lang.String password)
                                 throws DataBackendException,
                                        UnknownEntityException,
                                        PasswordMismatchException
Authenticates an user, and constructs an User object to represent him/her.
Parameters:
username - The user name.
password - The user password.
Returns:
An authenticated Turbine User.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if user account is not present.
PasswordMissmatchException - if the supplied password was incorrect.

getUser

public static User getUser(java.lang.String username)
                    throws DataBackendException,
                           UnknownEntityException
Constructs an User object to represent a registered user of the application.
Parameters:
username - The user name.
Returns:
A Turbine User.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if user account is not present.

getUsers

public static User[] getUsers(Criteria criteria)
                       throws DataBackendException
Retrieve a set of users that meet the specified criteria. As the keys for the criteria, you should use the constants that are defined in User interface, plus the names of the custom attributes you added to your user representation in the data storage. Use verbatim names of the attributes - without table name prefix in case of DB implementation.
Parameters:
criteria - The criteria of selection.
Returns:
a List of users meeting the criteria.
Throws:
DataBackendException - if there is a problem accessing the storage.

getAnonymousUser

public static User getAnonymousUser()
                             throws UnknownEntityException
Constructs an User object to represent an anonymous user of the application.
Returns:
An anonymous Turbine User.
Throws:
UnknownEntityException - if the anonymous User object couldn't be constructed.

saveUser

public static void saveUser(User user)
                     throws UnknownEntityException,
                            DataBackendException
Saves User's data in the permanent storage. The user account is required to exist in the storage.
Throws:
UnknownEntityException - if the user's account does not exist in the database.
DataBackendException - if there is a problem accessing the storage.

changePassword

public static void changePassword(User user,
                                  java.lang.String oldPassword,
                                  java.lang.String newPassword)
                           throws PasswordMismatchException,
                                  UnknownEntityException,
                                  DataBackendException
Change the password for an User.
Parameters:
user - an User to change password for.
oldPassword - the current password supplied by the user.
newPassword - the current password requested by the user.
Throws:
PasswordMismatchException - if the supplied password was incorrect.
UnknownEntityException - if the user's record does not exist in the database.
DataBackendException - if there is a problem accessing the storage.

forcePassword

public static void forcePassword(User user,
                                 java.lang.String password)
                          throws UnknownEntityException,
                                 DataBackendException
Forcibly sets new password for an User. This is supposed by the administrator to change the forgotten or compromised passwords. Certain implementatations of this feature would require administrative level access to the authenticating server / program.
Parameters:
user - an User to change password for.
password - the new password.
Throws:
UnknownEntityException - if the user's record does not exist in the database.
DataBackendException - if there is a problem accessing the storage.

getACL

public static AccessControlList getACL(User user)
                                throws DataBackendException,
                                       UnknownEntityException
Constructs an AccessControlList for a specific user.
Parameters:
user - the user for whom the AccessControlList are to be retrieved
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if user account is not present.

grant

public static void grant(User user,
                         Group group,
                         Role role)
                  throws DataBackendException,
                         UnknownEntityException
Grant an User a Role in a Group.
Parameters:
User - the user.
Group - the group.
Role - the role.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if user account, group or role is not present.

revoke

public static void revoke(User user,
                          Group group,
                          Role role)
                   throws DataBackendException,
                          UnknownEntityException
Revoke a Role in a Group from an User.
Parameters:
User - the user.
Group - the group.
Role - the role.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if user account, group or role is not present.

revokeAll

public static void revokeAll(User user)
                      throws DataBackendException,
                             UnknownEntityException
Revokes all roles from an User. This method is used when deleting an account.
Parameters:
user - the User.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the account is not present.

grant

public static void grant(Role role,
                         Permission permission)
                  throws DataBackendException,
                         UnknownEntityException
Grants a Role a Permission
Parameters:
role - the Role.
permission - the Permission.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if role or permission is not present.

revoke

public static void revoke(Role role,
                          Permission permission)
                   throws DataBackendException,
                          UnknownEntityException
Revokes a Permission from a Role.
Parameters:
role - the Role.
permission - the Permission.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if role or permission is not present.

revokeAll

public static void revokeAll(Role role)
                      throws DataBackendException,
                             UnknownEntityException
Revokes all permissions from a Role. This method is user when deleting a Role.
Parameters:
role - the Role
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the Role is not present.

addUser

public static void addUser(User user,
                           java.lang.String password)
                    throws DataBackendException,
                           EntityExistsException
Creates new user account with specified attributes. TODO throw more specific exception
Parameters:
user - the object describing account to be created.
Throws:
DataBackendException - if there was an error accessing the data backend.
EntityExistsException - if the user account already exists.

removeUser

public static void removeUser(User user)
                       throws DataBackendException,
                              UnknownEntityException
Removes an user account from the system. TODO throw more specific exception
Parameters:
user - the object describing the account to be removed.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the user account is not present.

getGlobalGroup

public static Group getGlobalGroup()
Provides a reference to the Group object that represents the global group.
Returns:
a Group object that represents the global group.

createGroup

public static Group createGroup(java.lang.String name)
                         throws TurbineSecurityException
Creates a new Group in the system. This is a convenience method.
Parameters:
name - The name of the new Group.
Returns:
An object representing the new Group.
Throws:
TurbineSecurityException - if the Group could not be created.

createPermission

public static Permission createPermission(java.lang.String name)
                                   throws TurbineSecurityException
Creates a new Permission in the system. This is a convenience method.
Parameters:
name - The name of the new Permission.
Returns:
An object representing the new Permission.
Throws:
TurbineSecurityException - if the Permission could not be created.

getGroup

public static Group getGroup(java.lang.String groupName)
                      throws DataBackendException,
                             UnknownEntityException
Retrieves a named Group.
Parameters:
groupName - The name of the Group to be retrieved.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the Group is not present.

getNewGroup

public static Group getNewGroup(java.lang.String groupName)
                         throws DataBackendException
Retrieves a named Group. If the Group does not exist, it creates a new Group based on the Services Group implementation. It is ok to pass in null or "" here and then use Group.setName() at a later point.
Parameters:
groupName - The name of the Group to be retrieved.
Throws:
DataBackendException - if there was an error accessing the data backend.

getNewRole

public static Role getNewRole(java.lang.String roleName)
                       throws TurbineSecurityException
Retrieves a named Permission. If the Permission does not exist, it creates a new Permission based on the Services Permission implementation. It is ok to pass in null or "" here and then use Permission.setName() at a later point.
Parameters:
roleName - The name of the Role to be retrieved.
Throws:
DataBackendException - if there was an error accessing the data backend.

getNewPermission

public static Permission getNewPermission(java.lang.String permissionName)
                                   throws DataBackendException
Retrieves a named Permission. If the Permission does not exist, it creates a new Permission based on the Services Permission implementation. It is ok to pass in null or "" here and then use Permission.setName() at a later point.
Parameters:
groupName - The name of the Permission to be retrieved.
Throws:
DataBackendException - if there was an error accessing the data backend.

getRole

public static Role getRole(java.lang.String roleName)
                    throws DataBackendException,
                           UnknownEntityException
Retrieves a named Role.
Parameters:
roleName - The name of the Role to be retrieved.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the Role is not present.

getPermission

public static Permission getPermission(java.lang.String permissionName)
                                throws DataBackendException,
                                       UnknownEntityException
Retrieves a named Permission.
Parameters:
permissionName - The name of the Permission to be retrieved.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the Permission is not present.

getGroups

public static GroupSet getGroups(Criteria criteria)
                          throws DataBackendException
Retrieve a set of Groups that meet the specified Criteria.
Parameters:
a - Criteria of Group selection.
Returns:
a set of Groups that meet the specified Criteria.

getRoles

public static RoleSet getRoles(Criteria criteria)
                        throws DataBackendException
Retrieve a set of Roles that meet the specified Criteria.
Parameters:
criteria - a Criteria of Roles selection.
Returns:
a set of Roles that meet the specified Criteria.

getPermissions

public static PermissionSet getPermissions(Criteria criteria)
                                    throws DataBackendException
Retrieve a set of Permissions that meet the specified Criteria.
Parameters:
criteria - a Criteria of Permissions selection.
Returns:
a set of Permissions that meet the specified Criteria.

getAllGroups

public static GroupSet getAllGroups()
                             throws DataBackendException
Retrieves all groups defined in the system.
Returns:
the names of all groups defined in the system.

getAllRoles

public static RoleSet getAllRoles()
                           throws DataBackendException
Retrieves all roles defined in the system.
Returns:
the names of all roles defined in the system.
Throws:
DataBackendException - if there was an error accessing the data backend.

getAllPermissions

public static PermissionSet getAllPermissions()
                                       throws DataBackendException
Retrieves all permissions defined in the system.
Returns:
the names of all roles defined in the system.
Throws:
DataBackendException - if there was an error accessing the data backend.

getPermissions

public static PermissionSet getPermissions(Role role)
                                    throws DataBackendException,
                                           UnknownEntityException
Retrieves all permissions associated with a role.
Parameters:
role - the role name, for which the permissions are to be retrieved.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the role is not present.

saveGroup

public static void saveGroup(Group group)
                      throws DataBackendException,
                             UnknownEntityException
Stores Group's attributes. The Groups is required to exist in the system.
Parameters:
group - The Group to be stored.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the group does not exist.

saveRole

public static void saveRole(Role role)
                     throws DataBackendException,
                            UnknownEntityException
Stores Role's attributes. The Roles is required to exist in the system.
Parameters:
role - The Role to be stored.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the role does not exist.

savePermission

public static void savePermission(Permission permission)
                           throws DataBackendException,
                                  UnknownEntityException
Stores Permission's attributes. The Permissions is required to exist in the system.
Parameters:
permission - The Permission to be stored.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the permission does not exist.

addGroup

public static void addGroup(Group group)
                     throws DataBackendException,
                            EntityExistsException
Creates a new group with specified attributes.
Parameters:
group - the object describing the group to be created.
Throws:
DataBackendException - if there was an error accessing the data backend.
EntityExistsException - if the group already exists.

addRole

public static void addRole(Role role)
                    throws DataBackendException,
                           EntityExistsException
Creates a new role with specified attributes.
Parameters:
group - the objects describing the group to be created.
Throws:
DataBackendException - if there was an error accessing the data backend.
EntityExistsException - if the role already exists.

addPermission

public static void addPermission(Permission permission)
                          throws DataBackendException,
                                 EntityExistsException
Creates a new permission with specified attributes.
Parameters:
group - the objects describing the group to be created.
Throws:
DataBackendException - if there was an error accessing the data backend.
EntityExistsException - if the permission already exists.

removeGroup

public static void removeGroup(Group group)
                        throws DataBackendException,
                               UnknownEntityException
Removes a Group from the system.
Parameters:
the - object describing group to be removed.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the group does not exist.

removeRole

public static void removeRole(Role role)
                       throws DataBackendException,
                              UnknownEntityException
Removes a Role from the system.
Parameters:
the - object describing role to be removed.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the role does not exist.

removePermission

public static void removePermission(Permission permission)
                             throws DataBackendException,
                                    UnknownEntityException
Removes a Permission from the system.
Parameters:
the - object describing permission to be removed.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the permission does not exist.

renameGroup

public static void renameGroup(Group group,
                               java.lang.String name)
                        throws DataBackendException,
                               UnknownEntityException
Renames an existing Group.
Parameters:
the - object describing the group to be renamed.
name - the new name for the group.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the group does not exist.

renameRole

public static void renameRole(Role role,
                              java.lang.String name)
                       throws DataBackendException,
                              UnknownEntityException
Renames an existing Role.
Parameters:
the - object describing the role to be renamed.
name - the new name for the role.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the role does not exist.

renamePermission

public static void renamePermission(Permission permission,
                                    java.lang.String name)
                             throws DataBackendException,
                                    UnknownEntityException
Renames an existing Permission.
Parameters:
the - object describing the permission to be renamed.
name - the new name for the permission.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the permission does not exist.


Copyright © 1999-2001 Apache Software Foundation. All Rights Reserved.