use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.
the class GrantPermissionManager method loadAllEntitiesPermissions.
public EntityWithPermissionVO loadAllEntitiesPermissions(AclClass aclClass, Integer page, Integer pageSize, boolean expandGroups, Integer filterMask) {
EntityWithPermissionVO result = new EntityWithPermissionVO();
Collection<? extends AbstractSecuredEntity> entities = entityManager.loadAllWithParents(aclClass, page, pageSize);
Map<AbstractSecuredEntity, List<AclPermissionEntry>> allPermissions = getEntitiesPermissions(entities);
result.setTotalCount(entityManager.loadTotalCount(aclClass));
List<EntityPermission> permissions = entities.stream().distinct().sorted(Comparator.comparingLong(BaseEntity::getId)).map(entity -> getEntityPermission(allPermissions, entity)).collect(toList());
if (expandGroups) {
expandGroups(permissions);
if (filterMask != null) {
permissions.forEach(entry -> {
Set<AclPermissionEntry> filtered = SetUtils.emptyIfNull(entry.getPermissions()).stream().filter(permission -> permissionsService.isMaskBitSet(permission.getMask(), filterMask)).collect(toSet());
entry.setPermissions(filtered);
});
}
}
result.setEntityPermissions(permissions);
return result;
}
use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.
the class GrantPermissionManager method changeOwner.
@Transactional(propagation = Propagation.REQUIRED)
public AclSecuredEntry changeOwner(final Long id, final AclClass aclClass, final String userName) {
Assert.isTrue(StringUtils.isNotBlank(userName), "User name is required " + "to change owner of an object.");
final AbstractSecuredEntity entity = entityManager.load(aclClass, id);
final UserContext userContext = userManager.loadUserContext(userName);
Assert.notNull(userContext, String.format("The user with name %s doesn't exist.", userName));
if (entity.getOwner().equalsIgnoreCase(userName)) {
LOGGER.info("The resource you're trying to change owner is already owned by this user.");
return new AclSecuredEntry(entity);
}
aclService.changeOwner(entity, userName);
return new AclSecuredEntry(entityManager.changeOwner(aclClass, id, userName));
}
use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.
the class GrantPermissionManager method runPermission.
public boolean runPermission(PipelineRun run, String permissionName) {
if (permissionsHelper.isOwner(run)) {
run.setMask(AbstractSecuredEntity.ALL_PERMISSIONS_MASK);
return true;
}
AbstractSecuredEntity parent = runManager.loadRunParent(run);
if (parent == null) {
run.setMask(0);
return false;
}
boolean allowed = permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), parent, permissionName);
if (allowed) {
run.setMask(getPermissionsMask(parent, true, true));
}
return allowed;
}
use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.
the class GrantPermissionManager method getPermissions.
public AclSecuredEntry getPermissions(Long id, AclClass aclClass) {
AbstractSecuredEntity entity = entityManager.load(aclClass, id);
MutableAcl acl = aclService.getOrCreateObjectIdentity(entity);
return convertAclToEntry(entity, acl);
}
use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.
the class GrantPermissionManager method runPermission.
public boolean runPermission(Long runId, String permissionName) {
PipelineRun pipelineRun = runManager.loadPipelineRun(runId);
if (permissionsHelper.isOwner(pipelineRun)) {
return true;
}
AbstractSecuredEntity parent = pipelineRun.getParent();
if (parent == null) {
return false;
}
return permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), parent, permissionName);
}
Aggregations