Top Description Fields Constructors Methods
jakarta.security.enterprise.authentication.mechanism.http

public Class HttpMessageContextWrapper

extends Object
implements HttpMessageContext
Class Inheritance
All Implemented Interfaces
jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext
Imports
java.security.Principal, java.util.Set, javax.security.auth.Subject, javax.security.auth.callback.CallbackHandler, jakarta.security.auth.message.MessageInfo, jakarta.security.enterprise.AuthenticationStatus, jakarta.security.enterprise.identitystore.CredentialValidationResult, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse

This class is an implementation of the HttpMessageContext interface that can be subclassed by developers wishing to provide extra or different functionality.

All methods default to calling the wrapped object.

Field Summary

Modifier and TypeField and Description
private final HttpMessageContext

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
cleanClientSubject()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.cleanClientSubject.

Convenience method to clean the subject associated with this context.
public AuthenticationStatus
public AuthenticationStatus
forward(String
a String specifying the pathname to the resource.
path
)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.forward.

Forwards to another resource (Jakarta Servlet, Jakarta Server Pages file, or HTML file) on the server.
public AuthenticationParameters
getAuthParameters()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getAuthParameters.

Returns the parameters that were provided with the SecurityContext#authenticate(AuthParameters) call.
public Principal
getCallerPrincipal()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getCallerPrincipal.

Gets the Principal set by a call to notifyContainerAboutLogin().
public Subject
getClientSubject()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getClientSubject.

Returns the subject for which authentication is to take place.
public Set<String>
getGroups()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getGroups.

Gets the groups set by a call to notifyContainerAboutLogin().
public CallbackHandler
getHandler()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getHandler.

Returns the low level Jakarta Authentication handler that the runtime provided when creating this HttpMessageContext, and which this context uses to communicate the authentication details to the runtime.
public MessageInfo
getMessageInfo()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getMessageInfo.

Returns the the low level Jakarta Authentication message info instance for the current request.
public HttpServletRequest
getRequest()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getRequest.

Returns the request object associated with the current request.
public HttpServletResponse
getResponse()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getResponse.

Returns the response object associated with the current request.
public HttpMessageContext
public boolean
isAuthenticationRequest()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.isAuthenticationRequest.

Checks if the current call to an authentication mechanism is the result from the application calling SecurityContext#authenticate(HttpServletRequest, HttpServletResponse, AuthenticationParameters)

If SecurityContext#authenticate was not called, the authentication mechanism may have been invoked by the container at the start of a request.

public boolean
isProtected()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.isProtected.

Checks if the currently requested resource is protected or not.
public boolean
isRegisterSession()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.isRegisterSession.

Check if the runtime has been asked to register an authentication session duing the current request.
public AuthenticationStatus
notifyContainerAboutLogin(String
the caller name that will become the caller principal
username
,
Set<String>
the groups associated with the caller principal
roles
)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.notifyContainerAboutLogin.

Asks the container to register the given caller name and groups in order to make them available to the application for use with SecurityContext#isCallerInRole(String) etc.

Note that after this call returned, the authenticated identity will not be immediately active.

public AuthenticationStatus
notifyContainerAboutLogin(Principal
the Principal that will become the caller principal
principal
,
Set<String>
the groups associated with the caller principal
roles
)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.notifyContainerAboutLogin.

Asks the container to register the given caller principal and groups in order to make them available to the application for use with SecurityContext#isCallerInRole(String) etc.

Note that this call may result in the container establishing two caller principals to represent the caller's identity -- the Principal provided here as the principal parameter, and a second principal used as the container's representation of the caller identity.

public AuthenticationStatus
notifyContainerAboutLogin(CredentialValidationResult
a CredentialValidationResult which is inspected for its status and from which the principal and groups are taken.
result
)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.notifyContainerAboutLogin.

Convenience method intended to pass the CredentialValidationResult result of an identity store directly on to the container.
public AuthenticationStatus
redirect(String
the location to redirect to
location
)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.redirect.

Sets the response status to SC_FOUND 302 (Found)

As a convenience this method returns SEND_CONTINUE, so this method can be used in one fluent return statement from an HttpAuthenticationMechanism

public AuthenticationStatus
public AuthenticationStatus
public void
setRegisterSession(String
the caller name for which authentication should be be remembered
callerName
,
Set<String>
the groups for which authentication should be remembered.
groups
)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.setRegisterSession.

Asks the runtime to register an authentication session.
public void
public void
setResponse(HttpServletResponse
the response object to be set.
response
)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.setResponse.

Set the response object.
public HttpMessageContext
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

httpMessageContextback to summary
private final HttpMessageContext httpMessageContext

Constructor Detail

HttpMessageContextWrapperback to summary
public HttpMessageContextWrapper(HttpMessageContext httpMessageContext)

Method Detail

cleanClientSubjectback to summary
public void cleanClientSubject()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.cleanClientSubject.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.cleanClientSubject.

Convenience method to clean the subject associated with this context.

Cleaning this subject is done as defined by the Servlet Container Profile of Jakarta Authentication for the ServerAuthModule#cleanSubject method and the HttpAuthenticationMechanism#cleanSubject(HttpServletRequest, HttpServletResponse, HttpMessageContext) method defined by this specification.

