Top Description Methods
io.undertow.security.api

public Interface SecurityContext

Known Direct Subinterfaces
io.undertow.security.api.AuthenticationMechanismContext
Known Direct Implementers
io.undertow.security.impl.AbstractSecurityContext
Imports
io.undertow.security.idm.Account, .IdentityManager, java.util.List

The security context. This context is attached to the exchange and holds all security related information.
Authors
Stuart Douglas, Darran Lofthouse
See Also
io.undertow.security.impl.SecurityContextImpl

Method Summary

Modifier and TypeMethod and Description
public void
addAuthenticationMechanism(AuthenticationMechanism
The mechanism to add
mechanism
)
Deprecated for removal since 1.3.0. This method is now only applicable to SecurityContext implementations that also implement the AuthenticationMechanismContext interface.

Adds an authentication mechanism to this context.

public boolean

Returns:

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.
authenticate
()

Performs authentication on the request.

public void
authenticationComplete(final Account
- The authenticated Account
account
,
final String
- The name of the mechanism used to authenticate the account.
mechanismName
,
final boolean
- If this mechanism requires caching
cachingRequired
)

Called by the AuthenticationMechanism to indicate that an account has been successfully authenticated.

public void
authenticationFailed(final String
- The message describing the failure.
message
,
final String
- The name of the mechanism reporting the failure.
mechanismName
)

Called by the AuthenticationMechanism to indicate that an authentication attempt has failed.

public Account

Returns:

The Account for the currently authenticated identity or null if no account is currently authenticated.
getAuthenticatedAccount
()

Obtain the Account for the currently authenticated identity.

public List<AuthenticationMechanism>

Returns:

A list of all authentication mechanisms in this context
getAuthenticationMechanisms
()
Deprecated for removal since 1.3.0. Obtaining lists of mechanisms is discouraged, however there should not be a need to call this anyway.

public IdentityManager

Returns:

The associated IdentityManager
getIdentityManager
()
Deprecated for removal since 1.2.0. Authentication mechanisms that rely on the IdentityManager should instead hold their own reference to it.

Obtain the associated IdentityManager to use to make account verification decisions.

public String

Returns:

The name of the mechanism that was used to authenticate
getMechanismName
()

public boolean

Returns:

true if a user has been authenticated for this request, false otherwise.
isAuthenticated
()

public boolean

Returns:

true If authentication is required
isAuthenticationRequired
()

Returns true if authentication is required

public boolean

Returns:

true if the login succeeded, false otherwise
login
(String
The username
username
,
String
The password
password
)

Attempts to log the user in using the provided credentials.

public void
logout()

de-authenticates the current exchange.

public void
registerNotificationReceiver(final NotificationReceiver
- The NotificationReceiver to register.
receiver
)

Register a NotificationReceiver interested in receiving notifications for security events that happen on this SecurityContext.

public void
removeNotificationReceiver(final NotificationReceiver
- The NotificationReceiver to remove.
receiver
)

Remove a previously registered NotificationReceiver from this SecurityContext.

public void
setAuthenticationRequired()

Marks this request as requiring authentication.

Method Detail

addAuthenticationMechanismback to summary
public void addAuthenticationMechanism(AuthenticationMechanism mechanism)

Deprecated

for removal since 1.3.0.

This method is now only applicable to SecurityContext implementations that also implement the AuthenticationMechanismContext interface.

Adds an authentication mechanism to this context. When authenticate() is called mechanisms will be iterated over in the order they are added, and given a chance to authenticate the user.

Parameters
mechanism:AuthenticationMechanism

The mechanism to add

Annotations
@Deprecated
since:1.3.0
forRemoval:true
authenticateback to summary
public boolean authenticate()

Performs authentication on the request. If authentication is REQUIRED then setAuthenticationRequired() should be called before calling this method. If the result indicates that a response has been sent to the client then no further attempts should be made to modify the response. The caller of this method is responsible for ending the exchange. If this method returns 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.

Returns:boolean

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.

authenticationCompleteback to summary
public void authenticationComplete(final Account account, final String mechanismName, final boolean cachingRequired)

Called by the 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.

Parameters
account:Account

- The authenticated Account

mechanismName:String

- The name of the mechanism used to authenticate the account.

cachingRequired:boolean

- If this mechanism requires caching

authenticationFailedback to summary
public void authenticationFailed(final String message, final String mechanismName)

Called by the 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.

Parameters
message:String

- The message describing the failure.

mechanismName:String

- The name of the mechanism reporting the failure.

getAuthenticatedAccountback to summary
public Account getAuthenticatedAccount()

Obtain the Account for the currently authenticated identity.

Returns:Account

The Account for the currently authenticated identity or null if no account is currently authenticated.

getAuthenticationMechanismsback to summary
public List<AuthenticationMechanism> getAuthenticationMechanisms()

Deprecated

for removal since 1.3.0.

Obtaining lists of mechanisms is discouraged, however there should not be a need to call this anyway.

Returns:List<AuthenticationMechanism>

A list of all authentication mechanisms in this context

Annotations
@Deprecated
since:1.3.0
forRemoval:true
getIdentityManagerback to summary
public IdentityManager getIdentityManager()

Deprecated

for removal since 1.2.0.

Authentication mechanisms that rely on the IdentityManager should instead hold their own reference to it.

Obtain the associated IdentityManager to use to make account verification decisions.

Returns:IdentityManager

The associated IdentityManager

Annotations
@Deprecated
since:1.2.0
forRemoval:true
getMechanismNameback to summary
public String getMechanismName()
Returns:String

The name of the mechanism that was used to authenticate

isAuthenticatedback to summary
public boolean isAuthenticated()
Returns:boolean

true if a user has been authenticated for this request, false otherwise.

isAuthenticationRequiredback to summary
public boolean isAuthenticationRequired()

Returns true if authentication is required

Returns:boolean

true If authentication is required

loginback to summary
public boolean login(String username, String password)

Attempts to log the user in using the provided credentials. This result will be stored in the current AuthenticatedSessionManager (if any), so subsequent requests will automatically be authenticated as this user.

This operation may block

Parameters
username:String

The username

password:String

The password

Returns:boolean

true if the login succeeded, false otherwise

logoutback to summary
public void logout()

de-authenticates the current exchange.

registerNotificationReceiverback to summary
public void registerNotificationReceiver(final NotificationReceiver receiver)

Register a NotificationReceiver interested in receiving notifications for security events that happen on this SecurityContext.

Parameters
receiver:NotificationReceiver

- The NotificationReceiver to register.

removeNotificationReceiverback to summary
public void removeNotificationReceiver(final NotificationReceiver receiver)

Remove a previously registered NotificationReceiver from this SecurityContext. If the supplied receiver has not been previously registered this method will fail silently.

Parameters
receiver:NotificationReceiver

- The NotificationReceiver to remove.

setAuthenticationRequiredback to summary
public void setAuthenticationRequired()

Marks this request as requiring authentication. Authentication challenge headers will only be sent if this method has been called. If authenticate() is called without first calling this method then the request will continue as normal even if the authentication was not successful.