Search in sources :

Example 6 with OpalCredential

use of org.obiba.mica.micaConfig.domain.OpalCredential 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 7 with OpalCredential

use of org.obiba.mica.micaConfig.domain.OpalCredential in project mica2 by obiba.

the class OpalCredentialServiceTests method testGetOpalCredential.

@Test
public void testGetOpalCredential() {
    OpalCredential credential = new OpalCredential("https://opal", AuthType.USERNAME, "test", "encrypted");
    when(opalCredentialRepository.findOne("https://opal")).thenReturn(credential);
    when(micaConfigService.decrypt("encrypted")).thenReturn("password");
    OpalCredential actual = opalCredentialService.getOpalCredential("https://opal");
    assertThat(actual, is(credential));
}
Also used : OpalCredential(org.obiba.mica.micaConfig.domain.OpalCredential) Test(org.junit.Test)

Example 8 with OpalCredential

use of org.obiba.mica.micaConfig.domain.OpalCredential in project mica2 by obiba.

the class OpalCredentialService method deleteOpalCredential.

public void deleteOpalCredential(String opalUrl) {
    OpalCredential credential = repository.findOne(opalUrl);
    if (credential == null)
        return;
    repository.delete(credential);
    if (credential.getAuthType() == AuthType.CERTIFICATE) {
        keyStoreService.deleteKeyPair(OpalService.OPAL_KEYSTORE, opalUrl);
    }
}
Also used : NoSuchOpalCredential(org.obiba.mica.micaConfig.NoSuchOpalCredential) OpalCredential(org.obiba.mica.micaConfig.domain.OpalCredential)

Aggregations

OpalCredential (org.obiba.mica.micaConfig.domain.OpalCredential)8 Test (org.junit.Test)3 NoSuchOpalCredential (org.obiba.mica.micaConfig.NoSuchOpalCredential)3 IOException (java.io.IOException)2 KeyStoreException (java.security.KeyStoreException)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors.toList (java.util.stream.Collectors.toList)2 Inject (javax.inject.Inject)2 NotNull (javax.validation.constraints.NotNull)2 KeyStoreService (org.obiba.mica.dataset.service.KeyStoreService)2 AuthType (org.obiba.mica.micaConfig.AuthType)2 OpalCredentialRepository (org.obiba.mica.micaConfig.repository.OpalCredentialRepository)2 KeyStoreManager (org.obiba.security.KeyStoreManager)2 Service (org.springframework.stereotype.Service)2 Validated (org.springframework.validation.annotation.Validated)2 OpalJavaClient (org.obiba.opal.rest.client.magma.OpalJavaClient)1 RestDatasource (org.obiba.opal.rest.client.magma.RestDatasource)1