Search in sources :

Example 1 with AclSecuredEntry

use of com.epam.pipeline.entity.security.acl.AclSecuredEntry 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));
}
Also used : UserContext(com.epam.pipeline.security.UserContext) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) AclSecuredEntry(com.epam.pipeline.entity.security.acl.AclSecuredEntry) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with AclSecuredEntry

use of com.epam.pipeline.entity.security.acl.AclSecuredEntry 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 3 with AclSecuredEntry

use of com.epam.pipeline.entity.security.acl.AclSecuredEntry 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 4 with AclSecuredEntry

use of com.epam.pipeline.entity.security.acl.AclSecuredEntry in project cloud-pipeline by epam.

the class GrantPermissionManager method convertAclToEntry.

private AclSecuredEntry convertAclToEntry(AbstractSecuredEntity entity, MutableAcl acl) {
    AclSecuredEntry entry = new AclSecuredEntry(entity);
    acl.getEntries().forEach(aclEntry -> entry.addPermission(new AclPermissionEntry(aclEntry.getSid(), aclEntry.getPermission().getMask())));
    return entry;
}
Also used : AclPermissionEntry(com.epam.pipeline.entity.security.acl.AclPermissionEntry) AclSecuredEntry(com.epam.pipeline.entity.security.acl.AclSecuredEntry)

Example 5 with AclSecuredEntry

use of com.epam.pipeline.entity.security.acl.AclSecuredEntry in project cloud-pipeline by epam.

the class GrantPermissionManager method convertAclToEntryForUser.

private AclSecuredEntry convertAclToEntryForUser(AbstractSecuredEntity entity, MutableAcl acl, Sid sid) {
    AclSid aclSid = new AclSid(sid);
    AclSecuredEntry entry = convertAclToEntry(entity, acl);
    List<AclPermissionEntry> filteredPermissions = entry.getPermissions().stream().filter(p -> p.getSid().equals(aclSid)).collect(toList());
    entry.setPermissions(filteredPermissions);
    return entry;
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) EntityEventServiceManager(com.epam.pipeline.manager.event.EntityEventServiceManager) StringUtils(org.apache.commons.lang3.StringUtils) PermissionGrantVO(com.epam.pipeline.controller.vo.PermissionGrantVO) PipelineApiService(com.epam.pipeline.manager.pipeline.PipelineApiService) ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ConfigurationProviderManager(com.epam.pipeline.manager.pipeline.runner.ConfigurationProviderManager) AbstractRunConfigurationEntry(com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry) AclPermission(com.epam.pipeline.security.acl.AclPermission) Map(java.util.Map) MutableAcl(org.springframework.security.acls.model.MutableAcl) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) PermissionFactory(org.springframework.security.acls.domain.PermissionFactory) DefaultRoles(com.epam.pipeline.entity.user.DefaultRoles) Set(java.util.Set) Acl(org.springframework.security.acls.model.Acl) EntityWithPermissionVO(com.epam.pipeline.controller.vo.security.EntityWithPermissionVO) Tool(com.epam.pipeline.entity.pipeline.Tool) Stream(java.util.stream.Stream) CollectionUtils(org.springframework.util.CollectionUtils) EntityVO(com.epam.pipeline.controller.vo.EntityVO) AclDataAccessException(org.springframework.security.acls.model.AclDataAccessException) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) AbstractEntityPermissionMapper(com.epam.pipeline.mapper.AbstractEntityPermissionMapper) DataStorageAction(com.epam.pipeline.entity.datastorage.DataStorageAction) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) RunConfigurationVO(com.epam.pipeline.controller.vo.configuration.RunConfigurationVO) ArrayList(java.util.ArrayList) DockerRegistryManager(com.epam.pipeline.manager.docker.DockerRegistryManager) Service(org.springframework.stereotype.Service) SetUtils(org.apache.commons.collections4.SetUtils) EntityManager(com.epam.pipeline.manager.EntityManager) Sid(org.springframework.security.acls.model.Sid) BaseEntity(com.epam.pipeline.entity.BaseEntity) Pair(org.apache.commons.math3.util.Pair) FolderManager(com.epam.pipeline.manager.pipeline.FolderManager) TaskStatus(com.epam.pipeline.entity.pipeline.TaskStatus) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) PermissionEvaluator(org.springframework.security.access.PermissionEvaluator) EntityPermissionVO(com.epam.pipeline.controller.vo.EntityPermissionVO) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) RunConfiguration(com.epam.pipeline.entity.configuration.RunConfiguration) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) AclSecuredEntry(com.epam.pipeline.entity.security.acl.AclSecuredEntry) PipelineWithPermissions(com.epam.pipeline.entity.pipeline.PipelineWithPermissions) MetadataEntityManager(com.epam.pipeline.manager.metadata.MetadataEntityManager) AclClass(com.epam.pipeline.entity.security.acl.AclClass) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) AbstractHierarchicalEntity(com.epam.pipeline.entity.AbstractHierarchicalEntity) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LoggerFactory(org.slf4j.LoggerFactory) EntityPermission(com.epam.pipeline.entity.security.acl.EntityPermission) Folder(com.epam.pipeline.entity.pipeline.Folder) UserContext(com.epam.pipeline.security.UserContext) MessageHelper(com.epam.pipeline.common.MessageHelper) Collectors.toMap(java.util.stream.Collectors.toMap) ListUtils(org.apache.commons.collections4.ListUtils) PipelineWithPermissionsMapper(com.epam.pipeline.mapper.PipelineWithPermissionsMapper) IssueComment(com.epam.pipeline.entity.issue.IssueComment) NodesManager(com.epam.pipeline.manager.cluster.NodesManager) IssueManager(com.epam.pipeline.manager.issue.IssueManager) Collectors.toSet(java.util.stream.Collectors.toSet) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) RepositoryTool(com.epam.pipeline.entity.pipeline.RepositoryTool) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) Collection(java.util.Collection) AccessControlEntry(org.springframework.security.acls.model.AccessControlEntry) AclPermissionEntry(com.epam.pipeline.entity.security.acl.AclPermissionEntry) NodeInstance(com.epam.pipeline.entity.cluster.NodeInstance) List(java.util.List) UserManager(com.epam.pipeline.manager.user.UserManager) SidRetrievalStrategy(org.springframework.security.acls.model.SidRetrievalStrategy) Optional(java.util.Optional) Authentication(org.springframework.security.core.Authentication) AclSecuredFilter(com.epam.pipeline.entity.filter.AclSecuredFilter) JdbcMutableAclServiceImpl(com.epam.pipeline.security.acl.JdbcMutableAclServiceImpl) MessageConstants(com.epam.pipeline.common.MessageConstants) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) ToolManager(com.epam.pipeline.manager.pipeline.ToolManager) Permission(org.springframework.security.acls.model.Permission) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Propagation(org.springframework.transaction.annotation.Propagation) Collectors.mapping(java.util.stream.Collectors.mapping) ToolGroupManager(com.epam.pipeline.manager.pipeline.ToolGroupManager) Logger(org.slf4j.Logger) AclSid(com.epam.pipeline.entity.security.acl.AclSid) Collectors.toList(java.util.stream.Collectors.toList) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) PipelinesWithPermissionsVO(com.epam.pipeline.controller.vo.PipelinesWithPermissionsVO) AccessControlEntryImpl(org.springframework.security.acls.domain.AccessControlEntryImpl) Data(lombok.Data) Issue(com.epam.pipeline.entity.issue.Issue) Comparator(java.util.Comparator) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) AclSid(com.epam.pipeline.entity.security.acl.AclSid) AclPermissionEntry(com.epam.pipeline.entity.security.acl.AclPermissionEntry) AclSecuredEntry(com.epam.pipeline.entity.security.acl.AclSecuredEntry)

