org.benow.security
Interface SecurityAdministrator

All Known Implementing Classes:
SecurityAdministratorImpl

public interface SecurityAdministrator

security: org.benow.security.SecurityAdministrator

Author:
andy

Field Summary
static java.lang.String DEFAULT_ADMIN_PASSWORD
           
static java.lang.String DEFAULT_USER_NAME
           
static java.lang.String REGISTERED_BOOTSTRAP
           
static java.lang.String REGISTERED_USER_NAME
           
 
Method Summary
 User authenticate(java.lang.String userName, java.lang.String password)
          Authenticated user in default application
 User authenticate(java.lang.String app, java.lang.String user, java.lang.String password)
          Authenticate the given user with the given password for the given application (optionally implemented).
 Permission createPermission(java.lang.Class<?> prefix, java.lang.String suffix)
           
 Permission createPermission(java.lang.String name)
           
 Role createRole(java.lang.Package pkg)
           
 Role createRole(java.lang.String name)
          Create a role with the given name
 Role createRole(java.lang.String name, java.lang.String description)
           
 User createUser(java.lang.String name)
          Creates a new user with the given name.
 Permission declarePermission(java.lang.Class<?> prefix, java.lang.String suffix)
          Create a permission, ensuring it exists and is remembered.
 Permission declarePermission(java.lang.Class<?> prefix, java.lang.String suffix, java.lang.String[] params)
           
 Permission declarePermission(Permission perm)
          ensures the given permission is known and remembered.
 Permission declarePermission(java.lang.String name)
          Creates a permission with the given name.
 void deleteRole(Role role)
          Deletes the given user
 void deleteUser(java.lang.String name)
          Deletes the user with the given name
 void deleteUser(User user)
          Deletes the given user.
 User doGetUserByEmail(java.lang.String email)
          Get user with given email
 void ensureAdminRolePermissions(java.lang.Class<?> forClass, java.lang.String[] permNames)
          Ensures the existence of the given permissions within an appropriate admin role for the class.
 User getAdministratorUser()
           
 java.util.Collection<java.lang.Class<?>> getClassesWithPermissionsInPackage(java.lang.String pkgName)
          Gets a list of classes within the given named package which have permissions
 java.util.Collection<java.lang.Class<?>> getDefaultClassesWithPermissions()
          Gets a list of classes within default package which have permissions
 User getDefaultUser()
           
 java.util.Collection<java.lang.String> getPackageNamesWithPermissions()
           
 java.util.Collection<java.lang.String> getPackageNamesWithPermissions(java.lang.String parentPkg)
           
 Permission getPermissionFor(java.lang.String name, java.lang.String value)
           
 java.util.List<Permission> getPermissions()
           
 java.util.Collection<Permission> getPermissionsForClass(java.lang.Class<?> forClass)
          Gets permissions declared in the given class.
 User getRegisteredTemplateUser()
           
 Role getRole(java.lang.Package pkg)
          Gets the admin role for the give pkg, creating if neccesary.
 Role getRole(java.lang.String name)
          Gets the declared role of the given name.
 java.util.Collection<Role> getRoles()
          Get all declared roles.
 User getUserByModuleKey(java.lang.Class<?> moduleClass, java.lang.Object key)
           
 User getUserByName(java.lang.String name)
          Gets the user with the given name from the default realm.
 User getUserByRealmAndName(java.lang.String realm, java.lang.String name)
          Gets the user with the given name within the given realm.
 java.util.Collection<java.lang.Class<?>> getUserModuleClasses()
          Gets the list of registered user module classes.
 java.util.Collection<User> getUsers()
          Method getUsers.
 void init()
          Called to initialize administrator
 void logout()
          Logout user associated with current thread
 void registerUserModuleClass(java.lang.Class<UserModule> moduleClass)
          Registers a user module class that will be included in a user when a user is created
 User validateAdministrator()
          Ensures the existance of an Administrator user having all declared roles (and hence permissions).
 void validateDeclaredRoles()
          Ensures the existance of registered roles.
 User validateDefaultUser()
           
 void validateSecurity()
          Validates DeclaredRoles and the Administrator user.
 

Field Detail

DEFAULT_ADMIN_PASSWORD

static final java.lang.String DEFAULT_ADMIN_PASSWORD
See Also:
Constant Field Values

