List of usage examples for java.util Properties hashCode
@Override public synchronized int hashCode()
From source file:org.holodeckb2b.security.handlers.CreateWSSHeaders.java
/** * Sets the message context properties for adding a Signature to the security header. * <p>Because other elements that need to be added to the header may also require a password the password callback * handler is not created in this method, but shared for the header. * //w w w . j a va 2 s.c om * @param mc The {@link MessageContext} to set up * @param sigConfig The configuration for creating the signature * @param pwdCBHandler The {@link PasswordCallbackHandler} to use for handing over the password to WSS4J library */ private void setupSignature(MessageContext mc, ISigningConfiguration sigCfg, PasswordCallbackHandler pwdCBHandler) { // Set up crypto engine Properties sigProperties = SecurityUtils.createCryptoConfig(SecurityUtils.CertType.priv); mc.setProperty(WSHandlerConstants.SIG_PROP_REF_ID, "" + sigProperties.hashCode()); mc.setProperty("" + sigProperties.hashCode(), sigProperties); // Set up signing config // AS4 requires that the ebMS message header (eb:Messaging element) and SOAP Body are signed mc.setProperty(WSHandlerConstants.SIGNATURE_PARTS, WSS4J_PART_EBMS_HEADER + (mc.isSOAP11() ? WSS4J_PART_S11_BODY : WSS4J_PART_S12_BODY)); // And if there are attachments also the attachments. Whether UsernameToken elements in the security header // should be signed is not specified. But to prevent manipulation Holodeck B2B includes them in the signature mc.setProperty(WSHandlerConstants.OPTIONAL_SIGNATURE_PARTS, WSS4J_PART_UT + WSS4J_PART_ATTACHMENTS); // The alias of the certificate to use for signing, converted to lower case because JKS aliasses are case // insensitive mc.setProperty(WSHandlerConstants.SIGNATURE_USER, sigCfg.getKeystoreAlias().toLowerCase()); // The password to access the certificate in the keystore pwdCBHandler.addUser(sigCfg.getKeystoreAlias().toLowerCase(), sigCfg.getCertificatePassword()); // How should certificate be referenced in header? mc.setProperty(WSHandlerConstants.SIG_KEY_ID, SecurityUtils .getWSS4JX509KeyId((sigCfg.getKeyReferenceMethod() != null ? sigCfg.getKeyReferenceMethod() : DefaultSecurityAlgorithm.KEY_REFERENCE))); // If BST is included, should complete cert path be included? if (sigCfg.getKeyReferenceMethod() == X509ReferenceType.BSTReference && (sigCfg.includeCertificatePath() != null ? sigCfg.includeCertificatePath() : false)) mc.setProperty(WSHandlerConstants.USE_SINGLE_CERTIFICATE, "false"); else mc.setProperty(WSHandlerConstants.USE_SINGLE_CERTIFICATE, "true"); // Algorithms to use mc.setProperty(WSHandlerConstants.SIG_DIGEST_ALGO, Utils.getValue(sigCfg.getHashFunction(), DefaultSecurityAlgorithm.MESSAGE_DIGEST)); mc.setProperty(WSHandlerConstants.SIG_ALGO, Utils.getValue(sigCfg.getSignatureAlgorithm(), DefaultSecurityAlgorithm.SIGNATURE)); }
From source file:org.holodeckb2b.security.handlers.CreateWSSHeaders.java
/** * Sets the message context properties for adding encryption to the security header. * <p>Because other elements that need to be added to the header may also require a password the password callback * handler is not created in this method, but shared for the header. * /*from www . j ava2s .c om*/ * @param mc The {@link MessageContext} to set up * @param sigConfig The configuration for creating the signature * @param pwdCBHandler The {@link PasswordCallbackHandler} to use for handing over the password to WSS4J library */ private void setupEncryption(MessageContext mc, IEncryptionConfiguration encCfg, PasswordCallbackHandler pwdCBHandler) { // Set up crypto engine Properties encProperties = SecurityUtils.createCryptoConfig(SecurityUtils.CertType.pub); mc.setProperty(WSHandlerConstants.ENC_PROP_REF_ID, "" + encProperties.hashCode()); mc.setProperty("" + encProperties.hashCode(), encProperties); // Set up encryption config // AS4 requires that only the payloads are encrypted, so we encrypt the Body only when it contains a payload Boolean includesBodyPayload = (Boolean) mc.getProperty(SecurityConstants.ENCRYPT_BODY); if (includesBodyPayload != null && includesBodyPayload) mc.setProperty(WSHandlerConstants.ENCRYPTION_PARTS, (mc.isSOAP11() ? WSS4J_PART_S11_BODY : WSS4J_PART_S12_BODY)); // And if there are attachments also the attachments must be encrypted. mc.setProperty(WSHandlerConstants.OPTIONAL_ENCRYPTION_PARTS, WSS4J_PART_ATTACHMENTS); // Symmetric encryption algorithms to use mc.setProperty(WSHandlerConstants.ENC_SYM_ALGO, Utils.getValue(encCfg.getAlgorithm(), DefaultSecurityAlgorithm.ENCRYPTION)); // The alias of the certificate to use for encryption mc.setProperty(WSHandlerConstants.ENCRYPTION_USER, encCfg.getKeystoreAlias()); // KeyTransport configuration defines settings for constructing the xenc:EncryptedKey // Set defaults String ktAlgorithm = DefaultSecurityAlgorithm.KEY_TRANSPORT; X509ReferenceType ktKeyReference = DefaultSecurityAlgorithm.KEY_REFERENCE; String ktDigest = DefaultSecurityAlgorithm.MESSAGE_DIGEST; IKeyTransport ktConfig = encCfg.getKeyTransport(); if (ktConfig != null) { // Key encryption algorithm ktAlgorithm = Utils.getValue(ktConfig.getAlgorithm(), DefaultSecurityAlgorithm.KEY_TRANSPORT); // If key transport algorithm is RSA-OAEP also the MGF must be set if (WSConstants.KEYTRANSPORT_RSAOEP_XENC11.equalsIgnoreCase(ktAlgorithm)) mc.setProperty(WSHandlerConstants.ENC_MGF_ALGO, ktConfig.getMGFAlgorithm()); // Message digest ktDigest = Utils.getValue(ktConfig.getDigestAlgorithm(), DefaultSecurityAlgorithm.MESSAGE_DIGEST); // Key refence method if (ktConfig.getKeyReferenceMethod() != null) ktKeyReference = ktConfig.getKeyReferenceMethod(); } // Set the relevant message context properties mc.setProperty(WSHandlerConstants.ENC_KEY_ID, SecurityUtils.getWSS4JX509KeyId(ktKeyReference)); mc.setProperty(WSHandlerConstants.ENC_DIGEST_ALGO, ktDigest); mc.setProperty(WSHandlerConstants.ENC_KEY_TRANSPORT, ktAlgorithm); }