Search in sources :

Example 1 with IntrospectionClient

use of org.wso2.keycloak.client.model.IntrospectionClient in project carbon-apimgt by wso2.

the class AMDefaultKeyManagerImpl method loadConfiguration.

@Override
public void loadConfiguration(KeyManagerConfiguration configuration) throws APIManagementException {
    this.configuration = configuration;
    String username = (String) configuration.getParameter(APIConstants.KEY_MANAGER_USERNAME);
    String password = (String) configuration.getParameter(APIConstants.KEY_MANAGER_PASSWORD);
    String keyManagerServiceUrl = (String) configuration.getParameter(APIConstants.AUTHSERVER_URL);
    String dcrEndpoint;
    if (configuration.getParameter(APIConstants.KeyManager.CLIENT_REGISTRATION_ENDPOINT) != null) {
        dcrEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.CLIENT_REGISTRATION_ENDPOINT);
    } else {
        dcrEndpoint = keyManagerServiceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0].concat(getTenantAwareContext().trim()).concat(APIConstants.KeyManager.KEY_MANAGER_OPERATIONS_DCR_ENDPOINT);
    }
    String tokenEndpoint;
    if (configuration.getParameter(APIConstants.KeyManager.TOKEN_ENDPOINT) != null) {
        tokenEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.TOKEN_ENDPOINT);
    } else {
        tokenEndpoint = keyManagerServiceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0].concat("/oauth2/token");
    }
    addKeyManagerConfigsAsSystemProperties(tokenEndpoint);
    String revokeEndpoint;
    if (configuration.getParameter(APIConstants.KeyManager.REVOKE_ENDPOINT) != null) {
        revokeEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.REVOKE_ENDPOINT);
    } else {
        revokeEndpoint = keyManagerServiceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0].concat("/oauth2/revoke");
    }
    String scopeEndpoint;
    if (configuration.getParameter(APIConstants.KeyManager.SCOPE_MANAGEMENT_ENDPOINT) != null) {
        scopeEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.SCOPE_MANAGEMENT_ENDPOINT);
    } else {
        scopeEndpoint = keyManagerServiceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0].concat(getTenantAwareContext().trim()).concat(APIConstants.KEY_MANAGER_OAUTH2_SCOPES_REST_API_BASE_PATH);
    }
    String introspectionEndpoint;
    if (configuration.getParameter(APIConstants.KeyManager.INTROSPECTION_ENDPOINT) != null) {
        introspectionEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.INTROSPECTION_ENDPOINT);
    } else {
        introspectionEndpoint = keyManagerServiceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0].concat(getTenantAwareContext().trim()).concat("/oauth2/introspect");
    }
    String userInfoEndpoint;
    if (configuration.getParameter(APIConstants.KeyManager.USERINFO_ENDPOINT) != null) {
        userInfoEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.USERINFO_ENDPOINT);
    } else {
        userInfoEndpoint = keyManagerServiceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0].concat(getTenantAwareContext().trim()).concat(APIConstants.KeyManager.KEY_MANAGER_OPERATIONS_USERINFO_ENDPOINT);
    }
    dcrClient = Feign.builder().client(new ApacheFeignHttpClient(APIUtil.getHttpClient(dcrEndpoint))).encoder(new GsonEncoder()).decoder(new GsonDecoder()).logger(new Slf4jLogger()).requestInterceptor(new BasicAuthRequestInterceptor(username, password)).requestInterceptor(new TenantHeaderInterceptor(tenantDomain)).errorDecoder(new KMClientErrorDecoder()).target(DCRClient.class, dcrEndpoint);
    authClient = Feign.builder().client(new ApacheFeignHttpClient(APIUtil.getHttpClient(tokenEndpoint))).encoder(new GsonEncoder()).decoder(new GsonDecoder()).logger(new Slf4jLogger()).errorDecoder(new KMClientErrorDecoder()).encoder(new FormEncoder()).target(AuthClient.class, tokenEndpoint);
    introspectionClient = Feign.builder().client(new ApacheFeignHttpClient(APIUtil.getHttpClient(introspectionEndpoint))).encoder(new GsonEncoder()).decoder(new GsonDecoder()).logger(new Slf4jLogger()).requestInterceptor(new BasicAuthRequestInterceptor(username, password)).requestInterceptor(new TenantHeaderInterceptor(tenantDomain)).errorDecoder(new KMClientErrorDecoder()).encoder(new FormEncoder()).target(IntrospectionClient.class, introspectionEndpoint);
    scopeClient = Feign.builder().client(new ApacheFeignHttpClient(APIUtil.getHttpClient(scopeEndpoint))).encoder(new GsonEncoder()).decoder(new GsonDecoder()).logger(new Slf4jLogger()).requestInterceptor(new BasicAuthRequestInterceptor(username, password)).requestInterceptor(new TenantHeaderInterceptor(tenantDomain)).errorDecoder(new KMClientErrorDecoder()).target(ScopeClient.class, scopeEndpoint);
    userClient = Feign.builder().client(new ApacheFeignHttpClient(APIUtil.getHttpClient(userInfoEndpoint))).encoder(new GsonEncoder()).decoder(new GsonDecoder()).logger(new Slf4jLogger()).requestInterceptor(new BasicAuthRequestInterceptor(username, password)).requestInterceptor(new TenantHeaderInterceptor(tenantDomain)).errorDecoder(new KMClientErrorDecoder()).target(UserClient.class, userInfoEndpoint);
}
Also used : UserClient(org.wso2.carbon.apimgt.impl.kmclient.model.UserClient) BasicAuthRequestInterceptor(feign.auth.BasicAuthRequestInterceptor) Slf4jLogger(feign.slf4j.Slf4jLogger) AuthClient(org.wso2.carbon.apimgt.impl.kmclient.model.AuthClient) TenantHeaderInterceptor(org.wso2.carbon.apimgt.impl.kmclient.model.TenantHeaderInterceptor) DCRClient(org.wso2.carbon.apimgt.impl.kmclient.model.DCRClient) KMClientErrorDecoder(org.wso2.carbon.apimgt.impl.kmclient.KMClientErrorDecoder) GsonEncoder(feign.gson.GsonEncoder) ScopeClient(org.wso2.carbon.apimgt.impl.kmclient.model.ScopeClient) IntrospectionClient(org.wso2.carbon.apimgt.impl.kmclient.model.IntrospectionClient) GsonDecoder(feign.gson.GsonDecoder) ApacheFeignHttpClient(org.wso2.carbon.apimgt.impl.kmclient.ApacheFeignHttpClient) FormEncoder(org.wso2.carbon.apimgt.impl.kmclient.FormEncoder)

