javax.security.auth.message.callback.CallerPrincipalCallback Java Examples
The following examples show how to use
javax.security.auth.message.callback.CallerPrincipalCallback.
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: TomEEHttpMessageContext.java From tomee with Apache License 2.0 | 6 votes |
@Override public AuthenticationStatus notifyContainerAboutLogin(final Principal principal, final Set<String> groups) { try { handler.handle(new Callback[] { new CallerPrincipalCallback(clientSubject, principal), new GroupPrincipalCallback(clientSubject, groups.toArray(new String[groups.size()])) }); } catch (final IOException | UnsupportedCallbackException e) { e.printStackTrace(); } this.principal = principal; this.groups = groups; TomEESecurityContext.registerContainerAboutLogin(principal, groups); return SUCCESS; }
Example #4
Source File: AutoApplySessionInterceptor.java From tomee with Apache License 2.0 | 6 votes |
private AuthenticationStatus validateRequest(final InvocationContext invocationContext) throws Exception { final HttpMessageContext httpMessageContext = (HttpMessageContext) invocationContext.getParameters()[2]; final Principal principal = httpMessageContext.getRequest().getUserPrincipal(); if (principal == null) { final Object authenticationStatus = invocationContext.proceed(); if (AuthenticationStatus.SUCCESS.equals(authenticationStatus)) { httpMessageContext.getMessageInfo().getMap().put("javax.servlet.http.registerSession", "true"); } return (AuthenticationStatus) authenticationStatus; } else { final CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(httpMessageContext.getClientSubject(), principal); httpMessageContext.getHandler().handle(new Callback[] {callerPrincipalCallback}); return AuthenticationStatus.SUCCESS; } }
Example #5
Source File: TheServerAuthModule.java From tomee with Apache License 2.0 | 6 votes |
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); Callback[] callbacks; if (request.getParameter("doLogin") != null) { callbacks = new Callback[]{new CallerPrincipalCallback(clientSubject, "test"), new GroupPrincipalCallback(clientSubject, new String[]{"architect"})}; } else { callbacks = new Callback[]{new CallerPrincipalCallback(clientSubject, (Principal) null)}; } try { handler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw (AuthException) new AuthException().initCause(e); } cdi(messageInfo, "vr"); return SUCCESS; }
Example #6
Source File: CallbackHandlerImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { String name = null; Principal principal = null; Subject subject = null; String[] groups = null; if (callbacks != null) { // Need to combine data from multiple callbacks so use this to hold // the data // Process the callbacks for (Callback callback : callbacks) { if (callback instanceof CallerPrincipalCallback) { CallerPrincipalCallback cpc = (CallerPrincipalCallback) callback; name = cpc.getName(); principal = cpc.getPrincipal(); subject = cpc.getSubject(); } else if (callback instanceof GroupPrincipalCallback) { GroupPrincipalCallback gpc = (GroupPrincipalCallback) callback; groups = gpc.getGroups(); } else { // This is a singleton so need to get correct Logger for // current TCCL Log log = LogFactory.getLog(CallbackHandlerImpl.class); log.error(sm.getString("callbackHandlerImpl.jaspicCallbackMissing", callback.getClass().getName())); } } // Create the GenericPrincipal Principal gp = getPrincipal(principal, name, groups); if (subject != null && gp != null) { subject.getPrivateCredentials().add(gp); } } }
Example #7
Source File: DoNothingServerAuthModule.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { try { // The JASPIC protocol for "do nothing" handler.handle(new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) }); return SUCCESS; } catch (IOException | UnsupportedCallbackException e) { throw (AuthException) new AuthException().initCause(e); } }
Example #8
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 #9
Source File: ConnectorCallbackHandler.java From tomee with Apache License 2.0 | 5 votes |
public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (final Callback callback : callbacks) { // jaspi to server communication if (callback instanceof CallerPrincipalCallback) { callerPrincipal = ((CallerPrincipalCallback) callback).getPrincipal(); } else if (callback instanceof GroupPrincipalCallback) { groupsArray = ((GroupPrincipalCallback) callback).getGroups(); } else if (callback instanceof PasswordValidationCallback) { final PasswordValidationCallback passwordValidationCallback = (PasswordValidationCallback) callback; final String userName = passwordValidationCallback.getUsername(); final char[] password = passwordValidationCallback.getPassword(); final SecurityService securityService = SystemInstance.get().getComponent(SecurityService.class); try { final Object loginObj = securityService.login(securityRealmName, userName, password == null ? "" : new String(password)); securityService.associate(loginObj); callerPrincipal = securityService.getCallerPrincipal(); passwordValidationCallback.setResult(true); } catch (final LoginException e) { passwordValidationCallback.setResult(false); } } // server to jaspi communication else if (callback instanceof CertStoreCallback) { //NOPMD // TODO implement me } else if (callback instanceof PrivateKeyCallback) { //NOPMD // TODO implement me } else if (callback instanceof SecretKeyCallback) { //NOPMD // TODO implement me } else if (callback instanceof TrustStoreCallback) { //NOPMD // TODO implement me } else { throw new UnsupportedCallbackException(callback); } } }