Class WikiPrincipal

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<java.security.Principal>, java.security.Principal

    public final class WikiPrincipal
    extends java.lang.Object
    implements java.security.Principal, java.lang.Comparable<java.security.Principal>, java.io.Serializable
    A lightweight, immutable Principal class. WikiPrincipals can be created with and optional "type" to denote what type of user profile Principal it represents (FULL_NAME, WIKI_NAME, LOGIN_NAME). Types are used to determine suitable user and login Principals in classes like Session. However, the type property of a WikiPrincipal does not affect a WikiPrincipal's logical equality or hash code; two WikiPrincipals with the same name but different types are still considered equal.
    Since:
    2.2
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.Comparator<java.security.Principal> COMPARATOR
      Static instance of Comparator that allows Principals to be sorted.
      static java.lang.String FULL_NAME
      WikiPrincipal type denoting a user's full name.
      static java.security.Principal GUEST
      Represents an anonymous user.
      static java.lang.String LOGIN_NAME
      WikiPrincipal type denoting a user's login name.
      static java.lang.String UNSPECIFIED
      Generic WikiPrincipal of unspecified type.
      static java.lang.String WIKI_NAME
      WikiPrincipal type denoting a user's wiki name.
    • Constructor Summary

      Constructors 
      Constructor Description
      WikiPrincipal​(java.lang.String name)
      Constructs a new WikiPrincipal with a given name and a type of UNSPECIFIED.
      WikiPrincipal​(java.lang.String name, java.lang.String type)
      Constructs a new WikiPrincipal with a given name and optional type designator.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(java.security.Principal o)
      Allows comparisons to any other Principal objects.
      boolean equals​(java.lang.Object obj)
      Two WikiPrincipals are considered equal if their names are equal (case-sensitive).
      java.lang.String getName()
      Returns the wiki name of the Principal.
      java.lang.String getType()
      Returns the Principal "type": LOGIN_NAME, FULL_NAME, WIKI_NAME or WIKI_NAME
      int hashCode()
      The hashCode() returned for the WikiPrincipal is the same as for its name.
      java.lang.String toString()
      Returns a human-readable representation of the object.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.security.Principal

        implies
    • Field Detail

      • GUEST

        public static final java.security.Principal GUEST
        Represents an anonymous user. WikiPrincipals may be created with an optional type designator: LOGIN_NAME, WIKI_NAME, FULL_NAME or UNSPECIFIED.
      • COMPARATOR

        public static final java.util.Comparator<java.security.Principal> COMPARATOR
        Static instance of Comparator that allows Principals to be sorted.
    • Constructor Detail

      • WikiPrincipal

        public WikiPrincipal​(java.lang.String name)
        Constructs a new WikiPrincipal with a given name and a type of UNSPECIFIED.
        Parameters:
        name - the name of the Principal
      • WikiPrincipal

        public WikiPrincipal​(java.lang.String name,
                             java.lang.String type)
        Constructs a new WikiPrincipal with a given name and optional type designator. If the supplied type parameter is not LOGIN_NAME, FULL_NAME, WIKI_NAME or WIKI_NAME, this method throws an IllegalArgumentException.
        Parameters:
        name - the name of the Principal
        type - the type for this principal, which may be LOGIN_NAME, FULL_NAME, WIKI_NAME or WIKI_NAME.
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns the wiki name of the Principal.
        Specified by:
        getName in interface java.security.Principal
        Returns:
        the name
      • equals

        public boolean equals​(java.lang.Object obj)
        Two WikiPrincipals are considered equal if their names are equal (case-sensitive).
        Specified by:
        equals in interface java.security.Principal
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object to compare
        Returns:
        the result of the equality test
      • hashCode

        public int hashCode()
        The hashCode() returned for the WikiPrincipal is the same as for its name.
        Specified by:
        hashCode in interface java.security.Principal
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code
      • toString

        public java.lang.String toString()
        Returns a human-readable representation of the object.
        Specified by:
        toString in interface java.security.Principal
        Overrides:
        toString in class java.lang.Object
        Returns:
        the string representation
      • compareTo

        public int compareTo​(java.security.Principal o)
        Allows comparisons to any other Principal objects. Primary sorting order is by the principal name, returned by getName(), as defined by PrincipalComparator.
        Specified by:
        compareTo in interface java.lang.Comparable<java.security.Principal>
        Since:
        2.7.0