Class 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
    • 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 are ANONYMOUS).
      • 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.
      • 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 empty
        principalId - the principal ID; may not be null or empty
        principalName - the principal name; may be null or empty
        principalType - 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 null
        principalName - the principal name; may be null or empty
        principalType - 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
      • 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 interface java.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
      • 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 ID
        principalId - 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 all AttivioRole 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 name
        subgroup - subgroup id,resource id, or AttivioRole.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 roles
        subgroup - subgroup ID, resource ID, or AttivioRole.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 all AttivioRole objects that have the same name as the given Enum.
        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 name
        propValue - 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 interface java.security.Principal
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        {inheritDoc}
        Specified by:
        equals in interface java.security.Principal
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        {inheritDoc}
        Specified by:
        toString in interface java.security.Principal
        Overrides:
        toString in class java.lang.Object
      • clone

        public AttivioPrincipal clone()
        Overrides:
        clone in class java.lang.Object