DEFAULT_USER_NAME

static final java.lang.String DEFAULT_USER_NAME
See Also:
Constant Field Values

REGISTERED_BOOTSTRAP

static final java.lang.String REGISTERED_BOOTSTRAP
See Also:
Constant Field Values

REGISTERED_USER_NAME

static final java.lang.String REGISTERED_USER_NAME
See Also:
Constant Field Values
Method Detail

init

void init()
          throws java.lang.SecurityException
Called to initialize administrator

Throws:
java.lang.SecurityException

authenticate

User authenticate(java.lang.String app,
                  java.lang.String user,
                  java.lang.String password)
                  throws java.lang.SecurityException
Authenticate the given user with the given password for the given application (optionally implemented). If authentication is successful, a Principal is returned (which may be used for authorization purposes - Permission checking, etc), if it fails, a security exception is thrown.

Throws:
java.lang.SecurityException

logout

void logout()
Logout user associated with current thread


getUserModuleClasses

java.util.Collection<java.lang.Class<?>> getUserModuleClasses()
Gets the list of registered user module classes. This list is used during population of UserModules for a given user.


registerUserModuleClass

void registerUserModuleClass(java.lang.Class<UserModule> moduleClass)
Registers a user module class that will be included in a user when a user is created

Parameters:
moduleClass -

createPermission

Permission createPermission(java.lang.String name)
                            throws NoSuchPermissionException
Throws:
NoSuchPermissionException

getPermissionFor

Permission getPermissionFor(java.lang.String name,
                            java.lang.String value)
                            throws NoSuchPermissionException
Throws:
NoSuchPermissionException

getRoles

java.util.Collection<Role> getRoles()
Get all declared roles.

Returns:
declared roles

getRole

Role getRole(java.lang.Package pkg)
Gets the admin role for the give pkg, creating if neccesary.


getUserByName

User getUserByName(java.lang.String name)
                   throws java.lang.SecurityException
Gets the user with the given name from the default realm.

Parameters:
name - Name of the user to fetch
Returns:
User The fetched user, or null if no such user.
Throws:
java.lang.SecurityException

getUserByRealmAndName

User getUserByRealmAndName(java.lang.String realm,
                           java.lang.String name)
                           throws java.lang.SecurityException
Gets the user with the given name within the given realm.

Parameters:
realm - Realm to which to fetch the user for
name - Name of the user to fetch
Returns:
User The fetched user, or null if no such user.
Throws:
java.lang.SecurityException

getRole

Role getRole(java.lang.String name)
             throws NoSuchRoleException
Gets the declared role of the given name. If no role is found, a new Role is created.

Throws:
NoSuchRoleException

ensureAdminRolePermissions

void ensureAdminRolePermissions(java.lang.Class<?> forClass,
                                java.lang.String[] permNames)
                                throws java.lang.SecurityException
Ensures the existence of the given permissions within an appropriate admin role for the class. The naming conventions are as follows:

Throws:
java.lang.SecurityException

validateDeclaredRoles

void validateDeclaredRoles()
                           throws java.lang.SecurityException
Ensures the existance of registered roles. Roles should be remembered as created. That is, the Role class should add created roles to a master list of roles. Implementing classes could add newly created static roles to a db, etc.

Throws:
java.lang.SecurityException

validateAdministrator

User validateAdministrator()
                           throws java.lang.SecurityException
Ensures the existance of an Administrator user having all declared roles (and hence permissions).

Name and password are pulled from the configuration if provided or admin, admin by default.

Throws:
java.lang.SecurityException

validateDefaultUser

User validateDefaultUser()
                         throws java.lang.SecurityException
Throws:
java.lang.SecurityException

getDefaultUser

User getDefaultUser()
                    throws java.lang.SecurityException
Throws:
java.lang.SecurityException

validateSecurity

void validateSecurity()
                      throws java.lang.SecurityException
Validates DeclaredRoles and the Administrator user.

Throws:
java.lang.SecurityException - on Error during validation.
See Also:
validateDeclaredRoles(), validateAdministrator()

createUser

User createUser(java.lang.String name)
                throws java.lang.SecurityException
Creates a new user with the given name. Override this method to use a custom user implementation

Throws:
java.lang.SecurityException

createRole

