Search in sources :

Example 1 with ConfiguredKeystore

use of com.adaptris.security.keystore.ConfiguredKeystore in project interlok by adaptris.

the class SecurityServiceCase method testSetKeystoreUrls.

@Test
public void testSetKeystoreUrls() throws Exception {
    CoreSecurityService input = create();
    ConfiguredUrl url = new ConfiguredUrl(PROPERTIES.getProperty(KEYSTORE_URL), PROPERTIES.getProperty(SECURITY_PASSWORD));
    input.addKeystoreUrl(url);
    assertEquals(1, input.getKeystoreUrls().size());
    assertTrue(input.getKeystoreUrls().contains(url));
    try {
        input.setKeystoreUrls(null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    ArrayList<ConfiguredKeystore> newList = new ArrayList<ConfiguredKeystore>();
    input.setKeystoreUrls(newList);
    assertEquals(0, input.getKeystoreUrls().size());
    assertEquals(newList, input.getKeystoreUrls());
}
Also used : ConfiguredUrl(com.adaptris.security.keystore.ConfiguredUrl) ArrayList(java.util.ArrayList) ConfiguredKeystore(com.adaptris.security.keystore.ConfiguredKeystore) Test(org.junit.Test)

Example 2 with ConfiguredKeystore

use of com.adaptris.security.keystore.ConfiguredKeystore 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 3 with ConfiguredKeystore

use of com.adaptris.security.keystore.ConfiguredKeystore in project interlok by adaptris.

the class StdSecurityService method getCertificate.

private Certificate getCertificate(String alias) throws AdaptrisSecurityException {
    Certificate c = null;
    for (Map.Entry<ConfiguredKeystore, KeystoreProxy> set : keystores.entrySet()) {
        ConfiguredKeystore ksi = set.getKey();
        KeystoreProxy ksm = set.getValue();
        if (ksm.containsAlias(alias)) {
            if (logR.isDebugEnabled()) {
                logR.debug("Certificate Alias " + alias + " found in " + ksi);
            }
            c = ksm.getCertificate(alias);
            break;
        }
    }
    if (c == null) {
        throw new KeystoreException("Alias " + alias + " not found in registered keystores");
    }
    return c;
}
Also used : KeystoreProxy(com.adaptris.security.keystore.KeystoreProxy) Map(java.util.Map) KeystoreException(com.adaptris.security.exc.KeystoreException) ConfiguredKeystore(com.adaptris.security.keystore.ConfiguredKeystore) Certificate(java.security.cert.Certificate)

Example 4 with ConfiguredKeystore

use of com.adaptris.security.keystore.ConfiguredKeystore in project interlok by adaptris.

the class StdSecurityService method getPrivateKey.

private PrivateKey getPrivateKey(String alias, char[] password) throws AdaptrisSecurityException {
    PrivateKey pk = null;
    for (Map.Entry<ConfiguredKeystore, KeystoreProxy> set : keystores.entrySet()) {
        ConfiguredKeystore ksi = set.getKey();
        KeystoreProxy ksm = set.getValue();
        if (ksm.containsAlias(alias)) {
            pk = ksm.getPrivateKey(alias, password);
            if (logR.isDebugEnabled()) {
                logR.debug("Private key alias " + alias + " found in " + ksi);
            }
            break;
        }
    }
    if (pk == null) {
        throw new KeystoreException("Private Key Alias " + alias + " not found in registered keystores");
    }
    return pk;
}
Also used : PrivateKey(java.security.PrivateKey) KeystoreProxy(com.adaptris.security.keystore.KeystoreProxy) Map(java.util.Map) KeystoreException(com.adaptris.security.exc.KeystoreException) ConfiguredKeystore(com.adaptris.security.keystore.ConfiguredKeystore)

Example 5 with ConfiguredKeystore

use of com.adaptris.security.keystore.ConfiguredKeystore in project interlok by adaptris.

the class StdSecurityService method logKeystores.

private void logKeystores() {
    if (logR.isDebugEnabled() && Constants.DEBUG) {
        StringBuffer sb = new StringBuffer("Registered Keystores :");
        for (ConfiguredKeystore ksi : keystores.keySet()) {
            sb.append("[");
            sb.append(ksi.toString());
            sb.append("]");
        }
    }
}
Also used : ConfiguredKeystore(com.adaptris.security.keystore.ConfiguredKeystore)

Aggregations

ConfiguredKeystore (com.adaptris.security.keystore.ConfiguredKeystore)5 KeystoreException (com.adaptris.security.exc.KeystoreException)2 KeystoreProxy (com.adaptris.security.keystore.KeystoreProxy)2 Map (java.util.Map)2 CoreException (com.adaptris.core.CoreException)1 SecurityServiceFactory (com.adaptris.security.SecurityServiceFactory)1 AdaptrisSecurityException (com.adaptris.security.exc.AdaptrisSecurityException)1 PasswordException (com.adaptris.security.exc.PasswordException)1 Alias (com.adaptris.security.keystore.Alias)1 ConfiguredUrl (com.adaptris.security.keystore.ConfiguredUrl)1 PrivateKey (java.security.PrivateKey)1 Certificate (java.security.cert.Certificate)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Test (org.junit.Test)1