Search in sources :

Example 16 with Secret

use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.

the class SecretAspectsTest method testproceedSaveEntitySecretRawIsNull.

@Test
public void testproceedSaveEntitySecretRawIsNull() throws Exception {
    DummyTenantAwareResourceEntity dummyEntity = new DummyTenantAwareResourceEntity(new Secret(null));
    when(proceedingJoinPoint.getArgs()).thenReturn(new Object[] { dummyEntity });
    underTest.proceedOnRepositorySave(proceedingJoinPoint);
    verifySecretManagementIgnoredDuringSave(dummyEntity.secret);
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) Test(org.junit.Test)

Example 17 with Secret

use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.

the class SecretAspectsTest method testproceedSaveAllEntity.

@Test
public void testproceedSaveAllEntity() throws Exception {
    DummyTenantAwareResourceEntity dummyEntity = new DummyTenantAwareResourceEntity(new Secret("raw"));
    when(proceedingJoinPoint.getArgs()).thenReturn(new Object[] { List.of(dummyEntity) });
    when(tenant.getName()).thenReturn("tenant");
    underTest.proceedOnRepositorySaveAll(proceedingJoinPoint);
    verify(secretService, times(1)).put(anyString(), eq("raw"));
    assertThat(dummyEntity.secret, IsInstanceOf.instanceOf(SecretProxy.class));
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) SecretProxy(com.sequenceiq.cloudbreak.service.secret.domain.SecretProxy) Test(org.junit.Test)

Example 18 with Secret

use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.

the class SecretAspectsTest method testproceedDeleteEntitySecretIsNull.

@Test
public void testproceedDeleteEntitySecretIsNull() {
    DummyEntity dummyEntity = new DummyEntity(new Secret(null, null));
    when(proceedingJoinPoint.getArgs()).thenReturn(new Object[] { dummyEntity });
    underTest.proceedOnRepositoryDelete(proceedingJoinPoint);
    verify(secretService, times(0)).delete(anyString());
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) Test(org.junit.Test)

Example 19 with Secret

use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.

the class SecretAspects method proceedDelete.

private Object proceedDelete(ProceedingJoinPoint proceedingJoinPoint) {
    Collection<Object> entities = convertFirstArgToCollection(proceedingJoinPoint);
    for (Object entity : entities) {
        try {
            for (Field field : entity.getClass().getDeclaredFields()) {
                if (field.isAnnotationPresent(SecretValue.class)) {
                    LOGGER.debug("Found SecretValue annotation on {}", field);
                    field.setAccessible(true);
                    Secret path = (Secret) field.get(entity);
                    if (path != null && path.getSecret() != null) {
                        secretService.delete(path.getSecret());
                        LOGGER.debug("Secret deleted at path: {}", path);
                    } else {
                        LOGGER.debug("Secret is null for field: {}.{}", field.getDeclaringClass(), field.getName());
                    }
                }
            }
        } catch (IllegalArgumentException e) {
            LOGGER.error("Given entity isn't instance of TenantAwareResource or AccountIdAwareResource. Secret is not deleted!", e);
            throw new CloudbreakServiceException(e);
        } catch (Exception e) {
            LOGGER.warn("Looks like something went wrong with Secret store. Secret is not deleted!", e);
            throw new CloudbreakServiceException(e);
        }
    }
    Object proceed;
    try {
        proceed = proceedingJoinPoint.proceed();
    } catch (RuntimeException re) {
        LOGGER.warn("Failed to invoke repository delete", re);
        throw re;
    } catch (Throwable throwable) {
        LOGGER.error("Failed to invoke repository delete", throwable);
        throw new CloudbreakServiceException(throwable);
    }
    return proceed;
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) Field(java.lang.reflect.Field) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 20 with Secret

use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.

the class TestUtil method setSecretField.

public static void setSecretField(Class<?> clazz, String fieldName, Object target, String raw, String secret) {
    Field field = ReflectionUtils.findField(clazz, fieldName);
    field.setAccessible(true);
    try {
        field.set(target, new Secret(raw, secret));
    } catch (IllegalAccessException ignore) {
    }
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) Field(java.lang.reflect.Field)

Aggregations

Secret (com.sequenceiq.cloudbreak.service.secret.domain.Secret)37 Test (org.junit.Test)11 Field (java.lang.reflect.Field)8 Test (org.junit.jupiter.api.Test)8 Stack (com.sequenceiq.freeipa.entity.Stack)7 SecretProxy (com.sequenceiq.cloudbreak.service.secret.domain.SecretProxy)5 SecretOperationException (com.sequenceiq.cloudbreak.service.secret.SecretOperationException)4 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)4 VaultSecret (com.sequenceiq.cloudbreak.service.secret.vault.VaultSecret)4 HostKeytabRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabRequest)4 HostKeytabResponse (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabResponse)4 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)4 Host (com.sequenceiq.freeipa.client.model.Host)4 KeytabCache (com.sequenceiq.freeipa.entity.KeytabCache)4 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)3 DetailedStackStatus (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus)3 Status (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status)3 InstanceStatus (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus)3 RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)3 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)3