net.sourceforge.sconman
Class SecurityContext

java.lang.Object
  extended by net.sourceforge.sconman.SecurityContext
All Implemented Interfaces:
IXMLSerializable

public class SecurityContext
extends java.lang.Object
implements IXMLSerializable

This class handles security elements, as users, roles, permissions, and does security checks

Author:
mikeshadow

Constructor Summary
SecurityContext(Project project)
          Main constructor
 
Method Summary
(package private)  Role addRole(java.lang.String roleName)
          Adds a new role, given its id
 Role addRole(User user, java.lang.String roleName)
          Adds a new role, given its id
(package private)  User addUser(java.lang.String login, java.lang.String password, java.lang.String firstName, java.lang.String lastName, java.lang.String email)
          Adds a new user
 User addUser(User user, java.lang.String login, java.lang.String password, java.lang.String firstName, java.lang.String lastName, java.lang.String email)
          Adds a new user to the system
(package private)  void check(User user, Permission permission)
          Checks a user permission
 boolean checkUserExists(java.lang.String login)
          Returns true if there's a user for the specified login
 void deserializeXML(org.kxml2.io.KXmlParser in)
          Deserialize from XML
(package private)  Permission getAddNewContentPermission(ContentType ctype)
          Returns the permission create contents of the specified type.
(package private)  Permission getAddNewContentPermission(User actor, ContentType ctype)
          Returns the permission create contents of the specified type.
(package private)  Permission getAdminProjectPermission()
          Returns the permission to admin the project.
(package private)  Permission getAdminProjectPermission(User actor)
          Returns the permission to admin the project.
(package private)  Permission getAdminRolesPermission()
          Returns the permission to admin roles.
(package private)  Permission getAdminRolesPermission(User actor)
          Returns the permission to admin roles.
(package private)  Permission getAdminUsersPermission()
          Returns the permission to admin users.
(package private)  Permission getAdminUsersPermission(User actor)
          Returns the permission to admin users.
(package private)  Permission getAllPermissions()
          Returns the permission to do everything
(package private)  Permission getDeleteContentPermission(ContentType ctype)
          Returns the permission delete contents of the specified type.
(package private)  Permission getDeleteContentPermission(User actor, ContentType ctype)
          Returns the permission delete contents of the specified type.
(package private)  java.lang.String getDigested(boolean hexFormat, java.lang.String str)
          Hashes a String, useful for password hidding
(package private)  Permission getModifyCategoryPermission(Category cat)
          Returns the permission to modify a category.
(package private)  Permission getModifyCategoryPermission(User actor, Category cat)
          Returns the permission to modify a category.
(package private)  Permission getModifyContentPermission(ContentType ctype)
          Returns the permission modify contents of the specified type.
(package private)  Permission getModifyContentPermission(User actor, ContentType ctype)
          Returns the permission modify contents of the specified type.
(package private)  Permission getPermission(Category cat, java.lang.String action)
          Returns the permission associated to the action on the category
(package private)  Permission getPermission(java.lang.String name)
          Returns a permission, known its id
(package private)  Permission getPermission(User user, Category cat, java.lang.String action)
          Returns the permission associated to the action on the category
(package private)  Permission getPermission(User user, ContentType ctype, java.lang.String action)
          Returns the permission associated to the action on the content type
(package private)  Project getProject()
          Returns the parent project
 Role getRole(java.lang.String name)
          Returns a role, known its id
(package private)  java.util.Map getRoles()
           
(package private)  User getUser(java.lang.String login)
          Returns a user known its login
 User getUser(User actor, java.lang.String login)
          Returns a user, known its login.
(package private)  Content getUserContent(java.lang.String login, java.lang.String password)
           
(package private)  Permission getViewCategoryPermission(Category cat)
          Returns the permission to view a category.
(package private)  Permission getViewCategoryPermission(User actor, Category cat)
          Returns the permission to view a category.
(package private)  Permission getViewContentPermission(ContentType ctype)
          Returns the permission view contents of the specified type.
(package private)  Permission getViewContentPermission(User actor, ContentType ctype)
          Returns the permission view contents of the specified type.
 User loginUser(java.lang.String login, java.lang.String password)
          Returns the user, known its login and password, or null if doesn't exists
(package private)  void removeRole(java.lang.String roleName)
          Removes a role, given its id
 void removeRole(User user, java.lang.String roleName)
          Removes a role, given its id, including all the users who contains the Role
 java.util.List searchUsers(User actor, java.lang.String login, java.lang.String fname, java.lang.String lname, int max)
          Returns the list of users that matches the criteria
 void serializeXML(org.kxml2.io.KXmlSerializer out)
          Serialize to XML
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SecurityContext

SecurityContext(Project project)
Main constructor

Parameters:
project - The owner project
Method Detail

getProject

Project getProject()
Returns the parent project

Returns:
The project

getPermission

Permission getPermission(java.lang.String name)
Returns a permission, known its id

Parameters:
id - The permission id
Returns:
The permission

getRoles

java.util.Map getRoles()

getRole

public Role getRole(java.lang.String name)
Returns a role, known its id

