Package io.undertow.security.impl
Class AbstractSecurityContext
- java.lang.Object
-
- io.undertow.security.impl.AbstractSecurityContext
-
- All Implemented Interfaces:
SecurityContext
- Direct Known Subclasses:
SecurityContextImpl
public abstract class AbstractSecurityContext extends java.lang.Object implements SecurityContext
A base class forSecurityContext
implementations predominantly focusing on the notification handling allowing the specific implementation for focus on authentication.- Author:
- Darran Lofthouse
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractSecurityContext.Node<T>
To reduce allocations we use a custom linked list data structure
-
Field Summary
Fields Modifier and Type Field Description protected HttpServerExchange
exchange
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractSecurityContext(HttpServerExchange exchange)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
authenticationComplete(Account account, java.lang.String mechanism, boolean cachingRequired)
Called by theAuthenticationMechanism
to indicate that an account has been successfully authenticated.protected void
authenticationComplete(Account account, java.lang.String mechanism, boolean programatic, boolean cachingRequired)
void
authenticationFailed(java.lang.String message, java.lang.String mechanism)
Called by theAuthenticationMechanism
to indicate that an authentication attempt has failed.Account
getAuthenticatedAccount()
Obtain theAccount
for the currently authenticated identity.java.lang.String
getMechanismName()
boolean
isAuthenticated()
boolean
isAuthenticationRequired()
Returns true if authentication is requiredvoid
logout()
de-authenticates the current exchange.void
registerNotificationReceiver(NotificationReceiver receiver)
Register aNotificationReceiver
interested in receiving notifications for security events that happen on this SecurityContext.void
removeNotificationReceiver(NotificationReceiver receiver)
Remove a previously registeredNotificationReceiver
from this SecurityContext.void
setAuthenticationRequired()
Marks this request as requiring authentication.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.undertow.security.api.SecurityContext
addAuthenticationMechanism, authenticate, getAuthenticationMechanisms, getIdentityManager, login
-
-
-
-
Field Detail
-
exchange
protected final HttpServerExchange exchange
-
-
Constructor Detail
-
AbstractSecurityContext
protected AbstractSecurityContext(HttpServerExchange exchange)
-
-
Method Detail
-
setAuthenticationRequired
public void setAuthenticationRequired()
Description copied from interface:SecurityContext
Marks this request as requiring authentication. Authentication challenge headers will only be sent if this method has been called. IfSecurityContext.authenticate()
is called without first calling this method then the request will continue as normal even if the authentication was not successful.- Specified by:
setAuthenticationRequired
in interfaceSecurityContext
-
isAuthenticationRequired
public boolean isAuthenticationRequired()
Description copied from interface:SecurityContext
Returns true if authentication is required- Specified by:
isAuthenticationRequired
in interfaceSecurityContext
- Returns:
true
If authentication is required
-
isAuthenticated
public boolean isAuthenticated()
- Specified by:
isAuthenticated
in interfaceSecurityContext
- Returns:
- true if a user has been authenticated for this request, false otherwise.
-
getAuthenticatedAccount
public Account getAuthenticatedAccount()
Description copied from interface:SecurityContext
Obtain theAccount
for the currently authenticated identity.- Specified by:
getAuthenticatedAccount
in interfaceSecurityContext
- Returns:
- The
Account
for the currently authenticated identity ornull
if no account is currently authenticated.
-
getMechanismName
public java.lang.String getMechanismName()
- Specified by:
getMechanismName
in interfaceSecurityContext
- Returns:
- The name of the mechanism used to authenticate the request.
-
authenticationComplete
public void authenticationComplete(Account account, java.lang.String mechanism, boolean cachingRequired)
Description copied from interface:SecurityContext
Called by theAuthenticationMechanism
to indicate that an account has been successfully authenticated. Note: A successful verification of an account using theIdentityManager
is not the same as a successful authentication decision, other factors could be taken into account to make the final decision.- Specified by:
authenticationComplete
in interfaceSecurityContext
- Parameters:
account
- - The authenticatedAccount
mechanism
- - The name of the mechanism used to authenticate the account.cachingRequired
- - If this mechanism requires caching
-
authenticationComplete
protected void authenticationComplete(Account account, java.lang.String mechanism, boolean programatic, boolean cachingRequired)
-
authenticationFailed
public void authenticationFailed(java.lang.String message, java.lang.String mechanism)
Description copied from interface:SecurityContext
Called by theAuthenticationMechanism
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.- Specified by:
authenticationFailed
in interfaceSecurityContext
- Parameters:
message
- - The message describing the failure.mechanism
- - The name of the mechanism reporting the failure.
-
registerNotificationReceiver
public void registerNotificationReceiver(NotificationReceiver receiver)
Description copied from interface:SecurityContext
Register aNotificationReceiver
interested in receiving notifications for security events that happen on this SecurityContext.- Specified by:
registerNotificationReceiver
in interfaceSecurityContext
- Parameters:
receiver
- - TheNotificationReceiver
to register.
-
removeNotificationReceiver
public void removeNotificationReceiver(NotificationReceiver receiver)
Description copied from interface:SecurityContext
Remove a previously registeredNotificationReceiver
from this SecurityContext. If the supplied receiver has not been previously registered this method will fail silently.- Specified by:
removeNotificationReceiver
in interfaceSecurityContext
- Parameters:
receiver
- - TheNotificationReceiver
to remove.
-
logout
public void logout()
Description copied from interface:SecurityContext
de-authenticates the current exchange.- Specified by:
logout
in interfaceSecurityContext
-
-