Package org.jboss.security.auth.message

Examples of org.jboss.security.auth.message.GenericMessageInfo


            if (reauthenticateFromSSO(ssoId, request))
               return true;
         }
      }     

      GenericMessageInfo messageInfo = new GenericMessageInfo();
      messageInfo.setRequestMessage(request);
      // FIXME: Change message info to operate on HttpServletResponse, to align with Servlet 3.0
      messageInfo.setResponseMessage(request.getResponse());
     
      //Put bits of information needed by tomcat server auth modules
      messageInfo.getMap().put("CACHE", cache);
     
      TomcatJASPICallbackHandler cbh = new TomcatJASPICallbackHandler();
     
      ServerAuthenticationManager sam = getServerAuthenticationManager();
      if(sam != null)
View Full Code Here


    */
   public Principal authenticate(Request request, HttpServletResponse response,
         LoginConfig config) throws Exception
   {
      log.debug("ExtendedSecurityMgrRealm:authenticate");
      MessageInfo authParam = new GenericMessageInfo(request, request.getResponse());
      GeneralizedAuthenticationManager gam = getAuthenticationManager();
      Subject clientSubject = new Subject();
      Subject serviceSubject = new Subject();
      Map sharedState = getSharedState(request,config);
      AuthStatus status = AuthStatus.FAILURE;
View Full Code Here

    */
   public Principal authenticate(Request request, Response response,
         LoginConfig config) throws Exception
   {
      log.debug("ExtendedSecurityMgrRealm:authenticate");
      MessageInfo authParam = new GenericMessageInfo(request,response);
      GeneralizedAuthenticationManager gam = getAuthenticationManager();
      Subject clientSubject = new Subject();
      Subject serviceSubject = new Subject();
      Map sharedState = getSharedState(request,config);
      AuthStatus status = AuthStatus.FAILURE;
View Full Code Here

                    return true;
            }
        }

        // TODO: change message info to operate on HttpServletResponse, to align with Servlet 3.0
        GenericMessageInfo messageInfo = new GenericMessageInfo();
        messageInfo.setRequestMessage(request);
        messageInfo.setResponseMessage(request.getResponse());

        // put bits of information needed by tomcat server auth modules
        messageInfo.getMap().put("CACHE", String.valueOf(cache));
        messageInfo.getMap().put("javax.security.auth.message.MessagePolicy.isMandatory", "true");

        WebJASPICallbackHandler cbh = new WebJASPICallbackHandler();
        ServerAuthenticationManager sam = getServerAuthenticationManager();
        String appContext = request.getLocalName() + " " + request.getContextPath();
        Subject clientSubject = new Subject();
View Full Code Here

            if (reauthenticateFromSSO(ssoId, request))
               return true;
         }
      }     

      GenericMessageInfo messageInfo = new GenericMessageInfo();
      messageInfo.setRequestMessage(request);
      messageInfo.setResponseMessage(response);
     
      //Put bits of information needed by tomcat server auth modules
      messageInfo.getMap().put("CACHE", cache);
     
      TomcatJASPICallbackHandler cbh = new TomcatJASPICallbackHandler();
     
      ServerAuthenticationManager sam = getServerAuthenticationManager();
      if(sam != null)
View Full Code Here

   public void testValidateRequest() throws Exception
   {
      Class[] clazzArr = new Class[] {HttpServlet.class};
      module = new SimpleServerAuthModule(clazzArr);
      Subject sub = createSubject();
      module.validateRequest(new GenericMessageInfo(null,null), sub, sub );
      module = null;
   }
View Full Code Here

   public void testSecureResponse() throws Exception
   {
      //ToDO: Enhance this test
      module = new SimpleServerAuthModule(new Class[] {HttpServlet.class});
      Subject sub = createSubject();
      module.secureResponse(new GenericMessageInfo(null,null), sub);
      module = null;
   }