Annotations
@Override
doNothingback to summary
public AuthenticationStatus doNothing()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.doNothing.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.doNothing.

Instructs the container to "do nothing".

When intending to do nothing, a Jakarta Security authentication mechanism has to indicate this explicitly via its return value.

As a convenience this method returns NOT_DONE, so this method can be used in one fluent return statement from an HttpAuthenticationMechanism

Returns:AuthenticationStatus

AuthenticationStatus#NOT_DONE

Annotations
@Override
forwardback to summary
public AuthenticationStatus forward(String path)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.forward.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.forward.

Forwards to another resource (Jakarta Servlet, Jakarta Server Pages file, or HTML file) on the server.

As a convenience this method returns SEND_CONTINUE, so this method can be used in one fluent return statement from an HttpAuthenticationMechanism

Parameters
path:String

a String specifying the pathname to the resource.

Returns:AuthenticationStatus

AuthenticationStatus#SEND_CONTINUE

Annotations
@Override
getAuthParametersback to summary
public AuthenticationParameters getAuthParameters()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getAuthParameters.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getAuthParameters.

Returns the parameters that were provided with the SecurityContext#authenticate(AuthParameters) call.

Returns:AuthenticationParameters

the parameters that were provided with the SecurityContext#authenticate(AuthParameters) call, or a default instance. Never null.

Annotations
@Override
getCallerPrincipalback to summary
public Principal getCallerPrincipal()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getCallerPrincipal.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getCallerPrincipal.

Gets the Principal set by a call to notifyContainerAboutLogin().

Returns:Principal

The caller principal

Annotations
@Override
getClientSubjectback to summary
public Subject getClientSubject()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getClientSubject.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getClientSubject.

Returns the subject for which authentication is to take place.

Note

This is a low level object that most higher level code would not need to use directly.

Returns:Subject

the subject for which authentication is to take place.

Annotations
@Override
getGroupsback to summary
public Set<String> getGroups()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getGroups.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getGroups.

Gets the groups set by a call to notifyContainerAboutLogin().

Returns:Set<String>

The groups

Annotations
@Override
getHandlerback to summary
public CallbackHandler getHandler()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getHandler.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getHandler.

Returns the low level Jakarta Authentication handler that the runtime provided when creating this HttpMessageContext, and which this context uses to communicate the authentication details to the runtime.

Note

This is a low level object that most higher level code would not need to use directly.

Returns:CallbackHandler

the handler that the runtime provided to this context

Annotations
@Override
getMessageInfoback to summary
public MessageInfo getMessageInfo()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getMessageInfo.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getMessageInfo.

Returns the the low level Jakarta Authentication message info instance for the current request.

Note

This is a low level object that most higher level code would not need to use directly.

Returns:MessageInfo

the message info instance for the current request.

Annotations
@Override
getRequestback to summary
public HttpServletRequest getRequest()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getRequest.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getRequest.

Returns the request object associated with the current request.

Returns:HttpServletRequest

the request object associated with the current request.

Annotations
@Override
getResponseback to summary
public HttpServletResponse getResponse()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getResponse.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.getResponse.

Returns the response object associated with the current request.

Returns:HttpServletResponse

the response object associated with the current request.

Annotations
@Override
getWrappedback to summary
public HttpMessageContext getWrapped()
isAuthenticationRequestback to summary
public boolean isAuthenticationRequest()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.isAuthenticationRequest.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.isAuthenticationRequest.

Checks if the current call to an authentication mechanism is the result from the application calling SecurityContext#authenticate(HttpServletRequest, HttpServletResponse, AuthenticationParameters)

If SecurityContext#authenticate was not called, the authentication mechanism may have been invoked by the container at the start of a request.

Returns:boolean

true if SecurityContext#authenticate was called, false if not.

Annotations
@Override
isProtectedback to summary
public boolean isProtected()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.isProtected.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.isProtected.

Checks if the currently requested resource is protected or not. A protected resource is a resource (e.g. a Jakarta Servlet, Jakarta Faces page, Jakarta Server Pages page etc) for which a constraint has been defined in e.g. web.xml.

Returns:boolean

true if a protected resource was requested, false if a public resource was requested.

Annotations
@Override
isRegisterSessionback to summary
public boolean isRegisterSession()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.isRegisterSession.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.isRegisterSession.

Check if the runtime has been asked to register an authentication session duing the current request.

Returns:boolean

true if code has asked to register an authentication session, false otherwise.

Annotations
@Override
notifyContainerAboutLoginback to summary
public AuthenticationStatus notifyContainerAboutLogin(String username, Set<String> roles)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.notifyContainerAboutLogin.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.notifyContainerAboutLogin.

Asks the container to register the given caller name and groups in order to make them available to the application for use with SecurityContext#isCallerInRole(String) etc.

Note that after this call returned, the authenticated identity will not be immediately active. This will only take place (should no errors occur) after the authentication mechanism in which this call takes place returns control back to the container (runtime).

As a convenience this method returns SUCCESS, so this method can be used in one fluent return statement from an HttpAuthenticationMechanism

