public Map<CaseInsensitiveString, List<CaseInsensitiveString>> templatesWithPipelinesForUser(CaseInsensitiveString username) { HashMap<CaseInsensitiveString, List<CaseInsensitiveString>> templatesToPipelinesMap = new HashMap<>(); Map<CaseInsensitiveString, Map<CaseInsensitiveString, Authorization>> authMap = goConfigService.getCurrentConfig().templatesWithAssociatedPipelines(); for (CaseInsensitiveString templateName : authMap.keySet()) { if (securityService.isAuthorizedToViewTemplate(templateName, new Username(username))) { templatesToPipelinesMap.put(templateName, new ArrayList<>()); Map<CaseInsensitiveString, Authorization> authorizationMap = authMap.get(templateName); for (CaseInsensitiveString pipelineName : authorizationMap.keySet()) { templatesToPipelinesMap.get(templateName).add(pipelineName); } } } return templatesToPipelinesMap; }
public void checkViewAccessToTemplateAnd403(Request request, Response response) { if (!securityService.isSecurityEnabled() || securityService.isUserAdmin(currentUsername())) { return; } String templateName = request.params("template_name"); if (StringUtils.isNotBlank(templateName) && !securityService.isAuthorizedToViewTemplate(new CaseInsensitiveString(templateName), currentUsername())) { throw renderForbiddenResponse(); } if (StringUtils.isBlank(templateName) && !securityService.isAuthorizedToViewTemplates(currentUsername())) { throw renderForbiddenResponse(); } }
public List<TemplateToPipelines> getTemplatesList(Username username) { List<TemplateToPipelines> templateToPipelinesForUser = new ArrayList<>(); List<Role> roles = goConfigService.rolesForUser(username.getUsername()); Map<CaseInsensitiveString, Map<CaseInsensitiveString, Authorization>> allTemplatesAssociatedWithPipelines = goConfigService.getCurrentConfig().templatesWithAssociatedPipelines(); for (CaseInsensitiveString templateName : allTemplatesAssociatedWithPipelines.keySet()) { if (securityService.isAuthorizedToViewTemplate(templateName, username)) { Map<CaseInsensitiveString, Authorization> pipelinesWithAuthorization = allTemplatesAssociatedWithPipelines.get(templateName); TemplateToPipelines templateToPipelines = new TemplateToPipelines(templateName, securityService.isAuthorizedToEditTemplate(templateName, username), securityService.isUserAdmin(username)); templateToPipelinesForUser.add(templateToPipelines); for (CaseInsensitiveString pipelineName : pipelinesWithAuthorization.keySet()) { templateToPipelines.add(new PipelineEditabilityInfo(pipelineName, canAuthorizedTemplateUserEditPipeline(username, roles, pipelinesWithAuthorization.get(pipelineName)), goConfigService.isPipelineEditable(pipelineName))); } } } return templateToPipelinesForUser; }