コード例 #1
0
  @Test
  public void shouldNotContinueWithConfigSaveIfUserIsUnauthorized() {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(false);
    when(goConfigService.isGroupAdministrator(currentUser.getUsername())).thenReturn(false);

    SCM updatedScm =
        new SCM(
            "id",
            new PluginConfiguration("plugin-id", "1"),
            new Configuration(
                new ConfigurationProperty(
                    new ConfigurationKey("key1"), new ConfigurationValue("value1"))));
    UpdateSCMConfigCommand command =
        new UpdateSCMConfigCommand(
            updatedScm,
            pluggableScmService,
            goConfigService,
            currentUser,
            result,
            "md5",
            entityHashingService);

    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.toString(), containsString("UNAUTHORIZED_TO_EDIT"));
  }
コード例 #2
0
  @Test
  public void shouldNotContinueWithConfigSaveIfObjectNotFound() {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    when(goConfigService.isGroupAdministrator(currentUser.getUsername())).thenReturn(false);

    SCM updatedScm =
        new SCM(
            "non-existent-id",
            new PluginConfiguration("plugin-id", "1"),
            new Configuration(
                new ConfigurationProperty(
                    new ConfigurationKey("key1"), new ConfigurationValue("value1"))));
    UpdateSCMConfigCommand command =
        new UpdateSCMConfigCommand(
            updatedScm,
            pluggableScmService,
            goConfigService,
            currentUser,
            result,
            "md5",
            entityHashingService);

    thrown.expect(NullPointerException.class);
    thrown.expectMessage("The pluggable scm material with id 'non-existent-id' is not found.");
    assertThat(command.canContinue(cruiseConfig), is(false));
  }
コード例 #3
0
  @Test
  public void shouldNotContinueWithConfigSaveIfRequestIsNotFresh() {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    when(goConfigService.isGroupAdministrator(currentUser.getUsername())).thenReturn(false);

    SCM updatedScm =
        new SCM(
            "id",
            new PluginConfiguration("plugin-id", "1"),
            new Configuration(
                new ConfigurationProperty(
                    new ConfigurationKey("key1"), new ConfigurationValue("value1"))));
    updatedScm.setName("material");
    when(entityHashingService.md5ForEntity(cruiseConfig.getSCMs().find("id"), "material"))
        .thenReturn("another-md5");
    UpdateSCMConfigCommand command =
        new UpdateSCMConfigCommand(
            updatedScm,
            pluggableScmService,
            goConfigService,
            currentUser,
            result,
            "md5",
            entityHashingService);

    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.toString(), containsString("STALE_RESOURCE_CONFIG"));
    assertThat(result.toString(), containsString(updatedScm.getName()));
  }
コード例 #4
0
ファイル: SecurityService.java プロジェクト: jango2015/gocd
 public boolean hasViewPermissionForPipeline(Username username, String pipelineName) {
   String groupName =
       goConfigService.findGroupNameByPipeline(new CaseInsensitiveString(pipelineName));
   if (groupName == null) {
     return true;
   }
   return hasViewPermissionForGroup(CaseInsensitiveString.str(username.getUsername()), groupName);
 }
コード例 #5
0
ファイル: SecurityService.java プロジェクト: jango2015/gocd
 public List<CaseInsensitiveString> viewablePipelinesFor(Username username) {
   List<CaseInsensitiveString> pipelines = new ArrayList<CaseInsensitiveString>();
   for (String group : goConfigService.allGroups()) {
     if (hasViewPermissionForGroup(CaseInsensitiveString.str(username.getUsername()), group)) {
       pipelines.addAll(goConfigService.pipelines(group));
     }
   }
   return pipelines;
 }
コード例 #6
0
 private boolean isAuthorized() {
   if (!(goConfigService.isUserAdmin(username)
       || goConfigService.isGroupAdministrator(username.getUsername()))) {
     result.unauthorized(
         LocalizedMessage.string("UNAUTHORIZED_TO_EDIT"), HealthStateType.unauthorised());
     return false;
   }
   return true;
 }
コード例 #7
0
ファイル: UserService.java プロジェクト: rusio/gocd
  public void addUserIfDoesNotExist(Username userName) {
    synchronized (enableUserMutex) {
      User user = new User(CaseInsensitiveString.str(userName.getUsername()));
      if (!(user.isAnonymous() || userExists(user))) {
        assertUnknownUsersAreAllowedToLogin();

        userDao.saveOrUpdate(user);
      }
    }
  }
コード例 #8
0
ファイル: GoConfigService.java プロジェクト: jyotisingh/gocd
 private boolean isAdminOfGroup(
     String toGroupName, Username username, HttpLocalizedOperationResult result) {
   if (!isUserAdminOfGroup(username.getUsername(), toGroupName)) {
     result.unauthorized(
         LocalizedMessage.string("UNAUTHORIZED_TO_EDIT_GROUP", toGroupName),
         HealthStateType.unauthorised());
     return false;
   }
   return true;
 }
