use of org.mule.runtime.http.api.server.ServerNotFoundException in project mule by mulesoft.
the class DefaultExtensionsOAuthManager method createDancer.
private AuthorizationCodeOAuthDancer createDancer(OAuthConfig config) throws MuleException {
OAuthAuthorizationCodeDancerBuilder dancerBuilder = oauthService.get().authorizationCodeGrantTypeDancerBuilder(lockId -> lockFactory.createLock(lockId), new LazyObjectStoreToMapAdapter(getObjectStoreSupplier(config)), expressionEvaluator);
final AuthCodeConfig authCodeConfig = config.getAuthCodeConfig();
final AuthorizationCodeGrantType grantType = config.getGrantType();
final OAuthCallbackConfig callbackConfig = config.getCallbackConfig();
dancerBuilder.encoding(getDefaultEncoding(muleContext)).clientCredentials(authCodeConfig.getConsumerKey(), authCodeConfig.getConsumerSecret()).tokenUrl(authCodeConfig.getAccessTokenUrl()).responseExpiresInExpr(grantType.getExpirationRegex()).responseRefreshTokenExpr(grantType.getRefreshTokenExpr()).responseAccessTokenExpr(grantType.getAccessTokenExpr()).resourceOwnerIdTransformer(ownerId -> ownerId + "-" + config.getOwnerConfigName());
String scopes = authCodeConfig.getScope().orElseGet(() -> grantType.getDefaultScope().orElse(null));
if (scopes != null) {
dancerBuilder.scopes(scopes);
}
HttpServer httpServer;
try {
httpServer = httpService.get().getServerFactory().lookup(callbackConfig.getListenerConfig());
} catch (ServerNotFoundException e) {
throw new MuleRuntimeException(createStaticMessage(format("Connector '%s' defines '%s' as the http:listener-config to use for provisioning callbacks, but no such definition " + "exists in the application configuration", config.getOwnerConfigName(), callbackConfig.getListenerConfig())), e);
}
dancerBuilder.localCallback(httpServer, callbackConfig.getCallbackPath()).externalCallbackUrl(getExternalCallback(httpServer, callbackConfig)).authorizationUrl(authCodeConfig.getAuthorizationUrl()).localAuthorizationUrlPath(callbackConfig.getLocalAuthorizePath()).localAuthorizationUrlResourceOwnerId("#[attributes.queryParams.resourceOwnerId]").state("#[attributes.queryParams.state]").customParameters(config.getCustomParameters()).customParametersExtractorsExprs(getParameterExtractors(config));
Pair<Optional<Flow>, Optional<Flow>> listenerFlows = getListenerFlows(config);
listenerFlows.getFirst().ifPresent(flow -> dancerBuilder.beforeDanceCallback(beforeCallback(config, flow)));
listenerFlows.getSecond().ifPresent(flow -> dancerBuilder.afterDanceCallback(afterCallback(config, flow)));
AuthorizationCodeOAuthDancer dancer = dancerBuilder.build();
if (started) {
start(dancer);
}
return dancer;
}
Aggregations