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 forSecurityContextimplementations 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 classAbstractSecurityContext.Node<T>To reduce allocations we use a custom linked list data structure
-
Field Summary
Fields Modifier and Type Field Description protected HttpServerExchangeexchange
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSecurityContext(HttpServerExchange exchange)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidauthenticationComplete(Account account, java.lang.String mechanism, boolean cachingRequired)Called by theAuthenticationMechanismto indicate that an account has been successfully authenticated.protected voidauthenticationComplete(Account account, java.lang.String mechanism, boolean programatic, boolean cachingRequired)voidauthenticationFailed(java.lang.String message, java.lang.String mechanism)Called by theAuthenticationMechanismto indicate that an authentication attempt has failed.AccountgetAuthenticatedAccount()Obtain theAccountfor the currently authenticated identity.java.lang.StringgetMechanismName()booleanisAuthenticated()booleanisAuthenticationRequired()Returns true if authentication is requiredvoidlogout()de-authenticates the current exchange.voidregisterNotificationReceiver(NotificationReceiver receiver)Register aNotificationReceiverinterested in receiving notifications for security events that happen on this SecurityContext.voidremoveNotificationReceiver(NotificationReceiver receiver)Remove a previously registeredNotificationReceiverfrom this SecurityContext.voidsetAuthenticationRequired()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:SecurityContextMarks 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:
setAuthenticationRequiredin interfaceSecurityContext
-
isAuthenticationRequired
public boolean isAuthenticationRequired()
Description copied from interface:SecurityContextReturns true if authentication is required- Specified by:
isAuthenticationRequiredin interfaceSecurityContext- Returns:
trueIf authentication is required
-
isAuthenticated
public boolean isAuthenticated()
- Specified by:
isAuthenticatedin interfaceSecurityContext- Returns:
- true if a user has been authenticated for this request, false otherwise.
-
getAuthenticatedAccount
public Account getAuthenticatedAccount()
Description copied from interface:SecurityContextObtain theAccountfor the currently authenticated identity.- Specified by:
getAuthenticatedAccountin interfaceSecurityContext- Returns:
- The
Accountfor the currently authenticated identity ornullif no account is currently authenticated.
-
getMechanismName
public java.lang.String getMechanismName()
- Specified by:
getMechanismNamein 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:SecurityContextCalled by theAuthenticationMechanismto indicate that an account has been successfully authenticated. Note: A successful verification of an account using theIdentityManageris not the same as a successful authentication decision, other factors could be taken into account to make the final decision.- Specified by:
authenticationCompletein interfaceSecurityContext- Parameters:
account- - The authenticatedAccountmechanism- - 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:SecurityContextCalled by theAuthenticationMechanismto 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:
authenticationFailedin 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:SecurityContextRegister aNotificationReceiverinterested in receiving notifications for security events that happen on this SecurityContext.- Specified by:
registerNotificationReceiverin interfaceSecurityContext- Parameters:
receiver- - TheNotificationReceiverto register.
-
removeNotificationReceiver
public void removeNotificationReceiver(NotificationReceiver receiver)
Description copied from interface:SecurityContextRemove a previously registeredNotificationReceiverfrom this SecurityContext. If the supplied receiver has not been previously registered this method will fail silently.- Specified by:
removeNotificationReceiverin interfaceSecurityContext- Parameters:
receiver- - TheNotificationReceiverto remove.
-
logout
public void logout()
Description copied from interface:SecurityContextde-authenticates the current exchange.- Specified by:
logoutin interfaceSecurityContext
-
-