use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.
the class DockerRegistryManager method parseAndValidateScope.
// expected format: repository:group/image:push
private List<DockerRegistryClaim> parseAndValidateScope(String userName, DockerRegistry registry, String scope) {
if (StringUtils.isBlank(scope)) {
// read permission for at least one child in the registry is required
if (!permissionManager.isActionAllowedForUser(registry, userName, AclPermission.READ)) {
DockerRegistry fullTree = getDockerRegistryTree(registry.getId());
permissionManager.filterTree(userName, fullTree, AclPermission.READ);
if (CollectionUtils.isEmpty(fullTree.getChildren())) {
throw new DockerAuthorizationException(registry.getPath(), messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_IS_NOT_ALLOWED, userName, registry.getPath()));
}
}
return Collections.emptyList();
}
List<DockerRegistryClaim> claims = DockerRegistryClaim.parseClaims(scope);
claims.forEach(claim -> {
AbstractSecuredEntity entity = registry;
List<Permission> permissions = claim.getRequestedPermissions();
boolean toolRequired = !permissions.contains(AclPermission.WRITE);
try {
ToolGroup toolGroup = toolGroupManager.loadToolGroupByImage(registry.getPath(), claim.getImageName());
entity = toolGroup;
Optional<Tool> tool = toolManager.loadToolInGroup(claim.getImageName(), toolGroup.getId());
entity = tool.orElseThrow(() -> new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_TOOL_IMAGE_UNAVAILABLE, claim.getImageName())));
} catch (IllegalArgumentException e) {
LOGGER.trace(e.getMessage(), e);
if (toolRequired) {
throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_TOOL_IMAGE_UNAVAILABLE, claim.getImageName()));
}
}
if (!permissionManager.isActionAllowedForUser(entity, userName, permissions)) {
throw new DockerAuthorizationException(registry.getPath(), messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_ACTION_IS_NOT_ALLOWED, scope, userName, registry.getPath()));
}
});
return claims;
}
use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.
the class NotificationManager method notifyIssueComment.
@Transactional(propagation = Propagation.REQUIRED)
public void notifyIssueComment(IssueComment comment, Issue issue, String htmlText) {
NotificationSettings newIssueCommentSettings = notificationSettingsManager.load(NotificationType.NEW_ISSUE_COMMENT);
if (newIssueCommentSettings == null || !newIssueCommentSettings.isEnabled()) {
LOGGER.info(messageHelper.getMessage(MessageConstants.INFO_NOTIFICATION_TEMPLATE_NOT_CONFIGURED, "new issue"));
return;
}
NotificationMessage message = new NotificationMessage();
message.setTemplate(new NotificationTemplate(newIssueCommentSettings.getTemplateId()));
AbstractSecuredEntity entity = entityManager.load(issue.getEntity().getEntityClass(), issue.getEntity().getEntityId());
List<PipelineUser> referencedUsers = userManager.loadUsersByNames(Arrays.asList(entity.getOwner(), issue.getAuthor()));
List<Long> ccUserIds = getMentionedUsers(comment.getText());
referencedUsers.stream().filter(u -> u.getUserName().equals(entity.getOwner())).findFirst().ifPresent(owner -> ccUserIds.add(owner.getId()));
message.setCopyUserIds(ccUserIds);
if (newIssueCommentSettings.isKeepInformedOwner()) {
PipelineUser author = referencedUsers.stream().filter(u -> u.getUserName().equals(issue.getAuthor())).findFirst().orElseThrow(() -> new IllegalArgumentException("No issue author was found"));
message.setToUserId(author.getId());
}
IssueComment copyWithHtml = comment.toBuilder().text(htmlText).build();
Map<String, Object> commentParams = jsonMapper.convertValue(copyWithHtml, new TypeReference<Map<String, Object>>() {
});
commentParams.put("issue", jsonMapper.convertValue(issue, new TypeReference<Map<String, Object>>() {
}));
message.setTemplateParameters(commentParams);
monitoringNotificationDao.createMonitoringNotification(message);
}
use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.
the class FolderManager method getProject.
public FolderWithMetadata getProject(Long entityId, AclClass entityClass) {
validateAclClass(entityClass);
Set<Pair<String, String>> projectIndicators = parseProjectIndicator();
if (CollectionUtils.isEmpty(projectIndicators)) {
throw new IllegalArgumentException("Can not detect project: project indicator not found.");
}
AbstractSecuredEntity entity = entityManager.load(entityClass, entityId);
AbstractSecuredEntity folderToStartSearch = entity.getAclClass().equals(AclClass.FOLDER) ? entity : entity.getParent();
if (folderToStartSearch == null) {
LOGGER.debug("Current entity doesn't have a Folder parent");
return null;
}
if (!folderToStartSearch.getAclClass().equals(AclClass.FOLDER)) {
throw new IllegalArgumentException("Parent must be a FOLDER.");
}
Map<Long, FolderWithMetadata> folders = convertListToMap(folderDao.loadParentFolders(folderToStartSearch.getId()));
return getProjectFolder(folders, folderToStartSearch.getId(), projectIndicators);
}
use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.
the class GrantPermissionManager method getEntityPermission.
private EntityPermission getEntityPermission(Map<AbstractSecuredEntity, List<AclPermissionEntry>> allPermissions, AbstractSecuredEntity entity) {
AbstractSecuredEntity aclEntity = getAclEntity(entity);
Map<AclSid, Integer> mergedPermissions = getEntityPermissions(aclEntity, allPermissions);
mergeWithParentPermissions(mergedPermissions, entity.getParent(), allPermissions);
Set<AclPermissionEntry> merged = buildAclPermissionEntries(mergedPermissions);
// clear parent, not to return full hierarchy
entity.clearParent();
EntityPermission entityPermission = new EntityPermission();
entityPermission.setEntity(entity);
entityPermission.setPermissions(merged);
return entityPermission;
}
use of com.epam.pipeline.entity.AbstractSecuredEntity in project cloud-pipeline by epam.
the class GrantPermissionManager method getPermissions.
public Map<AbstractSecuredEntity, List<AclPermissionEntry>> getPermissions(Set<AbstractSecuredEntity> securedEntities) {
Map<ObjectIdentity, Acl> acls = aclService.getObjectIdentities(securedEntities);
Map<AbstractSecuredEntity, List<AclPermissionEntry>> result = new HashMap<>();
securedEntities.forEach(securedEntity -> {
Acl acl = acls.get(new ObjectIdentityImpl(securedEntity));
Assert.isInstanceOf(MutableAcl.class, acl, messageHelper.getMessage(MessageConstants.ERROR_MUTABLE_ACL_RETURN));
List<AclPermissionEntry> permissions = new ArrayList<>();
acl.getEntries().forEach(aclEntry -> permissions.add(new AclPermissionEntry(aclEntry.getSid(), aclEntry.getPermission().getMask())));
result.put(securedEntity, permissions);
});
return result;
}
Aggregations