org.opensaml.xmlsec.SignatureSigningParameters Java Examples
The following examples show how to use
org.opensaml.xmlsec.SignatureSigningParameters.
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: SamlClient.java From saml-client with MIT License | 5 votes |
/** Sign a SamlObject with default settings. * Note that this method is a no-op if spCredential is unset. * @param samlObject The object to sign * * @throws SamlException if {@link SignatureSupport#signObject(SignableXMLObject, SignatureSigningParameters) signObject} fails * */ private void signSAMLObject(SignableSAMLObject samlObject) throws SamlException { if (spCredential != null) { try { // Describe how we're going to sign the request SignatureBuilder signer = new SignatureBuilder(); Signature signature = signer.buildObject(Signature.DEFAULT_ELEMENT_NAME); signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); signature.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256); signature.setKeyInfo( new X509KeyInfoGeneratorFactory().newInstance().generate(spCredential)); signature.setSigningCredential(spCredential); samlObject.setSignature(signature); // Actually sign the request SignatureSigningParameters signingParameters = new SignatureSigningParameters(); signingParameters.setSigningCredential(spCredential); signingParameters.setSignatureCanonicalizationAlgorithm( SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); signingParameters.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256); signingParameters.setKeyInfoGenerator(new X509KeyInfoGeneratorFactory().newInstance()); SignatureSupport.signObject(samlObject, signingParameters); } catch (SecurityException | MarshallingException | SignatureException e) { throw new SamlException("Failed to sign request", e); } } }