org.opensaml.xml.XMLObject Java Examples

The following examples show how to use org.opensaml.xml.XMLObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestAbstractTypeUnmarshaller.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
    RequestAbstractType req = (RequestAbstractType) samlObject;

    if (attribute.getLocalName().equals(RequestAbstractType.VERSION_ATTRIB_NAME)) {
        req.setVersion(SAMLVersion.valueOf(attribute.getValue()));
    } else if (attribute.getLocalName().equals(RequestAbstractType.ID_ATTRIB_NAME)) {
        req.setID(attribute.getValue());
        attribute.getOwnerElement().setIdAttributeNode(attribute, true);
    } else if (attribute.getLocalName().equals(RequestAbstractType.ISSUE_INSTANT_ATTRIB_NAME)
            && !DatatypeHelper.isEmpty(attribute.getValue())) {
        req.setIssueInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
    } else if (attribute.getLocalName().equals(RequestAbstractType.DESTINATION_ATTRIB_NAME)) {
        req.setDestination(attribute.getValue());
    } else if (attribute.getLocalName().equals(RequestAbstractType.CONSENT_ATTRIB_NAME)) {
        req.setConsent(attribute.getValue());
    } else {
        super.processAttribute(samlObject, attribute);
    }
}
 
Example #2
Source File: RSAKeyValueImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
public List<XMLObject> getOrderedChildren() {
    ArrayList<XMLObject> children = new ArrayList<XMLObject>();
    
    if (modulus != null) {
        children.add(modulus);
    }
    if (exponent != null) {
        children.add(exponent);
    }
    
    if (children.size() == 0) {
        return null;
    }
    
    return Collections.unmodifiableList(children);
}
 
Example #3
Source File: SPSSODescriptorMarshaller.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException {
    SPSSODescriptor descriptor = (SPSSODescriptor) samlObject;

    if (descriptor.isAuthnRequestsSignedXSBoolean() != null) {
        domElement.setAttributeNS(null, SPSSODescriptor.AUTH_REQUESTS_SIGNED_ATTRIB_NAME, descriptor
                .isAuthnRequestsSignedXSBoolean().toString());
    }

    if (descriptor.getWantAssertionsSignedXSBoolean() != null) {
        domElement.setAttributeNS(null, SPSSODescriptor.WANT_ASSERTIONS_SIGNED_ATTRIB_NAME, descriptor
                .getWantAssertionsSignedXSBoolean().toString());
    }

    super.marshallAttributes(samlObject, domElement);
}
 
Example #4
Source File: SOAPHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets the <code>soap11:actor</code> attribute from a given SOAP object.
 * 
 * @param soapObject the SOAP object to add the attribute to
 * 
 * @return the value of the actor attribute, or null if not present
 */
public static String getSOAP11ActorAttribute(XMLObject soapObject) {
    String value = null;
    if (soapObject instanceof ActorBearing) {
        value = DatatypeHelper.safeTrimOrNullString(((ActorBearing) soapObject).getSOAP11Actor());
        if (value != null) {
            return value;
        }
    }
    if (soapObject instanceof AttributeExtensibleXMLObject) {
        value = DatatypeHelper.safeTrimOrNullString(((AttributeExtensibleXMLObject) soapObject)
                .getUnknownAttributes().get(ActorBearing.SOAP11_ACTOR_ATTR_NAME));
        return value;
    }
    return null;
}
 
Example #5
Source File: AbstractMetadataProvider.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
public XMLObject getMetadata() throws MetadataProviderException {
    if (!isInitialized()) {
        throw new MetadataProviderException("Metadata provider has not been initialized");
    }

    XMLObject metadata = doGetMetadata();

    if (metadata == null) {
        log.debug("Metadata provider does not currently contain any metadata");
    }

    if (!isValid(metadata)) {
        log.debug("Metadata document exists, but it is no longer valid");
        return null;
    }

    return metadata;
}
 
