Search in sources :

Example 1 with SecurityConfiguration

use of org.opensaml.xml.security.SecurityConfiguration in project oxCore by GluuFederation.

the class AuthRequest method getEnvelopedSignatureRequest.

/**
 * This will generate an Enveloped Digital Signature xml String that you can use
 * for a POST SAML AuthnRequest.
 *
 * @param assertionConsumerServiceUrl
 * @param relayState
 *            optional
 * @return
 * @throws WSSecurityException
 * @throws SecurityException
 * @throws MarshallingException
 * @throws org.opensaml.xml.signature.SignatureException
 * @throws IOException
 * @throws TransformerException
 * @throws XMLStreamException
 * @throws ParserConfigurationException
 */
public String getEnvelopedSignatureRequest(String assertionConsumerServiceUrl, String relayState) throws WSSecurityException, SecurityException, MarshallingException, org.opensaml.xml.signature.SignatureException, IOException, TransformerException, XMLStreamException, ParserConfigurationException {
    String samlRequest = getRequest(false, assertionConsumerServiceUrl);
    AuthnRequest authReq = (AuthnRequest) string2XMLObject(samlRequest);
    Credential credential = this.samlSettings.getCredential();
    org.opensaml.xml.signature.Signature signature = (org.opensaml.xml.signature.Signature) Configuration.getBuilderFactory().getBuilder(org.opensaml.xml.signature.Signature.DEFAULT_ELEMENT_NAME).buildObject(org.opensaml.xml.signature.Signature.DEFAULT_ELEMENT_NAME);
    signature.setSigningCredential(credential);
    signature.setSignatureAlgorithm(this.samlSettings.getSigAlgUrl());
    signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
    SecurityConfiguration secConfig = Configuration.getGlobalSecurityConfiguration();
    SecurityHelper.prepareSignatureParams(signature, credential, secConfig, null);
    authReq.setSignature(signature);
    Configuration.getMarshallerFactory().getMarshaller(authReq).marshall(authReq);
    Signer.signObject(signature);
    String signedRequest = convertDocumentToString(authReq.getDOM().getOwnerDocument());
    LOG.info("\n\n**************************\nSigned Post AuthnRequest:\n" + signedRequest + "\n**************************\n\n");
    return signedRequest;
}
Also used : Credential(org.opensaml.xml.security.credential.Credential) AuthnRequest(org.opensaml.saml2.core.AuthnRequest) Signature(java.security.Signature) SecurityConfiguration(org.opensaml.xml.security.SecurityConfiguration)

Aggregations

Signature (java.security.Signature)1 AuthnRequest (org.opensaml.saml2.core.AuthnRequest)1 SecurityConfiguration (org.opensaml.xml.security.SecurityConfiguration)1 Credential (org.opensaml.xml.security.credential.Credential)1