public final class AccessTokenUtils
extends java.lang.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 | Class and Description |
---|---|
static class |
AccessTokenUtils.Scope
This enum defines the available scopes for a personal access token.
|
Modifier and Type | Field and Description |
---|---|
protected static java.util.regex.Pattern |
AUTHENTICITY_TOKEN_PATTERN |
protected static java.lang.String |
AUTHENTICITY_TOKEN_REGEX |
protected static java.lang.String |
COOKIES_HEADER |
protected static java.util.regex.Pattern |
FEED_TOKEN_PATTERN |
protected static java.lang.String |
FEED_TOKEN_REGEX |
protected static java.util.regex.Pattern |
HEALTH_CHECK_ACCESS_TOKEN_PATTERN |
protected static java.lang.String |
HEALTH_CHECK_ACCESS_TOKEN_REGEX |
protected static java.util.regex.Pattern |
NEW_USER_AUTHENTICITY_TOKEN_PATTERN |
protected static java.lang.String |
NEW_USER_AUTHENTICITY_TOKEN_REGEX |
protected static java.util.regex.Pattern |
PERSONAL_ACCESS_TOKEN_PATTERN |
protected static java.lang.String |
PERSONAL_ACCESS_TOKEN_REGEX |
protected static java.util.regex.Pattern |
REVOKE_PERSONAL_ACCESS_TOKEN_PATTERN |
protected static java.lang.String |
REVOKE_PERSONAL_ACCESS_TOKEN_REGEX |
protected static java.lang.String |
USER_AGENT |
Constructor and Description |
---|
AccessTokenUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.StringBuilder |
addFormData(java.lang.StringBuilder formData,
java.lang.String name,
java.lang.String value)
Adds the specified form param to the form data StringBuilder.
|
static java.lang.String |
createPersonalAccessToken(java.lang.String baseUrl,
java.lang.String username,
java.lang.String password,
java.lang.String tokenName,
AccessTokenUtils.Scope[] scopes)
Create a GitLab personal access token with the provided configuration.
|
static java.lang.String |
createPersonalAccessToken(java.lang.String baseUrl,
java.lang.String username,
java.lang.String password,
java.lang.String tokenName,
java.util.List<AccessTokenUtils.Scope> scopes)
Create a GitLab personal access token with the provided configuration.
|
protected static java.lang.String |
getContent(java.net.URLConnection connection)
Reads and returns the content from the provided URLConnection.
|
static java.lang.String |
getFeedToken(java.lang.String baseUrl,
java.lang.String username,
java.lang.String password)
Fetches the user's GitLab Feed token using HTML scraping.
|
static java.lang.String |
getHealthCheckAccessToken(java.lang.String baseUrl,
java.lang.String username,
java.lang.String password)
Fetches the GitLab health check access token using HTML scraping.
|
protected static java.lang.String |
login(java.lang.String baseUrl,
java.lang.String username,
java.lang.String password)
Gets a GitLab session cookie by logging in the specified user.
|
protected static void |
logout(java.lang.String baseUrl,
java.lang.String cookies)
Logs out the user associated with the GitLab session cookie.
|
static void |
revokePersonalAccessToken(java.lang.String baseUrl,
java.lang.String username,
java.lang.String password,
java.lang.String tokenName,
AccessTokenUtils.Scope[] scopes)
Revoke the first matching GitLab personal access token.
|
static void |
revokePersonalAccessToken(java.lang.String baseUrl,
java.lang.String username,
java.lang.String password,
java.lang.String tokenName,
java.util.List<AccessTokenUtils.Scope> scopes)
Revoke the first matching GitLab personal access token.
|
protected static final java.lang.String USER_AGENT
protected static final java.lang.String COOKIES_HEADER
protected static final java.lang.String NEW_USER_AUTHENTICITY_TOKEN_REGEX
protected static final java.util.regex.Pattern NEW_USER_AUTHENTICITY_TOKEN_PATTERN
protected static final java.lang.String AUTHENTICITY_TOKEN_REGEX
protected static final java.util.regex.Pattern AUTHENTICITY_TOKEN_PATTERN
protected static final java.lang.String PERSONAL_ACCESS_TOKEN_REGEX
protected static final java.util.regex.Pattern PERSONAL_ACCESS_TOKEN_PATTERN
protected static final java.lang.String REVOKE_PERSONAL_ACCESS_TOKEN_REGEX
protected static final java.util.regex.Pattern REVOKE_PERSONAL_ACCESS_TOKEN_PATTERN
protected static final java.lang.String FEED_TOKEN_REGEX
protected static final java.util.regex.Pattern FEED_TOKEN_PATTERN
protected static final java.lang.String HEALTH_CHECK_ACCESS_TOKEN_REGEX
protected static final java.util.regex.Pattern HEALTH_CHECK_ACCESS_TOKEN_PATTERN
public static final java.lang.String createPersonalAccessToken(java.lang.String baseUrl, java.lang.String username, java.lang.String password, java.lang.String tokenName, AccessTokenUtils.Scope[] 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
- an array of scopes for the new personal access tokenGitLabApiException
- if any exception occurspublic static final java.lang.String createPersonalAccessToken(java.lang.String baseUrl, java.lang.String username, java.lang.String password, java.lang.String tokenName, java.util.List<AccessTokenUtils.Scope> 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(java.lang.String baseUrl, java.lang.String username, java.lang.String password, java.lang.String tokenName, AccessTokenUtils.Scope[] 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
- an array of scopes of the personal access token to revokeGitLabApiException
- if any exception occurspublic static final void revokePersonalAccessToken(java.lang.String baseUrl, java.lang.String username, java.lang.String password, java.lang.String tokenName, java.util.List<AccessTokenUtils.Scope> 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 java.lang.String getFeedToken(java.lang.String baseUrl, java.lang.String username, java.lang.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 java.lang.String getHealthCheckAccessToken(java.lang.String baseUrl, java.lang.String username, java.lang.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 java.lang.String login(java.lang.String baseUrl, java.lang.String username, java.lang.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(java.lang.String baseUrl, java.lang.String cookies) throws GitLabApiException
baseUrl
- the GitLab server base URLcookies
- the GitLab session cookie to logoutGitLabApiException
- if any error occurspublic static final java.lang.StringBuilder addFormData(java.lang.StringBuilder formData, java.lang.String name, java.lang.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 java.lang.String getContent(java.net.URLConnection connection) throws GitLabApiException
connection
- the URLConnection to read the content fromGitLabApiException
- if any error occurs