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 class
AttivioPrincipal.PrincipalType
Contains the possible principal types.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ANONYMOUS
Constant to signify anonymous (realm or user).static AttivioPrincipal
ANONYMOUS_USER
Represents the anonymous user (whose realm ID, principal ID, and principal name areANONYMOUS
).static java.lang.String
ANONYMOUS_USER_GUID
The GUID of the anonymous user.protected java.util.UUID
correlationId
correlation id if setstatic java.lang.String
FIELD_PRINCIPAL_ID
The name of the field that stores the principal ID.static java.lang.String
FIELD_PRINCIPAL_NAME
The name of the field that stores the principal name.static java.lang.String
FIELD_REALM_ID
The name of the field that stores the security realm ID.protected java.util.Set<AttivioGroupMembership>
groupMemberships
Any group memberships of this principal.static java.lang.String
PARAMETER_PRINCIPAL_ID
The CGI parameter or query request property for the principal ID.static java.lang.String
PARAMETER_PRINCIPAL_NAME
The CGI parameter or query request property for the principal name.static java.lang.String
PARAMETER_REALM_ID
The CGI parameter or query request property for the realm ID.static java.lang.String
PRIN_NAME_UNKNOWN
The constant for the 'unknown' principal name.protected java.lang.String
principalId
The principal ID.protected java.lang.String
principalName
The principal name.protected AttivioPrincipal.PrincipalType
principalType
The principal type.protected BaseTypesMap<java.lang.String,java.lang.Object>
properties
Any additional properties.protected java.lang.String
realmId
The security realm ID.protected java.util.Set<AttivioRole>
roles
Optional roles used by the Security Client API authorization.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AttivioPrincipal()
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 void
addGroupMembership(AttivioGroupMembership groupMembership)
Adds a group membership to the set of this principal's group memberships.void
addRole(AttivioRole role)
Add a role to the principal.AttivioPrincipal
clone()
int
compareTo(AttivioPrincipal other)
{inheritDoc}boolean
equals(java.lang.Object obj)
{inheritDoc}static AttivioPrincipal
fromPrincipalString(java.lang.String principalString)
Creates an attivio principal from a principal string in the form of realmId:principalId:principalNamejava.util.UUID
getCorrelationId()
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.String
getName()
java.lang.String
getPassword()
java.lang.String
getPrincipalId()
AttivioPrincipalKey
getPrincipalKey()
java.lang.String
getPrincipalName()
java.lang.String
getPrincipalString()
AttivioPrincipal.PrincipalType
getPrincipalType()
BaseTypesMap<java.lang.String,java.lang.Object>
getProperties()
java.lang.Object
getProperty(java.lang.String propName)
java.lang.String
getRealmId()
java.util.Set<AttivioRole>
getRoles()
java.util.Set<AttivioRole>
getRoles(java.lang.Enum<?> enumRole)
Return allAttivioRole
objects that have the same name as the givenEnum
.java.util.Set<AttivioRole>
getRoles(java.lang.String roleName)
Return allAttivioRole
objects that have the given role name.int
hashCode()
{inheritDoc}boolean
hasRole(java.lang.Enum<?> enumRole)
Equivalent to hasRule(enumRole, AttivioRole.SUBGROUP_ANY);boolean
hasRole(java.lang.Enum<?> enumRole, java.lang.String subgroup)
boolean
hasRole(java.lang.String role)
Equivalent to hasRule(role , AttivioRole.SUBGROUP_ANY);boolean
hasRole(java.lang.String roleName, java.lang.String subgroup)
boolean
isAnonymous()
static boolean
isAnonymous(AttivioPrincipalKey prinKey)
static boolean
isAnonymous(java.lang.String realmId, java.lang.String principalId)
boolean
isGroup()
boolean
isUser()
boolean
removeGroupMembership(AttivioGroupMembership groupMembership)
Removes a group membership from the set of this principal's group memberships.void
setCorrelationId(java.util.UUID correlationId)
Set the correlation idvoid
setGroupMemberships(java.util.Set<AttivioGroupMembership> groupMemberships)
Sets the group memberships for this principal.void
setPassword(java.lang.String password)
Set a password with this principalvoid
setPrincipalId(java.lang.String principalId)
Sets the principal ID.void
setPrincipalName(java.lang.String principalName)
Sets the principal name.void
setPrincipalType(AttivioPrincipal.PrincipalType principalType)
Set the principal typevoid
setProperty(java.lang.String propName, java.lang.Object propValue)
Sets a property on the principal.void
setRealmId(java.lang.String realmId)
Sets the realm ID.void
setRoles(java.util.Set<AttivioRole> roles)
Set roles for this principal.java.lang.String
toString()
{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:
getName
in 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 allAttivioRole
objects 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 allAttivioRole
objects 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:
hashCode
in interfacejava.security.Principal
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
{inheritDoc}- Specified by:
equals
in interfacejava.security.Principal
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
{inheritDoc}- Specified by:
toString
in interfacejava.security.Principal
- Overrides:
toString
in classjava.lang.Object
-
compareTo
public int compareTo(AttivioPrincipal other)
{inheritDoc}- Specified by:
compareTo
in interfacejava.lang.Comparable<AttivioPrincipal>
-
clone
public AttivioPrincipal clone()
- Overrides:
clone
in classjava.lang.Object
-
-