public class FileBasedUserRepository<U extends RestxPrincipal> extends Object implements UserRepository<U>
One file is used to store users, in json format as a Map<String, U> read with jackson. Example:
[
{
"name": "admin",
"principalRoles": ["restx-admin"]
}
]
Another file is used to store user credentials. Storing credentials separately is a good practice, which allow to have different security policies on the two files, and avoid to have credentials part of the user class. Example:
{
"admin": "tuyvuicxvcx78vdsfuisd"
}
| Constructor and Description |
|---|
FileBasedUserRepository(Class<U> userClass,
com.fasterxml.jackson.databind.ObjectMapper mapper,
U defaultAdmin,
java.nio.file.Path usersPath,
java.nio.file.Path credentialsPath,
boolean reloadOnChange) |
| Modifier and Type | Method and Description |
|---|---|
U |
defaultAdmin()
Returns the default admin to use if none is defined and authentication succeeds.
|
com.google.common.base.Optional<String> |
findCredentialByUserName(String userName)
Finds a user credentials by userName
|
com.google.common.base.Optional<U> |
findUserByName(String name)
Finds a user by name in the repository.
|
boolean |
isAdminDefined()
Tells wether a restx admin is defined in this repository.
|
public FileBasedUserRepository(Class<U> userClass, com.fasterxml.jackson.databind.ObjectMapper mapper, U defaultAdmin, java.nio.file.Path usersPath, java.nio.file.Path credentialsPath, boolean reloadOnChange)
public com.google.common.base.Optional<U> findUserByName(String name)
UserRepositoryfindUserByName in interface UserRepository<U extends RestxPrincipal>public com.google.common.base.Optional<String> findCredentialByUserName(String userName)
UserRepositoryfindCredentialByUserName in interface UserRepository<U extends RestxPrincipal>public boolean isAdminDefined()
UserRepositoryisAdminDefined in interface UserRepository<U extends RestxPrincipal>public U defaultAdmin()
UserRepositorydefaultAdmin in interface UserRepository<U extends RestxPrincipal>Copyright © 2014. All Rights Reserved.