public final class AccessTokenUtils extends Object
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.
| Modifier and Type | Field and Description |
|---|---|
protected static Pattern |
AUTHENTICITY_TOKEN_PATTERN |
protected static String |
AUTHENTICITY_TOKEN_REGEX |
protected static String |
COOKIES_HEADER |
protected static Pattern |
FEED_TOKEN_PATTERN |
protected static String |
FEED_TOKEN_REGEX |
protected static Pattern |
HEALTH_CHECK_ACCESS_TOKEN_PATTERN |
protected static String |
HEALTH_CHECK_ACCESS_TOKEN_REGEX |
protected static Pattern |
NEW_USER_AUTHENTICITY_TOKEN_PATTERN |
protected static String |
NEW_USER_AUTHENTICITY_TOKEN_REGEX |
protected static Pattern |
PERSONAL_ACCESS_TOKEN_PATTERN |
protected static String |
PERSONAL_ACCESS_TOKEN_REGEX |
protected static Pattern |
REVOKE_PERSONAL_ACCESS_TOKEN_PATTERN |
protected static String |
REVOKE_PERSONAL_ACCESS_TOKEN_REGEX |
protected static String |
USER_AGENT |
| Constructor and Description |
|---|
AccessTokenUtils() |
| Modifier and Type | Method and Description |
|---|---|
static StringBuilder |
addFormData(StringBuilder formData,
String name,
String value)
Adds the specified form param to the form data StringBuilder.
|
static String |
createPersonalAccessToken(String baseUrl,
String username,
String password,
String tokenName,
List<String> scopes)
Create a GitLab personal access token with the provided configuration.
|
protected static String |
getContent(URLConnection connection)
Reads and returns the content from the provided URLConnection.
|
static String |
getFeedToken(String baseUrl,
String username,
String password)
Fetches the user's GitLab Feed token using HTML scraping.
|
static String |
getHealthCheckAccessToken(String baseUrl,
String username,
String password)
Fetches the GitLab health check access token using HTML scraping.
|
protected static String |
login(String baseUrl,
String username,
String password)
Gets a GitLab session cookie by logging in the specified user.
|
protected static void |
logout(String baseUrl,
String cookies)
Logs out the user associated with the GitLab session cookie.
|
static void |
revokePersonalAccessToken(String baseUrl,
String username,
String password,
String tokenName,
List<String> scopes)
Revoke the first matching GitLab personal access token.
|
protected static final String USER_AGENT
protected static final String COOKIES_HEADER
protected static final String NEW_USER_AUTHENTICITY_TOKEN_REGEX
protected static final Pattern NEW_USER_AUTHENTICITY_TOKEN_PATTERN
protected static final String AUTHENTICITY_TOKEN_REGEX
protected static final Pattern AUTHENTICITY_TOKEN_PATTERN
protected static final String PERSONAL_ACCESS_TOKEN_REGEX
protected static final Pattern PERSONAL_ACCESS_TOKEN_PATTERN
protected static final String REVOKE_PERSONAL_ACCESS_TOKEN_REGEX
protected static final Pattern REVOKE_PERSONAL_ACCESS_TOKEN_PATTERN
protected static final String FEED_TOKEN_REGEX
protected static final Pattern FEED_TOKEN_PATTERN
protected static final String HEALTH_CHECK_ACCESS_TOKEN_REGEX
protected static final Pattern HEALTH_CHECK_ACCESS_TOKEN_PATTERN
public static final String createPersonalAccessToken(String baseUrl, String username, String password, String tokenName, List<String> scopes) throws GitLabApiException
baseUrl - the GitLab server base URLusername - the user name to create the personal access token forpassword - the password of the user to create the personal access token fortokenName - the name for the new personal access tokenscopes - a List of scopes for the new personal access tokenGitLabApiException - if any exception occurspublic static final void revokePersonalAccessToken(String baseUrl, String username, String password, String tokenName, List<String> scopes) throws GitLabApiException
baseUrl - the GitLab server base URLusername - the user name to revoke the personal access token forpassword - the password of the user to revoke the personal access token fortokenName - the name of the personal access token to revokescopes - a List of scopes of the personal access token to revokeGitLabApiException - if any exception occurspublic static final String getFeedToken(String baseUrl, String username, String password) throws GitLabApiException
baseUrl - the GitLab server base URLusername - the user name the user to log in withpassword - the password of the provided usernameGitLabApiException - if any exception occurspublic static final String getHealthCheckAccessToken(String baseUrl, String username, String password) throws GitLabApiException
baseUrl - the GitLab server base URLusername - the user name of an admin user to log in withpassword - the password of the provided usernameGitLabApiException - if any exception occursprotected static final String login(String baseUrl, String username, String password) throws GitLabApiException
baseUrl - the GitLab server base URLusername - the user name to to login forpassword - the password of the user to login forGitLabApiException - if any error occursprotected static final void logout(String baseUrl, String cookies) throws GitLabApiException
baseUrl - the GitLab server base URLcookies - the GitLab session cookie to logoutGitLabApiException - if any error occurspublic static final StringBuilder addFormData(StringBuilder formData, String name, String value) throws GitLabApiException
formData - the StringBuilder instance holding the form data, if null will create the StringBuildername - the form param namevalue - the form param valueGitLabApiException - if any error occurs.protected static String getContent(URLConnection connection) throws GitLabApiException
connection - the URLConnection to read the content fromGitLabApiException - if any error occursCopyright © 2019. All rights reserved.