Parameters:
id - The role id
Returns:
The role

addRole

Role addRole(java.lang.String roleName)
Adds a new role, given its id

Parameters:
roleName -
Returns:

addRole

public Role addRole(User user,
                    java.lang.String roleName)
             throws SCMSecurityException
Adds a new role, given its id

Parameters:
user - The user that adds the role
roleName -
Returns:
Throws:
SCMSecurityException

removeRole

void removeRole(java.lang.String roleName)
          throws SCMStorageException
Removes a role, given its id

Parameters:
roleName -
Throws:
SCMStorageException

removeRole

public void removeRole(User user,
                       java.lang.String roleName)
                throws SCMSecurityException,
                       SCMStorageException
Removes a role, given its id, including all the users who contains the Role

Parameters:
user - The user that removes the role
roleName -
Throws:
SCMSecurityException
SCMStorageException

getUserContent

Content getUserContent(java.lang.String login,
                       java.lang.String password)
                 throws SCMStorageException
Throws:
SCMStorageException

loginUser

public User loginUser(java.lang.String login,
                      java.lang.String password)
               throws SCMLoginException
Returns the user, known its login and password, or null if doesn't exists

Parameters:
login - The user's login
password - The user's password
Returns:
Throws:
SCMLoginException

getUser

User getUser(java.lang.String login)
       throws SCMStorageException
Returns a user known its login

Parameters:
login -
Returns:
Throws:
SCMStorageException

getUser

public User getUser(User actor,
                    java.lang.String login)
             throws SCMStorageException,
                    SCMSecurityException
Returns a user, known its login. This operation can only be done by user administrators.

Parameters:
actor - The user that performs the action, that must have user administration permissions
login -
Returns:
Throws:
SCMStorageException
SCMSecurityException

searchUsers

public java.util.List searchUsers(User actor,
                                  java.lang.String login,
                                  java.lang.String fname,
                                  java.lang.String lname,
                                  int max)
                           throws SCMStorageException,
                                  SCMSecurityException
Returns the list of users that matches the criteria

Parameters:
actor -
login -
fname -
lname -
beginIndex -
endIndex -
Returns:
Throws:
SCMStorageException
SCMSecurityException

checkUserExists

public boolean checkUserExists(java.lang.String login)
                        throws SCMStorageException
Returns true if there's a user for the specified login

Parameters:
login -
Returns:
Throws:
SCMStorageException

addUser

User addUser(java.lang.String login,
             java.lang.String password,
             java.lang.String firstName,
             java.lang.String lastName,
             java.lang.String email)
       throws SCMStorageException
Adds a new user

Parameters:
login -
password -
firstName -
lastName -
email -
Returns:
Throws:
java.io.IOException
SCMStorageException

addUser

public User addUser(User user,
                    java.lang.String login,
                    java.lang.String password,
                    java.lang.String firstName,
                    java.lang.String lastName,
                    java.lang.String email)
             throws SCMStorageException,
                    SCMSecurityException
Adds a new user to the system

Parameters:
user -
login -
password -
firstName -
lastName -
email -
Returns:
Throws:
SCMException
SCMStorageException
SCMSecurityException

getPermission

Permission getPermission(User user,
                         ContentType ctype,
                         java.lang.String action)
                   throws SCMSecurityException
Returns the permission associated to the action on the content type

Parameters:
ctype -
string -
Returns:
Throws:
SCMSecurityException

getPermission

Permission getPermission(Category cat,
                         java.lang.String action)
Returns the permission associated to the action on the category

Parameters:
cat - The category
action - The action
Returns:

getPermission

Permission getPermission(User user,
                         Category cat,
                         java.lang.String action)
                   throws SCMSecurityException
Returns the permission associated to the action on the category

Parameters:
cat - The category
action - The action
Returns:
Throws:
SCMSecurityException

getAllPermissions

Permission getAllPermissions()
Returns the permission to do everything

Returns:
The permission to do everything

getAdminProjectPermission

Permission getAdminProjectPermission()
Returns the permission to admin the project.

Returns:
The permission to admin the project

getAdminProjectPermission

Permission getAdminProjectPermission(User actor)
                               throws SCMSecurityException
Returns the permission to admin the project. Only project administrators can request this permission.

Parameters:
actor - The user that request the permission
Returns:
The permission to admin the project
Throws:
SCMSecurityException - Thrown when the actor doesn't have the admin project permission

getAdminUsersPermission

Permission getAdminUsersPermission()
Returns the permission to admin users.

Returns:
The permission to admin users

getAdminUsersPermission

Permission getAdminUsersPermission(User actor)
                             throws SCMSecurityException
Returns the permission to admin users. Only project administrators can request this permission

Parameters:
actor - The user that request the permission
Returns:
The permission to admin users
Throws:
SCMSecurityException - Thrown when the actor doesn't have the admin project permission

getAdminRolesPermission

Permission getAdminRolesPermission()
Returns the permission to admin roles.

Returns:
The permission to admin roles

getAdminRolesPermission

Permission getAdminRolesPermission(User actor)
                             throws SCMSecurityException
