Package org.sonatype.configuration.validation

Examples of org.sonatype.configuration.validation.ValidationMessage


  public ValidationResponse validateConnectionInfo(ValidationContext ctx, CConnectionInfo connectionInfo) {
    ValidationResponse response = new ValidationResponse();

    if (StringUtils.isEmpty(connectionInfo.getHost())) {
      ValidationMessage msg = new ValidationMessage("host", "Host cannot be empty.");
      response.addValidationError(msg);
    }
    if (StringUtils.isEmpty(connectionInfo.getAuthScheme())) {
      ValidationMessage msg = new ValidationMessage("authScheme", "Authorization Scheme cannot be empty.");
      response.addValidationError(msg);
    }
    if (StringUtils.isEmpty(connectionInfo.getProtocol())) {
      ValidationMessage msg = new ValidationMessage("protocol", "Protocol cannot be empty.");
      response.addValidationError(msg);
    }
    if (StringUtils.isEmpty(connectionInfo.getSearchBase())) {
      ValidationMessage msg = new ValidationMessage("searchBase", "Search Base cannot be empty.");
      response.addValidationError(msg);
    }
    if (connectionInfo.getPort() < 1) {
      ValidationMessage msg = new ValidationMessage("port", "Port cannot be empty.");
      response.addValidationError(msg);
    }

    if (StringUtils.isNotEmpty(connectionInfo.getAuthScheme())
        && !connectionInfo.getAuthScheme().toLowerCase().equals("none")) {

      // user and pass required if authScheme != none
      if (StringUtils.isEmpty(connectionInfo.getSystemUsername())) {
        ValidationMessage msg = new ValidationMessage(
            "systemUsername",
            "Username cannot be empty unless the 'Authorization Scheme' is 'Anonymous Authentication'.");
        response.addValidationError(msg);
      }

      if (StringUtils.isEmpty(connectionInfo.getSystemPassword())) {
        ValidationMessage msg = new ValidationMessage(
            "systemPassword",
            "Password cannot be empty unless the 'Authorization Scheme' is 'Anonymous Authentication'.");
        response.addValidationError(msg);
      }
    }
View Full Code Here


                                                                   CUserAndGroupAuthConfiguration userAndGroupAuthConf)
  {
    ValidationResponse response = new ValidationResponse();

    if (StringUtils.isEmpty(userAndGroupAuthConf.getUserIdAttribute())) {
      ValidationMessage msg = new ValidationMessage("userIdAttribute", "User ID Attribute cannot be empty.");
      response.addValidationError(msg);
    }
    if (StringUtils.isEmpty(userAndGroupAuthConf.getUserObjectClass())) {
      ValidationMessage msg = new ValidationMessage("userObjectClass", "User Object Class cannot be empty.");
      response.addValidationError(msg);
    }
    if (StringUtils.isEmpty(userAndGroupAuthConf.getUserRealNameAttribute())) {
      ValidationMessage msg = new ValidationMessage(
          "userRealNameAttribute",
          "User Real Name Attribute cannot be empty.");
      response.addValidationError(msg);
    }
    if (StringUtils.isEmpty(userAndGroupAuthConf.getEmailAddressAttribute())) {
      ValidationMessage msg = new ValidationMessage(
          "emailAddressAttribute",
          "Email Address Attribute cannot be empty.");
      response.addValidationError(msg);
    }

    if (userAndGroupAuthConf.isLdapGroupsAsRoles()
        && StringUtils.isEmpty(userAndGroupAuthConf.getUserMemberOfAttribute())) {
      if (StringUtils.isEmpty(userAndGroupAuthConf.getGroupIdAttribute())) {
        ValidationMessage msg = new ValidationMessage(
            "groupIdAttribute",
            "Group ID Attribute cannot be empty when Use LDAP Groups as Roles is true.");
        response.addValidationError(msg);
      }
      if (StringUtils.isEmpty(userAndGroupAuthConf.getGroupMemberAttribute())) {
        ValidationMessage msg = new ValidationMessage(
            "groupMemberAttribute",
            "Group Member Attribute cannot be empty when Use LDAP Groups as Roles is true.");
        response.addValidationError(msg);
      }
      if (StringUtils.isEmpty(userAndGroupAuthConf.getGroupMemberFormat())) {
        ValidationMessage msg = new ValidationMessage(
            "groupMemberFormat",
            "Group Member Format cannot be empty when Use LDAP Groups as Roles is true.");
        response.addValidationError(msg);
      }
      if (StringUtils.isEmpty(userAndGroupAuthConf.getGroupObjectClass())) {
        ValidationMessage msg = new ValidationMessage(
            "groupObjectClass",
            "Group Object Class cannot be empty when Use LDAP Groups as Roles is true.");
        response.addValidationError(msg);
      }
    }
View Full Code Here

    for (CLdapServerConfiguration ldapServerConfig : ldapServers) {
      actualServerIds.add(ldapServerConfig.getId());
    }

    if (proposedOrder.size() != actualServerIds.size() || !proposedOrder.containsAll(actualServerIds)) {
      ValidationMessage msg = new ValidationMessage(
          "*",
          "Invalid order, the propsed order contains different elements then the actual order: propsed: " +
              proposedOrder + ", actual: " + actualServerIds);
      response.addValidationError(msg);
    }
View Full Code Here

        repositoryGroupId = property.getValue();
      }
    }

    if (StringUtils.isEmpty(repositoryTargetId)) {
      ValidationMessage message = new ValidationMessage("repositoryTargetId", "Privilege ID '"
          + privilege.getId() + "' requires a repositoryTargetId.", "Repository Target is required.");
      response.addValidationError(message);
    }

    if (!StringUtils.isEmpty(repositoryId) && !StringUtils.isEmpty(repositoryGroupId)) {
      ValidationMessage message = new ValidationMessage(
          "repositoryId",
          "Privilege ID '"
              + privilege.getId()
              + "' cannot be assigned to both a group and repository."
              + "  Either assign a group, a repository or neither (which assigns to ALL repositories).",
          "Cannot select both a Repository and Repository Group.");
      response.addValidationError(message);
    }

    if (StringUtils.isEmpty(method)) {
      response.addValidationError("Method cannot be empty on a privilege!");
    }
    else {
      String[] methods = null;

      if (method.contains(",")) {
        // it is a list of methods
        methods = method.split(",");
      }
      else {
        // it is a single method
        methods = new String[]{method};
      }

      boolean valid = true;

      for (String singlemethod : methods) {
        if (!"create".equals(singlemethod) && !"delete".equals(singlemethod)
            && !"read".equals(singlemethod) && !"update".equals(singlemethod)
            && !"*".equals(singlemethod)) {
          valid = false;

          break;
        }
      }

      if (!valid) {
        ValidationMessage message = new ValidationMessage(
            "method",
            "Privilege ID '" + privilege.getId()
                + "' Method is wrong! (Allowed methods are: create, delete, read and update)",
            "Invalid method selected.");
        response.addValidationError(message);
View Full Code Here

    try {
      // this will throw a NoSuchRoleMappingException, if there isn't one
      readUserRoleMapping(userRoleMapping.getUserId(), userRoleMapping.getSource());

      ValidationResponse vr = new ValidationResponse();
      vr.addValidationError(new ValidationMessage("*", "User Role Mapping for user '"
          + userRoleMapping.getUserId() + "' already exists."));

      throw new InvalidConfigurationException(vr);
    }
    catch (NoSuchRoleMappingException e) {
View Full Code Here

      context = initializeContext();
    }

    if (readUserRoleMapping(userRoleMapping.getUserId(), userRoleMapping.getSource()) == null) {
      ValidationResponse vr = new ValidationResponse();
      vr.addValidationError(new ValidationMessage("*", "No User Role Mapping found for user '"
          + userRoleMapping.getUserId() + "'."));

      throw new InvalidConfigurationException(vr);
    }

View Full Code Here

    if (!update
        && (StringUtils.isEmpty(privilege.getId()) || "0".equals(privilege.getId()) ||
        (existingIds.contains(privilege.getId())))) {
      String newId = idGenerator.generateId();

      ValidationMessage message =
          new ValidationMessage("id", "Fixed wrong privilege ID from '" + privilege.getId() + "' to '" + newId
              + "'");
      response.addValidationWarning(message);

      privilege.setId(newId);

      response.setModified(true);
    }

    if (StringUtils.isEmpty(privilege.getType())) {
      ValidationMessage message =
          new ValidationMessage("type", "Cannot have an empty type", "Privilege cannot have an invalid type");

      response.addValidationError(message);
    }

    if (StringUtils.isEmpty(privilege.getName())) {
      ValidationMessage message =
          new ValidationMessage("name", "Privilege ID '" + privilege.getId() + "' requires a name.",
              "Name is required.");
      response.addValidationError(message);
    }

    return response;
View Full Code Here

    }

    ApplicationValidationContext context = (ApplicationValidationContext) response.getContext();

    if (StringUtils.isEmpty(repo.getId())) {
      response.addValidationError(new ValidationMessage("id", "Repository ID's may not be empty!"));
    }
    else if (!repo.getId().matches(REPOSITORY_ID_PATTERN)) {
      response.addValidationError(
          new ValidationMessage("id",
              "Only letters, digits, underscores(_), hyphens(-), and dots(.) are allowed in Repository ID"));
    }
    // if repo id isn't valid, nothing below here will validate properly
    else {
      if (StringUtils.isEmpty(repo.getName())) {
        repo.setName(repo.getId());

        response.addValidationWarning(new ValidationMessage("id", "Repository with ID='" + repo.getId()
            + "' has no name, defaulted to it's ID."));

        response.setModified(true);
      }

      if (!validateLocalStatus(repo.getLocalStatus())) {
        response.addValidationError(
            new ValidationMessage("id", "LocalStatus of repository with ID='" + repo.getId()) + "' is wrong "
                + repo.getLocalStatus() + "! (Allowed values are: '" + LocalStatus.IN_SERVICE + "' and '"
                + LocalStatus.OUT_OF_SERVICE + "')");
      }
      if (context.getExistingRepositoryIds() != null) {
        if (context.getExistingRepositoryIds().contains(repo.getId())) {
          response.addValidationError(
              new ValidationMessage("id", "Repository with ID=" + repo.getId() + " already exists!"));
        }

        context.getExistingRepositoryIds().add(repo.getId());
      }

      if (context.getExistingRepositoryShadowIds() != null) {
        if (context.getExistingRepositoryShadowIds().contains(repo.getId())) {
          response.addValidationError(new ValidationMessage("id", "Repository " + repo.getId()
              + " conflicts with existing Shadow with same ID='" + repo.getId() + "'!"));
        }
      }

      if (context.getExistingRepositoryGroupIds() != null) {
        if (context.getExistingRepositoryGroupIds().contains(repo.getId())) {
          response.addValidationError(new ValidationMessage("id", "Repository " + repo.getId()
              + " conflicts with existing Group with same ID='" + repo.getId() + "'!"));
        }
      }
    }
View Full Code Here

    if (ctx != null) {
      response.setContext(ctx);
    }

    if (StringUtils.isEmpty(settings.getHostname())) {
      ValidationMessage msg = new ValidationMessage("host", "SMTP Host is empty.");
      response.addValidationError(msg);
    }

    if (settings.getPort() < 0) {
      ValidationMessage msg = new ValidationMessage(
          "port",
          "SMTP Port is inavlid.  Enter a port greater than 0.");
      response.addValidationError(msg);
    }

    if (StringUtils.isEmpty(settings.getSystemEmailAddress())) {
      ValidationMessage msg = new ValidationMessage("systemEmailAddress", "System Email Address is empty.");
      response.addValidationError(msg);
    }

    return response;
  }
View Full Code Here

          break;
        }
      }

      if (!valid) {
        ValidationMessage message =
            new ValidationMessage("method", "Privilege ID '" + privilege.getId()
                + "' Method is wrong! (Allowed methods are: create, delete, read and update)",
                "Invalid method selected.");
        response.addValidationError(message);
      }
    }
View Full Code Here

TOP

Related Classes of org.sonatype.configuration.validation.ValidationMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.