@SessionScoped public class KeycloakAuthenticationService extends Object implements AuthenticationService, Serializable
An AuthenticationService
implementation that integrates with Keycloak. This
implementation optionally wraps another AuthenticationService
so that an app can have
local and foreign user authentication.
Some important behaviour of this implementation:
login(String, String)
method throws an FailedAuthenticationException
if
there is no wrapped AuthenticationService
.
User
has depends on which properties have
been enabled in Keycloak. The user instance returned will have all values from the Keycloak
AccessToken
pertaining to the user that were not null.Constructor and Description |
---|
KeycloakAuthenticationService() |
Modifier and Type | Method and Description |
---|---|
protected User |
createKeycloakUser(org.keycloak.representations.AccessToken accessToken) |
User |
getUser()
Get the currently authenticated user.
|
boolean |
isLoggedIn() |
User |
login(String username,
String password)
Login with the given username and password, throwing an exception if the login fails.
|
void |
logout()
Log out the currently authenticated user.
|
public User login(String username, String password)
AuthenticationService
login
in interface AuthenticationService
username
- The username to log in with.password
- The password to authenticate with.User
.public boolean isLoggedIn()
isLoggedIn
in interface AuthenticationService
public void logout()
AuthenticationService
logout
in interface AuthenticationService
public User getUser()
AuthenticationService
getUser
in interface AuthenticationService
null
. If no
user is logged in, returns User.ANONYMOUS
.protected User createKeycloakUser(org.keycloak.representations.AccessToken accessToken)
Copyright © 2013-2015 JBoss, a division of Red Hat. All Rights Reserved.