Role createRole(java.lang.Package pkg)
                throws java.lang.SecurityException
Throws:
java.lang.SecurityException

createRole

Role createRole(java.lang.String name,
                java.lang.String description)
                throws java.lang.SecurityException
Throws:
java.lang.SecurityException

createPermission

Permission createPermission(java.lang.Class<?> prefix,
                            java.lang.String suffix)
                            throws java.lang.SecurityException
Throws:
java.lang.SecurityException

declarePermission

Permission declarePermission(java.lang.Class<?> prefix,
                             java.lang.String suffix)
                             throws java.lang.SecurityException
Create a permission, ensuring it exists and is remembered.

Parameters:
prefix -
suffix -
Returns:
created permission
Throws:
java.lang.SecurityException

declarePermission

Permission declarePermission(java.lang.Class<?> prefix,
                             java.lang.String suffix,
                             java.lang.String[] params)
                             throws java.lang.SecurityException
Throws:
java.lang.SecurityException

declarePermission

Permission declarePermission(Permission perm)
                             throws java.lang.SecurityException
ensures the given permission is known and remembered.

Parameters:
perm -
Returns:
validated permission
Throws:
java.lang.SecurityException

getUsers

java.util.Collection<User> getUsers()
Method getUsers.

Returns:
SubList

getUserByModuleKey

User getUserByModuleKey(java.lang.Class<?> moduleClass,
                        java.lang.Object key)
                        throws NoSuchUserWithModuleException,
                               java.lang.SecurityException
Throws:
NoSuchUserWithModuleException
java.lang.SecurityException

getPermissionsForClass

java.util.Collection<Permission> getPermissionsForClass(java.lang.Class<?> forClass)
                                                        throws NoSuchPermissionException
Gets permissions declared in the given class.

Parameters:
forClass -
Returns:
permissions declared in given class
Throws:
NoSuchPermissionException

getClassesWithPermissionsInPackage

java.util.Collection<java.lang.Class<?>> getClassesWithPermissionsInPackage(java.lang.String pkgName)
                                                                            throws NoSuchPermissionException
Gets a list of classes within the given named package which have permissions

Parameters:
pkgName -
Returns:
classes with permissions in the given package
Throws:
NoSuchPermissionException

getDefaultClassesWithPermissions

java.util.Collection<java.lang.Class<?>> getDefaultClassesWithPermissions()
Gets a list of classes within default package which have permissions

Returns:
classes with permissions in the default package

getPackageNamesWithPermissions

java.util.Collection<java.lang.String> getPackageNamesWithPermissions(java.lang.String parentPkg)
                                                                      throws NoSuchPermissionException
Parameters:
parentPkg -
Returns:
collection of names of child packages which have classes which have permissions within the given parent
Throws:
NoSuchPermissionException

getPackageNamesWithPermissions

java.util.Collection<java.lang.String> getPackageNamesWithPermissions()
Returns:
collection of names of root packages which have classes which have permissions

declarePermission

Permission declarePermission(java.lang.String name)
Creates a permission with the given name. Using the stack to resolve the prefix.

Parameters:
name -
Returns:
created permission.

deleteUser

void deleteUser(java.lang.String name)
                throws NoSuchUserException,
                       java.lang.SecurityException
Deletes the user with the given name

Parameters:
name -
Throws:
NoSuchUserException
java.lang.SecurityException

deleteUser

void deleteUser(User user)
Deletes the given user.

Parameters:
user -

deleteRole

void deleteRole(Role role)
Deletes the given user

Parameters:
role -

getAdministratorUser

User getAdministratorUser()
Returns:
the administrator user

authenticate

User authenticate(java.lang.String userName,
                  java.lang.String password)
                  throws NoSuchUserException
Authenticated user in default application

Parameters:
userName -
password -
Throws:
NoSuchUserException - on bad user or password

getPermissions

java.util.List<Permission> getPermissions()

doGetUserByEmail

User doGetUserByEmail(java.lang.String email)
                      throws java.lang.SecurityException
Get user with given email

Parameters:
email -
Returns:
Throws:
java.lang.SecurityException - when no matching user

createRole

Role createRole(java.lang.String name)
Create a role with the given name

Parameters:
name -
Returns:

getRegisteredTemplateUser

User getRegisteredTemplateUser()
Returns:
the template:registered user