Class UniqueRedirectService
- java.lang.Object
-
- jetbrains.buildServer.serverSide.oauth.UniqueRedirectService
-
public class UniqueRedirectService extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
UniqueRedirectService.RedirectIdCheckResult
-
Constructor Summary
Constructors Constructor Description UniqueRedirectService(ProjectManager projectManager, OAuthConnectionsManager connectionsManager, UniqueRedirectGenerator uniqueRedirectGenerator, OAuthRedirectSettingsStorage redirectSettingsStorage, WebLinks webLinks)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String
buildControllerPath(String providerType)
This will build a path with single placeholder that can be used to register controllers.static String
buildControllerPathWithId(String providerType, String redirectId)
This will build a concrete path including the redirect ID.String
buildRedirectPathForConnection(OAuthConnectionDescriptor connection)
Builds the unique redirect path for the given connection if the connection supports unique redirects.String
buildRedirectUrlForConnection(OAuthConnectionDescriptor connection)
Builds the redirect URL for the given OAuth connection.UniqueRedirectService.RedirectIdCheckResult
checkRedirectId(String path, String projectId, String connectionId)
protected String
extractRedirectIdFromPath(String requestPath)
Tries to extract the redirect id from the given request path.String
generateUniqueId()
Generates a unique redirect ID.String
getOrCreateRedirectIdForConnection(OAuthConnectionDescriptor connection)
Returns the stored redirect ID for the given OAuth connection.boolean
isFeatureEnabled(SProject project)
Checks if the unique redirect URL feature is enabled for the given project.boolean
isMatchingUniqueRedirectPath(String requestUrl, OAuthProvider provider)
Checks whether the given request URL matches the unique redirect path supported by the given provider.
-
-
-
Constructor Detail
-
UniqueRedirectService
public UniqueRedirectService(@NotNull ProjectManager projectManager, @NotNull OAuthConnectionsManager connectionsManager, @NotNull UniqueRedirectGenerator uniqueRedirectGenerator, @NotNull OAuthRedirectSettingsStorage redirectSettingsStorage, @NotNull WebLinks webLinks)
-
-
Method Detail
-
checkRedirectId
@NotNull public UniqueRedirectService.RedirectIdCheckResult checkRedirectId(@NotNull String path, @Nullable String projectId, @Nullable String connectionId)
-
buildControllerPath
@NotNull public static String buildControllerPath(@NotNull String providerType)
This will build a path with single placeholder that can be used to register controllers. The path will be structured like this:/oauth/{providerType}/{placeholder}/accessToken.html
- Parameters:
providerType
- the provider type, e.g. 'bitbucket'- Returns:
- the constructed path
- Since:
- 2024.03
-
buildControllerPathWithId
@NotNull public static String buildControllerPathWithId(@NotNull String providerType, @NotNull String redirectId)
This will build a concrete path including the redirect ID. The path will be structured like this:/oauth/{providerType}/{redirectId}/accessToken.html
- Parameters:
providerType
- the provider type, e.g. 'bitbucket'redirectId
- the redirect ID- Returns:
- the constructed path
- Since:
- 2024.03
-
buildRedirectPathForConnection
@Nullable public String buildRedirectPathForConnection(@NotNull OAuthConnectionDescriptor connection)
Builds the unique redirect path for the given connection if the connection supports unique redirects. The connection's redirect ID from data storage will be used to build the path.- Parameters:
connection
- the connection- Returns:
- unique redirect path, or null if not supported
- Since:
- 2024.03
- See Also:
buildControllerPathWithId(String, String)
-
buildRedirectUrlForConnection
@Nullable public String buildRedirectUrlForConnection(@NotNull OAuthConnectionDescriptor connection)
Builds the redirect URL for the given OAuth connection. A complete URL, including this application's root URL, will be built. This method only works for connections / OAuth provider implementations that support unique redirect URLs.- Parameters:
connection
- the OAuth connection for which the redirect URL is built- Returns:
- redirect URL, or null if not supported
- Since:
- 2024.07
-
extractRedirectIdFromPath
@Contract("null -> null") @Nullable protected String extractRedirectIdFromPath(@Nullable String requestPath)
Tries to extract the redirect id from the given request path.- Parameters:
requestPath
- the request path to extract the redirect id from, e.g. '/oauth/bitbucket/rid:123ca334f/accessToken.html'- Returns:
- the extracted redirect id, or null if the redirect id is not found or the input is null
- Since:
- 2024.03
-
generateUniqueId
@NotNull public String generateUniqueId()
Generates a unique redirect ID.- Returns:
- a unique ID string
- Since:
- 2024.03
-
isFeatureEnabled
public boolean isFeatureEnabled(@NotNull SProject project)
Checks if the unique redirect URL feature is enabled for the given project.- Parameters:
project
- the project to check the feature for- Returns:
- true if the feature is enabled, false otherwise
- Since:
- 2024.03
-
getOrCreateRedirectIdForConnection
@NotNull public String getOrCreateRedirectIdForConnection(@NotNull OAuthConnectionDescriptor connection)
Returns the stored redirect ID for the given OAuth connection. If no redirect ID has been stored yet, a new one will be generated and persisted.- Parameters:
connection
- the OAuth connection- Returns:
- the redirect ID
- Since:
- 2024.07
- See Also:
OAuthRedirectSettingsStorage#getOrCreateRedirectIdForConnection(OAuthConnectionDescriptor)
-
isMatchingUniqueRedirectPath
public boolean isMatchingUniqueRedirectPath(@NotNull String requestUrl, @NotNull OAuthProvider provider)
Checks whether the given request URL matches the unique redirect path supported by the given provider. This method does not check individual redirect IDs but rather just checks that the pattern matches.- Parameters:
requestUrl
- the complete request URLprovider
- the OAuth provider to check against- Returns:
- true if the request matches
- Since:
- 2024.07
-
-