org.opensaml.Configuration Java Examples
The following examples show how to use
org.opensaml.Configuration.
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: SSOAgentUtils.java From carbon-identity with Apache License 2.0 | 7 votes |
/** * Sign the SAML AuthnRequest message * * @param logoutRequest * @param signatureAlgorithm * @param cred * @return * @throws SSOAgentException */ public static LogoutRequest setSignature(LogoutRequest logoutRequest, String signatureAlgorithm, X509Credential cred) throws SSOAgentException { try { Signature signature = setSignatureRaw(signatureAlgorithm,cred); logoutRequest.setSignature(signature); List<Signature> signatureList = new ArrayList<Signature>(); signatureList.add(signature); // Marshall and Sign MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(logoutRequest); marshaller.marshall(logoutRequest); org.apache.xml.security.Init.init(); Signer.signObjects(signatureList); return logoutRequest; } catch (Exception e) { throw new SSOAgentException("Error while signing the Logout Request message", e); } }
Example #2
Source File: SAMLResponseBuilder.java From carbon-identity with Apache License 2.0 | 7 votes |
/** * Build Attribute Statement * * @param claims * @return AttributeStatement */ private AttributeStatement buildAttributeStatement(Map<String, String> claims) { AttributeStatement attStmt = null; if (claims != null) { attStmt = new AttributeStatementBuilder().buildObject(); Iterator<String> ite = claims.keySet().iterator(); for (int i = 0; i < claims.size(); i++) { Attribute attrib = new AttributeBuilder().buildObject(); String claimUri = ite.next(); attrib.setName(claimUri); // look // https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUsrManJavaAnyTypes XSStringBuilder stringBuilder = (XSStringBuilder) Configuration.getBuilderFactory() .getBuilder(XSString.TYPE_NAME); XSString stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(claims.get(claimUri)); attrib.getAttributeValues().add(stringValue); attStmt.getAttributes().add(attrib); } } return attStmt; }
Example #3
Source File: WSXACMLEntitlementServiceClient.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * 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 #4
Source File: SAMLUtils.java From cloudstack with Apache License 2.0 | 6 votes |
public static String encodeSAMLRequest(XMLObject authnRequest) throws MarshallingException, IOException { Marshaller marshaller = Configuration.getMarshallerFactory() .getMarshaller(authnRequest); Element authDOM = marshaller.marshall(authnRequest); StringWriter requestWriter = new StringWriter(); XMLHelper.writeNode(authDOM, requestWriter); String requestMessage = requestWriter.toString(); Deflater deflater = new Deflater(Deflater.DEFLATED, true); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater); deflaterOutputStream.write(requestMessage.getBytes(Charset.forName("UTF-8"))); deflaterOutputStream.close(); String encodedRequestMessage = Base64.encodeBytes(byteArrayOutputStream.toByteArray(), Base64.DONT_BREAK_LINES); encodedRequestMessage = URLEncoder.encode(encodedRequestMessage, HttpUtils.UTF_8).trim(); return encodedRequestMessage; }
Example #5
Source File: Util.java From carbon-commons with Apache License 2.0 | 6 votes |
/** * Serializing a SAML2 object into a String * * @param xmlObject object that needs to serialized. * @return serialized object * @throws Exception */ public static String marshall(XMLObject xmlObject) throws Exception { try { doBootstrap(); System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); 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 byteArrayOutputStrm.toString(); } catch (Exception e) { throw new Exception("Error Serializing the SAML Response", e); } }
Example #6
Source File: Util.java From carbon-commons with Apache License 2.0 | 6 votes |
/** * Constructing the XMLObject Object from a String * * @param authReqStr * @return Corresponding XMLObject which is a SAML2 object * @throws Exception */ public static XMLObject unmarshall(String authReqStr) throws Exception { try { doBootstrap(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = docBuilder.parse(new ByteArrayInputStream(authReqStr.trim().getBytes())); Element element = document.getDocumentElement(); UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element); return unmarshaller.unmarshall(element); } catch (Exception e) { throw new Exception("Error in constructing AuthRequest from " + "the encoded String ", e); } }
Example #7
Source File: IdentityUtil.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Constructing the SAML or XACML Objects from a String * * @param xmlString Decoded SAML or XACML String * @return SAML or XACML Object * @throws org.wso2.carbon.identity.base.IdentityException */ public static XMLObject unmarshall(String xmlString) throws IdentityException { try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setExpandEntityReferences(false); documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); org.apache.xerces.util.SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT); documentBuilderFactory.setAttribute(SECURITY_MANAGER_PROPERTY, securityManager); DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); docBuilder.setEntityResolver(new CarbonEntityResolver()); Document document = docBuilder.parse(new ByteArrayInputStream(xmlString.trim().getBytes(Charsets.UTF_8))); Element element = document.getDocumentElement(); UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element); return unmarshaller.unmarshall(element); } catch (ParserConfigurationException | UnmarshallingException | SAXException | IOException e) { String message = "Error in constructing XML Object from the encoded String"; throw IdentityException.error(message, e); } }
Example #8
Source File: Util.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Serializing a SAML2 object into a String * * @param xmlObject object that needs to serialized. * @return serialized object * @throws SAML2SSOUIAuthenticatorException */ public static String marshall(XMLObject xmlObject) throws SAML2SSOUIAuthenticatorException { try { doBootstrap(); System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); 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 byteArrayOutputStrm.toString(); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw new SAML2SSOUIAuthenticatorException("Error Serializing the SAML Response", e); } }
Example #9
Source File: WSXACMLMessageReceiver.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * ` * Serialize XML objects * * @param xmlObject : XACML or SAML objects to be serialized * @return serialized XACML or SAML objects * @throws EntitlementException */ private String marshall(XMLObject xmlObject) throws EntitlementException { try { doBootstrap(); System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject); Element element = marshaller.marshall(xmlObject); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(byteArrayOutputStream); writer.write(element, output); return byteArrayOutputStream.toString(); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw new EntitlementException("Error Serializing the SAML Response", e); } }
Example #10
Source File: WSXACMLMessageReceiver.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Constructing the SAML or XACML Objects from a String * * @param xmlString Decoded SAML or XACML String * @return SAML or XACML Object * @throws org.wso2.carbon.identity.entitlement.EntitlementException */ public XMLObject unmarshall(String xmlString) throws EntitlementException { try { doBootstrap(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setExpandEntityReferences(false); documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT); documentBuilderFactory.setAttribute(SECURITY_MANAGER_PROPERTY, securityManager); DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); docBuilder.setEntityResolver(new CarbonEntityResolver()); Document document = docBuilder.parse(new ByteArrayInputStream(xmlString.trim().getBytes())); Element element = document.getDocumentElement(); UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element); return unmarshaller.unmarshall(element); } catch (Exception e) { log.error("Error in constructing XML(SAML or XACML) Object from the encoded String", e); throw new EntitlementException("Error in constructing XML(SAML or XACML) from the encoded String ", e); } }
Example #11
Source File: WebServicePostEncoder.java From MaxKey with Apache License 2.0 | 6 votes |
protected String getSignatureAlgorithmURI(Credential credential, SecurityConfiguration config) throws MessageEncodingException { SecurityConfiguration secConfig; if (config != null) { secConfig = config; } else { secConfig = Configuration.getGlobalSecurityConfiguration(); } String signAlgo = secConfig.getSignatureAlgorithmURI(credential); if (signAlgo == null) { throw new MessageEncodingException( "The signing credential's algorithm URI could not be derived"); } return signAlgo; }
Example #12
Source File: AssertionMarshaller.java From lams with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException { Assertion assertion = (Assertion) samlObject; if (assertion.getVersion() != null) { domElement.setAttributeNS(null, Assertion.VERSION_ATTRIB_NAME, assertion.getVersion().toString()); } if (assertion.getIssueInstant() != null) { String issueInstantStr = Configuration.getSAMLDateFormatter().print(assertion.getIssueInstant()); domElement.setAttributeNS(null, Assertion.ISSUE_INSTANT_ATTRIB_NAME, issueInstantStr); } if (assertion.getID() != null) { domElement.setAttributeNS(null, Assertion.ID_ATTRIB_NAME, assertion.getID()); domElement.setIdAttributeNS(null, Assertion.ID_ATTRIB_NAME, true); } }
Example #13
Source File: AuthnStatementMarshaller.java From lams with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException { AuthnStatement authnStatement = (AuthnStatement) samlObject; if (authnStatement.getAuthnInstant() != null) { String authnInstantStr = Configuration.getSAMLDateFormatter().print(authnStatement.getAuthnInstant()); domElement.setAttributeNS(null, AuthnStatement.AUTHN_INSTANT_ATTRIB_NAME, authnInstantStr); } if (authnStatement.getSessionIndex() != null) { domElement.setAttributeNS(null, AuthnStatement.SESSION_INDEX_ATTRIB_NAME, authnStatement.getSessionIndex()); } if (authnStatement.getSessionNotOnOrAfter() != null) { String sessionNotOnOrAfterStr = Configuration.getSAMLDateFormatter().print( authnStatement.getSessionNotOnOrAfter()); domElement.setAttributeNS(null, AuthnStatement.SESSION_NOT_ON_OR_AFTER_ATTRIB_NAME, sessionNotOnOrAfterStr); } }
Example #14
Source File: Encrypter.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Helper method for constructors. */ private void init() { builderFactory = Configuration.getBuilderFactory(); keyInfoBuilder = (XMLSignatureBuilder<KeyInfo>) builderFactory.getBuilder(KeyInfo.DEFAULT_ELEMENT_NAME); dataReferenceBuilder = (XMLEncryptionBuilder<DataReference>) builderFactory.getBuilder(DataReference.DEFAULT_ELEMENT_NAME); referenceListBuilder = (XMLEncryptionBuilder<ReferenceList>) builderFactory.getBuilder(ReferenceList.DEFAULT_ELEMENT_NAME); retrievalMethodBuilder = (XMLSignatureBuilder<RetrievalMethod>) builderFactory.getBuilder(RetrievalMethod.DEFAULT_ELEMENT_NAME); keyNameBuilder = (XMLSignatureBuilder<KeyName>) builderFactory.getBuilder(KeyName.DEFAULT_ELEMENT_NAME); carriedKeyNameBuilder = (XMLEncryptionBuilder<CarriedKeyName>) builderFactory.getBuilder(CarriedKeyName.DEFAULT_ELEMENT_NAME); try{ idGenerator = new SecureRandomIdentifierGenerator(); }catch(NoSuchAlgorithmException e){ log.error("JVM does not support SHA1PRNG random number generation algorithm."); } keyPlacement = KeyPlacement.PEER; }
Example #15
Source File: HTTPSOAP11Encoder.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Builds the SOAP message to be encoded. * * @param samlMessage body of the SOAP message * * @return the SOAP message */ @SuppressWarnings("unchecked") protected Envelope buildSOAPMessage(SAMLObject samlMessage) { if (log.isDebugEnabled()) { log.debug("Building SOAP message"); } XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory(); SOAPObjectBuilder<Envelope> envBuilder = (SOAPObjectBuilder<Envelope>) builderFactory .getBuilder(Envelope.DEFAULT_ELEMENT_NAME); Envelope envelope = envBuilder.buildObject(); if (log.isDebugEnabled()) { log.debug("Adding SAML message to the SOAP message's body"); } SOAPObjectBuilder<Body> bodyBuilder = (SOAPObjectBuilder<Body>) builderFactory .getBuilder(Body.DEFAULT_ELEMENT_NAME); Body body = bodyBuilder.buildObject(); body.getUnknownXMLObjects().add(samlMessage); envelope.setBody(body); return envelope; }
Example #16
Source File: HTTPSOAP11Encoder.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Builds the SOAP message to be encoded. * * @param samlMessage body of the SOAP message * * @return the SOAP message */ @SuppressWarnings("unchecked") protected Envelope buildSOAPMessage(SAMLObject samlMessage) { log.debug("Building SOAP message"); XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory(); SOAPObjectBuilder<Envelope> envBuilder = (SOAPObjectBuilder<Envelope>) builderFactory .getBuilder(Envelope.DEFAULT_ELEMENT_NAME); Envelope envelope = envBuilder.buildObject(); log.debug("Adding SAML message to the SOAP message's body"); SOAPObjectBuilder<Body> bodyBuilder = (SOAPObjectBuilder<Body>) builderFactory .getBuilder(Body.DEFAULT_ELEMENT_NAME); Body body = bodyBuilder.buildObject(); body.getUnknownXMLObjects().add(samlMessage); envelope.setBody(body); return envelope; }
Example #17
Source File: CasHTTPSOAP11Encoder.java From cas4.0.x-server-wechat with Apache License 2.0 | 6 votes |
@Override protected Envelope buildSOAPMessage(final SAMLObject samlMessage) { final XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory(); final SOAPObjectBuilder<Envelope> envBuilder = (SOAPObjectBuilder<Envelope>) builderFactory.getBuilder(Envelope.DEFAULT_ELEMENT_NAME); final Envelope envelope = envBuilder.buildObject( SOAPConstants.SOAP11_NS, Envelope.DEFAULT_ELEMENT_LOCAL_NAME, OPENSAML_11_SOAP_NS_PREFIX); final SOAPObjectBuilder<Body> bodyBuilder = (SOAPObjectBuilder<Body>) builderFactory.getBuilder(Body.DEFAULT_ELEMENT_NAME); final Body body = bodyBuilder.buildObject( SOAPConstants.SOAP11_NS, Body.DEFAULT_ELEMENT_LOCAL_NAME, OPENSAML_11_SOAP_NS_PREFIX); body.getUnknownXMLObjects().add(samlMessage); envelope.setBody(body); return envelope; }
Example #18
Source File: MetadataCredentialResolver.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Constructor. * * @param metadataProvider provider of the metadata * * @throws IllegalArgumentException thrown if the supplied provider is null */ public MetadataCredentialResolver(MetadataProvider metadataProvider) { super(); if (metadataProvider == null) { throw new IllegalArgumentException("Metadata provider may not be null"); } metadata = metadataProvider; cache = new HashMap<MetadataCacheKey, SoftReference<Collection<Credential>>>(); keyInfoCredentialResolver = Configuration.getGlobalSecurityConfiguration() .getDefaultKeyInfoCredentialResolver(); rwlock = new ReentrantReadWriteLock(); if (metadata instanceof ObservableMetadataProvider) { ObservableMetadataProvider observable = (ObservableMetadataProvider) metadataProvider; observable.getObservers().add(new MetadataProviderObserver()); } }
Example #19
Source File: AttributeValueTypeMarshaller.java From lams with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException { AttributeValueType attributeValue = (AttributeValueType) xmlObject; if(!DatatypeHelper.isEmpty(attributeValue.getDataType())){ domElement.setAttributeNS(null,AttributeAssignmentType.DATA_TYPE_ATTRIB_NAME, attributeValue.getDataType()); } Attr attribute; for (Entry<QName, String> entry : attributeValue.getUnknownAttributes().entrySet()) { attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey()); attribute.setValue(entry.getValue()); domElement.setAttributeNodeNS(attribute); if (Configuration.isIDAttribute(entry.getKey()) || attributeValue.getUnknownAttributes().isIDAttribute(entry.getKey())) { attribute.getOwnerElement().setIdAttributeNode(attribute, true); } } }
Example #20
Source File: RequestAbstractTypeMarshaller.java From lams with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject samlElement, Element domElement) throws MarshallingException { RequestAbstractType request = (RequestAbstractType) samlElement; if (request.getID() != null) { domElement.setAttributeNS(null, RequestAbstractType.ID_ATTRIB_NAME, request.getID()); if (request.getMinorVersion() != 0) { domElement.setIdAttributeNS(null, RequestAbstractType.ID_ATTRIB_NAME, true); } } if (request.getIssueInstant() != null) { String date = Configuration.getSAMLDateFormatter().print(request.getIssueInstant()); domElement.setAttributeNS(null, RequestAbstractType.ISSUEINSTANT_ATTRIB_NAME, date); } if (request.getMinorVersion() != 0) { domElement.setAttributeNS(null, RequestAbstractType.MAJORVERSION_ATTRIB_NAME, "1"); domElement.setAttributeNS(null, RequestAbstractType.MINORVERSION_ATTRIB_NAME, Integer.toString(request .getMinorVersion())); } }
Example #21
Source File: WSXACMLEntitlementServiceClient.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * 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 #22
Source File: HTTPArtifactEncoder.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Builds the SAML 2 artifact for the outgoing message. * * @param artifactContext current request context * * @return SAML 2 artifact for outgoing message * * @throws MessageEncodingException thrown if the artifact can not be created */ protected AbstractSAML2Artifact buildArtifact(SAMLMessageContext artifactContext) throws MessageEncodingException { SAML2ArtifactBuilder artifactBuilder; if (artifactContext.getOutboundMessageArtifactType() != null) { artifactBuilder = Configuration.getSAML2ArtifactBuilderFactory().getArtifactBuilder( artifactContext.getOutboundMessageArtifactType()); } else { artifactBuilder = Configuration.getSAML2ArtifactBuilderFactory().getArtifactBuilder(defaultArtifactType); artifactContext.setOutboundMessageArtifactType(defaultArtifactType); } AbstractSAML2Artifact artifact = artifactBuilder.buildArtifact(artifactContext); if(artifact == null){ log.error("Unable to build artifact for message to relying party"); throw new MessageEncodingException("Unable to builder artifact for message to relying party"); } String encodedArtifact = artifact.base64Encode(); try { artifactMap.put(encodedArtifact, artifactContext.getInboundMessageIssuer(), artifactContext .getOutboundMessageIssuer(), artifactContext.getOutboundSAMLMessage()); } catch (MarshallingException e) { log.error("Unable to marshall assertion to be represented as an artifact", e); throw new MessageEncodingException("Unable to marshall assertion to be represented as an artifact", e); } return artifact; }
Example #23
Source File: Util.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Constructing the XMLObject Object from a String * * @param authReqStr * @return Corresponding XMLObject which is a SAML2 object * @throws SAML2SSOUIAuthenticatorException */ public static XMLObject unmarshall(String authReqStr) throws SAML2SSOUIAuthenticatorException { try { doBootstrap(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setExpandEntityReferences(false); documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT); documentBuilderFactory.setAttribute(SECURITY_MANAGER_PROPERTY, securityManager); DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); docBuilder.setEntityResolver(new CarbonEntityResolver()); Document document = docBuilder.parse(new ByteArrayInputStream(authReqStr.trim() .getBytes())); Element element = document.getDocumentElement(); UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element); return unmarshaller.unmarshall(element); } catch (Exception e) { log.error("Error in constructing AuthRequest from the encoded String", e); throw new SAML2SSOUIAuthenticatorException("Error in constructing AuthRequest from " + "the encoded String ", e); } }
Example #24
Source File: ResourceContentTypeMarshaller.java From lams with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException { ResourceContentType resourceContent = (ResourceContentType)xmlObject; Attr attribute; for (Entry<QName, String> entry : resourceContent.getUnknownAttributes().entrySet()) { attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey()); attribute.setValue(entry.getValue()); domElement.setAttributeNodeNS(attribute); if (Configuration.isIDAttribute(entry.getKey()) || resourceContent.getUnknownAttributes().isIDAttribute(entry.getKey())) { attribute.getOwnerElement().setIdAttributeNode(attribute, true); } } }
Example #25
Source File: Util.java From carbon-identity with Apache License 2.0 | 5 votes |
public static XMLObject buildXMLObject(QName objectQName) throws Exception { XMLObjectBuilder builder = org.opensaml.xml.Configuration.getBuilderFactory().getBuilder( objectQName); if (builder == null) { throw new Exception("Unable to retrieve builder for object QName " + objectQName); } return builder.buildObject(objectQName.getNamespaceURI(), objectQName.getLocalPart(), objectQName.getPrefix()); }
Example #26
Source File: AttributeValueTypeMarshaller.java From lams with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException { AttributeValueType attributeValue = (AttributeValueType) xmlObject; Attr attribute; for (Entry<QName, String> entry : attributeValue.getUnknownAttributes().entrySet()) { attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey()); attribute.setValue(entry.getValue()); domElement.setAttributeNodeNS(attribute); if (Configuration.isIDAttribute(entry.getKey()) || attributeValue.getUnknownAttributes().isIDAttribute(entry.getKey())) { attribute.getOwnerElement().setIdAttributeNode(attribute, true); } } }
Example #27
Source File: WSXACMLEntitlementServiceClient.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Create the issuer object to be added * * @return : the issuer of the statements */ private static Issuer createIssuer() { IssuerBuilder issuer = (IssuerBuilder) org.opensaml.xml.Configuration.getBuilderFactory(). getBuilder(Issuer.DEFAULT_ELEMENT_NAME); Issuer issuerObject = issuer.buildObject(); issuerObject.setValue(ISSUER_URL); issuerObject.setSPProvidedID("SPPProvierId"); return issuerObject; }
Example #28
Source File: WSXACMLEntitlementServiceClient.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Constructing the SAML or XACML Objects from a String * * @param xmlString Decoded SAML or XACML String * @return SAML or XACML Object * @throws EntitlementProxyException */ private XMLObject unmarshall(String xmlString) throws EntitlementProxyException { try { doBootstrap(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setExpandEntityReferences(false); documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT); documentBuilderFactory.setAttribute(SECURITY_MANAGER_PROPERTY, securityManager); DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); docBuilder.setEntityResolver(new CarbonEntityResolver()); Document document = docBuilder.parse(new ByteArrayInputStream(xmlString.trim().getBytes(Charset.forName ("UTF-8")))); Element element = document.getDocumentElement(); UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element); return unmarshaller.unmarshall(element); } catch (Exception e) { log.error("Error in constructing XML(SAML or XACML) Object from the encoded String", e); throw new EntitlementProxyException( "Error in constructing XML(SAML or XACML) from the encoded String", e); } }
Example #29
Source File: WSXACMLMessageReceiver.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Create XMLObject from a given QName * * @param objectQName: QName of the object to be built into a XMLObject * @return built xmlObject * @throws EntitlementException */ private static XMLObject buildXMLObject(QName objectQName) throws EntitlementException { XMLObjectBuilder builder = org.opensaml.xml.Configuration.getBuilderFactory().getBuilder(objectQName); if (builder == null) { throw new EntitlementException("Unable to retrieve builder for object QName " + objectQName); } return builder.buildObject(objectQName.getNamespaceURI(), objectQName.getLocalPart(), objectQName.getPrefix()); }
Example #30
Source File: WSXACMLEntitlementServiceClient.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Create XMLObject from a given QName * * @param objectQName: QName of the object to be built into a XMLObject * @return built xmlObject * @throws EntitlementProxyException */ private XMLObject buildXMLObject(QName objectQName) throws EntitlementProxyException { XMLObjectBuilder builder = org.opensaml.xml.Configuration.getBuilderFactory().getBuilder(objectQName); if (builder == null) { throw new EntitlementProxyException("Unable to retrieve builder for object QName " + objectQName); } return builder.buildObject(objectQName.getNamespaceURI(), objectQName.getLocalPart(), objectQName.getPrefix()); }