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 ConfigSaveState updateServerConfig(
     final MailHost mailHost,
     final LdapConfig ldapConfig,
     final PasswordFileConfig passwordFileConfig,
     final boolean shouldAllowAutoLogin,
     final String md5,
     final String artifactsDir,
     final Double purgeStart,
     final Double purgeUpto,
     final String jobTimeout,
     final String siteUrl,
     final String secureSiteUrl,
     final String taskRepositoryLocation) {
   final List<ConfigSaveState> result = new ArrayList<>();
   result.add(
       updateConfig(
           new GoConfigDao.NoOverwriteCompositeConfigCommand(
               md5,
               goConfigDao.mailHostUpdater(mailHost),
               securityUpdater(ldapConfig, passwordFileConfig, shouldAllowAutoLogin),
               serverConfigUpdater(
                   artifactsDir,
                   purgeStart,
                   purgeUpto,
                   jobTimeout,
                   siteUrl,
                   secureSiteUrl,
                   taskRepositoryLocation))));
   // should not reach here with empty result
   return result.get(0);
 }
Exemple #3
0
 private List<String> toUserNames(List<User> enabledUsers) {
   List<String> enabledUserNames = new ArrayList<String>();
   for (User enabledUser : enabledUsers) {
     enabledUserNames.add(enabledUser.getName());
   }
   return enabledUserNames;
 }
Exemple #4
0
 public List<CaseInsensitiveString> pipelines(String group) {
   PipelineConfigs configs = getCurrentConfig().pipelines(group);
   List<CaseInsensitiveString> pipelines = new ArrayList<>();
   for (PipelineConfig config : configs) {
     pipelines.add(config.name());
   }
   return pipelines;
 }
Exemple #5
0
 private PipelineConfigDependencyGraph findUpstream(PipelineConfig currentPipeline) {
   List<PipelineConfigDependencyGraph> graphs = new ArrayList<>();
   for (CaseInsensitiveString name : currentPipeline.upstreamPipelines()) {
     PipelineConfig pipelineConfig = getCurrentConfig().pipelineConfigByName(name);
     graphs.add(findUpstream(pipelineConfig));
   }
   return new PipelineConfigDependencyGraph(
       currentPipeline, graphs.toArray(new PipelineConfigDependencyGraph[0]));
 }
Exemple #6
0
 public List<PipelineConfig> downstreamPipelinesOf(String pipelineName) {
   List<PipelineConfig> dependencies = new ArrayList<>();
   for (PipelineConfig config : getAllPipelineConfigs()) {
     if (config.dependsOn(new CaseInsensitiveString(pipelineName))) {
       dependencies.add(config);
     }
   }
   return dependencies;
 }
Exemple #7
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 #8
0
    protected ConfigSaveState updatePartial(String xmlPartial, final String md5) throws Exception {
      LOGGER.debug("[Config Save] Updating partial");
      org.dom4j.Document document = documentRoot();
      Element root = document.getRootElement();

      Element configElement = ((Element) root.selectSingleNode(getXpath()));
      List nodes = configElement.getParent().content();
      int index = nodes.indexOf(configElement);

      LOGGER.debug("[Config Save] Converting to object");
      Element newConfigElement = reader.read(new StringReader(xmlPartial)).getRootElement();
      nodes.set(index, newConfigElement);

      return saveConfig(document.asXML(), md5);
    }
Exemple #9
0
  public void create(List<UserSearchModel> userSearchModels, HttpLocalizedOperationResult result) {
    if (userSearchModels.isEmpty()) {
      result.badRequest(LocalizedMessage.string("NO_USERS_SELECTED"));
      return;
    }
    synchronized (enableUserMutex) {
      for (UserSearchModel userSearchModel : userSearchModels) {
        User user = userSearchModel.getUser();

        if (userExists(user)) {
          result.conflict(
              LocalizedMessage.string(
                  "USER_ALREADY_EXISTS", user.getName(), user.getDisplayName(), user.getEmail()));
          return;
        }

        if (user.isAnonymous()) {
          result.badRequest(LocalizedMessage.string("USERNAME_NOT_PERMITTED", user.getName()));
          return;
        }

        if (!userSearchModel.getUserSourceType().equals(UserSourceType.PASSWORD_FILE)
            && validateEmailAndMatcher(result, user)) {
          return;
        }
        userDao.saveOrUpdate(user);
        result.setMessage(LocalizedMessage.string("USER_SUCCESSFULLY_ADDED", user.getName()));
      }
    }
  }
Exemple #10
0
 private void addRoleUsers(
     List<CaseInsensitiveString> users, final CaseInsensitiveString roleName) {
   Role role = security().getRoles().findByName(roleName);
   if (role != null) {
     for (RoleUser roleUser : role.getUsers()) {
       users.add(roleUser.getName());
     }
   }
 }
Exemple #11
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 #12
0
 private boolean willDisableAllAdmins(List<String> usersToBeDisabled) {
   List<String> enabledUserNames = toUserNames(userDao.enabledUsers());
   enabledUserNames.removeAll(usersToBeDisabled);
   return !userNameListContainsAdmin(enabledUserNames);
 }