Example #6
Source File: XMLObjectHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Marshall an XMLObject.  If the XMLObject already has a cached DOM via {@link XMLObject#getDOM()},
 * that Element will be returned.  Otherwise the object will be fully marshalled and that Element returned.
 * 
 * @param xmlObject the XMLObject to marshall
 * @return the marshalled Element
 * @throws MarshallingException if there is a problem marshalling the XMLObject
 */
public static Element marshall(XMLObject xmlObject) throws MarshallingException {
    Logger log = getLogger();
    log.debug("Marshalling XMLObject");
    
    if (xmlObject.getDOM() != null) {
        log.debug("XMLObject already had cached DOM, returning that element");
        return xmlObject.getDOM();
    }

    Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(xmlObject);
    if (marshaller == null) {
        log.error("Unable to marshall XMLOBject, no marshaller registered for object: "
                + xmlObject.getElementQName());
    }
    
    Element messageElem = marshaller.marshall(xmlObject);
    
    if (log.isTraceEnabled()) {
        log.trace("Marshalled XMLObject into DOM:");
        log.trace(XMLHelper.nodeToString(messageElem));
    }
    
    return messageElem;
}
 
Example #7
Source File: EncryptionMethodImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
public List<XMLObject> getOrderedChildren() {
    ArrayList<XMLObject> children = new ArrayList<XMLObject>();
    
    if (keySize != null) {
        children.add(keySize);
    }
    if (oaepParams != null) {
        children.add(oaepParams);
    }
    
    children.addAll(unknownChildren);
    
    if (children.size() == 0) {
        return null;
    }
    
    return Collections.unmodifiableList(children);
}
 
Example #8
Source File: RoleDescriptorImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
public List<XMLObject> getOrderedChildren() {
    ArrayList<XMLObject> children = new ArrayList<XMLObject>();

    if (getSignature() != null) {
        children.add(getSignature());
    }

    if (extensions != null) {
        children.add(getExtensions());
    }
    children.addAll(getKeyDescriptors());
    if (organization != null) {
        children.add(getOrganization());
    }
    children.addAll(getContactPersons());

    return Collections.unmodifiableList(children);
}
 
Example #9
Source File: SOAPHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a header block from the SOAP envelope contained within the specified message context's
 * {@link MessageContext#getOutboundMessage()}.
 * 
 * @param msgContext the message context being processed
 * @param headerName the name of the header block to return 
 * @param targetNodes the explicitly specified SOAP node actors (1.1) or roles (1.2) for which the header is desired
 * @param isFinalDestination true specifies that headers targeted for message final destination should be returned,
 *          false specifies they should not be returned
 * @return the list of matching header blocks
 */
public static List<XMLObject> getOutboundHeaderBlock(MessageContext msgContext, QName headerName,
        Set<String> targetNodes, boolean isFinalDestination) {
    XMLObject outboundEnvelope = msgContext.getOutboundMessage();
    if (outboundEnvelope == null) {
        throw new IllegalArgumentException("Message context does not contain an outbound SOAP envelope");
    }
    
    // SOAP 1.1 Envelope
    if (outboundEnvelope instanceof Envelope) {
        return getSOAP11HeaderBlock((Envelope) outboundEnvelope, headerName, targetNodes, isFinalDestination);
    }
    
    //TODO SOAP 1.2 support when object providers are implemented
    return Collections.emptyList();
}
 
Example #10
Source File: WSXACMLEntitlementServiceClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Serialize XML objects
 *
 * @param xmlObject : XACML or SAML objects to be serialized
 * @return serialized XACML or SAML objects
 */
private String marshall(XMLObject xmlObject) throws EntitlementProxyException {

    try {
        doBootstrap();
        System.setProperty(DOCUMENT_BUILDER_FACTORY, DOCUMENT_BUILDER_FACTORY_IMPL);

        MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory();
        Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
        Element element = marshaller.marshall(xmlObject);

        ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = impl.createLSSerializer();
        LSOutput output = impl.createLSOutput();
        output.setByteStream(byteArrayOutputStrm);
        writer.write(element, output);
        return new String(byteArrayOutputStrm.toByteArray(), Charset.forName("UTF-8"));
    } catch (Exception e) {
        log.error("Error Serializing the SAML Response");
        throw new EntitlementProxyException("Error Serializing the SAML Response", e);
    }
}
 
Example #11
Source File: AssertionUnmarshaller.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
        throws UnmarshallingException {

    Assertion assertion = (Assertion) parentSAMLObject;

    if (childSAMLObject instanceof Signature) {
        assertion.setSignature((Signature) childSAMLObject);
    } else if (childSAMLObject instanceof Conditions) {
        assertion.setConditions((Conditions) childSAMLObject);
    } else if (childSAMLObject instanceof Advice) {
        assertion.setAdvice((Advice) childSAMLObject);
    } else if (childSAMLObject instanceof Statement) {
        assertion.getStatements().add((Statement) childSAMLObject);
    } else {
        super.processChildElement(parentSAMLObject, childSAMLObject);
    }
}
 
Example #12
Source File: XACMLAuthzDecisionStatementTypeUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException {
    XACMLAuthzDecisionStatementType xacmlauthzdecisionstatement = (XACMLAuthzDecisionStatementType) parentObject;

    if (childObject instanceof RequestType) {
        xacmlauthzdecisionstatement.setRequest((RequestType) childObject);
    } else if (childObject instanceof ResponseType) {
        xacmlauthzdecisionstatement.setResponse((ResponseType) childObject);
    } else {
        super.processChildElement(parentObject, childObject);
    }
}
 
Example #13
Source File: ConditionTypeUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject)
        throws UnmarshallingException {
    if(childXMLObject instanceof ExpressionType){
        ConditionType conditionType = (ConditionType)parentXMLObject;
        conditionType.setExpression((ExpressionType)childXMLObject);
    } else {
        super.processChildElement(parentXMLObject, childXMLObject);
    }
}
 
Example #14
Source File: SOAPHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a <code>soap11:mustUnderstand</code> attribute to the given SOAP object.
 * 
 * @param soapObject the SOAP object to add the attribute to
 * @param mustUnderstand whether mustUnderstand is true or false
 */
public static void addSOAP11MustUnderstandAttribute(XMLObject soapObject, boolean mustUnderstand) {
    if (soapObject instanceof MustUnderstandBearing) {
        ((MustUnderstandBearing) soapObject).setSOAP11MustUnderstand(new XSBooleanValue(mustUnderstand, true));
    } else if (soapObject instanceof AttributeExtensibleXMLObject) {
        ((AttributeExtensibleXMLObject) soapObject).getUnknownAttributes().put(
                MustUnderstandBearing.SOAP11_MUST_UNDERSTAND_ATTR_NAME,
                new XSBooleanValue(mustUnderstand, true).toString());
    } else {
        throw new IllegalArgumentException("Specified object was neither MustUnderBearing nor AttributeExtensible");
    }
}
 
Example #15
Source File: DefaultSAML2SSOManager.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
protected Extensions getSAMLExtensions(HttpServletRequest request) {

        try {
            String samlRequest = request.getParameter(SSOConstants.HTTP_POST_PARAM_SAML2_AUTH_REQ);
            if (samlRequest == null) {
                samlRequest = (String) request.getAttribute(SSOConstants.HTTP_POST_PARAM_SAML2_AUTH_REQ);
            }

            if (samlRequest != null) {
                XMLObject xmlObject;
                if (SSOConstants.HTTP_POST.equals(request.getMethod())) {
                    xmlObject = unmarshall(SSOUtils.decodeForPost(samlRequest));
                } else {
                    xmlObject = unmarshall(SSOUtils.decode(samlRequest));
                }
                if (xmlObject instanceof AuthnRequest) {
                    AuthnRequest authnRequest = (AuthnRequest) xmlObject;
                    Extensions oldExtensions = authnRequest.getExtensions();
                    if (oldExtensions != null) {
                        ExtensionsBuilder extBuilder = new ExtensionsBuilder();
                        Extensions extensions = extBuilder.buildObject(SAMLConstants.SAML20P_NS,
                                Extensions.LOCAL_NAME, SAMLConstants.SAML20P_PREFIX);
                        extensions.setDOM(oldExtensions.getDOM());
                        return extensions;
                    }
                }
            }
        } catch (Exception e) { // TODO IDENTITY-2421
            //ignore
            log.debug("Error while loading SAML Extensions", e);
        }

        return null;
    }
 
Example #16
Source File: TimestampUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject)
        throws UnmarshallingException {
    Timestamp timestamp = (Timestamp) parentXMLObject;
    
    if (childXMLObject instanceof Created) {
        timestamp.setCreated((Created) childXMLObject);
    } else if (childXMLObject instanceof Expires) {
        timestamp.setExpires((Expires) childXMLObject);
    } else {
        timestamp.getUnknownXMLObjects().add(childXMLObject);
    }
}
 