Parameters
username:String

the caller name that will become the caller principal

roles:Set<String>

the groups associated with the caller principal

Returns:AuthenticationStatus

AuthenticationStatus#SUCCESS

Annotations
@Override
notifyContainerAboutLoginback to summary
public AuthenticationStatus notifyContainerAboutLogin(Principal principal, Set<String> roles)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.notifyContainerAboutLogin.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.notifyContainerAboutLogin.

Asks the container to register the given caller principal and groups in order to make them available to the application for use with SecurityContext#isCallerInRole(String) etc.

Note that this call may result in the container establishing two caller principals to represent the caller's identity -- the Principal provided here as the principal parameter, and a second principal used as the container's representation of the caller identity. A second principal is added only if the container uses a different Principal type to represent the caller. If the types are the same, only one Principal is added.

If a second principal is added, the value returned by Principal#getName() will be the same for both principals.

When two principals are added, the container's caller principal is returned from SecurityContext#getCallerPrincipal(), and the principal supplied here as a parameter can be retrieved using SecurityContext#getPrincipalsByType(Class). When only one is added, it is returned by SecurityContext#getCallerPrincipal().

Note that after this call returned, the authenticated identity will not be immediately active. This will only take place (should no errors occur) after the authentication mechanism in which this call takes place returns control back to the container (runtime).

As a convenience this method returns SUCCESS, so this method can be used in one fluent return statement from an HttpAuthenticationMechanism

Parameters
principal:Principal

the Principal that will become the caller principal

roles:Set<String>

the groups associated with the caller principal

Returns:AuthenticationStatus

AuthenticationStatus#SUCCESS

Annotations
@Override
notifyContainerAboutLoginback to summary
public AuthenticationStatus notifyContainerAboutLogin(CredentialValidationResult result)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.notifyContainerAboutLogin.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.notifyContainerAboutLogin.

Convenience method intended to pass the CredentialValidationResult result of an identity store directly on to the container.

If the outcome from the given CredentialValidationResult#getStatus() equals Status#VALID, the CallerPrincipal and groups are obtained from the CredentialValidationResult and passed into HttpMessageContext#notifyContainerAboutLogin(Principal, Set).

If the outcome from the given CredentialValidationResult#getStatus() is not equal to Status#VALID a failure result is returned.

Parameters
result:CredentialValidationResult

a CredentialValidationResult which is inspected for its status and from which the principal and groups are taken.

Returns:AuthenticationStatus

AuthenticationStatus#SUCCESS if CredentialValidationResult#getStatus() equals Status#VALID otherwise AuthenticationStatus#SEND_FAILURE

Annotations
@Override
redirectback to summary
public AuthenticationStatus redirect(String location)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.redirect.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.redirect.

Sets the response status to SC_FOUND 302 (Found)

As a convenience this method returns SEND_CONTINUE, so this method can be used in one fluent return statement from an HttpAuthenticationMechanism

Parameters
location:String

the location to redirect to

Returns:AuthenticationStatus

AuthenticationStatus#SEND_CONTINUE

Annotations
@Override
responseNotFoundback to summary
public AuthenticationStatus responseNotFound()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.responseNotFound.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.responseNotFound.

Sets the response status to 404 (not found).

As a convenience this method returns SEND_FAILURE, so this method can be used in one fluent return statement from an HttpAuthenticationMechanism

Returns:AuthenticationStatus

AuthenticationStatus#SEND_FAILURE

Annotations
@Override
responseUnauthorizedback to summary
public AuthenticationStatus responseUnauthorized()

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.responseUnauthorized.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.responseUnauthorized.

Sets the response status to 401 (unauthorized).

As a convenience this method returns SEND_FAILURE, so this method can be used in one fluent return statement from an HttpAuthenticationMechanism

Returns:AuthenticationStatus

AuthenticationStatus#SEND_FAILURE

Annotations
@Override
setRegisterSessionback to summary
public void setRegisterSession(String callerName, Set<String> groups)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.setRegisterSession.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.setRegisterSession.

Asks the runtime to register an authentication session. This will automatically remember the logged-in status as long as the current HTTP session remains valid. Without this being asked, a HttpAuthenticationMechanism has to manually re-authenticate with the runtime at the start of each request.

Parameters
callerName:String

the caller name for which authentication should be be remembered

groups:Set<String>

the groups for which authentication should be remembered.

Annotations
@Override
setRequestback to summary
public void setRequest(HttpServletRequest request)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.setRequest.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.setRequest.

Sets the request object.

Parameters
request:HttpServletRequest

the request object to be set

Annotations
@Override
setResponseback to summary
public void setResponse(HttpServletResponse response)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.setResponse.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.setResponse.

Set the response object.

Parameters
response:HttpServletResponse

the response object to be set.

Annotations
@Override
withRequestback to summary
public HttpMessageContext withRequest(HttpServletRequest request)

Implements jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.withRequest.

Doc from jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext.withRequest.

Sets the request object.

Parameters
request:HttpServletRequest

the request object to be set.

Returns:HttpMessageContext

the HttpMessageContext instance on which this method was called, useful for fluent style call call chains.

Annotations
@Override