private RampartConfig buildRampartConfig() { RampartConfig rampartConfig = new RampartConfig(); rampartConfig.setUser(username); rampartConfig.setEncryptionUser(encryptionUser); rampartConfig.setUserCertAlias(userCertAlias); rampartConfig.setPwCbClass(pwdCallbackClass); Properties cryptoProperties = new Properties(); cryptoProperties.put("org.apache.ws.security.crypto.merlin.keystore.type", "JKS"); cryptoProperties.put("org.apache.ws.security.crypto.merlin.file", keystorePath); cryptoProperties.put("org.apache.ws.security.crypto.merlin.keystore.password", keystorePwd); CryptoConfig cryptoConfig = new CryptoConfig(); cryptoConfig.setProvider("org.apache.ws.security.components.crypto.Merlin"); cryptoConfig.setProp(cryptoProperties); rampartConfig.setEncrCryptoConfig(cryptoConfig); rampartConfig.setSigCryptoConfig(cryptoConfig); return rampartConfig; }
public Policy loadPolicy(String xmlPath, String clientKey) throws Exception { StAXOMBuilder builder = new StAXOMBuilder(xmlPath); Policy policy = PolicyEngine.getPolicy(builder.getDocumentElement()); RampartConfig rc = new RampartConfig(); rc.setUser("admin"); rc.setUserCertAlias("wso2carbon"); rc.setEncryptionUser("wso2carbon"); rc.setPwCbClass(SecurityClient.class.getName()); CryptoConfig sigCryptoConfig = new CryptoConfig(); sigCryptoConfig.setProvider("org.apache.ws.security.components.crypto.Merlin"); Properties prop1 = new Properties(); prop1.put("org.apache.ws.security.crypto.merlin.keystore.type", "JKS"); prop1.put("org.apache.ws.security.crypto.merlin.file", clientKey); prop1.put("org.apache.ws.security.crypto.merlin.keystore.password", "wso2carbon"); sigCryptoConfig.setProp(prop1); CryptoConfig encrCryptoConfig = new CryptoConfig(); encrCryptoConfig.setProvider("org.apache.ws.security.components.crypto.Merlin"); Properties prop2 = new Properties(); prop2.put("org.apache.ws.security.crypto.merlin.keystore.type", "JKS"); prop2.put("org.apache.ws.security.crypto.merlin.file", clientKey); prop2.put("org.apache.ws.security.crypto.merlin.keystore.password", "wso2carbon"); encrCryptoConfig.setProp(prop2); rc.setSigCryptoConfig(sigCryptoConfig); rc.setEncrCryptoConfig(encrCryptoConfig); policy.addAssertion(rc); return policy; }