use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class TemplateConfigService method templatesWithPipelinesForUser.
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;
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class AuthorizationInterceptor method preHandle.
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (UserHelper.isAgent()) {
return true;
}
String pipelineName = request.getParameter("pipelineName");
if (pipelineName != null) {
Username username = UserHelper.getUserName();
String name = CaseInsensitiveString.str(username.getUsername());
if (request.getMethod().equalsIgnoreCase("get")) {
if (!securityService.hasViewPermissionForPipeline(username, pipelineName)) {
response.sendError(SC_UNAUTHORIZED);
return false;
}
} else if (request.getMethod().equalsIgnoreCase("post") || request.getMethod().equalsIgnoreCase("put")) {
if (isEditingConfigurationRequest(request)) {
return true;
}
String stageName = request.getParameter("stageName");
if (stageName != null) {
if (!securityService.hasOperatePermissionForStage(pipelineName, stageName, name)) {
response.sendError(SC_UNAUTHORIZED);
return false;
}
} else {
if (!securityService.hasOperatePermissionForPipeline(username.getUsername(), pipelineName)) {
response.sendError(SC_UNAUTHORIZED);
return false;
}
}
}
}
return true;
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class PatchEnvironmentCommandTest method setup.
@Before
public void setup() throws Exception {
initMocks(this);
pipelinesToAdd = new ArrayList<>();
pipelinesToRemove = new ArrayList<>();
agentsToAdd = new ArrayList<>();
agentsToRemove = new ArrayList<>();
envVarsToAdd = new ArrayList<>();
envVarsToRemove = new ArrayList<>();
result = new HttpLocalizedOperationResult();
currentUser = new Username(new CaseInsensitiveString("user"));
cruiseConfig = new GoConfigMother().defaultCruiseConfig();
environmentName = new CaseInsensitiveString("Dev");
environmentConfig = new BasicEnvironmentConfig(environmentName);
cruiseConfig.addEnvironment(environmentConfig);
pipelineConfig = new PipelineConfig();
String pipelineName = "pipeline-1";
pipelineConfig.setName(pipelineName);
cruiseConfig.addPipeline("First-Group", pipelineConfig);
agentConfig = new AgentConfig("uuid-1");
cruiseConfig.agents().add(agentConfig);
actionFailed = LocalizedMessage.string("ENV_UPDATE_FAILED", environmentConfig.name());
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class RoleConfigDeleteCommandTest method canContinue_shouldCheckIfRoleExists.
@Test
public void canContinue_shouldCheckIfRoleExists() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
Username viewUser = mock(Username.class);
BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
PluginRoleConfig role = new PluginRoleConfig("foo", "ldap");
when(goConfigService.isUserAdmin(viewUser)).thenReturn(true);
RoleConfigDeleteCommand command = new RoleConfigDeleteCommand(goConfigService, role, null, viewUser, result);
assertFalse(command.canContinue(cruiseConfig));
assertFalse(result.isSuccessful());
assertThat(result.httpCode(), is(404));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class RoleConfigUpdateCommandTest method setUp.
@Before
public void setUp() throws Exception {
currentUser = new Username("bob");
goConfigService = mock(GoConfigService.class);
cruiseConfig = GoConfigMother.defaultCruiseConfig();
entityHashingService = mock(EntityHashingService.class);
}
Aggregations