throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "response type"); StatusType statusType = responseType.getStatus(); if (statusType == null) throw new IllegalArgumentException(ErrorCodes.NULL_VALUE + "Status Type from the IDP"); .getAssertions(); if (assertions.size() == 0) throw new IllegalStateException(ErrorCodes.NULL_VALUE + "No assertions in reply from IDP");
/** * Create a Response Type * @param ID * @param issuerInfo * @param assertionType * @return * @throws ConfigurationException */ public static ResponseType createResponseType(String ID, IssuerInfoHolder issuerInfo, AssertionType assertionType) throws ConfigurationException { XMLGregorianCalendar issueInstant = XMLTimeUtil.getIssueInstant(); ResponseType responseType = new ResponseType(ID, issueInstant); //Issuer NameIDType issuer = issuerInfo.getIssuer(); responseType.setIssuer(issuer); //Status String statusCode = issuerInfo.getStatusCode(); if (statusCode == null) throw new IllegalArgumentException(ErrorCodes.ISSUER_INFO_MISSING_STATUS_CODE); responseType.setStatus(createStatusType(statusCode)); responseType.addAssertion(new RTChoiceType(assertionType)); return responseType; }
String inResponseTo = responseType.getInResponseTo();
NameIDType issuer = response.getIssuer(); if (issuer != null) { write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get(), ASSERTION_PREFIX)); Element sig = response.getSignature(); if (sig != null) { StaxUtil.writeDOMElement(writer, sig); StatusType status = response.getStatus(); write(status); List<RTChoiceType> choiceTypes = response.getAssertions(); if (choiceTypes != null) { for (RTChoiceType choiceType : choiceTypes) {
NameIDType issuer = new NameIDType(); issuer.setValue(StaxParserUtil.getElementText(xmlEventReader)); response.setIssuer(issuer); } else if (JBossSAMLConstants.SIGNATURE.get().equals(elementName)) { Element sig = StaxParserUtil.getDOMElement(xmlEventReader); response.setSignature(sig); } else if (JBossSAMLConstants.ASSERTION.get().equals(elementName)) { SAMLAssertionParser assertionParser = new SAMLAssertionParser(); response.addAssertion(new RTChoiceType((AssertionType) assertionParser.parse(xmlEventReader))); } else if (JBossSAMLConstants.STATUS.get().equals(elementName)) { response.setStatus(parseStatus(xmlEventReader)); } else if (JBossSAMLConstants.ENCRYPTED_ASSERTION.get().equals(elementName)) { Element encryptedAssertion = StaxParserUtil.getDOMElement(xmlEventReader); response.addAssertion(new RTChoiceType(new EncryptedAssertionType(encryptedAssertion))); } else throw logger.parserUnknownTag(elementName, startElement.getLocation());
responseType.setInResponseTo(sp.getRequestID()); responseType.setDestination(responseDestinationURI);
List<RTChoiceType> assertions = responseType.getAssertions(); if (assertions.size() == 0) throw new IllegalStateException(ErrorCodes.NULL_VALUE + "No assertions in reply from IDP"); assertion = responseType.getAssertions().get(0).getAssertion();
responseType.setStatus(JBossSAMLAuthnResponseFactory.createStatusTypeForResponder(status)); responseType.setDestination(responseURL);
/** * Parse the attributes at the response element * * @param startElement * @return * @throws ConfigurationException */ protected StatusResponseType parseBaseAttributes(StartElement startElement) throws ParsingException { ResponseType response = new ResponseType(super.parseBaseAttributes(startElement)); return response; } }
ResponseType responseType = (ResponseType) request.getSAML2Object(); checkDestination(responseType.getDestination(), getSPConfiguration().getServiceURL()); List<RTChoiceType> assertions = responseType.getAssertions(); if (assertions.size() == 0) throw logger.samlHandlerNoAssertionFromIDP(); if (assertion instanceof EncryptedAssertionType) { responseType = this.decryptAssertion(responseType, privateKey); assertion = responseType.getAssertions().get(0).getAssertion();
private ResponseType decryptAssertion(ResponseType responseType, PrivateKey privateKey) throws ProcessingException { if (privateKey == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "privateKey"); SAML2Response saml2Response = new SAML2Response(); try { Document doc = saml2Response.convert(responseType); Element enc = DocumentUtil.getElement(doc, new QName(JBossSAMLConstants.ENCRYPTED_ASSERTION.get())); if (enc == null) throw new ProcessingException(ErrorCodes.NULL_VALUE + "Null encrypted assertion element"); String oldID = enc.getAttribute(JBossSAMLConstants.ID.get()); Document newDoc = DocumentUtil.createDocument(); Node importedNode = newDoc.importNode(enc, true); newDoc.appendChild(importedNode); Element decryptedDocumentElement = XMLEncryptionUtil.decryptElementInDocument(newDoc, privateKey); SAMLParser parser = new SAMLParser(); JAXPValidationUtil.checkSchemaValidation(decryptedDocumentElement); AssertionType assertion = (AssertionType) parser.parse(StaxParserUtil.getXMLEventReader(DocumentUtil .getNodeAsStream(decryptedDocumentElement))); responseType.replaceAssertion(oldID, new RTChoiceType(assertion)); return responseType; } catch (Exception e) { throw new ProcessingException(e); } }
responseType.setStatus(JBossSAMLAuthnResponseFactory.createStatusType(status));
NameIDType issuer = response.getIssuer(); if (issuer != null) Element sig = response.getSignature(); if (sig != null) StatusType status = response.getStatus(); write(status); List<RTChoiceType> choiceTypes = response.getAssertions(); if (choiceTypes != null)
NameIDType issuer = new NameIDType(); issuer.setValue(StaxParserUtil.getElementText(xmlEventReader)); response.setIssuer(issuer); } else if (JBossSAMLConstants.SIGNATURE.get().equals(elementName)) { Element sig = StaxParserUtil.getDOMElement(xmlEventReader); response.setSignature(sig); } else if (JBossSAMLConstants.ASSERTION.get().equals(elementName)) { SAMLAssertionParser assertionParser = new SAMLAssertionParser(); response.addAssertion(new RTChoiceType((AssertionType) assertionParser.parse(xmlEventReader))); } else if (JBossSAMLConstants.STATUS.get().equals(elementName)) { response.setStatus(parseStatus(xmlEventReader)); } else if (JBossSAMLConstants.ENCRYPTED_ASSERTION.get().equals(elementName)) { Element encryptedAssertion = StaxParserUtil.getDOMElement(xmlEventReader); response.addAssertion(new RTChoiceType(new EncryptedAssertionType(encryptedAssertion))); } else throw logger.parserUnknownTag(elementName, startElement.getLocation());
responseType.setInResponseTo(sp.getRequestID()); responseType.setDestination(responseDestinationURI);
List<RTChoiceType> assertions = responseType.getAssertions(); if (assertions.size() == 0) throw new IllegalStateException(ErrorCodes.NULL_VALUE + "No assertions in reply from IDP"); assertion = responseType.getAssertions().get(0).getAssertion();
responseType.setStatus(JBossSAMLAuthnResponseFactory.createStatusTypeForResponder(status)); responseType.setDestination(responseURL);
/** * Parse the attributes at the response element * @param startElement * @return * @throws ConfigurationException */ protected StatusResponseType parseBaseAttributes(StartElement startElement) throws ParsingException { ResponseType response = new ResponseType(super.parseBaseAttributes(startElement)); return response; } }
ResponseType responseType = (ResponseType) request.getSAML2Object(); checkDestination(responseType.getDestination(), getSPConfiguration().getServiceURL()); List<RTChoiceType> assertions = responseType.getAssertions(); if (assertions.size() == 0) throw logger.samlHandlerNoAssertionFromIDP(); if (assertion instanceof EncryptedAssertionType) { responseType = this.decryptAssertion(responseType, privateKey); assertion = responseType.getAssertions().get(0).getAssertion();
private ResponseType decryptAssertion(ResponseType responseType, PrivateKey privateKey) throws ProcessingException { if (privateKey == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "privateKey"); SAML2Response saml2Response = new SAML2Response(); try { Document doc = saml2Response.convert(responseType); Element enc = DocumentUtil.getElement(doc, new QName(JBossSAMLConstants.ENCRYPTED_ASSERTION.get())); if (enc == null) throw new ProcessingException(ErrorCodes.NULL_VALUE + "Null encrypted assertion element"); String oldID = enc.getAttribute(JBossSAMLConstants.ID.get()); Document newDoc = DocumentUtil.createDocument(); Node importedNode = newDoc.importNode(enc, true); newDoc.appendChild(importedNode); Element decryptedDocumentElement = XMLEncryptionUtil.decryptElementInDocument(newDoc, privateKey); SAMLParser parser = new SAMLParser(); JAXPValidationUtil.checkSchemaValidation(decryptedDocumentElement); AssertionType assertion = (AssertionType) parser.parse(StaxParserUtil.getXMLEventReader(DocumentUtil .getNodeAsStream(decryptedDocumentElement))); responseType.replaceAssertion(oldID, new RTChoiceType(assertion)); return responseType; } catch (Exception e) { throw new ProcessingException(e); } }