Returns the permission to admin roles. Only project administrators can request this permission

Parameters:
actor - The user that request the permission
Returns:
The permission to admin roles
Throws:
SCMSecurityException - Thrown when the actor doesn't have the admin project permission

getViewCategoryPermission

Permission getViewCategoryPermission(Category cat)
Returns the permission to view a category.

Parameters:
cat - The category to view
Returns:
The permission to view the category

getViewCategoryPermission

Permission getViewCategoryPermission(User actor,
                                     Category cat)
                               throws SCMSecurityException
Returns the permission to view a category. Only project administrators can request this permission.

Parameters:
actor - The user that request the permission
cat - The category to view
Returns:
The permission to view the category
Throws:
SCMSecurityException - Thrown when the actor doesn't have the admin project permission

getModifyCategoryPermission

Permission getModifyCategoryPermission(Category cat)
Returns the permission to modify a category.

Parameters:
cat - The category to modify
Returns:
The permission to modify the category

getModifyCategoryPermission

Permission getModifyCategoryPermission(User actor,
                                       Category cat)
                                 throws SCMSecurityException
Returns the permission to modify a category. Only project administrators can request this permission.

Parameters:
actor - The user that request the permission
cat - The category to modify
Returns:
The permission to modify the category
Throws:
SCMSecurityException - Thrown when the actor doesn't have the admin project permission

getAddNewContentPermission

Permission getAddNewContentPermission(ContentType ctype)
Returns the permission create contents of the specified type.

Parameters:
ctype - The content type
Returns:
The permission to create new contents of the given type

getAddNewContentPermission

Permission getAddNewContentPermission(User actor,
                                      ContentType ctype)
                                throws SCMSecurityException
Returns the permission create contents of the specified type. Only project administrators can request this permission.

Parameters:
actor - The user that request the permission
ctype - The content type
Returns:
The permission to create new contents of the given type
Throws:
SCMSecurityException - Thrown when the actor doesn't have the admin project permission

getViewContentPermission

Permission getViewContentPermission(ContentType ctype)
Returns the permission view contents of the specified type.

Parameters:
ctype - The content type
Returns:
The permission to view contents of the given type

getViewContentPermission

Permission getViewContentPermission(User actor,
                                    ContentType ctype)
                              throws SCMSecurityException
Returns the permission view contents of the specified type. Only project administrators can request this permission.

Parameters:
actor - The user that request the permission
ctype - The content type
Returns:
The permission to view contents of the given type
Throws:
SCMSecurityException - Thrown when the actor doesn't have the admin project permission

getModifyContentPermission

Permission getModifyContentPermission(ContentType ctype)
Returns the permission modify contents of the specified type.

Parameters:
ctype - The content type
Returns:
The permission to modify contents of the given type

getModifyContentPermission

Permission getModifyContentPermission(User actor,
                                      ContentType ctype)
                                throws SCMSecurityException
Returns the permission modify contents of the specified type. Only project administrators can request this permission.

Parameters:
actor - The user that request the permission
ctype - The content type
Returns:
The permission to modify contents of the given type
Throws:
SCMSecurityException - Thrown when the actor doesn't have the admin project permission

getDeleteContentPermission

Permission getDeleteContentPermission(ContentType ctype)
Returns the permission delete contents of the specified type.

Parameters:
ctype - The content type
Returns:
The permission to delete contents of the given type

getDeleteContentPermission

Permission getDeleteContentPermission(User actor,
                                      ContentType ctype)
                                throws SCMSecurityException
Returns the permission delete contents of the specified type. Only project administrators can request this permission.

Parameters:
actor - The user that request the permission
ctype - The content type
Returns:
The permission to delete contents of the given type
Throws:
SCMSecurityException - Thrown when the actor doesn't have the admin project permission

check

void check(User user,
           Permission permission)
     throws SCMSecurityException
Checks a user permission

Parameters:
user - The user to check the permission against
permission - The permission to check
Throws:
SCMSecurityException - Throw when the user doesn't have the permission

getDigested

java.lang.String getDigested(boolean hexFormat,
                             java.lang.String str)
Hashes a String, useful for password hidding

Parameters:
str -
Returns:

serializeXML

public void serializeXML(org.kxml2.io.KXmlSerializer out)
                  throws java.io.IOException
Description copied from interface: IXMLSerializable
Serialize to XML

Specified by:
serializeXML in interface IXMLSerializable
Parameters:
out - The KXmlSerializer to do the output
Throws:
java.io.IOException - Thrown if there's an IO problem

deserializeXML

public void deserializeXML(org.kxml2.io.KXmlParser in)
                    throws org.xmlpull.v1.XmlPullParserException,
                           java.io.IOException
Description copied from interface: IXMLSerializable
Deserialize from XML

Specified by:
deserializeXML in interface IXMLSerializable
Parameters:
in - The KXml pull parser
Throws:
org.xmlpull.v1.XmlPullParserException - Thrown if there's an XML problem
java.io.IOException - Thrown if there's an IO problem


Copyright null null. All Rights Reserved.