Class CmsPrincipal
- java.lang.Object
-
- org.opencms.security.CmsPrincipal
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<I_CmsPrincipal>
,java.security.Principal
,I_CmsPrincipal
- Direct Known Subclasses:
CmsGroup
,CmsHistoryPrincipal
,CmsRoleAsPrincipal
,CmsUser
public abstract class CmsPrincipal extends java.lang.Object implements I_CmsPrincipal, java.lang.Comparable<I_CmsPrincipal>
Common methods shared among user and group principals, also contains several utility functions to deal with principal instances.- Since:
- 6.2.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description 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_ROLE, FLAG_GROUP_VIRTUAL, FLAG_USER_MANAGED, FLAG_USER_WEBUSER, PRINCIPAL_GROUP, PRINCIPAL_USER
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CmsPrincipal()
Empty constructor for subclassing.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(I_CmsPrincipal obj)
boolean
equals(java.lang.Object obj)
Compares the given object with this principal.static java.util.List<? extends CmsPrincipal>
filterCoreFlag(java.util.List<? extends CmsPrincipal> principals, int flag)
Filters out all principals that do not have the given flag set, but leaving principals with flags less than
untouched.I_CmsPrincipal.FLAG_CORE_LIMIT
static java.util.List<CmsGroup>
filterCoreGroups(java.util.List<CmsGroup> groups)
Filters out all groups with flags greater than
.I_CmsPrincipal.FLAG_CORE_LIMIT
static java.util.List<CmsUser>
filterCoreUsers(java.util.List<CmsUser> users)
Filters out all users with flags greater than
.I_CmsPrincipal.FLAG_CORE_LIMIT
static java.util.List<? extends CmsPrincipal>
filterFlag(java.util.List<? extends CmsPrincipal> 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.java.lang.String
getDisplayName(CmsObject cms, java.util.Locale locale, I_CmsGroupNameTranslation translation)
Returns the translated display name of this principal if it is a group and the display name otherwise.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.static java.lang.String
getType(I_CmsPrincipal principal)
Gets the type of a principal.int
hashCode()
Returns the hash code of this object.boolean
isEnabled()
Returnstrue
if this principal is enabled.boolean
isGroup()
Returnstrue
if this principal is of type
.CmsGroup
boolean
isUser()
Returnstrue
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, java.lang.String name)
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
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
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, getDescription
-
-
-
-
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_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
-
filterCoreFlag
public static java.util.List<? extends CmsPrincipal> filterCoreFlag(java.util.List<? extends CmsPrincipal> principals, int flag)
Filters out all principals that do not have the given flag set, but leaving principals with flags less than
untouched.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
objectsCmsPrincipal
flag
- the flag for filtering- Returns:
- the filtered principal list
-
filterCoreGroups
public static java.util.List<CmsGroup> filterCoreGroups(java.util.List<CmsGroup> groups)
Filters out all groups 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:
groups
- a list of
objectsCmsGroup
- Returns:
- the filtered principal list
-
filterCoreUsers
public static java.util.List<CmsUser> filterCoreUsers(java.util.List<CmsUser> users)
Filters out all users 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:
users
- a list of
objectsCmsUser
- Returns:
- the filtered principal list
-
filterFlag
public static java.util.List<? extends CmsPrincipal> filterFlag(java.util.List<? extends CmsPrincipal> 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
objectsCmsPrincipal
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
.
-
getType
public static java.lang.String getType(I_CmsPrincipal principal)
Gets the type of a principal.- Parameters:
principal
- the principal- Returns:
- the principal type
-
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
orI_CmsPrincipal.PRINCIPAL_GROUP
.
.I_CmsPrincipal.PRINCIPAL_USER
.- Parameters:
cms
- the OpenCms user context to use when reading the principalname
- 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 principalid
- 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 name) 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 principalname
- the name 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
orI_CmsPrincipal.PRINCIPAL_GROUP
.I_CmsPrincipal.PRINCIPAL_USER
- Parameters:
cms
- the OpenCms user context to use when reading the principaltype
- the principal typename
- 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 principalid
- 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(I_CmsPrincipal obj)
- Specified by:
compareTo
in interfacejava.lang.Comparable<I_CmsPrincipal>
- 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 interfaceI_CmsPrincipal
- Specified by:
equals
in interfacejava.security.Principal
- Overrides:
equals
in classjava.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 interfaceI_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 contextlocale
- the locale- Returns:
- the display name of this principal including the organizational unit
- Throws:
CmsException
- if the organizational unit could not be read
-
getDisplayName
public java.lang.String getDisplayName(CmsObject cms, java.util.Locale locale, I_CmsGroupNameTranslation translation) throws CmsException
Returns the translated display name of this principal if it is a group and the display name otherwise.- Parameters:
cms
- the current CMS contextlocale
- the localetranslation
- the group name translation to use- Returns:
- the translated display name
- Throws:
CmsException
- if something goes wrong
-
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
provide a much easier way to access the information contained in the flags.I_CmsPrincipal.isEnabled()
- Specified by:
getFlags
in interfaceI_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 interfaceI_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 interfaceI_CmsPrincipal
- Specified by:
getName
in interfacejava.security.Principal
- 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 interfaceI_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
(for groups) orI_CmsPrincipal.PRINCIPAL_GROUP
.
(for users).I_CmsPrincipal.PRINCIPAL_USER
.- Specified by:
getPrefixedName
in interfaceI_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 interfaceI_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 interfaceI_CmsPrincipal
- Specified by:
hashCode
in interfacejava.security.Principal
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hash code
- See Also:
Object.hashCode()
-
isEnabled
public boolean isEnabled()
Description copied from interface:I_CmsPrincipal
Returnstrue
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 interfaceI_CmsPrincipal
- Returns:
true
if this principal is enabled- See Also:
I_CmsPrincipal.isEnabled()
-
isGroup
public boolean isGroup()
Description copied from interface:I_CmsPrincipal
Returnstrue
if this principal is of type
.CmsGroup
- Specified by:
isGroup
in interfaceI_CmsPrincipal
- Returns:
true
if this principal is of typeCmsGroup
- See Also:
I_CmsPrincipal.isGroup()
-
isUser
public boolean isUser()
Description copied from interface:I_CmsPrincipal
Returnstrue
if this principal is of type
.CmsUser
- Specified by:
isUser
in interfaceI_CmsPrincipal
- Returns:
true
if this principal is of typeCmsUser
- 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 interfaceI_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 interfaceI_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
provide a much easier way to manipulate the information contained in the flags.I_CmsPrincipal.setEnabled(boolean)
- Specified by:
setFlags
in interfaceI_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 interfaceI_CmsPrincipal
- Parameters:
name
- the unique name of this principal to set- See Also:
I_CmsPrincipal.setName(java.lang.String)
-
-