Package org.jboss.identity.federation.core.saml.v2.factories

Examples of org.jboss.identity.federation.core.saml.v2.factories.JBossSAMLAuthnRequestFactory


      InputStream is = context.getResourceAsStream(configFile);
      if(is == null)
         throw new RuntimeException(configFile + " missing");

      //Get the chain from config
      chain = new DefaultSAML2HandlerChain();
     
      try
      {
         idpConfiguration = ConfigurationUtil.getIDPConfiguration(is);
         this.identityURL = idpConfiguration.getIdentityURL();
View Full Code Here


           
            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);
              
               Map<String,Object> requestOptions = new HashMap<String,Object>();
               requestOptions.put(GeneralConstants.CONFIGURATION, this.spConfiguration);
               saml2HandlerRequest.setOptions(requestOptions);
              
               SAML2HandlerResponse saml2HandlerResponse = new DefaultSAML2HandlerResponse();
            
               //Deal with handler chains
               for(SAML2Handler handler : handlers)
View Full Code Here

               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);
               saml2HandlerRequest.setRelayState(relayState);
              
               Map<String, Object> requestOptions = new HashMap<String, Object>();
               requestOptions.put(GeneralConstants.ROLE_GENERATOR, rg);
               requestOptions.put(GeneralConstants.ASSERTIONS_VALIDITY, this.assertionValidity);
               requestOptions.put(GeneralConstants.CONFIGURATION, this.idpConfiguration);
               Map<String,Object> attribs  = this.attribManager.getAttributes(userPrincipal, attributeKeys);
               requestOptions.put(GeneralConstants.ATTRIBUTES, attribs);
              
               saml2HandlerRequest.setOptions(requestOptions);
              
               List<String> roles = (List<String>) session.getAttribute(GeneralConstants.ROLES_ID);
               if(roles == null)
               {
                  roles = rg.generateRoles(userPrincipal);
View Full Code Here

            //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);
              
               Map<String,Object> requestOptions = new HashMap<String,Object>();
               requestOptions.put(GeneralConstants.CONFIGURATION, this.spConfiguration);
               saml2HandlerRequest.setOptions(requestOptions);
              
               SAML2HandlerResponse saml2HandlerResponse = new DefaultSAML2HandlerResponse();
            
               //Deal with handler chains
               for(SAML2Handler handler : handlers)
               {
                  if(saml2HandlerResponse.isInError())
                  {
                     response.sendError(saml2HandlerResponse.getErrorCode());
                     break;
                  }
                  if(samlObject instanceof RequestAbstractType)
                  {
                     handler.handleRequestType(saml2HandlerRequest, saml2HandlerResponse);
                  }
                  else
                  {
                     handler.handleStatusResponseType(saml2HandlerRequest, saml2HandlerResponse);
                  }
               }

               Document samlResponseDocument = saml2HandlerResponse.getResultingDocument();
               String relayState = saml2HandlerResponse.getRelayState();
              
               String destination = saml2HandlerResponse.getDestination();
              
              
               if(destination != null &&
                     samlResponseDocument != null)
               {
View Full Code Here

              
               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);
               saml2HandlerRequest.setRelayState(relayState);
              
               Map<String, Object> requestOptions = new HashMap<String, Object>();
               requestOptions.put(GeneralConstants.ROLE_GENERATOR, rg);
               requestOptions.put(GeneralConstants.ASSERTIONS_VALIDITY, this.assertionValidity);
               requestOptions.put(GeneralConstants.CONFIGURATION, this.idpConfiguration);
               Map<String,Object> attribs  = this.attribManager.getAttributes(userPrincipal, attributeKeys);
               requestOptions.put(GeneralConstants.ATTRIBUTES, attribs);
              
               saml2HandlerRequest.setOptions(requestOptions);
              
               List<String> roles = (List<String>) session.getAttribute(GeneralConstants.ROLES_ID);
               if(roles == null)
               {
                  roles = rg.generateRoles(userPrincipal);
                  session.setAttribute(GeneralConstants.ROLES_ID, roles);
               }
              
               SAML2HandlerResponse saml2HandlerResponse = new DefaultSAML2HandlerResponse();

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

               samlResponse = saml2HandlerResponse.getResultingDocument();
               relayState = saml2HandlerResponse.getRelayState();
              
               destination = saml2HandlerResponse.getDestination();
              
              
               //requestAbstractType = webRequestUtil.getSAMLRequest(samlMessage);
              
              
View Full Code Here

         Class<?> clazz;
         try
         {
            clazz = tcl.loadClass(clazzName);

            SAML2Handler samlhandler = (SAML2Handler) clazz.newInstance();
            List<KeyValueType> options = handler.getOption();

            Map<String, Object> mapOptions = new HashMap<String, Object>();

            for(KeyValueType kvtype : options)
            {
               mapOptions.put(kvtype.getKey(), kvtype.getValue());
            }
            samlhandler.init(mapOptions);

            handlerSet.add(samlhandler);
         }
         catch (ClassNotFoundException e)
         {
View Full Code Here

            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);
              
               Map<String,Object> requestOptions = new HashMap<String,Object>();
               requestOptions.put(GeneralConstants.CONFIGURATION, this.spConfiguration);
               saml2HandlerRequest.setOptions(requestOptions);
              
               SAML2HandlerResponse saml2HandlerResponse = new DefaultSAML2HandlerResponse();
            
               //Deal with handler chains
               for(SAML2Handler handler : handlers)
View Full Code Here

               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);
               saml2HandlerRequest.setRelayState(relayState);
              
               Map<String, Object> requestOptions = new HashMap<String, Object>();
               requestOptions.put(GeneralConstants.ROLE_GENERATOR, rg);
               requestOptions.put(GeneralConstants.ASSERTIONS_VALIDITY, this.assertionValidity);
               requestOptions.put(GeneralConstants.CONFIGURATION, this.idpConfiguration);
               Map<String,Object> attribs  = this.attribManager.getAttributes(userPrincipal, attributeKeys);
               requestOptions.put(GeneralConstants.ATTRIBUTES, attribs);
              
               saml2HandlerRequest.setOptions(requestOptions);
              
               List<String> roles = (List<String>) session.getAttribute(GeneralConstants.ROLES_ID);
               if(roles == null)
               {
                  roles = rg.generateRoles(userPrincipal);
View Full Code Here

            //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);
              
               Map<String,Object> requestOptions = new HashMap<String,Object>();
               requestOptions.put(GeneralConstants.CONFIGURATION, this.spConfiguration);
               saml2HandlerRequest.setOptions(requestOptions);
              
               SAML2HandlerResponse saml2HandlerResponse = new DefaultSAML2HandlerResponse();
            
               //Deal with handler chains
               for(SAML2Handler handler : handlers)
               {
                  if(saml2HandlerResponse.isInError())
                  {
                     response.sendError(saml2HandlerResponse.getErrorCode());
                     break;
                  }
                  if(samlObject instanceof RequestAbstractType)
                  {
                     handler.handleRequestType(saml2HandlerRequest, saml2HandlerResponse);
                  }
                  else
                  {
                     handler.handleStatusResponseType(saml2HandlerRequest, saml2HandlerResponse);
                  }
               }

               Document samlResponseDocument = saml2HandlerResponse.getResultingDocument();
               String relayState = saml2HandlerResponse.getRelayState();
              
               String destination = saml2HandlerResponse.getDestination();
              
              
               if(destination != null &&
                     samlResponseDocument != null)
               {
View Full Code Here

              
               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);
               saml2HandlerRequest.setRelayState(relayState);
              
               Map<String, Object> requestOptions = new HashMap<String, Object>();
               requestOptions.put(GeneralConstants.ROLE_GENERATOR, rg);
               requestOptions.put(GeneralConstants.ASSERTIONS_VALIDITY, this.assertionValidity);
               requestOptions.put(GeneralConstants.CONFIGURATION, this.idpConfiguration);
               Map<String,Object> attribs  = this.attribManager.getAttributes(userPrincipal, attributeKeys);
               requestOptions.put(GeneralConstants.ATTRIBUTES, attribs);
              
               saml2HandlerRequest.setOptions(requestOptions);
              
               List<String> roles = (List<String>) session.getAttribute(GeneralConstants.ROLES_ID);
               if(roles == null)
               {
                  roles = rg.generateRoles(userPrincipal);
                  session.setAttribute(GeneralConstants.ROLES_ID, roles);
               }
              
               SAML2HandlerResponse saml2HandlerResponse = new DefaultSAML2HandlerResponse();

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

               samlResponse = saml2HandlerResponse.getResultingDocument();
               relayState = saml2HandlerResponse.getRelayState();
              
               destination = saml2HandlerResponse.getDestination();
              
              
               //requestAbstractType = webRequestUtil.getSAMLRequest(samlMessage);
              
              
View Full Code Here

TOP

Related Classes of org.jboss.identity.federation.core.saml.v2.factories.JBossSAMLAuthnRequestFactory

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.