org.opencms.security
Class CmsPrincipal

java.lang.Object
  extended by org.opencms.security.CmsPrincipal
All Implemented Interfaces:
java.lang.Comparable, java.security.Principal, I_CmsPrincipal
Direct Known Subclasses:
CmsGroup, CmsHistoryPrincipal, CmsUser

public abstract class CmsPrincipal
extends java.lang.Object
implements I_CmsPrincipal, java.lang.Comparable

Common methods shared among user and group principals, also contains several utility functions to deal with principal instances.

Since:
6.2.0
Version:
$Revision: 1.9 $
Author:
Alexander Kandzior

Field Summary
protected  java.lang.String m_description
          The description of this principal.
protected  int m_flags
          The flags of this principal.
protected  CmsUUID m_id
          The unique id of this principal.
protected  java.lang.String m_name
          The fully qualified name of this principal.
 
Fields inherited from interface org.opencms.security.I_CmsPrincipal
FLAG_CORE_LIMIT, FLAG_DISABLED, FLAG_ENABLED, FLAG_GROUP_PROJECT_MANAGER, FLAG_GROUP_PROJECT_USER, FLAG_GROUP_ROLE, FLAG_GROUP_VIRTUAL, FLAG_USER_MANAGED, FLAG_USER_WEBUSER, PRINCIPAL_GROUP, PRINCIPAL_USER
 
Constructor Summary
protected CmsPrincipal()
          Empty constructor for subclassing.
 
Method Summary
 int compareTo(java.lang.Object obj)
           
 boolean equals(java.lang.Object obj)
          Compares the given object with this principal.
static java.util.List filterCore(java.util.List principals)
          Filters out all principals with flags greater than I_CmsPrincipal.FLAG_CORE_LIMIT.
static java.util.List filterCoreFlag(java.util.List principals, int flag)
          Filters out all principals that do not have the given flag set, but leaving principals with flags less than I_CmsPrincipal.FLAG_CORE_LIMIT untouched.
static java.util.List filterFlag(java.util.List principals, int flag)
          Filters out all principals that do not have the given flag set.
 java.lang.String getDescription()
          Returns the description of this principal.
 java.lang.String getDisplayName(CmsObject cms, java.util.Locale locale)
          Returns the display name of this principal including the organizational unit.
 int getFlags()
          Returns the flags of this principal.
 CmsUUID getId()
          Returns the unique id of this principal.
 java.lang.String getName()
          Returns the fully qualified name of this principal.
 java.lang.String getOuFqn()
          Returns the fully qualified name of the associated organizational unit.
static java.lang.String getPrefixedGroup(java.lang.String name)
          Returns the provided group name prefixed with I_CmsPrincipal.PRINCIPAL_GROUP.
 java.lang.String getPrefixedName()
          Returns this principals unique name prefixed with it's type.
static java.lang.String getPrefixedUser(java.lang.String name)
          Returns the provided user name prefixed with I_CmsPrincipal.PRINCIPAL_USER.
 java.lang.String getSimpleName()
          Returns the simple name of this organizational unit.
 int hashCode()
          Returns the hash code of this object.
 boolean isEnabled()
          Returns true if this principal is enabled.
 boolean isGroup()
          Returns true if this principal is of type CmsGroup.
 boolean isUser()
          Returns true if this principal is of type CmsUser.
static I_CmsPrincipal readPrefixedPrincipal(CmsObject cms, java.lang.String name)
          Utility function to read a prefixed principal from the OpenCms database using the provided OpenCms user context.
static I_CmsPrincipal readPrincipal(CmsObject cms, CmsUUID id)
          Utility function to read a principal by its id from the OpenCms database using the provided OpenCms user context.
static I_CmsPrincipal readPrincipal(CmsObject cms, java.lang.String type, java.lang.String name)
          Utility function to read a principal of the given type from the OpenCms database using the provided OpenCms user context.
static I_CmsPrincipal readPrincipalIncludingHistory(CmsObject cms, CmsUUID id)
          Utility function to read a principal by its id from the OpenCms database using the provided OpenCms user context.
 void setDescription(java.lang.String description)
          Sets the description of this principal.
 void setEnabled(boolean enabled)
          Enables (or disables) this principal, depending on the given status.
 void setFlags(int value)
          Sets this principals flags to the specified value.
 void setName(java.lang.String name)
          Sets the unique name of this principal.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opencms.security.I_CmsPrincipal
checkName
 
Methods inherited from interface java.security.Principal
toString
 

Field Detail

m_description

protected java.lang.String m_description
The description of this principal.


m_flags

protected int m_flags
The flags of this principal.


m_id

protected CmsUUID m_id
The unique id of this principal.


m_name

protected java.lang.String m_name
The fully qualified name of this principal.

Constructor Detail

CmsPrincipal

protected CmsPrincipal()
Empty constructor for subclassing.

