use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class CustomDdlServiceImpl method updateCustomDdl.
/**
* Updates an existing custom DDL by key.
*
* @param customDdlKey the custom DDL key
*
* @return the custom DDL information
*/
@NamespacePermission(fields = "#customDdlKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public CustomDdl updateCustomDdl(CustomDdlKey customDdlKey, CustomDdlUpdateRequest request) {
// Validate and trim the key.
customDdlHelper.validateCustomDdlKey(customDdlKey);
// Validate and trim the DDL.
Assert.hasText(request.getDdl(), "DDL must be specified.");
request.setDdl(request.getDdl().trim());
// Retrieve and ensure that a custom DDL exists with the specified key.
CustomDdlEntity customDdlEntity = customDdlDaoHelper.getCustomDdlEntity(customDdlKey);
// Update the entity with the new values.
customDdlEntity.setDdl(request.getDdl());
// Persist the entity.
customDdlEntity = customDdlDao.saveAndRefresh(customDdlEntity);
// Create and return the custom DDL object from the persisted entity.
return createCustomDdlFromEntity(customDdlEntity);
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationServiceImpl method updateNamespaceIamRoleAuthorization.
@NamespacePermission(fields = "#namespace", permissions = NamespacePermissionEnum.GRANT)
@Override
public NamespaceIamRoleAuthorization updateNamespaceIamRoleAuthorization(String namespace, NamespaceIamRoleAuthorizationUpdateRequest request) {
Assert.hasText(namespace, "Namespace must be specified");
Assert.notNull(request, "NamespaceIamRoleAuthorizationCreateRequest must be specified");
validateIamRoles(request.getIamRoles());
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(namespace.trim());
List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = getNamespaeIamRoleAuthorizationEntities(namespaceEntity);
for (NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity : namespaceIamRoleAuthorizationEntities) {
namespaceIamRoleAuthorizationDao.delete(namespaceIamRoleAuthorizationEntity);
}
NamespaceIamRoleAuthorization result = new NamespaceIamRoleAuthorization(namespaceEntity.getCode(), new ArrayList<>());
for (IamRole iamRole : request.getIamRoles()) {
NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = createNamespaceIamRoleAuthorizationEntity(namespaceEntity, iamRole);
namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity);
result.getIamRoles().add(new IamRole(namespaceIamRoleAuthorizationEntity.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getDescription()));
}
return result;
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationServiceImpl method createNamespaceIamRoleAuthorization.
@NamespacePermission(fields = "#request?.namespace", permissions = NamespacePermissionEnum.GRANT)
@Override
public NamespaceIamRoleAuthorization createNamespaceIamRoleAuthorization(NamespaceIamRoleAuthorizationCreateRequest request) {
Assert.notNull(request, "NamespaceIamRoleAuthorizationCreateRequest must be specified");
Assert.hasText(request.getNamespace(), "Namespace must be specified");
validateIamRoles(request.getIamRoles());
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getNamespace().trim());
assertNamespaceIamRoleAuthorizationNotExist(namespaceEntity);
NamespaceIamRoleAuthorization result = new NamespaceIamRoleAuthorization(namespaceEntity.getCode(), new ArrayList<>());
for (IamRole iamRole : request.getIamRoles()) {
NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = createNamespaceIamRoleAuthorizationEntity(namespaceEntity, iamRole);
namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity);
result.getIamRoles().add(new IamRole(namespaceIamRoleAuthorizationEntity.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getDescription()));
}
return result;
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class NamespaceSecurityAdvice method checkPermission.
/**
* Check permission on the service methods before the execution. The method is expected to throw AccessDeniedException if current user does not have the
* permissions.
*
* @param joinPoint The join point
*/
@Before("serviceMethods()")
public void checkPermission(JoinPoint joinPoint) {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature.getMethod();
List<NamespacePermission> namespacePermissions = new ArrayList<>();
if (method.isAnnotationPresent(NamespacePermissions.class)) {
namespacePermissions.addAll(Arrays.asList(method.getAnnotation(NamespacePermissions.class).value()));
} else if (method.isAnnotationPresent(NamespacePermission.class)) {
namespacePermissions.add(method.getAnnotation(NamespacePermission.class));
}
if (!namespacePermissions.isEmpty()) {
String[] parameterNames = methodSignature.getParameterNames();
Object[] args = joinPoint.getArgs();
Map<String, Object> variables = new HashMap<>();
for (int i = 0; i < parameterNames.length; i++) {
variables.put(parameterNames[i], args[i]);
}
List<AccessDeniedException> accessDeniedExceptions = new ArrayList<>();
for (NamespacePermission namespacePermission : namespacePermissions) {
for (String field : namespacePermission.fields()) {
try {
namespaceSecurityHelper.checkPermission(spelExpressionHelper.evaluate(field, Object.class, variables), namespacePermission.permissions());
} catch (AccessDeniedException accessDeniedException) {
accessDeniedExceptions.add(accessDeniedException);
}
}
}
if (!accessDeniedExceptions.isEmpty()) {
throw namespaceSecurityHelper.getAccessDeniedException(accessDeniedExceptions);
}
}
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class BusinessObjectDefinitionTagServiceImpl method deleteBusinessObjectDefinitionTag.
@NamespacePermission(fields = "#businessObjectDefinitionTagKey.businessObjectDefinitionKey.namespace", permissions = { NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT, NamespacePermissionEnum.WRITE })
@Override
public BusinessObjectDefinitionTag deleteBusinessObjectDefinitionTag(BusinessObjectDefinitionTagKey businessObjectDefinitionTagKey) {
// Validate and trim the business object definition tag key.
validateBusinessObjectDefinitionTagKey(businessObjectDefinitionTagKey);
// Retrieve and ensure that a business object definition tag exists.
BusinessObjectDefinitionTagEntity businessObjectDefinitionTagEntity = getBusinessObjectDefinitionTagEntity(businessObjectDefinitionTagKey);
// Delete this business object format.
businessObjectDefinitionTagDao.delete(businessObjectDefinitionTagEntity);
// Notify the search index that a business object definition must be updated.
searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionTagKey.getBusinessObjectDefinitionKey()), SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Create and return the business object definition tag object from the deleted entity.
return createBusinessObjectDefinitionTagFromEntity(businessObjectDefinitionTagEntity);
}
Aggregations