@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage(); try { response.getWriter().write("validateRequest invoked\n"); boolean isMandatory = Boolean.valueOf((String) messageInfo.getMap().get("javax.security.auth.message.MessagePolicy.isMandatory")); response.getWriter().write("isMandatory: " + isMandatory + "\n"); handler.handle(new Callback[] { new CallerPrincipalCallback(clientSubject, "test"), new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) }); } catch (IOException | UnsupportedCallbackException e) { throw (AuthException) new AuthException().initCause(e); } return SUCCESS; }
@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 { // The JASPIC protocol for "do nothing" callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) }; } try { handler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw (AuthException) new AuthException().initCause(e); } return SUCCESS; }
@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 { // The JASPIC protocol for "do nothing" callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) }; } try { handler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw (AuthException) new AuthException().initCause(e); } return SUCCESS; }
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { try { HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage(); if ("include".equals(request.getParameter("dispatch"))) { request.getRequestDispatcher("/includedServlet") .include(request, response); // "Do nothing", required protocol when returning SUCCESS handler.handle(new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) }); // When using includes, the response stays open and the main // resource can also write to the response return SUCCESS; } else { request.getRequestDispatcher("/forwardedServlet") .forward(request, response); // MUST NOT invoke the resource, so CAN NOT return SUCCESS here. return SEND_CONTINUE; } } catch (IOException | ServletException | UnsupportedCallbackException e) { throw (AuthException) new AuthException().initCause(e); } }
handler.handle(new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) });
callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, userPrincipal) }; new CallerPrincipalCallback(clientSubject, "test") : new CallerPrincipalCallback(clientSubject, new MyPrincipal("test")), callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) };
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); Callback[] callbacks; if (request.getParameter("doLogin") != null) { // For the test perform a login by directly "returning" the details of the authenticated user. // Normally credentials would be checked and the details fetched from some repository callbacks = new Callback[] { // The name of the authenticated user new CallerPrincipalCallback(clientSubject, "test"), // the roles of the authenticated user new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) }; } else { // The JASPIC protocol for "do nothing" callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) }; } try { // Communicate the details of the authenticated user to the container. In many // cases the handler will just store the details and the container will actually handle // the login after we return from this method. handler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw (AuthException) new AuthException().initCause(e); } return SUCCESS; }
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); Callback[] callbacks; if (request.getParameter("doLogin") != null) { // For the test perform a login by directly "returning" the details of the authenticated user. // Normally credentials would be checked and the details fetched from some repository callbacks = new Callback[] { // The name of the authenticated user new CallerPrincipalCallback(clientSubject, "test"), // the roles of the authenticated user new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) }; } else { // The JASPIC protocol for "do nothing" callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) }; } try { // Communicate the details of the authenticated user to the container. In many // cases the handler will just store the details and the container will actually handle // the login after we return from this method. handler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw (AuthException) new AuthException().initCause(e); } return SUCCESS; }
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); Callback[] callbacks; if (request.getParameter("doLogin") != null) { // For the test perform a login by directly "returning" the details of the authenticated user. // Normally credentials would be checked and the details fetched from some repository callbacks = new Callback[] { // The name of the authenticated user new CallerPrincipalCallback(clientSubject, "test"), // the roles of the authenticated user new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) }; } else { // The JASPIC protocol for "do nothing" callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) }; } try { // Communicate the details of the authenticated user to the container. In many // cases the handler will just store the details and the container will actually handle // the login after we return from this method. handler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw (AuthException) new AuthException().initCause(e); } return SUCCESS; }
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); Callback[] callbacks; if (request.getAttribute("doLogin") != null) { // notice "getAttribute" here, this is set by the Servlet // For the test perform a login by directly "returning" the details of the authenticated user. // Normally credentials would be checked and the details fetched from some repository callbacks = new Callback[] { // The name of the authenticated user new CallerPrincipalCallback(clientSubject, "test"), // the roles of the authenticated user new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) }; } else { // The JASPIC protocol for "do nothing" callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) }; } try { // Communicate the details of the authenticated user to the container. In many // cases the handler will just store the details and the container will actually handle // the login after we return from this method. handler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw (AuthException) new AuthException().initCause(e); } return SUCCESS; }
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage(); if ("cdi".equals(request.getParameter("tech"))) { callCDIBean(request, response, "validateRequest"); } else if ("ejb".equals(request.getParameter("tech"))) { callEJBBean(response, "validateRequest"); } try { handler.handle(new Callback[] { new CallerPrincipalCallback(clientSubject, "test"), new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) }); return SUCCESS; } catch (IOException | UnsupportedCallbackException e) { throw (AuthException) new AuthException().initCause(e); } }
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { try { handler.handle(new Callback[] { new CallerPrincipalCallback(clientSubject, "test"), new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) }); } catch (IOException | UnsupportedCallbackException e) { throw (AuthException) new AuthException().initCause(e); } // Wrap the request - the resource to be invoked should get to see this messageInfo.setRequestMessage(new TestHttpServletRequestWrapper( (HttpServletRequest) messageInfo.getRequestMessage()) ); // Wrap the response - the resource to be invoked should get to see this messageInfo.setResponseMessage(new TestHttpServletResponseWrapper( (HttpServletResponse) messageInfo.getResponseMessage()) ); return SUCCESS; }
public static void notifyContainerAboutLogin(Subject clientSubject, CallbackHandler handler, Principal callerPrincipal, Set<String> groups) { handleCallbacks(clientSubject, handler, new CallerPrincipalCallback(clientSubject, callerPrincipal), groups); }
public static void notifyContainerAboutLogin(Subject clientSubject, CallbackHandler handler, Principal callerPrincipal, Set<String> groups) { handleCallbacks(clientSubject, handler, new CallerPrincipalCallback(clientSubject, callerPrincipal), groups); }
public void updateOtherPartySubject( Subject subject, String username, String password) { CallerPrincipalCallback pvCallback = new CallerPrincipalCallback(subject, username); Callback[] callbacks = new Callback[] { pvCallback }; try { _handler.handle(callbacks); } catch (Exception e) { log.log(Level.SEVERE, "WSS0216.callbackhandler.handle.exception", new Object[] { "CallerPrincipalCallback"}); throw new XWSSecurityRuntimeException(e); } }
public static void notifyContainerAboutLogin(Subject clientSubject, CallbackHandler handler, String callerPrincipalName, Set<String> groups) { handleCallbacks(clientSubject, handler, new CallerPrincipalCallback(clientSubject, callerPrincipalName), groups); }
public static void notifyContainerAboutLogin(Subject clientSubject, CallbackHandler handler, String callerPrincipalName, Set<String> groups) { handleCallbacks(clientSubject, handler, new CallerPrincipalCallback(clientSubject, callerPrincipalName), groups); }
public void updateOtherPartySubject( final Subject subject, final X509Certificate cert) { Principal principal = cert.getSubjectX500Principal(); AccessController.doPrivileged( new PrivilegedAction() { public Object run() { subject.getPublicCredentials().add(cert); return null; } }); CallerPrincipalCallback pvCallback = new CallerPrincipalCallback(subject,principal); Callback[] callbacks = new Callback[] { pvCallback }; try { _handler.handle(callbacks); } catch (Exception e) { log.log(Level.SEVERE, "WSS0216.callbackhandler.handle.exception", new Object[] { "CallerPrincipalCallback"}); throw new XWSSecurityRuntimeException(e); } }
/** * Register with the CallbackHandler * @param userPrincipal * @param username * @param password */ protected void registerWithCallbackHandler(Principal userPrincipal, String username, String password) { if(this.callbackHandler instanceof TomcatJASPICallbackHandler) { TomcatJASPICallbackHandler cbh = (TomcatJASPICallbackHandler) callbackHandler; PasswordValidationCallback passwordValidationCallback = new PasswordValidationCallback(null,username,password.toCharArray()); cbh.setPasswordValidationCallback(passwordValidationCallback); cbh.setCallerPrincipalCallback(new CallerPrincipalCallback(null,userPrincipal)); } else throw new RuntimeException(" Unsupported Callback handler " + this.callbackHandler.getClass().getCanonicalName()); } }
public Callback handleCallerPrincipalCallbackWithMapping(CallerPrincipalCallback cpc) { CallerPrincipalCallback asCPC; Principal eisPrincipal = cpc.getPrincipal(); String eisName = cpc.getName(); Principal asPrincipal = getMappedPrincipal(eisPrincipal, eisName); asCPC = new CallerPrincipalCallback(cpc.getSubject(), asPrincipal); return asCPC; /* Set<Principal> principals = cpc.getSubject().getPrincipals(); for (Principal p : principals) { Principal mappedPrincipal = (Principal) securityMap.get(p); if (mappedPrincipal != null) { DistinguishedPrincipalCredential dpc = new DistinguishedPrincipalCredential(mappedPrincipal); cpc.getSubject().getPublicCredentials().add(dpc); } } SecurityContext.setCurrent(new SecurityContext(cpc.getSubject())); */ }