Method Detail

filterCore

public static java.util.List filterCore(java.util.List principals)
Filters out all principals with flags greater than I_CmsPrincipal.FLAG_CORE_LIMIT.

The given parameter list is directly modified, so the returned list is the same object as the input list.

Parameters:
principals - a list of CmsPrincipal objects
Returns:
the filtered principal list

filterCoreFlag

public static java.util.List filterCoreFlag(java.util.List principals,
                                            int flag)
Filters out all principals that do not have the given flag set, but leaving principals with flags less than I_CmsPrincipal.FLAG_CORE_LIMIT untouched.

The given parameter list is directly modified, so the returned list is the same object as the input list.

Parameters:
principals - a list of CmsPrincipal objects
flag - the flag for filtering
Returns:
the filtered principal list

filterFlag

public static java.util.List filterFlag(java.util.List principals,
                                        int flag)
Filters out all principals that do not have the given flag set.

The given parameter list is directly modified, so the returned list is the same object as the input list.

Parameters:
principals - the list of CmsPrincipal objects
flag - the flag for filtering
Returns:
the filtered principal list

getPrefixedGroup

public static java.lang.String getPrefixedGroup(java.lang.String name)
Returns the provided group name prefixed with I_CmsPrincipal.PRINCIPAL_GROUP..

Parameters:
name - the name to add the prefix to
Returns:
the provided group name prefixed with I_CmsPrincipal.PRINCIPAL_GROUP.

getPrefixedUser

public static java.lang.String getPrefixedUser(java.lang.String name)
Returns the provided user name prefixed with I_CmsPrincipal.PRINCIPAL_USER..

Parameters:
name - the name to add the prefix to
Returns:
the provided user name prefixed with I_CmsPrincipal.PRINCIPAL_USER.

readPrefixedPrincipal

public static I_CmsPrincipal readPrefixedPrincipal(CmsObject cms,
                                                   java.lang.String name)
                                            throws CmsException
Utility function to read a prefixed principal from the OpenCms database using the provided OpenCms user context.

The principal must be either prefixed with I_CmsPrincipal.PRINCIPAL_GROUP. or I_CmsPrincipal.PRINCIPAL_USER..

Parameters:
cms - the OpenCms user context to use when reading the principal
name - the prefixed principal name
Returns:
the principal read from the OpenCms database
Throws:
CmsException - in case the principal could not be read

readPrincipal

public static I_CmsPrincipal readPrincipal(CmsObject cms,
                                           CmsUUID id)
                                    throws CmsException
Utility function to read a principal by its id from the OpenCms database using the provided OpenCms user context.

Parameters:
cms - the OpenCms user context to use when reading the principal
id - the id of the principal to read
Returns:
the principal read from the OpenCms database
Throws:
CmsException - in case the principal could not be read

readPrincipal

public static I_CmsPrincipal readPrincipal(CmsObject cms,
                                           java.lang.String type,
                                           java.lang.String name)
                                    throws CmsException
Utility function to read a principal of the given type from the OpenCms database using the provided OpenCms user context.

The type must either be I_CmsPrincipal.PRINCIPAL_GROUP or I_CmsPrincipal.PRINCIPAL_USER.

Parameters:
cms - the OpenCms user context to use when reading the principal
type - the principal type
name - the principal name
Returns:
the principal read from the OpenCms database
Throws:
CmsException - in case the principal could not be read

readPrincipalIncludingHistory

public static I_CmsPrincipal readPrincipalIncludingHistory(CmsObject cms,
                                                           CmsUUID id)
                                                    throws CmsException
Utility function to read a principal by its id from the OpenCms database using the provided OpenCms user context.

Parameters:
cms - the OpenCms user context to use when reading the principal
id - the id of the principal to read
Returns:
the principal read from the OpenCms database
Throws:
CmsException - in case the principal could not be read

compareTo

public int compareTo(java.lang.Object obj)
Specified by:
compareTo in interface java.lang.Comparable
See Also:
Comparable.compareTo(java.lang.Object)

equals

public boolean equals(java.lang.Object obj)
Description copied from interface: I_CmsPrincipal
Compares the given object with this principal.

Specified by:
equals in interface java.security.Principal
Specified by:
equals in interface I_CmsPrincipal
Overrides:
equals in class java.lang.Object
Parameters:
obj - object to compare
Returns:
true if the object is equal
See Also:
Object.equals(java.lang.Object)

getDescription

public java.lang.String getDescription()
Description copied from interface: I_CmsPrincipal
Returns the description of this principal.

Specified by:
getDescription in interface I_CmsPrincipal
Returns:
the description of this principal
See Also:
I_CmsPrincipal.getDescription()

getDisplayName

public java.lang.String getDisplayName(CmsObject cms,
                                       java.util.Locale locale)
                                throws CmsException