Example #17
Source File: AttributedDateTimeUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processElementContent(XMLObject xmlObject, String elementContent) {
    AttributedDateTime dateTime = (AttributedDateTime) xmlObject;
    if (!DatatypeHelper.isEmpty(elementContent)) {
        dateTime.setValue(elementContent);
    }
}
 
Example #18
Source File: IDPSSODescriptorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public List<XMLObject> getOrderedChildren() {
    ArrayList<XMLObject> children = new ArrayList<XMLObject>();

    children.addAll(super.getOrderedChildren());
    children.addAll(singleSignOnServices);
    children.addAll(nameIDMappingServices);
    children.addAll(assertionIDRequestServices);
    children.addAll(attributeProfiles);
    children.addAll(attributes);

    return Collections.unmodifiableList(children);
}
 
Example #19
Source File: AttributeConsumingServiceMarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException {
    AttributeConsumingService service = (AttributeConsumingService) samlObject;

    domElement.setAttributeNS(null, AttributeConsumingService.INDEX_ATTRIB_NAME, Integer.toString(service
            .getIndex()));

    if (service.isDefaultXSBoolean() != null) {
        domElement.setAttributeNS(null, AttributeConsumingService.IS_DEFAULT_ATTRIB_NAME, service
                .isDefaultXSBoolean().toString());
    }
}
 
