public class SecurityContextImpl extends Object implements SecurityContext
Constructor and Description |
---|
SecurityContextImpl(HttpServerExchange exchange,
AuthenticationMode authenticationMode,
IdentityManager identityManager) |
SecurityContextImpl(HttpServerExchange exchange,
IdentityManager identityManager) |
Modifier and Type | Method and Description |
---|---|
void |
addAuthenticationMechanism(AuthenticationMechanism handler)
Adds an authentication mechanism to this context.
|
boolean |
authenticate()
Performs authentication on the request.
|
void |
authenticationComplete(Account account,
String mechanism,
boolean cachingRequired)
Called by the
AuthenticationMechanism to indicate that an account has been successfully authenticated. |
protected void |
authenticationComplete(Account account,
String mechanism,
boolean programatic,
boolean cachingRequired) |
void |
authenticationFailed(String message,
String mechanism)
Called by the
AuthenticationMechanism to indicate that an authentication attempt has failed. |
Account |
getAuthenticatedAccount()
Obtain the
Account for the currently authenticated identity. |
List<AuthenticationMechanism> |
getAuthenticationMechanisms() |
IdentityManager |
getIdentityManager()
Obtain the associated
IdentityManager to use to make account verification decisions. |
String |
getMechanismName() |
boolean |
isAuthenticated() |
boolean |
isAuthenticationRequired()
Returns true if authentication is required
|
boolean |
login(String username,
String password)
Attempts to log the user in using the provided credentials.
|
void |
logout()
de-authenticates the current exchange.
|
void |
registerNotificationReceiver(NotificationReceiver receiver)
Register a
NotificationReceiver interested in receiving notifications for security events that happen on this SecurityContext. |
void |
removeNotificationReceiver(NotificationReceiver receiver)
Remove a previously registered
NotificationReceiver from this SecurityContext. |
void |
setAuthenticationRequired()
Marks this request as requiring authentication.
|
void |
setProgramaticMechName(String programaticMechName)
Set the name of the mechanism used for authentication to be reported if authentication was handled programatically.
|
public SecurityContextImpl(HttpServerExchange exchange, IdentityManager identityManager)
public SecurityContextImpl(HttpServerExchange exchange, AuthenticationMode authenticationMode, IdentityManager identityManager)
public boolean authenticate()
SecurityContext
true
it can still have committed the response (e.g. form auth redirects back to the original
page). Callers should check that the exchange has not been ended before proceeding.authenticate
in interface SecurityContext
true
if either the request is successfully authenticated or if there is no failure validating the
current request so that the request should continue to be processed, false
if authentication was not
completed and challenge has been prepared for the client.public void setAuthenticationRequired()
SecurityContext
SecurityContext.authenticate()
is called without first calling this method then the request will continue as normal even if the authentication
was not successful.setAuthenticationRequired
in interface SecurityContext
public boolean isAuthenticationRequired()
SecurityContext
isAuthenticationRequired
in interface SecurityContext
true
If authentication is requiredpublic boolean isAuthenticated()
isAuthenticated
in interface SecurityContext
public void setProgramaticMechName(String programaticMechName)
programaticMechName
- public String getMechanismName()
getMechanismName
in interface SecurityContext
public void addAuthenticationMechanism(AuthenticationMechanism handler)
SecurityContext
SecurityContext.authenticate()
is
called mechanisms will be iterated over in the order they are added, and given a chance to authenticate the user.addAuthenticationMechanism
in interface SecurityContext
handler
- The mechanism to addpublic List<AuthenticationMechanism> getAuthenticationMechanisms()
getAuthenticationMechanisms
in interface SecurityContext
public Account getAuthenticatedAccount()
SecurityContext
Account
for the currently authenticated identity.getAuthenticatedAccount
in interface SecurityContext
Account
for the currently authenticated identity or null
if no account is currently authenticated.public IdentityManager getIdentityManager()
SecurityContext
IdentityManager
to use to make account verification decisions.getIdentityManager
in interface SecurityContext
IdentityManager
public boolean login(String username, String password)
SecurityContext
AuthenticatedSessionManager
(if any), so subsequent requests will automatically be authenticated
as this user.
This operation may blocklogin
in interface SecurityContext
username
- The usernamepassword
- The passwordtrue
if the login succeeded, false otherwisepublic void logout()
SecurityContext
logout
in interface SecurityContext
public void authenticationComplete(Account account, String mechanism, boolean cachingRequired)
SecurityContext
AuthenticationMechanism
to indicate that an account has been successfully authenticated.
Note: A successful verification of an account using the IdentityManager
is not the same as a successful
authentication decision, other factors could be taken into account to make the final decision.authenticationComplete
in interface SecurityContext
account
- - The authenticated Account
mechanism
- - The name of the mechanism used to authenticate the account.cachingRequired
- - If this mechanism requires cachingprotected void authenticationComplete(Account account, String mechanism, boolean programatic, boolean cachingRequired)
public void authenticationFailed(String message, String mechanism)
SecurityContext
AuthenticationMechanism
to indicate that an authentication attempt has failed.
This should only be called where an authentication attempt has truly failed, for authentication mechanisms where an
additional round trip with the client is expected this should not be called.
Where possible the failure message should contain the name of the identity that authentication was being attempted for,
however as this is not always possible to identify in advance a generic message may be all that can be reported.authenticationFailed
in interface SecurityContext
message
- - The message describing the failure.mechanism
- - The name of the mechanism reporting the failure.public void registerNotificationReceiver(NotificationReceiver receiver)
SecurityContext
NotificationReceiver
interested in receiving notifications for security events that happen on this SecurityContext.registerNotificationReceiver
in interface SecurityContext
receiver
- - The NotificationReceiver
to register.public void removeNotificationReceiver(NotificationReceiver receiver)
SecurityContext
NotificationReceiver
from this SecurityContext.
If the supplied receiver has not been previously registered this method will fail silently.removeNotificationReceiver
in interface SecurityContext
receiver
- - The NotificationReceiver
to remove.Copyright © 2014 JBoss by Red Hat. All rights reserved.