View Full Code Here

    @Override
    public AuthenticationMechanismOutcome authenticate(final HttpServerExchange exchange, final SecurityContext sc) {
        final ServletRequestContext requestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
        final JASPIServerAuthenticationManager sam = createJASPIAuthenticationManager();
        final GenericMessageInfo messageInfo = createMessageInfo(exchange, sc);
        final String applicationIdentifier = buildApplicationIdentifier(requestContext);
        final JASPICallbackHandler cbh = new JASPICallbackHandler();

        UndertowLogger.ROOT_LOGGER.debugf("validateRequest for layer [%s] and applicationContextIdentifier [%s]", JASPI_HTTP_SERVLET_LAYER, applicationIdentifier);

        Account cachedAccount = null;
        final JASPICSecurityContext jaspicSecurityContext = (JASPICSecurityContext) exchange.getSecurityContext();
        final AuthenticatedSessionManager sessionManager = exchange.getAttachment(AuthenticatedSessionManager.ATTACHMENT_KEY);

        if (sessionManager != null) {
            AuthenticatedSessionManager.AuthenticatedSession authSession = sessionManager.lookupSession(exchange);
            cachedAccount = authSession.getAccount();
            // if there is a cached account we set it in the security context so that the principal is available to
            // SAM modules via request.getUserPrincipal().
            if (cachedAccount !=  null) {
                jaspicSecurityContext.setCachedAuthenticatedAccount(cachedAccount);
            }
        }

        AuthenticationMechanismOutcome outcome = AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
        Account authenticatedAccount = null;

        boolean isValid = sam.isValid(messageInfo, new Subject(), JASPI_HTTP_SERVLET_LAYER, applicationIdentifier, cbh);
        jaspicSecurityContext.setCachedAuthenticatedAccount(null);

        if (isValid) {
            // The CBH filled in the JBOSS SecurityContext, we need to create an Undertow account based on that
            org.jboss.security.SecurityContext jbossSct = SecurityActions.getSecurityContext();
            authenticatedAccount = createAccount(cachedAccount, jbossSct);
        }

        // authType resolution (check message info first, then check for the configured auth method, then use mech-specific name).
        String authType = (String) messageInfo.getMap().get(JASPI_AUTH_TYPE);
        if (authType == null)
            authType = this.configuredAuthMethod != null ? this.configuredAuthMethod : MECHANISM_NAME;

        if (isValid && authenticatedAccount != null) {
            outcome = AuthenticationMechanismOutcome.AUTHENTICATED;

            Object registerObj = messageInfo.getMap().get(JASPI_REGISTER_SESSION);
            boolean cache = false;
            if(registerObj != null && (registerObj instanceof String)) {
                cache = Boolean.valueOf((String)registerObj);
            }
            sc.authenticationComplete(authenticatedAccount, authType, cache);
        } else if (isValid && authenticatedAccount == null && !isMandatory(requestContext)) {
            outcome = AuthenticationMechanismOutcome.NOT_ATTEMPTED;
        } else {
            outcome = AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
            sc.authenticationFailed("JASPIC authentication failed.", authType);
        }

        // A SAM can wrap the HTTP request/response objects - update the servlet request context with the values found in the message info.
        ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
        servletRequestContext.setServletRequest((HttpServletRequest) messageInfo.getRequestMessage());
        servletRequestContext.setServletResponse((HttpServletResponse) messageInfo.getResponseMessage());

        secureResponse(exchange, sam, messageInfo, cbh);

        return outcome;
View Full Code Here

    }

    private GenericMessageInfo createMessageInfo(final HttpServerExchange exchange, final SecurityContext securityContext) {
        ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);

        GenericMessageInfo messageInfo = new GenericMessageInfo();

        messageInfo.setRequestMessage(servletRequestContext.getServletRequest());
        messageInfo.setResponseMessage(servletRequestContext.getServletResponse());

        messageInfo.getMap().put("javax.security.auth.message.MessagePolicy.isMandatory", isMandatory(servletRequestContext).toString());

        // additional context data, useful to provide access to Undertow resources during the modules processing
        messageInfo.getMap().put(SECURITY_CONTEXT_ATTACHMENT_KEY, securityContext);
        messageInfo.getMap().put(HTTP_SERVER_EXCHANGE_ATTACHMENT_KEY, exchange);

        return messageInfo;
    }
View Full Code Here

     *
     * @return the constructed {@code MessageInfo} object.
     */
    private MessageInfo buildMessageInfo() {
        ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
        GenericMessageInfo messageInfo = new GenericMessageInfo();
        messageInfo.setRequestMessage(servletRequestContext.getServletRequest());
        messageInfo.setResponseMessage(servletRequestContext.getServletResponse());
        // when calling cleanSubject, isMandatory must be set to true.
        messageInfo.getMap().put("javax.security.auth.message.MessagePolicy.isMandatory", "true");
        return messageInfo;

    }
View Full Code Here

TOP

Related Classes of org.jboss.security.auth.message.GenericMessageInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.