Search in sources :

Example 1 with AbstractSecuredEntity

use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.

the class IssueManager method createIssue.

/**
 * Creates a new issue that refers to existing {@link com.epam.pipeline.entity.AbstractSecuredEntity}.
 * If {@link com.epam.pipeline.entity.AbstractSecuredEntity} doesn't exist an error will be occurred.
 * @param issueVO {@link IssueVO} to create
 * @return create {@link Issue}
 */
@Transactional(propagation = Propagation.REQUIRED)
public Issue createIssue(IssueVO issueVO) {
    validateIssueParameters(issueVO);
    EntityVO entityVO = issueVO.getEntity();
    validateEntityParameters(entityVO);
    AbstractSecuredEntity entity = ensureEntityExists(entityVO);
    Issue issue = issueMapper.toIssue(issueVO);
    issue.setAuthor(authManager.getAuthorizedUser());
    issueDao.createIssue(issue);
    issueVO.getAttachments().forEach(a -> attachmentDao.updateAttachmentIssueId(a.getId(), issue.getId()));
    notificationManager.notifyIssue(issue, entity, StringUtils.defaultIfBlank(issueVO.getHtmlText(), issue.getText()));
    return issue;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) Issue(com.epam.pipeline.entity.issue.Issue) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with AbstractSecuredEntity

use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.

the class GrantPermissionManager method deleteAllPermissions.

@Transactional(propagation = Propagation.REQUIRED)
public AclSecuredEntry deleteAllPermissions(Long id, AclClass aclClass) {
    AbstractSecuredEntity entity = entityManager.load(aclClass, id);
    Assert.isTrue(!entity.isLocked(), messageHelper.getMessage(MessageConstants.ERROR_ENTITY_IS_LOCKED, entity.getAclClass(), entity.getId()));
    MutableAcl acl = aclService.getOrCreateObjectIdentity(entity);
    acl = deleteAllAces(acl);
    return convertAclToEntry(entity, acl);
}
Also used : AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) MutableAcl(org.springframework.security.acls.model.MutableAcl) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with AbstractSecuredEntity

use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.

the class GrantPermissionManager method getEntitiesPermissions.

private Map<AbstractSecuredEntity, List<AclPermissionEntry>> getEntitiesPermissions(Collection<? extends AbstractSecuredEntity> entities) {
    Set<AbstractSecuredEntity> result = new HashSet<>(entities);
    entities.forEach(entity -> {
        AbstractSecuredEntity parent = entity.getParent();
        while (parent != null) {
            result.add(parent);
            parent = parent.getParent();
        }
    });
    return getPermissions(result);
}
Also used : AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) HashSet(java.util.HashSet)

Example 4 with AbstractSecuredEntity

use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.

the class GrantPermissionManager method metadataEntityPermission.

public boolean metadataEntityPermission(Long entityId, String permissionName) {
    MetadataEntity entity = metadataEntityManager.load(entityId);
    if (entity.getParent() == null || entity.getParent().getId() == null) {
        return isAdmin(getSids());
    }
    AbstractSecuredEntity securedEntity = entityManager.load(AclClass.FOLDER, entity.getParent().getId());
    return permissionsHelper.isAllowed(permissionName, securedEntity);
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity)

Example 5 with AbstractSecuredEntity

use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.

the class GrantPermissionManager method loadEntityPermission.

public EntityPermissionVO loadEntityPermission(final AclClass entityClass, final Long id) {
    AbstractSecuredEntity entity = entityManager.loadEntityWithParents(entityClass, id);
    Assert.notNull(entity, messageHelper.getMessage(MessageConstants.ERROR_ENTITY_NOT_FOUND, id, entityClass));
    AbstractSecuredEntity aclEntity = getAclEntity(entity);
    Map<AbstractSecuredEntity, List<AclPermissionEntry>> allPermissions = getEntitiesPermissions(Collections.singleton(aclEntity));
    EntityPermission entityPermission = getEntityPermission(allPermissions, entity);
    return entityPermissionMapper.toEntityPermissionVO(entityPermission);
}
Also used : EntityPermission(com.epam.pipeline.entity.security.acl.EntityPermission) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Aggregations

AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)21 Transactional (org.springframework.transaction.annotation.Transactional)8 MutableAcl (org.springframework.security.acls.model.MutableAcl)7 AclSid (com.epam.pipeline.entity.security.acl.AclSid)5 EntityPermission (com.epam.pipeline.entity.security.acl.EntityPermission)5 AclSecuredEntry (com.epam.pipeline.entity.security.acl.AclSecuredEntry)4 AclPermission (com.epam.pipeline.security.acl.AclPermission)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Collectors.toList (java.util.stream.Collectors.toList)4 Permission (org.springframework.security.acls.model.Permission)4 EntityVO (com.epam.pipeline.controller.vo.EntityVO)3 Issue (com.epam.pipeline.entity.issue.Issue)3 IssueComment (com.epam.pipeline.entity.issue.IssueComment)3 MetadataEntity (com.epam.pipeline.entity.metadata.MetadataEntity)3 DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)3 AclPermissionEntry (com.epam.pipeline.entity.security.acl.AclPermissionEntry)3 GrantedAuthoritySid (org.springframework.security.acls.domain.GrantedAuthoritySid)3 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)3 Sid (org.springframework.security.acls.model.Sid)3