Package com.floragunn.searchguard.user
Class User
- java.lang.Object
-
- com.floragunn.searchguard.user.User
-
- All Implemented Interfaces:
CustomAttributesAware,Serializable
public class User extends Object implements Serializable, CustomAttributesAware
A authenticated user and attributes associated to them (like roles, tenant, custom attributes) Do not subclass from this class!- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUser.Builder
-
Field Summary
Fields Modifier and Type Field Description static UserANONYMOUSstatic StringUSER_TENANT
-
Constructor Summary
Constructors Constructor Description User(String name)Create a new authenticated user without roles and attributesUser(String name, String subName, Set<String> roles, Set<String> searchGuardRoles, String requestedTenant, Map<String,Object> structuredAttributes, Map<String,String> attributes, boolean isInjected)User(String name, Collection<String> roles, AuthCredentials customAttributes)Create a new authenticated user
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddAttributes(Map<String,String> attributes)Deprecated.Use structured attributes insteadvoidaddRole(String role)Associate this user with a backend rolevoidaddRoles(Collection<String> roles)Associate this user with a set of backend rolesvoidaddSearchGuardRoles(Collection<String> sgRoles)voidaddStructuredAttribute(String key, Object value)booleanequals(Object obj)static User.BuilderforUser(String username)Map<String,String>getCustomAttributesMap()Deprecated.use getStructuredAttributes() insteadStringgetName()StringgetRequestedTenant()Set<String>getRoles()Set<String>getSearchGuardRoles()Map<String,Object>getStructuredAttributes()StringgetSubName()inthashCode()booleanisInjected()booleanisUserInRole(String role)Check if this user is a member of a backend rolevoidsetInjected(boolean isInjected)voidsetRequestedTenant(String requestedTenant)StringtoString()StringtoStringWithAttributes()
-
-
-
Field Detail
-
ANONYMOUS
public static final User ANONYMOUS
-
USER_TENANT
public static final String USER_TENANT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
User
public User(String name, String subName, Set<String> roles, Set<String> searchGuardRoles, String requestedTenant, Map<String,Object> structuredAttributes, Map<String,String> attributes, boolean isInjected)
-
User
public User(String name, Collection<String> roles, AuthCredentials customAttributes)
Create a new authenticated user- Parameters:
name- The username (must not be null or empty)roles- Roles of which the user is a member off (maybe null)customAttributes- Custom attributes associated with this (maybe null)- Throws:
IllegalArgumentException- if name is null or empty
-
User
public User(String name)
Create a new authenticated user without roles and attributes- Parameters:
name- The username (must not be null or empty)- Throws:
IllegalArgumentException- if name is null or empty
-
-
Method Detail
-
forUser
public static User.Builder forUser(String username)
-
getName
public final String getName()
-
getSubName
public String getSubName()
-
getRoles
public final Set<String> getRoles()
- Returns:
- A unmodifiable set of the backend roles this user is a member of
-
addRole
public final void addRole(String role)
Associate this user with a backend role- Parameters:
role- The backend role
-
addRoles
public final void addRoles(Collection<String> roles)
Associate this user with a set of backend roles- Parameters:
roles- The backend roles
-
isUserInRole
public final boolean isUserInRole(String role)
Check if this user is a member of a backend role- Parameters:
role- The backend role- Returns:
- true if this user is a member of the backend role, false otherwise
-
addAttributes
@Deprecated public final void addAttributes(Map<String,String> attributes)
Deprecated.Use structured attributes instead
-
getRequestedTenant
public final String getRequestedTenant()
-
setRequestedTenant
public final void setRequestedTenant(String requestedTenant)
-
isInjected
public boolean isInjected()
-
setInjected
public void setInjected(boolean isInjected)
-
toStringWithAttributes
public final String toStringWithAttributes()
-
getCustomAttributesMap
@Deprecated public final Map<String,String> getCustomAttributesMap()
Deprecated.use getStructuredAttributes() insteadGet the custom attributes associated with this user- Specified by:
getCustomAttributesMapin interfaceCustomAttributesAware- Returns:
- A modifiable map with all the current custom attributes associated with this user
-
addSearchGuardRoles
public final void addSearchGuardRoles(Collection<String> sgRoles)
-
-