Package org.jboss.identity.federation.web.core

Examples of org.jboss.identity.federation.web.core.HTTPContext


            SAML2HandlerResponse response ) throws ProcessingException
      {
         //Handler a log out response from IDP
         StatusResponseType statusResponseType = (StatusResponseType) request.getSAML2Object();
        
         HTTPContext httpContext = (HTTPContext) request.getContext();
         HttpServletRequest servletRequest = httpContext.getRequest();
         HttpSession session = servletRequest.getSession(false);
        
         //TODO: Deal with partial logout report
        
         StatusType statusType = statusResponseType.getStatus();
View Full Code Here


         SAML2Object samlObject = request.getSAML2Object();
         if(samlObject instanceof LogoutRequestType == false)
            return;
        
         LogoutRequestType logOutRequest = (LogoutRequestType) samlObject;
         HTTPContext httpContext = (HTTPContext) request.getContext();
         HttpServletRequest servletRequest = httpContext.getRequest();
         HttpSession session = servletRequest.getSession(false);
        
         String relayState = servletRequest.getParameter("RelayState");
        
         session.invalidate(); //Invalidate the current session at the SP
View Full Code Here

               if(!isValid)
                  throw new GeneralSecurityException("Validation check failed");

               String issuer = null;
               IssuerInfoHolder idpIssuer = new IssuerInfoHolder(this.identityURL);
               ProtocolContext protocolContext = new HTTPContext(request,response, context);
               //Create the request/response
               SAML2HandlerRequest saml2HandlerRequest =
                  new DefaultSAML2HandlerRequest(protocolContext,
                        idpIssuer.getIssuer(), samlObject,
                        HANDLER_TYPE.IDP);
               saml2HandlerRequest.setRelayState(relayState);
              
               Map<String, Object> requestOptions = new HashMap<String, Object>();
               requestOptions.put("ROLE_GENERATOR", rg);
               saml2HandlerRequest.setOptions(requestOptions);
              
               SAML2HandlerResponse saml2HandlerResponse = new DefaultSAML2HandlerResponse();

               Set<SAML2Handler> handlers = chain.handlers();
              
               if(samlObject instanceof StatusResponseType)
               {
                  statusResponseType = (StatusResponseType) samlObject;
                  issuer = statusResponseType.getIssuer().getValue();
                  webRequestUtil.isTrusted(issuer);
                 
                  if(handlers != null)
                  {
                     for(SAML2Handler handler: handlers)
                     {
                        handler.handleStatusResponseType(saml2HandlerRequest, saml2HandlerResponse);
                     }
                  } 
               }
               else
                  throw new RuntimeException("Unknown type:" + samlObject.getClass().getName());

               samlResponse = saml2HandlerResponse.getResultingDocument();
               relayState = saml2HandlerResponse.getRelayState();
              
               destination = saml2HandlerResponse.getDestination();
            }
            catch(Exception e)
            {
               throw new RuntimeException(e);
            }
             
         }
         else
         //Send valid saml response after processing the request
         if(samlRequestMessage != null)
         {
            //Get the SAML Request Message
            RequestAbstractType requestAbstractType =  null;
            StatusResponseType statusResponseType = null;
           
            try
            {
               samlObject = webRequestUtil.getSAMLObject(samlRequestMessage);
              
               boolean isPost = webRequestUtil.hasSAMLRequestInPostProfile();
               boolean isValid = validate(request.getRemoteAddr(),
                     request.getQueryString(),
                     new SessionHolder(samlRequestMessage, null), isPost);
              
               if(!isValid)
                  throw new GeneralSecurityException("Validation check failed");

               String issuer = null;
               IssuerInfoHolder idpIssuer = new IssuerInfoHolder(this.identityURL);
               ProtocolContext protocolContext = new HTTPContext(request,response, context);
               //Create the request/response
               SAML2HandlerRequest saml2HandlerRequest =
                  new DefaultSAML2HandlerRequest(protocolContext,
                        idpIssuer.getIssuer(), samlObject,
                        HANDLER_TYPE.IDP);
View Full Code Here

      }
     
      public void handleStatusResponseType( SAML2HandlerRequest request,
            SAML2HandlerResponse response ) throws ProcessingException
      {
         HTTPContext httpContext = (HTTPContext) request.getContext();
         ResponseType responseType = (ResponseType) request.getSAML2Object();
         List<Object> assertions = responseType.getAssertionOrEncryptedAssertion();
         if(assertions.size() == 0)
            throw new IllegalStateException("No assertions in reply from IDP");
        
         Object assertion = assertions.get(0);
         if(assertion instanceof EncryptedElementType)
         {
            responseType = this.decryptAssertion(responseType);
         }
        
         Principal userPrincipal = handleSAMLResponse(responseType);
         if(userPrincipal == null)
         {
            response.setError(403, "User Principal not determined: Forbidden");
         }
         else
         {
            //add it to the session
            HttpSession session = httpContext.getRequest().getSession(false);
            session.setAttribute(GeneralConstants.PRINCIPAL_ID, userPrincipal);
         }
      }
View Full Code Here

     
      //only handle IDP side
      if(request.getType() == SAML2HandlerRequest.HANDLER_TYPE.SP)
         return;
     
      HTTPContext httpContext = (HTTPContext) request.getContext();
      HttpSession session = httpContext.getRequest().getSession(false);
     
      Principal userPrincipal = (Principal) session.getAttribute(GeneralConstants.PRINCIPAL_ID);
      List<String> roles = (List<String>) session.getAttribute(GeneralConstants.ROLES_ID);
     
      if(roles == null)
View Full Code Here

           
            //Ask the handler chain to generate the saml request
            Set<SAML2Handler> handlers = chain.handlers();
           
            IssuerInfoHolder holder = new IssuerInfoHolder(this.serviceURL);
            ProtocolContext protocolContext = new HTTPContext(request,response, context);
            //Create the request/response
            SAML2HandlerRequest saml2HandlerRequest =
               new DefaultSAML2HandlerRequest(protocolContext,
                     holder.getIssuer(), null,
                     HANDLER_TYPE.SP);
            SAML2HandlerResponse saml2HandlerResponse = new DefaultSAML2HandlerResponse();
         
            saml2HandlerResponse.setDestination(identityURL);
           
            //Reset the state
            try
            {
               for(SAML2Handler handler: handlers)
               {
                  handler.reset();
                  if(saml2HandlerResponse.isInError())
                  {
                     response.sendError(saml2HandlerResponse.getErrorCode());
                     break;
                  }
                  saml2HandlerRequest.setTypeOfRequestToBeGenerated(GENERATE_REQUEST_TYPE.AUTH);
                  handler.generateSAMLRequest(saml2HandlerRequest, saml2HandlerResponse);
               }
            }
            catch(ProcessingException pe)
            {
               throw new RuntimeException(pe);
            }
            Document samlResponseDocument = saml2HandlerResponse.getResultingDocument();
            String relayState = saml2HandlerResponse.getRelayState();
           
            String destination = saml2HandlerResponse.getDestination();
           
           
            if(destination != null &&
                  samlResponseDocument != null)
            {
               try
               {
                  this.sendToDestination(samlResponseDocument, relayState, destination, response);
               }
               catch (Exception e)
               {
                  if(trace)
                     log.trace("Exception:",e);
                  throw new ServletException("Server Error");
               }
               return;
            }
         }
        
         //See if we got a response from IDP
         if(samlResponse != null && samlResponse.length() > 0 )
         {
            boolean isValid = false;
            try
            {
               isValid = this.validate(request);
            }
            catch (Exception e)
            {
               throw new ServletException(e);
            }
            if(!isValid)
               throw new ServletException("Validity check failed");
           
            //deal with SAML response from IDP
            byte[] base64DecodedResponse = PostBindingUtil.base64Decode(samlResponse);
            InputStream is = new ByteArrayInputStream(base64DecodedResponse);

            try
            {
               SAML2Response saml2Response = new SAML2Response();
              
               SAML2Object samlObject = saml2Response.getSAML2ObjectFromStream(is);
              
               Set<SAML2Handler> handlers = chain.handlers();
               IssuerInfoHolder holder = new IssuerInfoHolder(this.serviceURL);
               ProtocolContext protocolContext = new HTTPContext(request,response, context);
               //Create the request/response
               SAML2HandlerRequest saml2HandlerRequest =
                  new DefaultSAML2HandlerRequest(protocolContext,
                        holder.getIssuer(), samlObject,
                        HANDLER_TYPE.SP);
View Full Code Here

     
         //we got a logout response from a SP
         SAML2Object samlObject = request.getSAML2Object();
         StatusResponseType statusResponseType = (StatusResponseType) samlObject;
        
         HTTPContext httpContext = (HTTPContext) request.getContext();
         HttpServletRequest httpRequest = httpContext.getRequest();
         HttpSession httpSession = httpRequest.getSession(false);
        
         String relayState = request.getRelayState();
        
         ServletContext servletCtx = httpContext.getServletContext();
         IdentityServer server = (IdentityServer)servletCtx.getAttribute("IDENTITY_SERVER");
        
         if(server == null)
            throw new ProcessingException("Identity Server not found");
        
View Full Code Here

      }
     
      public void handleRequestType( SAML2HandlerRequest request,
            SAML2HandlerResponse response ) throws ProcessingException
      {
         HTTPContext httpContext = (HTTPContext) request.getContext();
         HttpSession session = httpContext.getRequest().getSession(false);
         String sessionID = session.getId();
        
         String relayState = httpContext.getRequest().getParameter("RelayState");
        
         LogoutRequestType logOutRequest = (LogoutRequestType) request.getSAML2Object();
         String issuer = logOutRequest.getIssuer().getValue();
         try
         {
            SAML2Response saml2Response = new SAML2Response();
            SAML2Request saml2Request = new SAML2Request();
           
            ServletContext servletCtx = httpContext.getServletContext();
            IdentityServer server = (IdentityServer)servletCtx.getAttribute("IDENTITY_SERVER");
           
            if(server == null)
               throw new ProcessingException("Identity Server not found");
           
View Full Code Here

   }
  

   public static HttpServletRequest getHttpRequest(SAML2HandlerRequest request)
   {
      HTTPContext context = (HTTPContext) request.getContext();
      return context.getRequest();
   }
View Full Code Here

      return context.getRequest();
   }
  
   public static HttpSession getHttpSession(SAML2HandlerRequest request)
   {
      HTTPContext context = (HTTPContext) request.getContext();
      return context.getRequest().getSession(false);
   }
View Full Code Here

TOP

Related Classes of org.jboss.identity.federation.web.core.HTTPContext

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.