Package com.floragunn.searchguard.user
Class User
- java.lang.Object
-
- com.floragunn.searchguard.user.User
-
- All Implemented Interfaces:
CustomAttributesAware,Serializable,org.elasticsearch.common.io.stream.Writeable
public class User extends Object implements Serializable, org.elasticsearch.common.io.stream.Writeable, CustomAttributesAware
A authenticated user and attributes associated to them (like roles, tenant, custom attributes) Do not subclass from this class!- See Also:
- Serialized Form
-
-
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, Collection<String> roles, AuthCredentials customAttributes)Create a new authenticated userUser(org.elasticsearch.common.io.stream.StreamInput in)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttributes(Map<String,String> attributes)Associate this user with a set of rolesvoidaddRole(String role)Associate this user with a backend rolevoidaddRoles(Collection<String> roles)Associate this user with a set of backend rolesvoidaddSearchGuardRoles(Collection<String> sgRoles)voidcopyRolesFrom(User user)Copy all backend roles from another userbooleanequals(Object obj)Map<String,String>getCustomAttributesMap()Get the custom attributes associated with this userStringgetName()StringgetRequestedTenant()Set<String>getRoles()Set<String>getSearchGuardRoles()inthashCode()booleanisInjected()booleanisUserInRole(String role)Check if this user is a member of a backend rolevoidsetInjected(boolean isInjected)voidsetRequestedTenant(String requestedTenant)StringtoString()StringtoStringWithAttributes()voidwriteTo(org.elasticsearch.common.io.stream.StreamOutput out)
-
-
-
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(org.elasticsearch.common.io.stream.StreamInput in) throws IOException- Throws:
IOException
-
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
-
getName
public final String getName()
-
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
public final void addAttributes(Map<String,String> attributes)
Associate this user with a set of roles- Parameters:
roles- The roles
-
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()
-
copyRolesFrom
public final void copyRolesFrom(User user)
Copy all backend roles from another user- Parameters:
user- The user from which the backend roles should be copied over
-
writeTo
public void writeTo(org.elasticsearch.common.io.stream.StreamOutput out) throws IOException- Specified by:
writeToin interfaceorg.elasticsearch.common.io.stream.Writeable- Throws:
IOException
-
getCustomAttributesMap
public final Map<String,String> getCustomAttributesMap()
Get 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)
-
-