コード例 #9
0
ファイル: SecurityService.java プロジェクト: jango2015/gocd
 public List<PipelineConfigs> viewableGroupsFor(Username username) {
   ArrayList<PipelineConfigs> list = new ArrayList<PipelineConfigs>();
   for (PipelineConfigs pipelineConfigs : goConfigService.getCurrentConfig().getGroups()) {
     if (hasViewPermissionForGroup(
         CaseInsensitiveString.str(username.getUsername()), pipelineConfigs.getGroup())) {
       list.add(pipelineConfigs);
     }
   }
   return list;
 }
コード例 #10
0
 @Override
 public boolean canContinue(CruiseConfig cruiseConfig) {
   if (goConfigService.groups().hasGroup(groupName)
       && !goConfigService.isUserAdminOfGroup(currentUser.getUsername(), groupName)) {
     result.unauthorized(
         LocalizedMessage.string("UNAUTHORIZED_TO_EDIT_GROUP", groupName),
         HealthStateType.unauthorised());
     return false;
   }
   return true;
 }
コード例 #11
0
  @Test
  public void shouldContinueWithConfigSaveIfUserIsGroupAdmin() {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(false);
    when(goConfigService.isGroupAdministrator(currentUser.getUsername())).thenReturn(true);

    CreatePackageRepositoryCommand command =
        new CreatePackageRepositoryCommand(
            goConfigService, packageRepositoryService, packageRepository, currentUser, result);

    assertThat(command.canContinue(cruiseConfig), is(true));
  }
コード例 #12
0
ファイル: SecurityService.java プロジェクト: jango2015/gocd
 public List<String> modifiableGroupsForUser(Username userName) {
   if (isUserAdmin(userName)) {
     return goConfigService.allGroups();
   }
   List<String> modifiableGroups = new ArrayList<String>();
   for (String group : goConfigService.allGroups()) {
     if (isUserAdminOfGroup(userName.getUsername(), group)) {
       modifiableGroups.add(group);
     }
   }
   return modifiableGroups;
 }
コード例 #13
0
ファイル: GoConfigService.java プロジェクト: jyotisingh/gocd
 public boolean canEditPipeline(
     String pipelineName, Username username, LocalizedOperationResult result, String groupName) {
   if (!doesPipelineExist(pipelineName, result)) {
     return false;
   }
   if (!isUserAdminOfGroup(username.getUsername(), groupName)) {
     result.unauthorized(
         LocalizedMessage.string("UNAUTHORIZED_TO_EDIT_PIPELINE", pipelineName),
         HealthStateType.unauthorisedForPipeline(pipelineName));
     return false;
   }
   return true;
 }
コード例 #14
0
  @Test
  public void shouldContinueWithConfigSaveIfUserIsGroupAdmin() {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(false);
    when(goConfigService.isGroupAdministrator(currentUser.getUsername())).thenReturn(true);
    when(entityHashingService.md5ForEntity(any(PackageRepository.class))).thenReturn("md5");

    UpdatePackageRepositoryCommand command =
        new UpdatePackageRepositoryCommand(
            goConfigService,
            packageRepositoryService,
            newPackageRepo,
            currentUser,
            "md5",
            entityHashingService,
            result,
            repoId);

    assertThat(command.canContinue(cruiseConfig), is(true));
  }
コード例 #15
0
ファイル: GoConfigService.java プロジェクト: jyotisingh/gocd
 private boolean isUserTemplateAdmin(Username username) {
   return getCurrentConfig().getTemplates().canViewAndEditTemplate(username.getUsername());
 }
コード例 #16
0
ファイル: SecurityService.java プロジェクト: jango2015/gocd
 public boolean isUserGroupAdmin(Username username) {
   return goConfigService.isGroupAdministrator(username.getUsername());
 }
コード例 #17
0
ファイル: GoConfigService.java プロジェクト: jyotisingh/gocd
 public boolean isAuthorizedToEditTemplate(String templateName, Username username) {
   return isUserAdmin(username)
       || getCurrentConfig()
           .getTemplates()
           .canUserEditTemplate(templateName, username.getUsername());
 }
コード例 #18
0
ファイル: SecurityService.java プロジェクト: jango2015/gocd
 public boolean hasViewOrOperatePermissionForPipeline(Username username, String pipelineName) {
   return hasViewPermissionForPipeline(username, pipelineName)
       || hasOperatePermissionForPipeline(username.getUsername(), pipelineName);
 }
コード例 #19
0
ファイル: GoConfigService.java プロジェクト: jyotisingh/gocd
 public boolean isGroupAdministrator(final Username userName) {
   return getCurrentConfig().isGroupAdministrator(userName.getUsername());
 }
コード例 #20
0
ファイル: GoConfigService.java プロジェクト: jyotisingh/gocd
 public boolean isUserAdmin(Username username) {
   return isAdministrator(CaseInsensitiveString.str(username.getUsername()));
 }
コード例 #21
0
ファイル: GoConfigService.java プロジェクト: jyotisingh/gocd
 public boolean isAuthorizedToViewAndEditTemplates(Username username) {
   return getCurrentConfig().getTemplates().canViewAndEditTemplate(username.getUsername());
 }