Class OAuthProvider
- java.lang.Object
-
- jetbrains.buildServer.serverSide.oauth.OAuthProvider
-
- All Implemented Interfaces:
ConnectionProvider
,ServerExtension
,TeamCityExtension
- Direct Known Subclasses:
AzureDevOpsOAuthProvider
,BitBucketOAuthProvider
,GitHubOAuthProviderBase
,GitLabComOAuthProvider
,GoogleOAuthProvider
,SpaceOAuthProvider
,TfsAuthProvider
public abstract class OAuthProvider extends Object implements ConnectionProvider
Represents OAuth provider service
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
OAuthProvider.CapabilityResolver
-
Field Summary
Fields Modifier and Type Field Description static String
COMPOUND_STORAGE_ID_PREFIX
protected Map<ConnectionCapability,OAuthProvider.CapabilityResolver>
myCapabilityResolvers
protected static OAuthProvider.CapabilityResolver
NOPE
-
Constructor Summary
Constructors Constructor Description OAuthProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OAuthToken
applyAccessibleEntities(SUser user, OAuthConnectionDescriptor connection, OAuthToken token, List<String> accessibleEntities)
Apply the requested accessible entities restriction to the token.protected String
buildCompoundTokenStorageId(String prefix, String suffix)
boolean
connectionHasCapability(OAuthConnectionDescriptor connectionDescriptor, ConnectionCapability capability)
boolean
connectionIsHidden(OAuthConnectionDescriptor connection)
String
describeConnection(OAuthConnectionDescriptor connection)
String
describeConnectionForUI(OAuthConnectionDescriptor connection)
Will be combined with getAdditionalUIConnectionDescription return valueString
getAccessibleEntitiesEndpoint()
Get the relative endpoint URL to the provider-specific REST service to manage accessible entities.String
getAdditionalUIConnectionDescription(OAuthConnectionDescriptor connection)
Will not be escaped, and so should not include any unvalidated user inputString
getCapabilitiesUrl()
Get the URL to rendering the dynamic description of a connection's capabilities.protected OAuthProvider.CapabilityResolver
getCapabilityResolver(ConnectionCapability capability)
Map<String,String>
getDefaultProperties()
String
getEditParametersUrl()
String
getFallbackRedirectPath()
Returns the path to be included in redirect URLs.PropertiesProcessor
getPropertiesProcessor()
String
getProviderTypeForUniqueRedirect()
Returns the provider type to be included in unique redirect URLs.String
getScope(OAuthConnectionDescriptor connectionDescriptor, String defaultScope)
String
getScopeForIntent(OAuthConnectionDescriptor connection, TokenIntent intent)
Returns the provider-specific OAuth scope to request for the given token intent.Set<TokenIntentType>
getSupportedTokenIntentTypes()
Gets the token intent types this provider fully supports.String
getTokenPopupPath()
String
getTokenStorageId(OAuthConnectionDescriptor connection)
Returns an id of the token storage used by connection.Set<String>
getTokenStorageParameters()
Returns the parameters used when constructing the token storage ID for connections of this provider type.Map<String,String>
getTokenUsageParamsForVcsRoot(OAuthConnectionDescriptor connection, OAuthToken token)
Returns the necessary parameters for usage of the provided token for authentication in aSVcsRoot
.boolean
isAccessibleEntitiesSupported()
Whether this provider supports the "accessible entities" field of theOAuthToken
record.boolean
isAcquiringTokenSupported()
Whether acquiring tokens is supported for this provider.boolean
isAcquiringTokenSupportedForConnection(OAuthConnectionDescriptor connection)
Whether acquiring tokens is supported using this connection in particular.boolean
isAvailable()
boolean
isCapabilitiesEnabledForProject(SProject project)
Whether capabilities (if supported) are enabled in the scope of the given project.boolean
isCapabilitiesSupported()
Whether this provider supports resolving ofConnectionCapability
for individual connections.boolean
isSuitableToken(OAuthToken token, TokenIntent intent)
boolean
isTokenRefreshSupported()
boolean
isUniqueRedirectsSupported()
Whether this provider supports the creation of unique redirect URLs.OAuthToken
refreshToken(OAuthConnectionDescriptor connection, OAuthToken token)
protected void
registerCapabilityResolver(ConnectionCapability capability, OAuthProvider.CapabilityResolver resolver)
TestConnectionResult
testConnection(String projectId, Map<String,String> parameters)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jetbrains.buildServer.serverSide.connections.ConnectionProvider
describeConnection, getDisplayName, getDisplayOrderRank, getType, getTypeForUrl
-
-
-
-
Field Detail
-
COMPOUND_STORAGE_ID_PREFIX
public static final String COMPOUND_STORAGE_ID_PREFIX
- See Also:
- Constant Field Values
-
NOPE
protected static final OAuthProvider.CapabilityResolver NOPE
-
myCapabilityResolvers
protected final Map<ConnectionCapability,OAuthProvider.CapabilityResolver> myCapabilityResolvers
-
-
Method Detail
-
describeConnection
@NotNull public String describeConnection(@NotNull OAuthConnectionDescriptor connection)
- Returns:
- human friendly description of OAuth connection
-
describeConnectionForUI
@NotNull public String describeConnectionForUI(@NotNull OAuthConnectionDescriptor connection)
Will be combined with getAdditionalUIConnectionDescription return value- Parameters:
connection
-- Returns:
- Description of OAuth connection for ui
-
getAdditionalUIConnectionDescription
@NotNull public String getAdditionalUIConnectionDescription(@NotNull OAuthConnectionDescriptor connection)
Will not be escaped, and so should not include any unvalidated user input- Parameters:
connection
-- Returns:
- Additional description for ui
-
getTokenStorageId
@NotNull public String getTokenStorageId(@NotNull OAuthConnectionDescriptor connection)
Returns an id of the token storage used by connection. Depending on the connection type multiple connections can use the same token storage. In case of OAuth2 apps, this id may be based on the client/application id of the OAuth2 app configured in a third party system.- Parameters:
connection
- descriptor- Returns:
- token storage id
-
buildCompoundTokenStorageId
@NotNull protected String buildCompoundTokenStorageId(@NotNull String prefix, @NotNull String suffix)
-
getPropertiesProcessor
@Nullable public PropertiesProcessor getPropertiesProcessor()
- Specified by:
getPropertiesProcessor
in interfaceConnectionProvider
- Returns:
- processor for connection provider parameters. Properties processor performs validation function and is called when connection is edited or created.
-
getDefaultProperties
@Nullable public Map<String,String> getDefaultProperties()
- Specified by:
getDefaultProperties
in interfaceConnectionProvider
- Returns:
- all default parameters related to this ConnectionProvider. Defaults for all possible parameter names.
-
getEditParametersUrl
@Nullable public String getEditParametersUrl()
- Specified by:
getEditParametersUrl
in interfaceConnectionProvider
- Returns:
- URL to edit connection parameters page
-
isTokenRefreshSupported
public boolean isTokenRefreshSupported()
-
refreshToken
@NotNull public OAuthToken refreshToken(@NotNull OAuthConnectionDescriptor connection, @NotNull OAuthToken token)
-
getScope
@Nullable public String getScope(@NotNull OAuthConnectionDescriptor connectionDescriptor, @Nullable String defaultScope)
-
isAvailable
public boolean isAvailable()
- Specified by:
isAvailable
in interfaceConnectionProvider
-
getTokenPopupPath
public String getTokenPopupPath()
-
isAcquiringTokenSupported
public boolean isAcquiringTokenSupported()
Whether acquiring tokens is supported for this provider. See also: JSP Tag oauth:obtainToken- Returns:
- true, if supported
- Since:
- 2023.05
-
isAcquiringTokenSupportedForConnection
public boolean isAcquiringTokenSupportedForConnection(@NotNull OAuthConnectionDescriptor connection)
Whether acquiring tokens is supported using this connection in particular. Defaults toisAcquiringTokenSupported()
. See also: JSP Tag oauth:obtainToken- Parameters:
connection
- the connection in question- Returns:
- true, if supported
- Since:
- 2023.09
-
isSuitableToken
public boolean isSuitableToken(@NotNull OAuthToken token, @NotNull TokenIntent intent)
-
getScopeForIntent
@Nullable public String getScopeForIntent(@NotNull OAuthConnectionDescriptor connection, @NotNull TokenIntent intent)
Returns the provider-specific OAuth scope to request for the given token intent.- Parameters:
connection
- the connection to be used for issuing the tokenintent
- the intended token usage- Returns:
- specific OAuth scope, if any
- Since:
- 2024.03
-
isCapabilitiesSupported
public boolean isCapabilitiesSupported()
Whether this provider supports resolving ofConnectionCapability
for individual connections.- Returns:
- true if supported
- Since:
- 2023.07
-
isCapabilitiesEnabledForProject
public boolean isCapabilitiesEnabledForProject(@NotNull SProject project)
Whether capabilities (if supported) are enabled in the scope of the given project.- Parameters:
project
- project scope- Returns:
- true if enabled
- Since:
- 2023.07
-
getCapabilitiesUrl
@Nullable public String getCapabilitiesUrl()
Get the URL to rendering the dynamic description of a connection's capabilities. Can only be used if capabilities are supported by this provider.- Returns:
- relative URL or null if not supported
- Since:
- 2023.07
-
connectionHasCapability
public boolean connectionHasCapability(@NotNull OAuthConnectionDescriptor connectionDescriptor, @NotNull ConnectionCapability capability)
-
registerCapabilityResolver
protected void registerCapabilityResolver(@NotNull ConnectionCapability capability, @NotNull OAuthProvider.CapabilityResolver resolver)
-
getCapabilityResolver
@NotNull protected OAuthProvider.CapabilityResolver getCapabilityResolver(@NotNull ConnectionCapability capability)
-
connectionIsHidden
public boolean connectionIsHidden(@NotNull OAuthConnectionDescriptor connection)
-
testConnection
public TestConnectionResult testConnection(@NotNull String projectId, @NotNull Map<String,String> parameters)
-
isAccessibleEntitiesSupported
public boolean isAccessibleEntitiesSupported()
Whether this provider supports the "accessible entities" field of theOAuthToken
record.- Returns:
- false, by default
- Since:
- 2024.03
-
applyAccessibleEntities
@NotNull public OAuthToken applyAccessibleEntities(@NotNull SUser user, @NotNull OAuthConnectionDescriptor connection, @NotNull OAuthToken token, @NotNull List<String> accessibleEntities)
Apply the requested accessible entities restriction to the token. Unless this provider supports accessible entities, this is a no-op. SeeisAccessibleEntitiesSupported()
- Parameters:
user
- the current userconnection
- the connection used to issue the tokentoken
- the issued OAuth tokenaccessibleEntities
- the requested accessible entity restrictions- Returns:
- the potentially altered token
- Since:
- 2024.03
-
isUniqueRedirectsSupported
public boolean isUniqueRedirectsSupported()
Whether this provider supports the creation of unique redirect URLs. Providers wanting to support this feature should return true here and ensure that the respective access token controllers are registered viaBaseAccessTokenController.registerController(WebControllerManager, String)
. Also, the two related methodsgetProviderTypeForUniqueRedirect()
andgetFallbackRedirectPath()
must be implemented.- Returns:
- false, by default
- Since:
- 2024.03
-
getProviderTypeForUniqueRedirect
@NotNull public String getProviderTypeForUniqueRedirect()
Returns the provider type to be included in unique redirect URLs.- Returns:
- URL-compatible provider type
- Since:
- 2024.03
- See Also:
isUniqueRedirectsSupported()
-
getFallbackRedirectPath
@Nullable public String getFallbackRedirectPath()
Returns the path to be included in redirect URLs. Normally this should be the access token controller path. This will be used as a fallback if this provider does not support unique redirect URLs. This will be used as a fallback if a connection does not have a redirect ID parameter.- Returns:
- a controller path starting with a slash
- Since:
- 2024.03
- See Also:
isUniqueRedirectsSupported()
-
getAccessibleEntitiesEndpoint
@Nullable public String getAccessibleEntitiesEndpoint()
Get the relative endpoint URL to the provider-specific REST service to manage accessible entities. Such a service is only available if this provider supports accessible entities. SeeisAccessibleEntitiesSupported()
- Returns:
- a relative endpoint URL
- Since:
- 2024.03
-
getSupportedTokenIntentTypes
@NotNull public Set<TokenIntentType> getSupportedTokenIntentTypes()
Gets the token intent types this provider fully supports. Full support means that the methodsgetScopeForIntent(OAuthConnectionDescriptor, TokenIntent)
andisSuitableToken(OAuthToken, TokenIntent)
are implemented with sufficient logic to cater for the claimed token intent types.- Returns:
- set of supported token intent types
- Since:
- 2024.03
-
getTokenUsageParamsForVcsRoot
@NotNull public Map<String,String> getTokenUsageParamsForVcsRoot(@NotNull OAuthConnectionDescriptor connection, @NotNull OAuthToken token)
Returns the necessary parameters for usage of the provided token for authentication in aSVcsRoot
. By default, this provides the following values:- oauthUsername
OauthToken#getOauthLogin
- tokenType
- refreshable (if refreshable tokens are enabled)
- Parameters:
connection
- the token's connectiontoken
- the token to be potentially used on a VCS root- Returns:
- mutable map of parameters
- Since:
- 2024.07
-
getTokenStorageParameters
@NotNull public Set<String> getTokenStorageParameters()
Returns the parameters used when constructing the token storage ID for connections of this provider type. Implementors must make sure this corresponds with the implementation ofgetTokenStorageId(OAuthConnectionDescriptor)
.- Returns:
- set of parameter names
- Since:
- 2024.12
- See Also:
getTokenStorageId(OAuthConnectionDescriptor)
-
-