Example #20
Source File: ObligationTypeMarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject samlElement, Element domElement) throws MarshallingException {
    ObligationType obligation = (ObligationType) samlElement;

    if (!DatatypeHelper.isEmpty(obligation.getObligationId())) {
        domElement.setAttributeNS(null, ObligationType.OBLIGATION_ID_ATTRIB_NAME, obligation.getObligationId());
    }
    if (obligation.getFulfillOn() != null) {
        if (obligation.getFulfillOn().equals(EffectType.Deny)) {
            domElement.setAttributeNS(null, ObligationType.FULFILL_ON_ATTRIB_NAME, EffectType.Deny.toString());
        } else {
            domElement.setAttributeNS(null, ObligationType.FULFILL_ON_ATTRIB_NAME, EffectType.Permit.toString());
        }                     
    }
}
 
Example #21
Source File: OrganizationNameMarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException {
    OrganizationName name = (OrganizationName) samlObject;

    if (name.getName() != null) {
        Attr attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), SAMLConstants.XML_NS,
                OrganizationName.LANG_ATTRIB_NAME, SAMLConstants.XML_PREFIX);
        attribute.setValue(name.getName().getLanguage());
        domElement.setAttributeNodeNS(attribute);
    }
}
 
Example #22
Source File: BodyUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    Body body = (Body) xmlObject;
    QName attribQName = XMLHelper.constructQName(attribute.getNamespaceURI(), attribute.getLocalName(), attribute
            .getPrefix());
    if (attribute.isId()) {
        body.getUnknownAttributes().registerID(attribQName);
    }
    body.getUnknownAttributes().put(attribQName, attribute.getValue());
}
 
