Class AccessToken

java.lang.Object
org.miaixz.bus.gitlab.support.AccessToken

public final class AccessToken extends Object
This class uses HTML scraping to create and revoke GitLab personal access tokens, the user's Feed token, and for fetching the current Health Check access token.

NOTE: This relies on HTML scraping and has been tested on GitLab-CE 11.0.0 to 11.10.1 for proper functionality. It may not work on earlier or later versions.

  • Constructor Details

    • AccessToken

      public AccessToken()
  • Method Details

    • createPersonalAccessToken

      public static String createPersonalAccessToken(String baseUrl, String username, String password, String tokenName, AccessToken.Scope[] scopes) throws GitLabApiException
      Create a GitLab personal access token with the provided configuration.
      Parameters:
      baseUrl - the GitLab server base URL
      username - the user name to create the personal access token for
      password - the password of the user to create the personal access token for
      tokenName - the name for the new personal access token
      scopes - an array of scopes for the new personal access token
      Returns:
      the created personal access token
      Throws:
      GitLabApiException - if any exception occurs
    • createPersonalAccessToken

      public static String createPersonalAccessToken(String baseUrl, String username, String password, String tokenName, List<AccessToken.Scope> scopes) throws GitLabApiException
      Create a GitLab personal access token with the provided configuration.
      Parameters:
      baseUrl - the GitLab server base URL
      username - the user name to create the personal access token for
      password - the password of the user to create the personal access token for
      tokenName - the name for the new personal access token
      scopes - a List of scopes for the new personal access token
      Returns:
      the created personal access token
      Throws:
      GitLabApiException - if any exception occurs
    • revokePersonalAccessToken

      public static void revokePersonalAccessToken(String baseUrl, String username, String password, String tokenName, AccessToken.Scope[] scopes) throws GitLabApiException
      Revoke the first matching GitLab personal access token.
      Parameters:
      baseUrl - the GitLab server base URL
      username - the user name to revoke the personal access token for
      password - the password of the user to revoke the personal access token for
      tokenName - the name of the personal access token to revoke
      scopes - an array of scopes of the personal access token to revoke
      Throws:
      GitLabApiException - if any exception occurs
    • revokePersonalAccessToken

      public static void revokePersonalAccessToken(String baseUrl, String username, String password, String tokenName, List<AccessToken.Scope> scopes) throws GitLabApiException
      Revoke the first matching GitLab personal access token.
      Parameters:
      baseUrl - the GitLab server base URL
      username - the user name to revoke the personal access token for
      password - the password of the user to revoke the personal access token for
      tokenName - the name of the personal access token to revoke
      scopes - a List of scopes of the personal access token to revoke
      Throws:
      GitLabApiException - if any exception occurs
    • getFeedToken

      public static String getFeedToken(String baseUrl, String username, String password) throws GitLabApiException
      Fetches the user's GitLab Feed token using HTML scraping.
      Parameters:
      baseUrl - the GitLab server base URL
      username - the user name the user to log in with
      password - the password of the provided username
      Returns:
      the fetched Feed token
      Throws:
      GitLabApiException - if any exception occurs
    • getHealthCheckAccessToken

      public static String getHealthCheckAccessToken(String baseUrl, String username, String password) throws GitLabApiException
      Fetches the GitLab health check access token using HTML scraping.
      Parameters:
      baseUrl - the GitLab server base URL
      username - the user name of an admin user to log in with
      password - the password of the provided username
      Returns:
      the fetched health check access token
      Throws:
      GitLabApiException - if any exception occurs
    • addFormData

      public static StringBuilder addFormData(StringBuilder formData, String name, String value) throws GitLabApiException
      Adds the specified form param to the form data StringBuilder. If the provided formData is null, will create the StringBuilder instance first.
      Parameters:
      formData - the StringBuilder instance holding the form data, if null will create the StringBuilder
      name - the form param name
      value - the form param value
      Returns:
      the form data StringBuilder
      Throws:
      GitLabApiException - if any error occurs.