Exemple #1
0
 public Collection<String> allRoleNames(CruiseConfig cruiseConfig) {
   List<String> roles = new ArrayList<String>();
   for (Role role : allRoles(cruiseConfig)) {
     roles.add(CaseInsensitiveString.str(role.getName()));
   }
   return roles;
 }
Exemple #2
0
  public void addUserIfDoesNotExist(Username userName) {
    synchronized (enableUserMutex) {
      User user = new User(CaseInsensitiveString.str(userName.getUsername()));
      if (!(user.isAnonymous() || userExists(user))) {
        assertUnknownUsersAreAllowedToLogin();

        userDao.saveOrUpdate(user);
      }
    }
  }
Exemple #3
0
 private List<String> invertSelections(List<String> selectedPipelines) {
   List<String> unselectedPipelines = new ArrayList<>();
   List<PipelineConfig> pipelineConfigList = cruiseConfig().getAllPipelineConfigs();
   for (PipelineConfig pipelineConfig : pipelineConfigList) {
     String pipelineName = CaseInsensitiveString.str(pipelineConfig.name());
     if (!selectedPipelines.contains(pipelineName)) {
       unselectedPipelines.add(pipelineName);
     }
   }
   return unselectedPipelines;
 }
Exemple #4
0
 public MaterialConfig findMaterialWithName(
     final CaseInsensitiveString pipelineName, final CaseInsensitiveString materialName) {
   MaterialConfigs materialConfigs = materialConfigsFor(pipelineName);
   for (MaterialConfig materialConfig : materialConfigs) {
     if (materialName.equals(materialConfig.getName())) {
       return materialConfig;
     }
   }
   LOGGER.error("material [" + materialName + "] not found in pipeline [" + pipelineName + "]");
   return null;
 }
Exemple #5
0
 public JobConfigIdentifier translateToActualCase(JobConfigIdentifier identifier) {
   PipelineConfig pipelineConfig =
       getCurrentConfig()
           .pipelineConfigByName(new CaseInsensitiveString(identifier.getPipelineName()));
   String translatedPipelineName = CaseInsensitiveString.str(pipelineConfig.name());
   StageConfig stageConfig =
       pipelineConfig.findBy(new CaseInsensitiveString(identifier.getStageName()));
   if (stageConfig == null) {
     throw new StageNotFoundException(
         new CaseInsensitiveString(identifier.getPipelineName()),
         new CaseInsensitiveString(identifier.getStageName()));
   }
   String translatedStageName = CaseInsensitiveString.str(stageConfig.name());
   JobConfig plan = stageConfig.jobConfigByInstanceName(identifier.getJobName(), true);
   if (plan == null) {
     throw new JobNotFoundException(
         identifier.getPipelineName(), identifier.getStageName(), identifier.getJobName());
   }
   String translatedJobName = plan.translatedName(identifier.getJobName());
   return new JobConfigIdentifier(translatedPipelineName, translatedStageName, translatedJobName);
 }
Exemple #6
0
  private List<UserModel> allUsersForDisplay() {
    Collection<User> users = allUsers();
    ArrayList<UserModel> userModels = new ArrayList<UserModel>();
    for (User user : users) {
      String userName = user.getName();

      ArrayList<String> roles = new ArrayList<String>();
      for (Role role : goConfigService.rolesForUser(new CaseInsensitiveString(userName))) {
        roles.add(CaseInsensitiveString.str(role.getName()));
      }

      userModels.add(
          new UserModel(
              user,
              roles,
              securityService.isUserAdmin(new Username(new CaseInsensitiveString(userName)))));
    }
    return userModels;
  }
Exemple #7
0
 public Set<String> usersThatCanOperateOnStage(
     CruiseConfig cruiseConfig, PipelineConfig pipelineConfig) {
   SortedSet<String> users = new TreeSet<String>();
   PipelineConfigs group = cruiseConfig.findGroupOfPipeline(pipelineConfig);
   if (group.hasAuthorizationDefined()) {
     if (group.hasOperationPermissionDefined()) {
       users.addAll(group.getOperateUserNames());
       List<String> roles = group.getOperateRoleNames();
       for (Role role : cruiseConfig.server().security().getRoles()) {
         if (roles.contains(CaseInsensitiveString.str(role.getName()))) {
           users.addAll(role.usersOfRole());
         }
       }
     }
   } else {
     users.addAll(allUsernames());
   }
   return users;
 }
Exemple #8
0
 public boolean isAdministrator(CaseInsensitiveString username) {
   return isAdministrator(username.toString());
 }
Exemple #9
0
 public boolean isUserAdmin(Username username) {
   return isAdministrator(CaseInsensitiveString.str(username.getUsername()));
 }