Package org.jboss.identity.federation.api.saml.v2.request

Examples of org.jboss.identity.federation.api.saml.v2.request.SAML2Request


      if(trace)
         log.trace("AssertionConsumerURL=" + assertionConsumerURL +
            "::assertion validity=" + assertionValidity);
      ResponseType responseType = null;    
     
      SAML2Response saml2Response = new SAML2Response();
           
      //Create a response type
      String id = IDGenerator.create("ID_");

      IssuerInfoHolder issuerHolder = new IssuerInfoHolder(identityURL);
      issuerHolder.setStatusCode(JBossSAMLURIConstants.STATUS_SUCCESS.get());

      IDPInfoHolder idp = new IDPInfoHolder();
      idp.setNameIDFormatValue(userPrincipal.getName());
      idp.setNameIDFormat(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get());

      SPInfoHolder sp = new SPInfoHolder();
      sp.setResponseDestinationURI(assertionConsumerURL);
      responseType = saml2Response.createResponseType(id, sp, idp, issuerHolder);
     
     
      //Add information on the roles
      AssertionType assertion = (AssertionType) responseType.getAssertionOrEncryptedAssertion().get(0);

      AttributeStatementType attrStatement = saml2Response.createAttributeStatement(roles);
      assertion.getStatementOrAuthnStatementOrAuthzDecisionStatement().add(attrStatement);
     
      //Add timed conditions
      saml2Response.createTimedConditions(assertion, assertionValidity);
      //Lets see how the response looks like
      if(log.isTraceEnabled())
      {
         StringWriter sw = new StringWriter();
         try
         {
            saml2Response.marshall(responseType, sw);
         }
         catch (JAXBException e)
         {
            log.trace(e);
         }
         catch (SAXException e)
         {
            log.trace(e);
         }
         log.trace("Response="+sw.toString());
      }
     
      if(trace)
         log.trace("Support Sig=" + supportSignature + " ::Post Profile?=" + hasSAMLRequestInPostProfile());
      if(supportSignature && hasSAMLRequestInPostProfile())
      {
         try
         {
            SAML2Signature saml2Signature = new SAML2Signature();
            samlResponseDocument = saml2Signature.sign(responseType, keyManager.getSigningKeyPair());
        
         catch (Exception e)
         { 
            if(trace) log.trace(e);
         }
      }
      else
         try
         {
            samlResponseDocument = saml2Response.convert(responseType);
         }
         catch (Exception e)
         {
            log.trace(e);
         }
View Full Code Here


         String identityURL, boolean supportSignature)
   {
      Document samlResponse = null;
      ResponseType responseType = null;

      SAML2Response saml2Response = new SAML2Response();

      //Create a response type
      String id = IDGenerator.create("ID_");

      IssuerInfoHolder issuerHolder = new IssuerInfoHolder(identityURL);
      issuerHolder.setStatusCode(status);

      IDPInfoHolder idp = new IDPInfoHolder();
      idp.setNameIDFormatValue(null);
      idp.setNameIDFormat(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get());

      SPInfoHolder sp = new SPInfoHolder();
      sp.setResponseDestinationURI(responseURL);
      try
      {
         responseType = saml2Response.createResponseType(id, sp, idp, issuerHolder);
      }
      catch (ConfigurationException e1)
      {
         if(trace) log.trace(e1);
         responseType = saml2Response.createResponseType();
      }

      //Lets see how the response looks like
      if(log.isTraceEnabled())
      {
         log.trace("Error_ResponseType = ");
         StringWriter sw = new StringWriter();
         try
         {
            saml2Response.marshall(responseType, sw);
         }
         catch (JAXBException e)
         {
            log.trace(e);
         }
         catch (SAXException e)
         {
            log.trace(e);
         }
         log.trace("Response="+sw.toString());
      }

      if(supportSignature)
      {
         try
         {
            //SigAlg
            String algo = keyManager.getSigningKey().getAlgorithm();
            String sigAlg = SignatureUtil.getXMLSignatureAlgorithmURI(algo);
           
            sigAlg = URLEncoder.encode(sigAlg, "UTF-8");
            
            SAML2Signature ss = new SAML2Signature();
            samlResponse = ss.sign(responseType, keyManager.getSigningKeyPair());
         }
         catch (Exception e)
         {
            if(trace) log.trace(e);
         }
      }
      else
         try
         {
            samlResponse = saml2Response.convert(responseType);
         }
         catch (Exception e)
         {
            if(trace) log.trace(e);
         }
View Full Code Here

    * @throws GeneralSecurityException
    */
   public static String getSAMLResponseURLWithSignature(ResponseType responseType, String relayState,
         PrivateKey signingKey) throws IOException, GeneralSecurityException
   {
      SAML2Response saml2Response = new SAML2Response();
      
      Document responseDoc = null;
      
      try
      {
         responseDoc = saml2Response.convert(responseType);
      }
      catch (JAXBException e)
      {
         throw new ParsingException(e);
      }
View Full Code Here

      // deal with SAML response from IDP
      byte[] base64DecodedResponse = Base64.decode(samlResponse);
      InputStream is = new ByteArrayInputStream(base64DecodedResponse);

      SAML2Response saml2Response = new SAML2Response();

      ResponseType responseType;
      try
      {
         responseType = saml2Response.getResponseType(is);
      }
      catch (ParsingException e)
      {
         throw new RuntimeException(e);
      }
View Full Code Here

    * @throws MarshalException
    * @throws GeneralSecurityException
    */
   public Document sign(ResponseType response,KeyPair keypair) throws JAXBException, ParserConfigurationException, GeneralSecurityException, MarshalException, XMLSignatureException 
   {
      SAML2Response saml2Request = new SAML2Response();
      Document doc = saml2Request.convert(response);
      doc.normalize();
     
      String referenceURI = "#" + response.getID();
     
      return XMLSignatureUtil.sign(doc,
View Full Code Here

   public Document sign(ResponseType response,
         String idValueOfAssertion,
         KeyPair keypair,
         String referenceURI) throws JAXBException, ParserConfigurationException, XPathException, TransformerFactoryConfigurationError, TransformerException, GeneralSecurityException, MarshalException, XMLSignatureException
   {
      SAML2Response saml2Request = new SAML2Response();
      Document doc = saml2Request.convert(response);
      
     
      Node assertionNode = DocumentUtil.getNodeWithAttribute(doc,
            JBossSAMLURIConstants.ASSERTION_NSURI.get(),
            "Assertion",
View Full Code Here

      if(trace)
         log.trace("AssertionConsumerURL=" + assertionConsumerURL +
            "::assertion validity=" + assertionValidity);
      ResponseType responseType = null;    
     
      SAML2Response saml2Response = new SAML2Response();
           
      //Create a response type
      String id = IDGenerator.create("ID_");

      IssuerInfoHolder issuerHolder = new IssuerInfoHolder(identityURL);
      issuerHolder.setStatusCode(JBossSAMLURIConstants.STATUS_SUCCESS.get());

      IDPInfoHolder idp = new IDPInfoHolder();
      idp.setNameIDFormatValue(userPrincipal.getName());
      idp.setNameIDFormat(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get());

      SPInfoHolder sp = new SPInfoHolder();
      sp.setResponseDestinationURI(assertionConsumerURL);
      responseType = saml2Response.createResponseType(id, sp, idp, issuerHolder);
     
      //Add information on the roles
      AssertionType assertion = (AssertionType) responseType.getAssertionOrEncryptedAssertion().get(0);

      AttributeStatementType attrStatement = saml2Response.createAttributeStatement(roles);
      assertion.getStatementOrAuthnStatementOrAuthzDecisionStatement().add(attrStatement);
     
      //Add timed conditions
      saml2Response.createTimedConditions(assertion, assertionValidity);
     
      //Add in the attributes information
      if(this.attributeManager != null)
      {
         try
         {
            Map<String, Object> attribs =
               attributeManager.getAttributes(userPrincipal, this.attribKeys);
            AttributeStatementType attStatement = StatementUtil.createAttributeStatement(attribs);
            assertion.getStatementOrAuthnStatementOrAuthzDecisionStatement().add(attStatement);
         }
         catch(Exception e)
         {
            log.error("Exception in generating attributes:",e);
         }
      }
      //Lets see how the response looks like
      if(log.isTraceEnabled())
      {
         StringWriter sw = new StringWriter();
         try
         {
            saml2Response.marshall(responseType, sw);
         }
         catch (JAXBException e)
         {
            log.trace(e);
         }
         catch (SAXException e)
         {
            log.trace(e);
         }
         log.trace("Response="+sw.toString());
      }
     
      if(trace)
         log.trace("Support Sig=" + supportSignature + " ::Post Profile?=" + hasSAMLRequestInPostProfile());
      if(supportSignature && hasSAMLRequestInPostProfile())
      {
         try
         {
            SAML2Signature saml2Signature = new SAML2Signature();
            samlResponseDocument = saml2Signature.sign(responseType, keyManager.getSigningKeyPair());
        
         catch (Exception e)
         { 
            if(trace) log.trace(e);
         }
      }
      else
         try
         {
            samlResponseDocument = saml2Response.convert(responseType);
         }
         catch (Exception e)
         {
            log.trace(e);
         }
View Full Code Here

         log.trace("Support Sig=" + supportSignature + " ::Post Profile?=" + hasSAMLRequestInPostProfile());
      if(supportSignature && hasSAMLRequestInPostProfile())
      {
         try
         {
            SAML2Signature saml2Signature = new SAML2Signature();
            samlResponseDocument = saml2Signature.sign(responseType, keyManager.getSigningKeyPair());
        
         catch (Exception e)
         { 
            if(trace) log.trace(e);
         }
View Full Code Here

            String algo = keyManager.getSigningKey().getAlgorithm();
            String sigAlg = SignatureUtil.getXMLSignatureAlgorithmURI(algo);
           
            sigAlg = URLEncoder.encode(sigAlg, "UTF-8");
            
            SAML2Signature ss = new SAML2Signature();
            samlResponse = ss.sign(responseType, keyManager.getSigningKeyPair());
         }
         catch (Exception e)
         {
            if(trace) log.trace(e);
         }
View Full Code Here

    private static final PicketLinkLogger logger = PicketLinkLoggerFactory.getLogger();

    public static SAMLDocumentHolder parseRedirectBinding(String samlMessage) {
        InputStream is;
        is = RedirectBindingUtil.base64DeflateDecode(samlMessage);
        SAML2Request saml2Request = new SAML2Request();
        try {
            saml2Request.getSAML2ObjectFromStream(is);
            return saml2Request.getSamlDocumentHolder();
        } catch (Exception e) {
            logger.samlBase64DecodingError(e);
        }
        return null;
View Full Code Here

TOP

Related Classes of org.jboss.identity.federation.api.saml.v2.request.SAML2Request

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.