Package com.attivio.sdk.security
Class AttivioPrincipal
- java.lang.Object
-
- com.attivio.sdk.security.AttivioPrincipal
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Comparable<AttivioPrincipal>,java.security.Principal
public class AttivioPrincipal extends java.lang.Object implements java.security.Principal, java.io.Serializable, java.lang.Comparable<AttivioPrincipal>, java.lang.Cloneable
Represents a principal (a user or a group).
A principal is characterized by three attributes:- realm ID - the ID of the security realm in which the principal is defined
- principal ID - the unique ID of the principal
- principal name - the name of the principal
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAttivioPrincipal.PrincipalTypeContains the possible principal types.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringANONYMOUSConstant to signify anonymous (realm or user).static AttivioPrincipalANONYMOUS_USERRepresents the anonymous user (whose realm ID, principal ID, and principal name areANONYMOUS).static java.lang.StringANONYMOUS_USER_GUIDThe GUID of the anonymous user.protected java.util.UUIDcorrelationIdcorrelation id if setstatic java.lang.StringFIELD_PRINCIPAL_IDThe name of the field that stores the principal ID.static java.lang.StringFIELD_PRINCIPAL_NAMEThe name of the field that stores the principal name.static java.lang.StringFIELD_REALM_IDThe name of the field that stores the security realm ID.protected java.util.Set<AttivioGroupMembership>groupMembershipsAny group memberships of this principal.static java.lang.StringPARAMETER_PRINCIPAL_IDThe CGI parameter or query request property for the principal ID.static java.lang.StringPARAMETER_PRINCIPAL_NAMEThe CGI parameter or query request property for the principal name.static java.lang.StringPARAMETER_REALM_IDThe CGI parameter or query request property for the realm ID.static java.lang.StringPRIN_NAME_UNKNOWNThe constant for the 'unknown' principal name.protected java.lang.StringprincipalIdThe principal ID.protected java.lang.StringprincipalNameThe principal name.protected AttivioPrincipal.PrincipalTypeprincipalTypeThe principal type.protected BaseTypesMap<java.lang.String,java.lang.Object>propertiesAny additional properties.protected java.lang.StringrealmIdThe security realm ID.protected java.util.Set<AttivioRole>rolesOptional roles used by the Security Client API authorization.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAttivioPrincipal()The default constructor.AttivioPrincipal(AttivioPrincipalKey principalKey, java.lang.String principalName, AttivioPrincipal.PrincipalType principalType)Constructs an Attivio principal from a principal key, name, and type.AttivioPrincipal(java.lang.String realmId, java.lang.String principalId, java.lang.String principalName, AttivioPrincipal.PrincipalType principalType)Creates an Attivio principal object from a realm ID, a principal ID, a principal name, and a principal type.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddGroupMembership(AttivioGroupMembership groupMembership)Adds a group membership to the set of this principal's group memberships.voidaddRole(AttivioRole role)Add a role to the principal.AttivioPrincipalclone()intcompareTo(AttivioPrincipal other){inheritDoc}booleanequals(java.lang.Object obj){inheritDoc}static AttivioPrincipalfromPrincipalString(java.lang.String principalString)Creates an attivio principal from a principal string in the form of realmId:principalId:principalNamejava.util.UUIDgetCorrelationId()Get the correlation ID used to tie different instances of the same document sent in back to their original source.java.util.Set<AttivioGroupMembership>getGroupMemberships()java.lang.StringgetName()java.lang.StringgetPassword()java.lang.StringgetPrincipalId()AttivioPrincipalKeygetPrincipalKey()java.lang.StringgetPrincipalName()java.lang.StringgetPrincipalString()AttivioPrincipal.PrincipalTypegetPrincipalType()BaseTypesMap<java.lang.String,java.lang.Object>getProperties()java.lang.ObjectgetProperty(java.lang.String propName)java.lang.StringgetRealmId()java.util.Set<AttivioRole>getRoles()java.util.Set<AttivioRole>getRoles(java.lang.Enum<?> enumRole)Return allAttivioRoleobjects that have the same name as the givenEnum.java.util.Set<AttivioRole>getRoles(java.lang.String roleName)Return allAttivioRoleobjects that have the given role name.inthashCode(){inheritDoc}booleanhasRole(java.lang.Enum<?> enumRole)Equivalent to hasRule(enumRole, AttivioRole.SUBGROUP_ANY);booleanhasRole(java.lang.Enum<?> enumRole, java.lang.String subgroup)booleanhasRole(java.lang.String role)Equivalent to hasRule(role , AttivioRole.SUBGROUP_ANY);booleanhasRole(java.lang.String roleName, java.lang.String subgroup)booleanisAnonymous()static booleanisAnonymous(AttivioPrincipalKey prinKey)static booleanisAnonymous(java.lang.String realmId, java.lang.String principalId)booleanisGroup()booleanisUser()booleanremoveGroupMembership(AttivioGroupMembership groupMembership)Removes a group membership from the set of this principal's group memberships.voidsetCorrelationId(java.util.UUID correlationId)Set the correlation idvoidsetGroupMemberships(java.util.Set<AttivioGroupMembership> groupMemberships)Sets the group memberships for this principal.voidsetPassword(java.lang.String password)Set a password with this principalvoidsetPrincipalId(java.lang.String principalId)Sets the principal ID.voidsetPrincipalName(java.lang.String principalName)Sets the principal name.voidsetPrincipalType(AttivioPrincipal.PrincipalType principalType)Set the principal typevoidsetProperty(java.lang.String propName, java.lang.Object propValue)Sets a property on the principal.voidsetRealmId(java.lang.String realmId)Sets the realm ID.voidsetRoles(java.util.Set<AttivioRole> roles)Set roles for this principal.java.lang.StringtoString(){inheritDoc}
-
-
-
Field Detail
-
PRIN_NAME_UNKNOWN
public static final java.lang.String PRIN_NAME_UNKNOWN
The constant for the 'unknown' principal name.- See Also:
- Constant Field Values
-
ANONYMOUS
public static final java.lang.String ANONYMOUS
Constant to signify anonymous (realm or user).- See Also:
- Constant Field Values
-
ANONYMOUS_USER
public static final AttivioPrincipal ANONYMOUS_USER
Represents the anonymous user (whose realm ID, principal ID, and principal name areANONYMOUS).
-
ANONYMOUS_USER_GUID
public static final java.lang.String ANONYMOUS_USER_GUID
The GUID of the anonymous user.
-
FIELD_REALM_ID
public static final java.lang.String FIELD_REALM_ID
The name of the field that stores the security realm ID.- See Also:
- Constant Field Values
-
FIELD_PRINCIPAL_ID
public static final java.lang.String FIELD_PRINCIPAL_ID
The name of the field that stores the principal ID.- See Also:
- Constant Field Values
-
FIELD_PRINCIPAL_NAME
public static final java.lang.String FIELD_PRINCIPAL_NAME
The name of the field that stores the principal name.- See Also:
- Constant Field Values
-
PARAMETER_REALM_ID
public static final java.lang.String PARAMETER_REALM_ID
The CGI parameter or query request property for the realm ID.- See Also:
- Constant Field Values
-
PARAMETER_PRINCIPAL_ID
public static final java.lang.String PARAMETER_PRINCIPAL_ID
The CGI parameter or query request property for the principal ID.- See Also:
- Constant Field Values
-
PARAMETER_PRINCIPAL_NAME
public static final java.lang.String PARAMETER_PRINCIPAL_NAME
The CGI parameter or query request property for the principal name.- See Also:
- Constant Field Values
-
realmId
protected java.lang.String realmId
The security realm ID.
-
principalId
protected java.lang.String principalId
The principal ID.
-
principalName
protected java.lang.String principalName
The principal name.
-
principalType
protected AttivioPrincipal.PrincipalType principalType
The principal type.
-
roles
protected java.util.Set<AttivioRole> roles
Optional roles used by the Security Client API authorization.
-
groupMemberships
protected java.util.Set<AttivioGroupMembership> groupMemberships
Any group memberships of this principal.
-
correlationId
protected java.util.UUID correlationId
correlation id if set
-
properties
protected BaseTypesMap<java.lang.String,java.lang.Object> properties
Any additional properties.
-
-
Constructor Detail
-
AttivioPrincipal
protected AttivioPrincipal()
The default constructor.
-
AttivioPrincipal
public AttivioPrincipal(java.lang.String realmId, java.lang.String principalId, java.lang.String principalName, AttivioPrincipal.PrincipalType principalType)Creates an Attivio principal object from a realm ID, a principal ID, a principal name, and a principal type.- Parameters:
realmId- the security realm ID; may not be null or emptyprincipalId- the principal ID; may not be null or emptyprincipalName- the principal name; may be null or emptyprincipalType- the principal type; may not be null or empty
-
AttivioPrincipal
public AttivioPrincipal(AttivioPrincipalKey principalKey, java.lang.String principalName, AttivioPrincipal.PrincipalType principalType)
Constructs an Attivio principal from a principal key, name, and type.- Parameters:
principalKey- the principal key; may not be nullprincipalName- the principal name; may be null or emptyprincipalType- the principal type; may not be null or empty
-
-
Method Detail
-
setRealmId
public void setRealmId(java.lang.String realmId)
Sets the realm ID.- Parameters:
realmId- the realm ID
-
getRealmId
public java.lang.String getRealmId()
- Returns:
- the security realm ID
-
setPrincipalId
public void setPrincipalId(java.lang.String principalId)
Sets the principal ID.- Parameters:
principalId- the principal ID
-
getPrincipalId
public java.lang.String getPrincipalId()
- Returns:
- the principal ID
-
getPrincipalKey
public AttivioPrincipalKey getPrincipalKey()
- Returns:
- the principal key
-
getPrincipalString
public java.lang.String getPrincipalString()
- Returns:
- string in the form of realmId:principalId:principalName
-
fromPrincipalString
public static AttivioPrincipal fromPrincipalString(java.lang.String principalString)
Creates an attivio principal from a principal string in the form of realmId:principalId:principalName- Parameters:
principalString-- Returns:
- the created principal
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfacejava.security.Principal- Returns:
- the principal name; may be null or empty if not filled in
-
setPrincipalName
public void setPrincipalName(java.lang.String principalName)
Sets the principal name.- Parameters:
principalName- the principal name
-
getPrincipalName
public java.lang.String getPrincipalName()
- Returns:
- the principal name; may be null or empty if not filled in
-
getPrincipalType
public AttivioPrincipal.PrincipalType getPrincipalType()
- Returns:
- the principal type
-
setPrincipalType
public void setPrincipalType(AttivioPrincipal.PrincipalType principalType)
Set the principal type- Parameters:
principalType-
-
isAnonymous
public boolean isAnonymous()
- Returns:
- true if this principal represents the anonymous
-
isAnonymous
public static boolean isAnonymous(java.lang.String realmId, java.lang.String principalId)- Parameters:
realmId- the realm IDprincipalId- the principal ID- Returns:
- true if the principal denoted by the realm ID and the principal ID is anonymous
-
isAnonymous
public static boolean isAnonymous(AttivioPrincipalKey prinKey)
- Parameters:
prinKey- the principal key- Returns:
- true if the principal denoted by the given key is anonymous
-
isUser
public boolean isUser()
- Returns:
- true if the principal represents a user
-
isGroup
public boolean isGroup()
- Returns:
- true if the principal represents a group
-
getRoles
public java.util.Set<AttivioRole> getRoles()
- Returns:
- the roles
-
getRoles
public java.util.Set<AttivioRole> getRoles(java.lang.String roleName)
Return allAttivioRoleobjects that have the given role name.- Parameters:
roleName- the role name to match- Returns:
- the matching roles
-
hasRole
public boolean hasRole(java.lang.String roleName, java.lang.String subgroup)- Parameters:
roleName- role namesubgroup- subgroup id,resource id, orAttivioRole.SUBGROUP_ANY- Returns:
- true, if the principal has the given role/subgroup.
-
hasRole
public boolean hasRole(java.lang.Enum<?> enumRole, java.lang.String subgroup)- Parameters:
enumRole- enum used for rolessubgroup- subgroup ID, resource ID, orAttivioRole.SUBGROUP_ANY- Returns:
- true, if the principal has the given role/subgroup.
-
hasRole
public boolean hasRole(java.lang.Enum<?> enumRole)
Equivalent to hasRule(enumRole, AttivioRole.SUBGROUP_ANY);- Parameters:
enumRole- enum used for roles- Returns:
- true, if the principal has the given role
-
hasRole
public boolean hasRole(java.lang.String role)
Equivalent to hasRule(role , AttivioRole.SUBGROUP_ANY);- Parameters:
role- role name- Returns:
- true, if the principal has the given role
-
getRoles
public java.util.Set<AttivioRole> getRoles(java.lang.Enum<?> enumRole)
Return allAttivioRoleobjects that have the same name as the givenEnum.- Parameters:
enumRole- enum used for roles- Returns:
- matching roles
-
addRole
public void addRole(AttivioRole role)
Add a role to the principal.
-
setRoles
public void setRoles(java.util.Set<AttivioRole> roles)
Set roles for this principal.- Parameters:
roles- the roles to set
-
getGroupMemberships
public java.util.Set<AttivioGroupMembership> getGroupMemberships()
- Returns:
- the group memberships for this principal
-
setGroupMemberships
public void setGroupMemberships(java.util.Set<AttivioGroupMembership> groupMemberships)
Sets the group memberships for this principal.- Parameters:
groupMemberships- the group memberships
-
addGroupMembership
public void addGroupMembership(AttivioGroupMembership groupMembership)
Adds a group membership to the set of this principal's group memberships.- Parameters:
groupMembership- the group membership to add
-
removeGroupMembership
public boolean removeGroupMembership(AttivioGroupMembership groupMembership)
Removes a group membership from the set of this principal's group memberships.- Parameters:
groupMembership- the group membership to remove- Returns:
- true if the group membership was present and removed
-
getCorrelationId
public java.util.UUID getCorrelationId()
Get the correlation ID used to tie different instances of the same document sent in back to their original source.- Returns:
- correlation id or null if not set
-
setCorrelationId
public void setCorrelationId(java.util.UUID correlationId)
Set the correlation id- Parameters:
correlationId-
-
setProperty
public void setProperty(java.lang.String propName, java.lang.Object propValue)Sets a property on the principal.- Parameters:
propName- the property namepropValue- the property value
-
setPassword
public void setPassword(java.lang.String password)
Set a password with this principal- Parameters:
password-
-
getPassword
public java.lang.String getPassword()
- Returns:
- null or a password if set on the principal
-
getProperty
public java.lang.Object getProperty(java.lang.String propName)
- Parameters:
propName- the name of the property- Returns:
- the property value
-
getProperties
public BaseTypesMap<java.lang.String,java.lang.Object> getProperties()
-
hashCode
public int hashCode()
{inheritDoc}- Specified by:
hashCodein interfacejava.security.Principal- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
{inheritDoc}- Specified by:
equalsin interfacejava.security.Principal- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
{inheritDoc}- Specified by:
toStringin interfacejava.security.Principal- Overrides:
toStringin classjava.lang.Object
-
compareTo
public int compareTo(AttivioPrincipal other)
{inheritDoc}- Specified by:
compareToin interfacejava.lang.Comparable<AttivioPrincipal>
-
clone
public AttivioPrincipal clone()
- Overrides:
clonein classjava.lang.Object
-
-