use of com.adaptris.security.keystore.Alias in project interlok by adaptris.
the class TestDefaultSecurityService method testDefaultEncryptionWithMultipleKeystores.
@Test
public void testDefaultEncryptionWithMultipleKeystores() throws Exception {
ConfiguredUrl keystore = new ConfiguredUrl();
String filename = "" + Math.abs(new Random().nextInt()) + ".ks";
String newUrl = "file:///" + config.getProperty(Config.CFG_ROOT) + "/" + filename + "?keystoreType=JKS";
keystore.setUrl(newUrl + "&" + Constants.KEYSTORE_PASSWORD + "=" + config.getProperty(Config.KEYSTORE_COMMON_KEYSTORE_PW));
String cn = "OtherUniqueAlias";
Config.getInstance().buildKeystore(newUrl, cn, false);
them = new Alias(cn, config.getProperty(Config.KEYSTORE_COMMON_PRIVKEY_PW));
service.registerKeystore(keystore);
Output output = service.encrypt(RAW_DATA, us, them);
output = service.sign(RAW_DATA, us, output);
String encrypted = output.getAsString();
output = service.verify(encrypted, them, us);
String payload = output.getAsString();
assertEquals("Data Verification", payload, RAW_DATA);
}
use of com.adaptris.security.keystore.Alias in project interlok by adaptris.
the class CoreSecurityService method retrieveRemotePartner.
final Alias retrieveRemotePartner(AdaptrisMessage m) throws AdaptrisSecurityException {
Alias rpa = remotePartnerAlias;
if (m.headersContainsKey(getRemotePartnerMetadataKey())) {
String aliasName = m.getMetadataValue(getRemotePartnerMetadataKey());
log.debug("Message metadata overrides configured remote partner with [" + aliasName + "]");
rpa = new Alias(aliasName);
}
if (rpa == null) {
throw new AdaptrisSecurityException("No Remote Partner alias");
}
return rpa;
}
use of com.adaptris.security.keystore.Alias in project interlok by adaptris.
the class CoreSecurityService method initService.
@Override
protected final void initService() throws CoreException {
try {
pkPassword = getPrivateKeyPasswordProvider().retrievePrivateKeyPassword();
} catch (PasswordException e) {
throw new CoreException("Could not get password using " + getPrivateKeyPasswordProvider().getClass().getCanonicalName(), e);
}
try {
if (isEmpty(localPartner)) {
throw new CoreException("No Local Partner configured");
}
localPartnerAlias = new Alias(localPartner, pkPassword);
if (isEmpty(remotePartner)) {
log.warn("Remote partner not configured, " + "must be set individually as message metadata");
} else {
remotePartnerAlias = new Alias(remotePartner);
}
SecurityServiceFactory factory = securityFactory;
if (factory == null) {
factory = SecurityServiceFactory.defaultInstance();
}
service = factory.createService();
for (Iterator i = keystoreUrls.iterator(); i.hasNext(); ) {
ConfiguredKeystore url = (ConfiguredKeystore) i.next();
service.registerKeystore(url);
}
service.setEncryptionAlgorithm(encryptionAlgorithm);
if (successId != null && failId != null) {
branchingEnabled = true;
} else {
log.debug("No Success Id or Fail Id, branching disabled");
}
} catch (AdaptrisSecurityException e) {
throw new CoreException(e);
}
}
use of com.adaptris.security.keystore.Alias in project interlok by adaptris.
the class TestDefaultSecurityService method setUp.
@Before
public void setUp() throws Exception {
config = Config.getInstance().getProperties();
if (config == null) {
fail("No Configuration(!) available");
}
ConfiguredUrl configuredKeystore = new ConfiguredUrl();
configuredKeystore.setUrl(config.getProperty(Config.KEYSTORE_TEST_URL) + "&" + Constants.KEYSTORE_PASSWORD + "=" + config.getProperty(Config.KEYSTORE_COMMON_KEYSTORE_PW));
Config.getInstance().buildKeystore(config.getProperty(Config.KEYSTORE_TEST_URL), null, true);
service = SecurityServiceFactory.defaultInstance().createService();
service.registerKeystore(configuredKeystore);
EncryptionAlgorithm alg = new EncryptionAlgorithm(config.getProperty(Config.SECURITY_ALG), config.getProperty(Config.SECURITY_ALGSIZE));
service.setEncryptionAlgorithm(alg);
us = new Alias(config.getProperty(Config.KEYSTORE_COMMON_PRIVKEY_ALIAS), config.getProperty(Config.KEYSTORE_COMMON_PRIVKEY_PW));
them = new Alias(config.getProperty(Config.KEYSTORE_COMMON_PRIVKEY_ALIAS));
}
Aggregations