Example #23
Source File: AttributeAssignmentTypeUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {

    AttributeAssignmentType attrib = (AttributeAssignmentType) samlObject;

    if (attribute.getLocalName().equals(AttributeAssignmentType.ATTR_ID_ATTRIB_NAME)) {
        attrib.setAttributeId(DatatypeHelper.safeTrimOrNullString(attribute.getValue()));
    } else{        	
    	super.processAttribute(samlObject, attribute);
    }
}
 
Example #24
Source File: SignChallengeTypeImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public List<XMLObject> getOrderedChildren() {
    List<XMLObject> children = new ArrayList<XMLObject>();
    if (challenge != null) {
        children.add(challenge);
    }
    children.addAll(unknownChildren);
    return Collections.unmodifiableList(children);
}
 
Example #25
Source File: EnvironmentMatchTypeMarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
    EnvironmentMatchType matchType = (EnvironmentMatchType) xmlObject;

    if (!DatatypeHelper.isEmpty(matchType.getMatchId())) {
        domElement.setAttribute(EnvironmentMatchType.MATCH_ID_ATTRIB_NAME, matchType.getMatchId());
    }
}
 
Example #26
Source File: XMLAttributeHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a <code>xml:base</code> attribute to the given XML object.
 * 
 * @param xmlObject the XML object to which to add the attribute
 * @param base the base value
 */
public static void addXMLBase(XMLObject xmlObject, String base) {
    if (xmlObject instanceof BaseBearing) {
        ((BaseBearing)xmlObject).setXMLBase(base);
    } else if (xmlObject instanceof AttributeExtensibleXMLObject) {
        ((AttributeExtensibleXMLObject)xmlObject).getUnknownAttributes()
            .put(BaseBearing.XML_BASE_ATTR_NAME, base);
    } else {
        throw new IllegalArgumentException("Specified object was neither BaseBearing nor AttributeExtensible");
    }
}
 
Example #27
Source File: BinarySecretMarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
    BinarySecret bs = (BinarySecret) xmlObject;
    if (bs.getType() != null) {
        domElement.setAttributeNS(null, BinarySecret.TYPE_ATTRIB_NAME, bs.getType());
    }
    
    XMLHelper.marshallAttributeMap(bs.getUnknownAttributes(), domElement);
}
 
Example #28
Source File: RuleCombinerParametersTypeUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject)
        throws UnmarshallingException {
    RuleCombinerParametersType ruleCombinerParametersType = (RuleCombinerParametersType) parentXMLObject;
    
    if(childXMLObject instanceof CombinerParameterType){
        ruleCombinerParametersType.getCombinerParameters().add((CombinerParameterType)childXMLObject);
    } else {
        super.processChildElement(parentXMLObject, childXMLObject);
    }
}
 
Example #29
Source File: DetailMarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
    Detail detail = (Detail) xmlObject;

    Attr attribute;
    for (Entry<QName, String> entry : detail.getUnknownAttributes().entrySet()) {
        attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
        attribute.setValue(entry.getValue());
        domElement.setAttributeNodeNS(attribute);
        if (Configuration.isIDAttribute(entry.getKey()) 
                || detail.getUnknownAttributes().isIDAttribute(entry.getKey())) {
            attribute.getOwnerElement().setIdAttributeNode(attribute, true);
        }
    }
}
 
Example #30
Source File: IDPListUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
        throws UnmarshallingException {
    IDPList list = (IDPList) parentSAMLObject;

    if (childSAMLObject instanceof IDPEntry) {
        list.getIDPEntrys().add((IDPEntry) childSAMLObject);
    } else if (childSAMLObject instanceof GetComplete) {
        list.setGetComplete((GetComplete) childSAMLObject);
    } else {
        super.processChildElement(parentSAMLObject, childSAMLObject);
    }
}