Search in sources :

Example 11 with AbstractSecuredEntity

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

the class GrantPermissionManager method toolPermission.

public boolean toolPermission(RepositoryTool repoTool, String permissionName) {
    if (!repoTool.getRegistered()) {
        return true;
    }
    AbstractSecuredEntity tool = repoTool.getTool();
    if (tool == null) {
        return true;
    }
    boolean allowed = permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), tool, permissionName);
    if (allowed) {
        tool.setMask(getPermissionsMask(tool, true, true));
        repoTool.setMask(tool.getMask());
    }
    return allowed;
}
Also used : AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity)

Example 12 with AbstractSecuredEntity

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

the class GrantPermissionManager method deletePermissions.

@Transactional(propagation = Propagation.REQUIRED)
public AclSecuredEntry deletePermissions(Long id, AclClass aclClass, String user, boolean isPrincipal) {
    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);
    Sid sid = aclService.getSid(user.toUpperCase(), isPrincipal);
    int sidEntryIndex = findSidEntry(acl, sid);
    if (sidEntryIndex != -1) {
        acl.deleteAce(sidEntryIndex);
        acl = aclService.updateAcl(acl);
    }
    AclSecuredEntry aclSecuredEntry = convertAclToEntryForUser(entity, acl, sid);
    updateEventsWithChildrenAndIssues(entity);
    return aclSecuredEntry;
}
Also used : AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) MutableAcl(org.springframework.security.acls.model.MutableAcl) AclSecuredEntry(com.epam.pipeline.entity.security.acl.AclSecuredEntry) Sid(org.springframework.security.acls.model.Sid) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) AclSid(com.epam.pipeline.entity.security.acl.AclSid) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with AbstractSecuredEntity

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

the class GrantPermissionManager method setPermissions.

@Transactional(propagation = Propagation.REQUIRED)
public AclSecuredEntry setPermissions(PermissionGrantVO grantVO) {
    validateParameters(grantVO);
    AbstractSecuredEntity entity = entityManager.load(grantVO.getAclClass(), grantVO.getId());
    Assert.isTrue(!entity.isLocked(), messageHelper.getMessage(MessageConstants.ERROR_ENTITY_IS_LOCKED, entity.getAclClass(), entity.getId()));
    MutableAcl acl = aclService.getOrCreateObjectIdentity(entity);
    Permission permission = permissionFactory.buildFromMask(grantVO.getMask());
    String sidName = grantVO.getUserName().toUpperCase();
    Sid sid = aclService.createOrGetSid(sidName, grantVO.getPrincipal());
    LOGGER.debug("Granting permissions for sid {}", sid);
    int sidEntryIndex = findSidEntry(acl, sid);
    if (sidEntryIndex != -1) {
        acl.deleteAce(sidEntryIndex);
    }
    acl.insertAce(Math.max(sidEntryIndex, 0), permission, sid, true);
    MutableAcl updatedAcl = aclService.updateAcl(acl);
    AclSecuredEntry aclSecuredEntry = convertAclToEntryForUser(entity, updatedAcl, sid);
    updateEventsWithChildrenAndIssues(entity);
    return aclSecuredEntry;
}
Also used : AclPermission(com.epam.pipeline.security.acl.AclPermission) EntityPermission(com.epam.pipeline.entity.security.acl.EntityPermission) Permission(org.springframework.security.acls.model.Permission) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) MutableAcl(org.springframework.security.acls.model.MutableAcl) AclSecuredEntry(com.epam.pipeline.entity.security.acl.AclSecuredEntry) Sid(org.springframework.security.acls.model.Sid) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) AclSid(com.epam.pipeline.entity.security.acl.AclSid) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with AbstractSecuredEntity

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

the class GrantPermissionManager method mergeWithParentPermissions.

private void mergeWithParentPermissions(Map<AclSid, Integer> mergedPermissions, AbstractSecuredEntity parent, Map<AbstractSecuredEntity, List<AclPermissionEntry>> allPermissions) {
    AbstractSecuredEntity currentParent = parent;
    while (currentParent != null) {
        mergePermissions(mergedPermissions, allPermissions.get(currentParent));
        currentParent = currentParent.getParent();
    }
}
Also used : AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity)

Example 15 with AbstractSecuredEntity

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

the class IssueManager method ensureEntityExists.

private AbstractSecuredEntity ensureEntityExists(EntityVO entityVO) {
    AbstractSecuredEntity entity = entityManager.load(entityVO.getEntityClass(), entityVO.getEntityId());
    Assert.notNull(entity, messageHelper.getMessage(MessageConstants.ERROR_ENTITY_NOT_FOUND, entityVO.getEntityId(), entityVO.getEntityClass()));
    return entity;
}
Also used : AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity)

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