Class Group
- java.lang.Object
-
- org.apache.wiki.auth.authorize.Group
-
public class Group extends java.lang.Object
Groups are a specialized type of ad-hoc role used by the wiki system. Unlike externally-provided roles (such as those provided by an LDAP server or web container), JSPWiki groups can be created dynamically by wiki users, without requiring special container privileges or administrator intervention. They are designed to provide a lightweight role-based access control system that complements existing role systems.
Group names are case-insensitive, and have a few naming restrictions, which are enforced by the
GroupManager:- Groups cannot have the same name as a built-in Role (e.g., "Admin", "Authenticated" etc.)
- Groups cannot have the same name as an existing user
Note: prior to JSPWiki 2.4.19, Group was an interface; it is now a concrete, final class.
Groups are related to
GroupPrincipals. A GroupPrincipal, when injected into the Principal set of a Session's Subject, means that the user is a member of a Group of the same name -- it is, in essence, an "authorization token." GroupPrincipals, unlike Groups, are thread-safe, lightweight and immutable. That's why we use them in Subjects rather than the Groups themselves.- Since:
- 2.3
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedGroup(java.lang.String name, java.lang.String wiki)Protected constructor to prevent direct instantiation except by other package members.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(java.security.Principal user)Adds a Principal to the group.voidclear()Clears all Principals from the group list.booleanequals(java.lang.Object o)Two DefaultGroups are equal if they contain identical member Principals and have the same name.java.util.DategetCreated()Returns the creation date.java.lang.StringgetCreator()Returns the creator of this Group.java.util.DategetLastModified()Returns the last-modified date.java.lang.StringgetModifier()Returns the name of the user who last modified this group.java.lang.StringgetName()The name of the group.java.security.PrincipalgetPrincipal()Returns the GroupPrincipal that represents this Group.java.lang.StringgetWiki()Returns the wiki name.inthashCode()The hashcode is calculated as a XOR sum over all members of the Group.booleanisMember(java.security.Principal principal)Returnstrueif a Principal is a member of the group.java.security.Principal[]members()Returns the members of the group as an array of Principal objects.booleanremove(java.security.Principal user)Removes a Principal from the group.voidsetCreated(java.util.Date date)Sets the created date.voidsetCreator(java.lang.String creator)Sets the creator of this Group.voidsetLastModified(java.util.Date date)Sets the last-modified datevoidsetModifier(java.lang.String modifier)Sets the name of the user who last modified this group.java.lang.StringtoString()Returns a string representation of the Group.
-
-
-
Constructor Detail
-
Group
protected Group(java.lang.String name, java.lang.String wiki)
Protected constructor to prevent direct instantiation except by other package members. Callers should useGroupManager.parseGroup(String, String, boolean)orGroupManager.parseGroup(org.apache.wiki.api.core.Context, boolean). instead.- Parameters:
name- the name of the groupwiki- the wiki the group belongs to
-
-
Method Detail
-
add
public boolean add(java.security.Principal user)
Adds a Principal to the group.- Parameters:
user- the principal to add- Returns:
trueif the operation was successful
-
clear
public void clear()
Clears all Principals from the group list.
-
equals
public boolean equals(java.lang.Object o)
Two DefaultGroups are equal if they contain identical member Principals and have the same name.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the object to compare- Returns:
- the comparison
-
hashCode
public int hashCode()
The hashcode is calculated as a XOR sum over all members of the Group.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code
-
getCreated
public java.util.Date getCreated()
Returns the creation date.- Returns:
- the creation date
-
getCreator
public final java.lang.String getCreator()
Returns the creator of this Group.- Returns:
- the creator
-
getLastModified
public java.util.Date getLastModified()
Returns the last-modified date.- Returns:
- the date and time of last modification
-
getModifier
public final java.lang.String getModifier()
Returns the name of the user who last modified this group.- Returns:
- the modifier
-
getName
public java.lang.String getName()
The name of the group. This is set in the class constructor.- Returns:
- the name of the Group
-
getPrincipal
public java.security.Principal getPrincipal()
Returns the GroupPrincipal that represents this Group.- Returns:
- the group principal
-
getWiki
public java.lang.String getWiki()
Returns the wiki name.- Returns:
- the wiki name
-
isMember
public boolean isMember(java.security.Principal principal)
Returnstrueif a Principal is a member of the group. Specifically, the Principal'sgetName()method must return the same value as one of the Principals in the group member list. The Principal's type does not need to match.- Parameters:
principal- the principal about whom membership status is sought- Returns:
- the result of the operation
-
members
public java.security.Principal[] members()
Returns the members of the group as an array of Principal objects.- Returns:
- the members
-
remove
public boolean remove(java.security.Principal user)
Removes a Principal from the group.- Parameters:
user- the principal to remove- Returns:
trueif the operation was successful
-
setCreated
public void setCreated(java.util.Date date)
Sets the created date.- Parameters:
date- the creation date
-
setCreator
public final void setCreator(java.lang.String creator)
Sets the creator of this Group.- Parameters:
creator- the creator
-
setLastModified
public void setLastModified(java.util.Date date)
Sets the last-modified date- Parameters:
date- the last-modified date
-
setModifier
public final void setModifier(java.lang.String modifier)
Sets the name of the user who last modified this group.- Parameters:
modifier- the modifier
-
toString
public java.lang.String toString()
Returns a string representation of the Group.- Overrides:
toStringin classjava.lang.Object- Returns:
- the string
- See Also:
Object.toString()
-
-