Returns the display name of this principal including the organizational unit.

Parameters:
cms - the cms context
locale - the locale
Returns:
the display name of this principal including the organizational unit
Throws:
CmsException - if the organizational unit could not be read

getFlags

public int getFlags()
Description copied from interface: I_CmsPrincipal
Returns the flags of this principal.

The principal flags are used to store special information about the principals state encoded bitwise. Usually the flags int value should not be directly accessed. Utility methods like I_CmsPrincipal.isEnabled() provide a much easier way to access the information contained in the flags.

Specified by:
getFlags in interface I_CmsPrincipal
Returns:
the flags of this principal
See Also:
I_CmsPrincipal.getFlags()

getId

public CmsUUID getId()
Description copied from interface: I_CmsPrincipal
Returns the unique id of this principal.

Specified by:
getId in interface I_CmsPrincipal
Returns:
the unique id of this principal
See Also:
I_CmsPrincipal.getId()

getName

public java.lang.String getName()
Returns the fully qualified name of this principal.

Specified by:
getName in interface java.security.Principal
Specified by:
getName in interface I_CmsPrincipal
Returns:
the fully qualified name of this principal
See Also:
Principal.getName()

getOuFqn

public java.lang.String getOuFqn()
Returns the fully qualified name of the associated organizational unit.

Specified by:
getOuFqn in interface I_CmsPrincipal
Returns:
the fully qualified name of the associated organizational unit

getPrefixedName

public java.lang.String getPrefixedName()
Description copied from interface: I_CmsPrincipal
Returns this principals unique name prefixed with it's type.

The type prefix can either be I_CmsPrincipal.PRINCIPAL_GROUP. (for groups) or I_CmsPrincipal.PRINCIPAL_USER. (for users).

Specified by:
getPrefixedName in interface I_CmsPrincipal
Returns:
this principals unique name prefixed with this principals type
See Also:
I_CmsPrincipal.getPrefixedName()

getSimpleName

public java.lang.String getSimpleName()
Returns the simple name of this organizational unit.

Specified by:
getSimpleName in interface I_CmsPrincipal
Returns:
the simple name of this organizational unit.

hashCode

public int hashCode()
Description copied from interface: I_CmsPrincipal
Returns the hash code of this object.

Specified by:
hashCode in interface java.security.Principal
Specified by:
hashCode in interface I_CmsPrincipal
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code
See Also:
Object.hashCode()

isEnabled

public boolean isEnabled()
Description copied from interface: I_CmsPrincipal
Returns true if this principal is enabled.

A principal may be disabled in order to disable it, for example to prevent logins of a user. If a principal is just disabled but not deleted, the credentials of the principal in the VFS are still valid.

Specified by:
isEnabled in interface I_CmsPrincipal
Returns:
true if this principal is enabled
See Also:
I_CmsPrincipal.isEnabled()

isGroup

public boolean isGroup()
Description copied from interface: I_CmsPrincipal
Returns true if this principal is of type CmsGroup.

Specified by:
isGroup in interface I_CmsPrincipal
Returns:
true if this principal is of type CmsGroup
See Also:
I_CmsPrincipal.isGroup()

isUser

public boolean isUser()
Description copied from interface: I_CmsPrincipal
Returns true if this principal is of type CmsUser.

Specified by:
isUser in interface I_CmsPrincipal
Returns:
true if this principal is of type CmsUser
See Also:
I_CmsPrincipal.isUser()

setDescription

public void setDescription(java.lang.String description)
Description copied from interface: I_CmsPrincipal
Sets the description of this principal.

Specified by:
setDescription in interface I_CmsPrincipal
Parameters:
description - the principal description to set
See Also:
I_CmsPrincipal.setDescription(java.lang.String)

setEnabled

public void setEnabled(boolean enabled)
Description copied from interface: I_CmsPrincipal
Enables (or disables) this principal, depending on the given status.

Specified by:
setEnabled in interface I_CmsPrincipal
Parameters:
enabled - the principal status to set
See Also:
I_CmsPrincipal.setEnabled(boolean)

setFlags

public void setFlags(int value)
Description copied from interface: I_CmsPrincipal
Sets this principals flags to the specified value.

The principal flags are used to store special information about the principals state encoded bitwise. Usually the flags integer value should not be directly accessed. Utility methods like I_CmsPrincipal.setEnabled(boolean) provide a much easier way to manipulate the information contained in the flags.

Specified by:
setFlags in interface I_CmsPrincipal
Parameters:
value - the value to set this principals flags to
See Also:
I_CmsPrincipal.setFlags(int)

setName

public void setName(java.lang.String name)
Description copied from interface: I_CmsPrincipal
Sets the unique name of this principal.

Specified by:
setName in interface I_CmsPrincipal
Parameters:
name - the unique name of this principal to set
See Also:
I_CmsPrincipal.setName(java.lang.String)