Java Code Examples for javax.security.auth.message.AuthStatus#SUCCESS
The following examples show how to use
javax.security.auth.message.AuthStatus#SUCCESS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SessionSAM.java From eplmp with Eclipse Public License 1.0 | 6 votes |
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI()); String login = (String) request.getSession().getAttribute("login"); String groups = (String) request.getSession().getAttribute("groups"); CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, login); GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{groups}); Callback[] callbacks = new Callback[]{callerPrincipalCallback, groupPrincipalCallback}; try { callbackHandler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw new AuthException(e.getMessage()); } return AuthStatus.SUCCESS; }
Example 2
Source File: GuestSAM.java From eplmp with Eclipse Public License 1.0 | 6 votes |
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI()); CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, ""); GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{UserGroupMapping.GUEST_ROLE_ID}); Callback[] callbacks = {callerPrincipalCallback, groupPrincipalCallback}; try { callbackHandler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw new AuthException(e.getMessage()); } return AuthStatus.SUCCESS; }
Example 3
Source File: CustomServerAuthContext.java From eplmp with Eclipse Public License 1.0 | 6 votes |
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage(); AuthServices.addCORSHeaders(response); LOGGER.log(Level.FINE, "validateRequest @" + request.getMethod() + " " + request.getRequestURI()); if (isOptionsRequest(request)) { return AuthStatus.SUCCESS; } CustomSAM module = getModule(messageInfo); if (module != null) { return module.validateRequest(messageInfo, clientSubject, serviceSubject); } response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return AuthStatus.FAILURE; }
Example 4
Source File: AbstractServerAuthModule.java From lams with GNU General Public License v2.0 | 5 votes |
/** * This method delegates to a login module if configured in the module options. * The sub classes will need to validate the request */ public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { String loginModuleName = (String) options.get("login-module-delegate"); if(loginModuleName != null) { ClassLoader tcl = SecurityActions.getContextClassLoader(); try { Class clazz = tcl.loadClass(loginModuleName); LoginModule lm = (LoginModule) clazz.newInstance(); lm.initialize(clientSubject, callbackHandler, new HashMap(), options); lm.login(); lm.commit(); } catch (Exception e) { throw new AuthException(e.getLocalizedMessage()); } } else { return validate(clientSubject, messageInfo) ? AuthStatus.SUCCESS : AuthStatus.FAILURE; } return AuthStatus.SUCCESS; }
Example 5
Source File: SimpleClientAuthModule.java From lams with GNU General Public License v2.0 | 5 votes |
/** * @see ClientAuthModule#secureRequest(javax.security.auth.message.MessageInfo, javax.security.auth.Subject) */ public AuthStatus secureRequest(MessageInfo param, Subject source) throws AuthException { source.getPrincipals().add(this.principal); source.getPublicCredentials().add(this.credential); return AuthStatus.SUCCESS; }
Example 6
Source File: SimpleClientAuthModule.java From lams with GNU General Public License v2.0 | 5 votes |
/** * @see ClientAuthModule#validateResponse(javax.security.auth.message.MessageInfo, javax.security.auth.Subject, javax.security.auth.Subject) */ public AuthStatus validateResponse(MessageInfo messageInfo, Subject source, Subject recipient) throws AuthException { //Custom check: Check that the source of the response and the recipient // of the response have identical credentials Set sourceSet = source.getPrincipals(SimplePrincipal.class); Set recipientSet = recipient.getPrincipals(SimplePrincipal.class); if(sourceSet == null && recipientSet == null) throw new AuthException(); if(sourceSet.size() != recipientSet.size()) throw new AuthException(PicketBoxMessages.MESSAGES.sizeMismatchMessage("source", "recipient")); return AuthStatus.SUCCESS; }
Example 7
Source File: JWTSAM.java From eplmp with Eclipse Public License 1.0 | 5 votes |
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage(); LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI()); String authorization = request.getHeader("Authorization"); String[] splitAuthorization = authorization.split(" "); String jwt = splitAuthorization[1]; JWTokenUserGroupMapping jwTokenUserGroupMapping = JWTokenFactory.validateAuthToken(key, jwt); if (jwTokenUserGroupMapping != null) { UserGroupMapping userGroupMapping = jwTokenUserGroupMapping.getUserGroupMapping(); CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, userGroupMapping.getLogin()); GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{userGroupMapping.getGroupName()}); Callback[] callbacks = new Callback[]{callerPrincipalCallback, groupPrincipalCallback}; try { callbackHandler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw new AuthException(e.getMessage()); } JWTokenFactory.refreshTokenIfNeeded(key, response, jwTokenUserGroupMapping); return AuthStatus.SUCCESS; } response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return AuthStatus.FAILURE; }
Example 8
Source File: TomEESecurityServerAuthModule.java From tomee with Apache License 2.0 | 5 votes |
private AuthStatus mapToAuthStatus(final AuthenticationStatus authenticationStatus) { switch (authenticationStatus) { case SUCCESS: case NOT_DONE: return AuthStatus.SUCCESS; case SEND_FAILURE: return AuthStatus.SEND_FAILURE; case SEND_CONTINUE: return AuthStatus.SEND_CONTINUE; default: throw new IllegalArgumentException(); } }
Example 9
Source File: AuthenticatorBase.java From Tomcat8-Source-Read with MIT License | 4 votes |
private boolean authenticateJaspic(Request request, Response response, JaspicState state, boolean requirePrincipal) { boolean cachedAuth = checkForCachedAuthentication(request, response, false); Subject client = new Subject(); AuthStatus authStatus; try { authStatus = state.serverAuthContext.validateRequest(state.messageInfo, client, null); } catch (AuthException e) { log.debug(sm.getString("authenticator.loginFail"), e); return false; } request.setRequest((HttpServletRequest) state.messageInfo.getRequestMessage()); response.setResponse((HttpServletResponse) state.messageInfo.getResponseMessage()); if (authStatus == AuthStatus.SUCCESS) { GenericPrincipal principal = getPrincipal(client); if (log.isDebugEnabled()) { log.debug("Authenticated user: " + principal); } if (principal == null) { request.setUserPrincipal(null); request.setAuthType(null); if (requirePrincipal) { return false; } } else if (cachedAuth == false || !principal.getUserPrincipal().equals(request.getUserPrincipal())) { // Skip registration if authentication credentials were // cached and the Principal did not change. @SuppressWarnings("rawtypes")// JASPIC API uses raw types Map map = state.messageInfo.getMap(); if (map != null && map.containsKey("javax.servlet.http.registerSession")) { register(request, response, principal, "JASPIC", null, null, true, true); } else { register(request, response, principal, "JASPIC", null, null); } } request.setNote(Constants.REQ_JASPIC_SUBJECT_NOTE, client); return true; } return false; }
Example 10
Source File: SimpleServerAuthModule.java From lams with GNU General Public License v2.0 | 4 votes |
/** * @see ServerAuthModule#secureResponse(javax.security.auth.message.MessageInfo, javax.security.auth.Subject) */ public AuthStatus secureResponse(MessageInfo param, Subject source) throws AuthException { return AuthStatus.SUCCESS; }
Example 11
Source File: AllSuccessServerAuthModule.java From lams with GNU General Public License v2.0 | 4 votes |
public AuthStatus secureResponse(MessageInfo arg0, Subject arg1) throws AuthException { return AuthStatus.SUCCESS; }
Example 12
Source File: TomEESecurityServerAuthModule.java From tomee with Apache License 2.0 | 4 votes |
@Override public AuthStatus secureResponse(final MessageInfo messageInfo, final Subject serviceSubject) throws AuthException { return AuthStatus.SUCCESS; }