Search in sources :

Example 1 with Alias

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);
}
Also used : ConfiguredUrl(com.adaptris.security.keystore.ConfiguredUrl) Random(java.util.Random) Alias(com.adaptris.security.keystore.Alias) Test(org.junit.Test)

Example 2 with Alias

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;
}
Also used : Alias(com.adaptris.security.keystore.Alias) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException)

Example 3 with Alias

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);
    }
}
Also used : PasswordException(com.adaptris.security.exc.PasswordException) CoreException(com.adaptris.core.CoreException) Alias(com.adaptris.security.keystore.Alias) Iterator(java.util.Iterator) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException) ConfiguredKeystore(com.adaptris.security.keystore.ConfiguredKeystore) SecurityServiceFactory(com.adaptris.security.SecurityServiceFactory)

Example 4 with Alias

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));
}
Also used : ConfiguredUrl(com.adaptris.security.keystore.ConfiguredUrl) Alias(com.adaptris.security.keystore.Alias) Before(org.junit.Before)

Aggregations

Alias (com.adaptris.security.keystore.Alias)4 AdaptrisSecurityException (com.adaptris.security.exc.AdaptrisSecurityException)2 ConfiguredUrl (com.adaptris.security.keystore.ConfiguredUrl)2 CoreException (com.adaptris.core.CoreException)1 SecurityServiceFactory (com.adaptris.security.SecurityServiceFactory)1 PasswordException (com.adaptris.security.exc.PasswordException)1 ConfiguredKeystore (com.adaptris.security.keystore.ConfiguredKeystore)1 Iterator (java.util.Iterator)1 Random (java.util.Random)1 Before (org.junit.Before)1 Test (org.junit.Test)1