use of javax.security.auth.message.MessageInfo in project OpenAM by OpenRock.
the class JaspiAuthModuleWrapper method onLoginSuccess.
/**
* Post processing of successful authentication, which initialises the underlying JASPI ServerAuthModule, as a new
* instance of this class is created for the Post Authentication Process, and then calls the subtypes
* onLoginSuccess method, and then finally calls the JASPI ServerAuthModule's secureResponse method.
*
* @param requestParamsMap {@inheritDoc}
* @param request {@inheritDoc}
* @param response {@inheritDoc}
* @param ssoToken {@inheritDoc}
* @throws AuthenticationException {@inheritDoc}
*/
public void onLoginSuccess(Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) throws AuthenticationException {
try {
Map<String, Object> config = initialize(requestParamsMap, request, response, ssoToken);
serverAuthModule.initialize(createRequestMessagePolicy(), null, null, config);
MessageInfo messageInfo = prepareMessageInfo(request, response);
onLoginSuccess(messageInfo, requestParamsMap, request, response, ssoToken);
AuthStatus authStatus = serverAuthModule.secureResponse(messageInfo, null);
if (AuthStatus.SEND_SUCCESS.equals(authStatus)) {
// nothing to do here just carry on
debug.message("Successfully secured response.");
} else if (AuthStatus.SEND_FAILURE.equals(authStatus)) {
// Send HttpServletResponse to client and exit.
debug.message("Failed to secured response, included response message");
throw new AuthenticationException(resourceBundleName, "authFailed", null);
} else if (AuthStatus.SEND_CONTINUE.equals(authStatus)) {
// Send HttpServletResponse to client and exit.
debug.message("Has not finished securing response. Requires more information from client.");
throw new AuthenticationException(resourceBundleName, "authFailed", null);
} else {
debug.error("Invalid AuthStatus, " + authStatus.toString());
throw new AuthenticationException(resourceBundleName, "authFailed", null);
}
} catch (AuthException e) {
debug.error("Authentication Failed", e);
throw new AuthenticationException(resourceBundleName, "authFailed", null);
}
}
use of javax.security.auth.message.MessageInfo in project OpenAM by OpenRock.
the class JaspiAuthModuleWrapperTest method setUp.
@BeforeMethod
public void setUp() {
amLoginModuleBinder = mock(AMLoginModuleBinder.class);
serverAuthModule = mock(ServerAuthModule.class);
jaspiAuthModuleWrapper = new JaspiAuthModuleWrapper<ServerAuthModule>(serverAuthModule, "amAuthPersistentCookie") {
@Override
protected Map<String, Object> initialize(Subject subject, Map sharedState, Map options) {
return config;
}
@Override
protected boolean process(MessageInfo messageInfo, Subject clientSubject, Callback[] callbacks) throws LoginException {
processMethodCalled = true;
return true;
}
@Override
protected Map<String, Object> initialize(Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) throws AuthenticationException {
return config;
}
@Override
protected void onLoginSuccess(MessageInfo messageInfo, Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) throws AuthenticationException {
onLoginSuccessMethodCalled = true;
}
@Override
public Principal getPrincipal() {
return null;
}
};
jaspiAuthModuleWrapper.setAMLoginModule(amLoginModuleBinder);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
given(amLoginModuleBinder.getHttpServletRequest()).willReturn(request);
given(amLoginModuleBinder.getHttpServletResponse()).willReturn(response);
}
use of javax.security.auth.message.MessageInfo in project wildfly by wildfly.
the class JASPICSecurityContext method logout.
/**
* <p>
* JASPIC 1.1 specification: if there is an {@code AuthConfigProvider} for the {@code HttpServlet} layer and
* application context, then @{@code logout} must acquire a {@code ServerAuthContext} and call {@code cleanSubject}
* on the acquired context.
* </p>
* <p>
* The specified {@code Subject} should be non-null and should be the {@code Subject} returning from the most recent
* call to {@code validateRequest}. In our case, that {@code Subject} is set in the underlying security context, so
* we must retrieve it from there before calling {@code cleanSubject}.
* </p>
* <p>
* Once {@code cleanSubject} returns, {@code logout} must perform the regular (non-JASPIC) {@code logout} processing.
* </p>
*/
@Override
public void logout() {
if (!isAuthenticated())
return;
// call cleanSubject() if there is an AuthConfigProvider for the HttpServlet layer and appContext.
String appContext = this.buildAppContext();
if (AuthConfigFactory.getFactory().getConfigProvider(layer, appContext, null) != null) {
Subject authenticatedSubject = this.getAuthenticatedSubject();
MessageInfo messageInfo = this.buildMessageInfo();
this.manager.cleanSubject(messageInfo, authenticatedSubject, layer, appContext, handler);
}
// following the return from cleanSubject(), logout must perform the regular logout processing.
super.logout();
}
use of javax.security.auth.message.MessageInfo in project Payara by payara.
the class ClientAuthConfigImpl method createAuthContext.
@Override
@SuppressWarnings("unchecked")
protected <M> M createAuthContext(String authContextID, Map<String, ?> properties) throws AuthException {
if (!authContextHelper.isProtected(new ClientAuthModule[0], authContextID)) {
return null;
}
ClientAuthContext context = new ClientAuthContext() {
ClientAuthModule[] module = init();
ClientAuthModule[] init() throws AuthException {
ClientAuthModule[] clientModules;
try {
clientModules = authContextHelper.getModules(new ClientAuthModule[0], authContextID);
} catch (AuthException ae) {
logIfLevel(SEVERE, ae, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "unable to load client auth modules");
throw ae;
}
MessagePolicy requestPolicy = policyDelegate.getRequestPolicy(authContextID, properties);
MessagePolicy responsePolicy = policyDelegate.getResponsePolicy(authContextID, properties);
boolean noModules = true;
for (int i = 0; i < clientModules.length; i++) {
if (clientModules[i] != null) {
if (isLoggable(FINE)) {
logIfLevel(FINE, null, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "initializing module");
}
noModules = false;
checkMessageTypes(clientModules[i].getSupportedMessageTypes());
clientModules[i].initialize(requestPolicy, responsePolicy, callbackHandler, authContextHelper.getInitProperties(i, properties));
}
}
if (noModules) {
logIfLevel(WARNING, null, "CLientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "contains no Auth Modules");
}
return clientModules;
}
@Override
public AuthStatus validateResponse(MessageInfo arg0, Subject arg1, Subject arg2) throws AuthException {
AuthStatus[] status = new AuthStatus[module.length];
for (int i = 0; i < module.length; i++) {
if (module[i] == null) {
continue;
}
if (isLoggable(FINE)) {
logIfLevel(FINE, null, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "calling vaidateResponse on module");
}
status[i] = module[i].validateResponse(arg0, arg1, arg2);
if (authContextHelper.exitContext(validateResponseSuccessValues, i, status[i])) {
return authContextHelper.getReturnStatus(validateResponseSuccessValues, SEND_FAILURE, status, i);
}
}
return authContextHelper.getReturnStatus(validateResponseSuccessValues, SEND_FAILURE, status, status.length - 1);
}
@Override
public AuthStatus secureRequest(MessageInfo arg0, Subject arg1) throws AuthException {
AuthStatus[] status = new AuthStatus[module.length];
for (int i = 0; i < module.length; i++) {
if (module[i] == null) {
continue;
}
if (isLoggable(FINE)) {
logIfLevel(FINE, null, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "calling secureResponse on module");
}
status[i] = module[i].secureRequest(arg0, arg1);
if (authContextHelper.exitContext(secureResponseSuccessValues, i, status[i])) {
return authContextHelper.getReturnStatus(secureResponseSuccessValues, AuthStatus.SEND_FAILURE, status, i);
}
}
return authContextHelper.getReturnStatus(secureResponseSuccessValues, AuthStatus.SEND_FAILURE, status, status.length - 1);
}
@Override
public void cleanSubject(MessageInfo arg0, Subject arg1) throws AuthException {
for (int i = 0; i < module.length; i++) {
if (module[i] == null) {
continue;
}
if (isLoggable(FINE)) {
logIfLevel(FINE, null, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "calling cleanSubject on module");
}
module[i].cleanSubject(arg0, arg1);
}
}
};
return (M) context;
}
use of javax.security.auth.message.MessageInfo in project Payara by payara.
the class RealmAdapter method invokePostAuthenticateDelegate.
/**
* Post authentication for given request and response.
*
* @param request Request we are processing
* @param response Response we are creating
* @param context The Context to which client of this class is attached.
* @exception IOException if an input/output error occurs
*/
@Override
public boolean invokePostAuthenticateDelegate(HttpRequest request, HttpResponse response, Context context) throws IOException {
boolean result = false;
ServerAuthContext serverAuthContext = null;
try {
if (httpServletHelper != null) {
HttpServletRequest req = (HttpServletRequest) request.getRequest();
MessageInfo messageInfo = (MessageInfo) req.getAttribute(MESSAGE_INFO);
if (messageInfo != null) {
// JSR 196 is enabled for this application
serverAuthContext = (ServerAuthContext) messageInfo.getMap().get(SERVER_AUTH_CONTEXT);
if (serverAuthContext != null) {
try {
context.fireContainerEvent(BEFORE_POST_AUTHENTICATION, null);
result = SUCCESS.equals(serverAuthContext.secureResponse(messageInfo, null));
} finally {
context.fireContainerEvent(AFTER_POST_AUTHENTICATION, null);
}
}
}
}
} catch (AuthException ex) {
throw new IOException(ex);
} finally {
if (httpServletHelper != null && serverAuthContext != null) {
if (request instanceof HttpRequestWrapper) {
request.removeNote(WRAPPED_REQUEST);
}
if (response instanceof HttpResponseWrapper) {
request.removeNote(WRAPPED_RESPONSE);
}
}
}
return result;
}
Aggregations