All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.db.user.UserTokenValidator Maven / Gradle / Ivy

/*
 * SonarQube
 * Copyright (C) 2009-2016 SonarSource SA
 * mailto:contact AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.db.user;

import static com.google.common.base.Preconditions.checkArgument;

public class UserTokenValidator {
  private static final int MAX_TOKEN_NAME_LENGTH = 100;
  private static final int MAX_TOKEN_HASH_LENGTH = 255;

  private UserTokenValidator() {
    // utility methods
  }

  public static String checkTokenName(String name) {
    checkArgument(name.length() <= MAX_TOKEN_NAME_LENGTH, "Token name length (%s) is longer than the maximum authorized (%s)", name.length(), MAX_TOKEN_NAME_LENGTH);
    return name;
  }

  static String checkTokenHash(String hash) {
    checkArgument(hash.length() <= MAX_TOKEN_HASH_LENGTH, "Token hash length (%s) is longer than the maximum authorized (%s)", hash.length(), MAX_TOKEN_HASH_LENGTH);
    return hash;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy