Package org.opensaml

Examples of org.opensaml.SAMLResponse


      try
      {
         String response = null;
        
         //construct the SAML Response
         SAMLResponse authResponse = new SAMLResponse();
         authResponse.setId(this.idProvider.getIdentifier());
        
         if(success)
         {
            //create a successfull authenticationstatment
            SAMLNameIdentifier id = new SAMLNameIdentifier();
            id.setName(username);
            id.setFormat(SAMLNameIdentifier.FORMAT_UNSPECIFIED);
            SAMLSubject subject = new SAMLSubject();
            subject.setNameIdentifier(id);
           
            String methodStr = SAMLAuthenticationStatement.AuthenticationMethod_Password;
            SAMLAuthenticationStatement authStatement = new SAMLAuthenticationStatement();
           
            authStatement.setAuthMethod(methodStr);
            authStatement.setSubject(subject);
            authStatement.setAuthInstant(new Date());
           
            //create an assertion
            SAMLAssertion authAssertion = new SAMLAssertion();
            authAssertion.setId(this.idProvider.getIdentifier());
            authAssertion.setIssuer(assertingParty);
            authAssertion.addStatement(authStatement);
           
            //create the SAMLResponse           
            authResponse.addAssertion(authAssertion);
         }
         else
         {
            SAMLException loginFailed = new SAMLException(LOGIN_FAILED);
            authResponse.setStatus(loginFailed);
         }
        
         response = authResponse.toString();
        
         return response;
      }
      catch(SAMLException sme)
      {
View Full Code Here


      String assertingParty = null;
      String username = null;
      try
      {                       
          bis = new ByteArrayInputStream(resp.getBytes());
          SAMLResponse response = new SAMLResponse(bis);
         
          Iterator assertions = response.getAssertions();
          if(assertions!=null && assertions.hasNext())
          {
              success = true;
              SAMLAssertion authAssertion = (SAMLAssertion)assertions.next();
              assertToken = authAssertion.getId();
View Full Code Here

        throws Exception {
        final WebApplicationService service = this.samlArgumentExtractor.extractService(request);
        final String artifactId = service != null ? service.getArtifactId() : null;
        final String serviceId = service != null ? service.getId() : "UNKNOWN";
        final String errorMessage = (String) model.get("description");
        final SAMLResponse samlResponse = new SAMLResponse(artifactId, serviceId, new ArrayList<Object>(), new SAMLException(errorMessage));
        samlResponse.setIssueInstant(new Date());

        response.setContentType("text/xml; charset=" + this.encoding);
        response.getWriter().print("<?xml version=\"1.0\" encoding=\"" + this.encoding + "\"?>");
        response.getWriter().print("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header/><SOAP-ENV:Body>");
        response.getWriter().print(samlResponse.toString());
        response.getWriter().print("</SOAP-ENV:Body></SOAP-ENV:Envelope>");
    }
View Full Code Here

            final Assertion assertion = getAssertionFrom(model);
            final Authentication authentication = assertion.getChainedAuthentications().get(0);
            final Date currentDate = new Date();
            final String authenticationMethod = (String) authentication.getAttributes().get(SamlAuthenticationMetaDataPopulator.ATTRIBUTE_AUTHENTICATION_METHOD);
            final Service service = assertion.getService();
            final SAMLResponse samlResponse = new SAMLResponse(null, service.getId(), new ArrayList<Object>(), null);

            samlResponse.setIssueInstant(currentDate);

            // this should be true, but we never enforced it, so we need to check to be safe
            if (service instanceof SamlService) {
                final SamlService samlService = (SamlService) service;

                if (samlService.getRequestID() != null) {
                    samlResponse.setInResponseTo(samlService.getRequestID());
                }
            }

            final SAMLAssertion samlAssertion = new SAMLAssertion();
            samlAssertion.setIssueInstant(currentDate);
            samlAssertion.setIssuer(this.issuer);
            samlAssertion.setNotBefore(currentDate);
            samlAssertion.setNotOnOrAfter(new Date(currentDate.getTime()
                + this.issueLength));

            final SAMLAudienceRestrictionCondition samlAudienceRestrictionCondition = new SAMLAudienceRestrictionCondition();
            samlAudienceRestrictionCondition.addAudience(service.getId());

            final SAMLAuthenticationStatement samlAuthenticationStatement = new SAMLAuthenticationStatement();
            samlAuthenticationStatement.setAuthInstant(authentication
                .getAuthenticatedDate());
            samlAuthenticationStatement
                .setAuthMethod(authenticationMethod != null
                    ? authenticationMethod
                    : SAMLAuthenticationStatement.AuthenticationMethod_Unspecified);

            samlAuthenticationStatement
                .setSubject(getSamlSubject(authentication));

            if (!authentication.getPrincipal().getAttributes().isEmpty()) {
                final SAMLAttributeStatement attributeStatement = new SAMLAttributeStatement();
   
                attributeStatement.setSubject(getSamlSubject(authentication));
                samlAssertion.addStatement(attributeStatement);

                for (final Entry<String, Object> e : authentication.getPrincipal().getAttributes().entrySet()) {
                    final SAMLAttribute attribute = new SAMLAttribute();
                    attribute.setName(e.getKey());
                    attribute.setNamespace(NAMESPACE);

                    if (e.getValue() instanceof Collection<?>) {
                        final Collection<?> c = (Collection<?>) e.getValue();
                        if (c.isEmpty()) {
                            // 100323 bnoordhuis: don't add the attribute, it causes a org.opensaml.MalformedException
                            continue;
                        }
                        attribute.setValues(c);
                    } else {
                        attribute.addValue(e.getValue());
                    }
   
                    attributeStatement.addAttribute(attribute);
                }
            }

            samlAssertion.addStatement(samlAuthenticationStatement);
            samlAssertion.addCondition(samlAudienceRestrictionCondition);
            samlResponse.addAssertion(samlAssertion);

            final String xmlResponse = samlResponse.toString();

            response.setContentType("text/xml; charset=" + this.encoding);
            response.getWriter().print("<?xml version=\"1.0\" encoding=\"" + this.encoding + "\"?>");
            response.getWriter().print("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header/><SOAP-ENV:Body>");
            response.getWriter().print(xmlResponse);
View Full Code Here

TOP

Related Classes of org.opensaml.SAMLResponse

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.