Example 2 with IntrospectionClient

use of org.wso2.keycloak.client.model.IntrospectionClient in project apim-km-keycloak by wso2-extensions.

the class KeycloakClient method loadConfiguration.

/**
 * {@code APIManagerComponent} calls this method, passing KeyManagerConfiguration as a {@code String}.
 *
 * @param keyManagerConfiguration Configuration as a {@link KeyManagerConfiguration}
 * @throws APIManagementException This is the custom exception class for API management.
 */
@Override
public void loadConfiguration(KeyManagerConfiguration keyManagerConfiguration) throws APIManagementException {
    this.configuration = keyManagerConfiguration;
    String clientRegistrationEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.CLIENT_REGISTRATION_ENDPOINT);
    String clientId = (String) configuration.getParameter(KeycloakConstants.CLIENT_ID);
    String clientSecret = (String) configuration.getParameter(KeycloakConstants.CLIENT_SECRET);
    BasicAuthRequestInterceptor basicAuthRequestInterceptor = new BasicAuthRequestInterceptor(clientId, clientSecret);
    String tokenEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.TOKEN_ENDPOINT);
    String revokeEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.REVOKE_ENDPOINT);
    Gson gson = new GsonBuilder().serializeNulls().create();
    if (StringUtils.isNotEmpty(clientId) && StringUtils.isNotEmpty(clientSecret) && StringUtils.isNotEmpty(tokenEndpoint) && StringUtils.isNotEmpty(revokeEndpoint)) {
        AccessTokenGenerator accessTokenGenerator = new AccessTokenGenerator(tokenEndpoint, revokeEndpoint, clientId, clientSecret);
        dcrClient = Feign.builder().client(new OkHttpClient()).decoder(new GsonDecoder(gson)).encoder(new GsonEncoder(gson)).requestInterceptor(new BearerInterceptor(accessTokenGenerator)).target(DCRClient.class, clientRegistrationEndpoint);
        String introspectEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.INTROSPECTION_ENDPOINT);
        introspectionClient = Feign.builder().client(new OkHttpClient()).encoder(new GsonEncoder(gson)).decoder(new GsonDecoder(gson)).logger(new Slf4jLogger()).requestInterceptor(basicAuthRequestInterceptor).encoder(new FormEncoder()).target(IntrospectionClient.class, introspectEndpoint);
    } else {
        throw new APIManagementException("Error while configuring Keycloak Connector");
    }
}
Also used : OkHttpClient(feign.okhttp.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) BasicAuthRequestInterceptor(feign.auth.BasicAuthRequestInterceptor) Slf4jLogger(feign.slf4j.Slf4jLogger) Gson(com.google.gson.Gson) DCRClient(org.wso2.keycloak.client.model.DCRClient) AccessTokenGenerator(org.wso2.carbon.apimgt.impl.recommendationmgt.AccessTokenGenerator) GsonEncoder(feign.gson.GsonEncoder) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) IntrospectionClient(org.wso2.keycloak.client.model.IntrospectionClient) GsonDecoder(feign.gson.GsonDecoder) FormEncoder(org.wso2.carbon.apimgt.impl.kmclient.FormEncoder)

Aggregations

BasicAuthRequestInterceptor (feign.auth.BasicAuthRequestInterceptor)2 GsonDecoder (feign.gson.GsonDecoder)2 GsonEncoder (feign.gson.GsonEncoder)2 Slf4jLogger (feign.slf4j.Slf4jLogger)2 FormEncoder (org.wso2.carbon.apimgt.impl.kmclient.FormEncoder)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 OkHttpClient (feign.okhttp.OkHttpClient)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 ApacheFeignHttpClient (org.wso2.carbon.apimgt.impl.kmclient.ApacheFeignHttpClient)1 KMClientErrorDecoder (org.wso2.carbon.apimgt.impl.kmclient.KMClientErrorDecoder)1 AuthClient (org.wso2.carbon.apimgt.impl.kmclient.model.AuthClient)1 DCRClient (org.wso2.carbon.apimgt.impl.kmclient.model.DCRClient)1 IntrospectionClient (org.wso2.carbon.apimgt.impl.kmclient.model.IntrospectionClient)1 ScopeClient (org.wso2.carbon.apimgt.impl.kmclient.model.ScopeClient)1 TenantHeaderInterceptor (org.wso2.carbon.apimgt.impl.kmclient.model.TenantHeaderInterceptor)1 UserClient (org.wso2.carbon.apimgt.impl.kmclient.model.UserClient)1 AccessTokenGenerator (org.wso2.carbon.apimgt.impl.recommendationmgt.AccessTokenGenerator)1 DCRClient (org.wso2.keycloak.client.model.DCRClient)1 IntrospectionClient (org.wso2.keycloak.client.model.IntrospectionClient)1