Search in sources :

Example 91 with Username

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;
}
Also used : HashMap(java.util.HashMap) Username(com.thoughtworks.go.server.domain.Username) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 92 with Username

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;
}
Also used : Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 93 with Username

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());
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Before(org.junit.Before)

Example 94 with Username

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 95 with Username

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);
}
Also used : Username(com.thoughtworks.go.server.domain.Username) EntityHashingService(com.thoughtworks.go.server.service.EntityHashingService) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Before(org.junit.Before)

Aggregations

Username (com.thoughtworks.go.server.domain.Username)391 Test (org.junit.Test)317 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)170 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)81 Before (org.junit.Before)42 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)36 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)33 Pipeline (com.thoughtworks.go.domain.Pipeline)30 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)27 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)21 StringContains.containsString (org.hamcrest.core.StringContains.containsString)20 Modification (com.thoughtworks.go.domain.materials.Modification)17 ArrayList (java.util.ArrayList)16 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)15 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)14 TimeProvider (com.thoughtworks.go.util.TimeProvider)13 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)12 Date (java.util.Date)12 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)11 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)10