/** * Parse the {@link SAML11AttributeQueryType} * * @param xmlEventReader * @return * @throws ParsingException */ public static SAML11AuthenticationQueryType parseSAML11AuthenticationQuery( XMLEventReader xmlEventReader) throws ParsingException { SAML11AuthenticationQueryType query = new SAML11AuthenticationQueryType(); StartElement startElement; // There may be additional things under subject confirmation while (xmlEventReader.hasNext()) { XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader); if (xmlEvent instanceof EndElement) { EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader); if (StaxParserUtil.matches(endElement, SAML11Constants.AUTHENTICATION_QUERY)) break; else throw logger.parserUnknownEndElement(StaxParserUtil.getEndElementName(endElement)); } if (xmlEvent instanceof StartElement) { startElement = (StartElement) xmlEvent; String startTag = StaxParserUtil.getStartElementName(startElement); if (startTag.equals(JBossSAMLConstants.SUBJECT.get())) { SAML11SubjectParser parser = new SAML11SubjectParser(); query.setSubject((SAML11SubjectType) parser.parse(xmlEventReader)); } else throw logger.parserUnknownTag(startTag, startElement.getLocation()); } } return query; }
/** * Parse an {@code SAML11AttributeStatementType} * * @param xmlEventReader * @return * @throws ParsingException */ public static SAML11AttributeStatementType parseSAML11AttributeStatement( XMLEventReader xmlEventReader) throws ParsingException { SAML11AttributeStatementType attributeStatementType = new SAML11AttributeStatementType(); StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader); String ATTRIBSTATEMT = JBossSAMLConstants.ATTRIBUTE_STATEMENT.get(); StaxParserUtil.validate(startElement, ATTRIBSTATEMT); while (xmlEventReader.hasNext()) { XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader); if (xmlEvent instanceof EndElement) { EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader); StaxParserUtil.validate(endElement, JBossSAMLConstants.ATTRIBUTE_STATEMENT.get()); break; } // Get the next start element startElement = StaxParserUtil.peekNextStartElement(xmlEventReader); String tag = startElement.getName().getLocalPart(); if (JBossSAMLConstants.ATTRIBUTE.get().equals(tag)) { SAML11AttributeType attribute = parseSAML11Attribute(xmlEventReader); attributeStatementType.add(attribute); } else if (JBossSAMLConstants.SUBJECT.get().equals(tag)) { SAML11SubjectParser parser = new SAML11SubjectParser(); SAML11SubjectType subject = (SAML11SubjectType) parser.parse(xmlEventReader); attributeStatementType.setSubject(subject); } else throw logger.parserUnknownTag(tag, startElement.getLocation()); } return attributeStatementType; }
public static SAML11AuthorizationDecisionStatementType parseSAML11AuthorizationDecisionStatement( XMLEventReader xmlEventReader) throws ParsingException { SAML11AuthorizationDecisionStatementType authzDecision = null; StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader); StaxParserUtil.validate(startElement, SAML11Constants.AUTHORIZATION_DECISION_STATEMENT); Attribute decision = startElement.getAttributeByName(new QName(SAML11Constants.DECISION)); if (decision == null) throw logger.parserRequiredAttribute("Decision"); String decisionValue = StaxParserUtil.getAttributeValue(decision); Attribute resource = startElement.getAttributeByName(new QName(SAML11Constants.RESOURCE)); if (resource == null) throw logger.parserRequiredAttribute("Namespace"); String resValue = StaxParserUtil.getAttributeValue(resource); authzDecision = new SAML11AuthorizationDecisionStatementType( URI.create(resValue), SAML11DecisionType.valueOf(decisionValue)); while (xmlEventReader.hasNext()) { XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader); if (xmlEvent instanceof EndElement) { EndElement end = StaxParserUtil.getNextEndElement(xmlEventReader); if (StaxParserUtil.matches(end, SAML11Constants.AUTHORIZATION_DECISION_STATEMENT)) break; } startElement = StaxParserUtil.peekNextStartElement(xmlEventReader); if (startElement == null) break; String tag = StaxParserUtil.getStartElementName(startElement); if (SAML11Constants.ACTION.equals(tag)) { startElement = StaxParserUtil.getNextStartElement(xmlEventReader); SAML11ActionType samlAction = new SAML11ActionType(); Attribute namespaceAttr = startElement.getAttributeByName(new QName(SAML11Constants.NAMESPACE)); if (namespaceAttr != null) { samlAction.setNamespace(StaxParserUtil.getAttributeValue(namespaceAttr)); } samlAction.setValue(StaxParserUtil.getElementText(xmlEventReader)); authzDecision.addAction(samlAction); } else if (JBossSAMLConstants.SUBJECT.get().equals(tag)) { SAML11SubjectParser parser = new SAML11SubjectParser(); authzDecision.setSubject((SAML11SubjectType) parser.parse(xmlEventReader)); } else throw logger.parserUnknownTag(tag, startElement.getLocation()); } return authzDecision; }
/** * Parse the {@link SAML11AuthorizationDecisionQueryType} * * @param xmlEventReader * @return * @throws ParsingException */ public static SAML11AuthorizationDecisionQueryType parseSAML11AuthorizationDecisionQueryType( XMLEventReader xmlEventReader) throws ParsingException { SAML11AuthorizationDecisionQueryType query = new SAML11AuthorizationDecisionQueryType(); StartElement startElement; // There may be additional things under subject confirmation while (xmlEventReader.hasNext()) { XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader); if (xmlEvent instanceof EndElement) { EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader); if (StaxParserUtil.matches(endElement, SAML11Constants.AUTHORIZATION_DECISION_QUERY)) break; else throw logger.parserUnknownEndElement(StaxParserUtil.getEndElementName(endElement)); } if (xmlEvent instanceof StartElement) { startElement = (StartElement) xmlEvent; String startTag = StaxParserUtil.getStartElementName(startElement); if (startTag.equals(JBossSAMLConstants.SUBJECT.get())) { SAML11SubjectParser parser = new SAML11SubjectParser(); query.setSubject((SAML11SubjectType) parser.parse(xmlEventReader)); } else if (startTag.equals(SAML11Constants.RESOURCE)) { startElement = StaxParserUtil.getNextStartElement(xmlEventReader); query.setResource(URI.create(StaxParserUtil.getElementText(xmlEventReader))); } else if (startTag.equals(SAML11Constants.ACTION)) { startElement = StaxParserUtil.getNextStartElement(xmlEventReader); SAML11ActionType action = new SAML11ActionType(); Attribute nsAttr = startElement.getAttributeByName(new QName(SAML11Constants.NAMESPACE)); if (nsAttr != null) { action.setNamespace(StaxParserUtil.getAttributeValue(nsAttr)); } action.setValue(StaxParserUtil.getElementText(xmlEventReader)); query.add(action); } else throw logger.parserUnknownTag(startTag, startElement.getLocation()); } } return query; }
/** * Parse the AuthnStatement inside the assertion * * @param xmlEventReader * @return * @throws ParsingException */ public static SAML11AuthenticationStatementType parseAuthenticationStatement( XMLEventReader xmlEventReader) throws ParsingException { StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader); StaxParserUtil.validate(startElement, SAML11Constants.AUTHENTICATION_STATEMENT); Attribute authMethod = startElement.getAttributeByName(new QName(SAML11Constants.AUTHENTICATION_METHOD)); if (authMethod == null) throw logger.parserRequiredAttribute(SAML11Constants.AUTHENTICATION_METHOD); Attribute authInstant = startElement.getAttributeByName(new QName(SAML11Constants.AUTHENTICATION_INSTANT)); if (authInstant == null) throw logger.parserRequiredAttribute(SAML11Constants.AUTHENTICATION_INSTANT); SAML11AuthenticationStatementType authStat = new SAML11AuthenticationStatementType( URI.create(StaxParserUtil.getAttributeValue(authMethod)), XMLTimeUtil.parse(StaxParserUtil.getAttributeValue(authInstant))); while (xmlEventReader.hasNext()) { XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader); if (xmlEvent == null) break; if (xmlEvent instanceof EndElement) { xmlEvent = StaxParserUtil.getNextEvent(xmlEventReader); EndElement endElement = (EndElement) xmlEvent; String endElementTag = StaxParserUtil.getEndElementName(endElement); if (endElementTag.equals(SAML11Constants.AUTHENTICATION_STATEMENT)) break; else throw logger.parserUnknownEndElement(endElementTag); } startElement = null; if (xmlEvent instanceof StartElement) { startElement = (StartElement) xmlEvent; } else { startElement = StaxParserUtil.peekNextStartElement(xmlEventReader); } if (startElement == null) break; String tag = StaxParserUtil.getStartElementName(startElement); if (JBossSAMLConstants.SUBJECT.get().equalsIgnoreCase(tag)) { SAML11SubjectParser subjectParser = new SAML11SubjectParser(); SAML11SubjectType subject = (SAML11SubjectType) subjectParser.parse(xmlEventReader); SAML11SubjectStatementType subStat = new SAML11SubjectStatementType(); subStat.setSubject(subject); authStat.setSubject(subject); } else if (JBossSAMLConstants.SUBJECT_LOCALITY.get().equals(tag)) { startElement = StaxParserUtil.getNextStartElement(xmlEventReader); SAML11SubjectLocalityType subjectLocalityType = new SAML11SubjectLocalityType(); Attribute address = startElement.getAttributeByName(new QName(SAML11Constants.IP_ADDRESS)); if (address != null) { subjectLocalityType.setIpAddress(StaxParserUtil.getAttributeValue(address)); } Attribute dns = startElement.getAttributeByName(new QName(SAML11Constants.DNS_ADDRESS)); if (dns != null) { subjectLocalityType.setDnsAddress(StaxParserUtil.getAttributeValue(dns)); } authStat.setSubjectLocality(subjectLocalityType); StaxParserUtil.validate( StaxParserUtil.getNextEndElement(xmlEventReader), JBossSAMLConstants.SUBJECT_LOCALITY.get()); } else if (SAML11Constants.AUTHORITY_BINDING.equals(tag)) { Attribute authorityKindAttr = startElement.getAttributeByName(new QName(SAML11Constants.AUTHORITY_KIND)); if (authorityKindAttr == null) throw logger.parserRequiredAttribute("AuthorityKind"); Attribute locationAttr = startElement.getAttributeByName(new QName(SAML11Constants.LOCATION)); if (locationAttr == null) throw logger.parserRequiredAttribute("Location"); URI location = URI.create(StaxParserUtil.getAttributeValue(locationAttr)); Attribute bindingAttr = startElement.getAttributeByName(new QName(SAML11Constants.BINDING)); if (bindingAttr == null) throw logger.parserRequiredAttribute("Binding"); URI binding = URI.create(StaxParserUtil.getAttributeValue(bindingAttr)); QName authorityKind = QName.valueOf(StaxParserUtil.getAttributeValue(authorityKindAttr)); SAML11AuthorityBindingType authorityBinding = new SAML11AuthorityBindingType(authorityKind, location, binding); authStat.add(authorityBinding); } else throw logger.parserUnknownTag("", startElement.getLocation()); } return authStat; }