Search in sources :

Example 1 with KeyStoreManager

use of org.obiba.security.KeyStoreManager in project mica2 by obiba.

the class OpalService method getOpalJavaClient.

private OpalJavaClient getOpalJavaClient(String opalUrl) throws URISyntaxException {
    String alias = opalUrl;
    OpalCredential opalCredential = getOpalCredential(opalUrl);
    if (opalCredential.getAuthType() == AuthType.CERTIFICATE) {
        KeyStoreManager kms = keyStoreService.getKeyStore(OPAL_KEYSTORE);
        if (!kms.aliasExists(alias))
            throw new IllegalStateException("Trying to use opal certificate credential but could not be found in keystore.");
        return new OpalJavaClient(cleanupOpalUrl(opalUrl), kms.getKeyStore(), alias, micaConfigService.getConfig().getSecretKey());
    }
    return new OpalJavaClient(cleanupOpalUrl(opalCredential.getOpalUrl()), opalCredential.getUsername(), opalCredential.getPassword());
}
Also used : KeyStoreManager(org.obiba.security.KeyStoreManager) OpalCredential(org.obiba.mica.micaConfig.domain.OpalCredential) OpalJavaClient(org.obiba.opal.rest.client.magma.OpalJavaClient)

Example 2 with KeyStoreManager

use of org.obiba.security.KeyStoreManager in project mica2 by obiba.

the class KeyStoreService method createOrUpdateCertificate.

public void createOrUpdateCertificate(String name, String alias, String algo, int size, String cn, String ou, String o, String locality, String state, String country) {
    KeyStoreManager ksm = getKeyStore(name);
    ksm.createOrUpdateKey(alias, algo, size, getCertificateInfo(cn, ou, o, locality, state, country));
    saveKeyStore(ksm);
}
Also used : KeyStoreManager(org.obiba.security.KeyStoreManager)

Example 3 with KeyStoreManager

use of org.obiba.security.KeyStoreManager in project mica2 by obiba.

the class KeyStoreService method createOrUpdateCertificate.

public void createOrUpdateCertificate(String name, String alias, String privateKey, String publicCertificate) {
    KeyStoreManager ksm = getKeyStore(name);
    ksm.importKey(alias, new ByteArrayInputStream(privateKey.getBytes()), new ByteArrayInputStream(publicCertificate.getBytes()));
    saveKeyStore(ksm);
}
Also used : KeyStoreManager(org.obiba.security.KeyStoreManager) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 4 with KeyStoreManager

use of org.obiba.security.KeyStoreManager in project mica2 by obiba.

the class OpalCredentialServiceTests method testDeleteCertificateCredential.

@Test
public void testDeleteCertificateCredential() throws KeyStoreException {
    OpalCredential credential = new OpalCredential("https://opal", AuthType.CERTIFICATE);
    when(opalCredentialRepository.findOne("https://opal")).thenReturn(credential);
    KeyStoreManager keyStore = mock(KeyStoreManager.class);
    doNothing().when(keyStore).deleteKey("https://opal");
    when(keyStoreService.getKeyStore("opal")).thenReturn(keyStore);
    opalCredentialService.deleteOpalCredential("https://opal");
    verify(opalCredentialRepository).delete(any(OpalCredential.class));
}
Also used : KeyStoreManager(org.obiba.security.KeyStoreManager) OpalCredential(org.obiba.mica.micaConfig.domain.OpalCredential) Test(org.junit.Test)

Example 5 with KeyStoreManager

use of org.obiba.security.KeyStoreManager in project mica2 by obiba.

the class SslContextFactoryImpl method prepareServerKeystore.

/**
 * Prepares the keystore for serving HTTPs requests. This method will create the keystore if it does not exist
 * and generate a self-signed certificate. If the keystore already exists, it is not modified in any way.
 *
 * @return a prepared keystore
 */
private KeyStoreManager prepareServerKeystore() {
    KeyStoreManager keystore = keyStoreService.getSystemKeyStore();
    if (!keystore.aliasExists(X509ExtendedKeyManagerImpl.HTTPS_ALIAS)) {
        keystore.createOrUpdateKey(X509ExtendedKeyManagerImpl.HTTPS_ALIAS, "RSA", 2048, generateCertificateInfo());
        keyStoreService.saveKeyStore(keystore);
    }
    return keystore;
}
Also used : KeyStoreManager(org.obiba.security.KeyStoreManager)

Aggregations

KeyStoreManager (org.obiba.security.KeyStoreManager)7 OpalCredential (org.obiba.mica.micaConfig.domain.OpalCredential)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 SSLContext (javax.net.ssl.SSLContext)1 Test (org.junit.Test)1 OpalJavaClient (org.obiba.opal.rest.client.magma.OpalJavaClient)1 X509ExtendedKeyManagerImpl (org.obiba.ssl.X509ExtendedKeyManagerImpl)1