Package org.apache.wiki.auth
Class WikiPrincipal
- java.lang.Object
-
- org.apache.wiki.auth.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 ofUNSPECIFIED
.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)
TwoWikiPrincipal
s 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()
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.
-
-
-
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.
-
FULL_NAME
public static final java.lang.String FULL_NAME
WikiPrincipal type denoting a user's full name.- See Also:
- Constant Field Values
-
LOGIN_NAME
public static final java.lang.String LOGIN_NAME
WikiPrincipal type denoting a user's login name.- See Also:
- Constant Field Values
-
WIKI_NAME
public static final java.lang.String WIKI_NAME
WikiPrincipal type denoting a user's wiki name.- See Also:
- Constant Field Values
-
UNSPECIFIED
public static final java.lang.String UNSPECIFIED
Generic WikiPrincipal of unspecified type.- See Also:
- Constant Field Values
-
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 ofUNSPECIFIED
.- 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 suppliedtype
parameter is notLOGIN_NAME
,FULL_NAME
,WIKI_NAME
orWIKI_NAME
, this method throws anIllegalArgumentException
.- Parameters:
name
- the name of the Principaltype
- the type for this principal, which may beLOGIN_NAME
,FULL_NAME
,WIKI_NAME
orWIKI_NAME
.
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns the wiki name of the Principal.- Specified by:
getName
in interfacejava.security.Principal
- Returns:
- the name
-
equals
public boolean equals(java.lang.Object obj)
TwoWikiPrincipal
s are considered equal if their names are equal (case-sensitive).- Specified by:
equals
in interfacejava.security.Principal
- Overrides:
equals
in classjava.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 interfacejava.security.Principal
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hash code
-
getType
public java.lang.String getType()
- Returns:
- the type
-
toString
public java.lang.String toString()
Returns a human-readable representation of the object.- Specified by:
toString
in interfacejava.security.Principal
- Overrides:
toString
in classjava.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 byPrincipalComparator
.- Specified by:
compareTo
in interfacejava.lang.Comparable<java.security.Principal>
- Since:
- 2.7.0
-
-