Aggregations

AclSecuredEntry (com.epam.pipeline.entity.security.acl.AclSecuredEntry)5 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)4 AclSid (com.epam.pipeline.entity.security.acl.AclSid)3 Transactional (org.springframework.transaction.annotation.Transactional)3 AclPermissionEntry (com.epam.pipeline.entity.security.acl.AclPermissionEntry)2 EntityPermission (com.epam.pipeline.entity.security.acl.EntityPermission)2 GrantedAuthoritySid (org.springframework.security.acls.domain.GrantedAuthoritySid)2 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)2 MutableAcl (org.springframework.security.acls.model.MutableAcl)2 Sid (org.springframework.security.acls.model.Sid)2 MessageConstants (com.epam.pipeline.common.MessageConstants)1 MessageHelper (com.epam.pipeline.common.MessageHelper)1 EntityPermissionVO (com.epam.pipeline.controller.vo.EntityPermissionVO)1 EntityVO (com.epam.pipeline.controller.vo.EntityVO)1 PermissionGrantVO (com.epam.pipeline.controller.vo.PermissionGrantVO)1 PipelinesWithPermissionsVO (com.epam.pipeline.controller.vo.PipelinesWithPermissionsVO)1 RunConfigurationVO (com.epam.pipeline.controller.vo.configuration.RunConfigurationVO)1 EntityWithPermissionVO (com.epam.pipeline.controller.vo.security.EntityWithPermissionVO)1 AbstractHierarchicalEntity (com.epam.pipeline.entity.AbstractHierarchicalEntity)1 BaseEntity (com.epam.pipeline.entity.BaseEntity)1