Package org.apache.wiki.auth

# Class WikiPrincipal

java.lang.Object
org.apache.wiki.auth.WikiPrincipal

All Implemented Interfaces:
  `Serializable`, `Comparable<Principal>`, `Principal`

public final class WikiPrincipal extends Object implements Principal, Comparable<Principal>, 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 final Comparator<Principal>`
`COMPARATOR`
Static instance of Comparator that allows Principals to be sorted.
`static final String`
`FULL_NAME`
WikiPrincipal type denoting a user's full name.
`static final Principal`
`GUEST`
Represents an anonymous user.
`static final String`
`LOGIN_NAME`
WikiPrincipal type denoting a user's login name.
`static final String`
`UNSPECIFIED`
Generic WikiPrincipal of unspecified type.
`static final String`
`WIKI_NAME`
WikiPrincipal type denoting a user's wiki name.

## Constructor Summary

Constructors
Constructor
Description
`WikiPrincipal(String name)`
Constructs a new WikiPrincipal with a given name and a type of `UNSPECIFIED`.
`WikiPrincipal(String name, String type)`
Constructs a new WikiPrincipal with a given name and optional type designator.

## Method Summary

Modifier and Type
Method
Description
`int`
`compareTo(Principal o)`
Allows comparisons to any other Principal objects.
`boolean`
`equals(Object obj)`
Two `WikiPrincipal`s are considered equal if their names are equal (case-sensitive).
`String`
`getName()`
Returns the wiki name of the Principal.
`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.
`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 Details

### GUEST

public static final 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 String FULL_NAME
WikiPrincipal type denoting a user's full name.

See Also:
  - Constant Field Values

### LOGIN_NAME

public static final String LOGIN_NAME
WikiPrincipal type denoting a user's login name.

See Also:
  - Constant Field Values

### WIKI_NAME

public static final String WIKI_NAME
WikiPrincipal type denoting a user's wiki name.

See Also:
  - Constant Field Values

### UNSPECIFIED

public static final String UNSPECIFIED
Generic WikiPrincipal of unspecified type.

See Also:
  - Constant Field Values

### COMPARATOR

public static final Comparator<Principal> COMPARATOR
Static instance of Comparator that allows Principals to be sorted.

## Constructor Details

### WikiPrincipal

public WikiPrincipal(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(String name, 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 Details

### getName

public String getName()
Returns the wiki name of the Principal.

Specified by:
  `getName` in interface `Principal`
Returns:
  the name

### equals

public boolean equals(Object obj)
Two `WikiPrincipal`s are considered equal if their names are equal (case-sensitive).

Specified by:
  `equals` in interface `Principal`
Overrides:
  `equals` in class `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 `Principal`
Overrides:
  `hashCode` in class `Object`
Returns:
  the hash code

### getType

public String getType()
Returns the Principal "type": `LOGIN_NAME`, `FULL_NAME`, `WIKI_NAME` or `WIKI_NAME`

Returns:
  the type

### toString

public String toString()
Returns a human-readable representation of the object.

Specified by:
  `toString` in interface `Principal`
Overrides:
  `toString` in class `Object`
Returns:
  the string representation

### compareTo

public int compareTo(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 `Comparable<Principal>`
Since:
  2.7.0