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());
}
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);
}
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);
}
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));
}
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;
}
Aggregations