Search in sources :

Example 1 with SecretOperationException

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

the class SecretAspectService method proceedDelete.

public 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 {}. Secret is not deleted!", AccountIdAwareResource.class.getSimpleName(), e);
            throw new SecretOperationException(e.getMessage());
        } catch (Exception e) {
            LOGGER.warn("Looks like something went wrong with Secret store. Secret is not deleted!", e);
            throw new SecretOperationException(e.getMessage());
        }
    }
    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 SecretOperationException(throwable);
    }
    return proceed;
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) Field(java.lang.reflect.Field) SecretOperationException(com.sequenceiq.cloudbreak.service.secret.SecretOperationException) SecretOperationException(com.sequenceiq.cloudbreak.service.secret.SecretOperationException)

Example 2 with SecretOperationException

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

the class RecursiveSecretAspectService method proceedSave.

public Object proceedSave(ProceedingJoinPoint proceedingJoinPoint) {
    Queue<Object> entities = convertFirstArgToQueue(proceedingJoinPoint);
    Object entity;
    while ((entity = entities.poll()) != null) {
        try {
            for (Field field : entity.getClass().getDeclaredFields()) {
                if (field.isAnnotationPresent(SecretValue.class)) {
                    LOGGER.info("Found SecretValue annotation on {} in entity of type {}", field, entity.getClass());
                    field.setAccessible(true);
                    Object fieldValue = field.get(entity);
                    if (fieldValue instanceof Secret) {
                        Secret value = (Secret) field.get(entity);
                        if (value != null && value.getRaw() != null && value.getSecret() == null) {
                            String path = String.format("%s/%s/%s-%s", entity.getClass().getSimpleName().toLowerCase(), field.getName().toLowerCase(), UUID.randomUUID().toString(), Long.toHexString(System.currentTimeMillis()));
                            String secret = secretService.put(path, value.getRaw());
                            LOGGER.info("Field: '{}' is saved at path: {}", field.getName(), path);
                            field.set(entity, new SecretProxy(secretService, secret));
                        }
                    } else {
                        entities.add(fieldValue);
                    }
                }
            }
        } catch (IllegalArgumentException e) {
            LOGGER.error("Given entity isn't instance of TenantAwareResource. Secret is not saved!", e);
            throw new SecretOperationException(e);
        } catch (Exception e) {
            LOGGER.warn("Looks like something went wrong with Secret store. Secret is not saved!", e);
            throw new SecretOperationException(e);
        }
    }
    Object proceed;
    try {
        proceed = proceedingJoinPoint.proceed();
    } catch (RuntimeException re) {
        LOGGER.warn("Failed to invoke repository save", re);
        throw re;
    } catch (Throwable throwable) {
        LOGGER.error("Failed to invoke repository save", throwable);
        throw new SecretOperationException(throwable);
    }
    return proceed;
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) Field(java.lang.reflect.Field) SecretOperationException(com.sequenceiq.cloudbreak.service.secret.SecretOperationException) SecretProxy(com.sequenceiq.cloudbreak.service.secret.domain.SecretProxy) SecretOperationException(com.sequenceiq.cloudbreak.service.secret.SecretOperationException)

Example 3 with SecretOperationException

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

the class RecursiveSecretAspectService method proceedDelete.

public Object proceedDelete(ProceedingJoinPoint proceedingJoinPoint) {
    Queue<Object> entities = convertFirstArgToQueue(proceedingJoinPoint);
    Object entity;
    while ((entity = entities.poll()) != null) {
        try {
            for (Field field : entity.getClass().getDeclaredFields()) {
                if (field.isAnnotationPresent(SecretValue.class)) {
                    LOGGER.info("Found SecretValue annotation on {} in entity of type {}", field, entity.getClass());
                    field.setAccessible(true);
                    Object fieldValue = field.get(entity);
                    if (fieldValue instanceof Secret) {
                        Secret path = (Secret) field.get(entity);
                        if (path != null && path.getSecret() != null) {
                            secretService.delete(path.getSecret());
                            LOGGER.info("Secret deleted at path: {}", path);
                        } else {
                            LOGGER.info("Secret is null for field: {}.{}", field.getDeclaringClass(), field.getName());
                        }
                    } else {
                        entities.add(fieldValue);
                    }
                }
            }
        } catch (IllegalArgumentException e) {
            LOGGER.error("Given entity isn't instance of TenantAwareResource. Secret is not deleted!", e);
            throw new SecretOperationException(e);
        } catch (Exception e) {
            LOGGER.warn("Looks like something went wrong with Secret store. Secret is not deleted!", e);
            throw new SecretOperationException(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 SecretOperationException(throwable);
    }
    return proceed;
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) Field(java.lang.reflect.Field) SecretOperationException(com.sequenceiq.cloudbreak.service.secret.SecretOperationException) SecretOperationException(com.sequenceiq.cloudbreak.service.secret.SecretOperationException)

Example 4 with SecretOperationException

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

the class SecretAspectService method proceedSave.

public Object proceedSave(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 value = (Secret) field.get(entity);
                    if (value != null && value.getRaw() != null && value.getSecret() == null) {
                        String accountId = findAccountId(entity);
                        String path = String.format("%s/%s/%s/%s-%s", accountId, entity.getClass().getSimpleName().toLowerCase(), field.getName().toLowerCase(), UUID.randomUUID(), Long.toHexString(System.currentTimeMillis()));
                        String secret = secretService.put(path, value.getRaw());
                        LOGGER.debug("Field: '{}' is saved at path: {}", field.getName(), path);
                        field.set(entity, new SecretProxy(secretService, secret));
                    }
                }
            }
        } catch (IllegalArgumentException e) {
            LOGGER.error("Given entity isn't instance of {}. Secret is not updated!", AccountIdAwareResource.class.getSimpleName(), e);
            throw new SecretOperationException(e.getMessage());
        } catch (Exception e) {
            LOGGER.warn("Looks like something went wrong with Secret store. Secret is not updated!", e);
            throw new SecretOperationException(e.getMessage());
        }
    }
    Object proceed;
    try {
        proceed = proceedingJoinPoint.proceed();
    } catch (RuntimeException re) {
        LOGGER.warn("Failed to invoke repository save", re);
        throw re;
    } catch (Throwable throwable) {
        LOGGER.error("Failed to invoke repository save", throwable);
        throw new SecretOperationException(throwable);
    }
    return proceed;
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) Field(java.lang.reflect.Field) SecretOperationException(com.sequenceiq.cloudbreak.service.secret.SecretOperationException) SecretProxy(com.sequenceiq.cloudbreak.service.secret.domain.SecretProxy) SecretOperationException(com.sequenceiq.cloudbreak.service.secret.SecretOperationException)

Aggregations

SecretOperationException (com.sequenceiq.cloudbreak.service.secret.SecretOperationException)4 Secret (com.sequenceiq.cloudbreak.service.secret.domain.Secret)4 Field (java.lang.reflect.Field)4 SecretProxy (com.sequenceiq.cloudbreak.service.secret.domain.SecretProxy)2