Created
April 2, 2023 10:53
-
-
Save inspirit941/16a6bf4c27b03fda3477294626bb9b19 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.witherview.keycloak.oauth.remoteuserstorage; | |
| import com.witherview.keycloak.oauth.account.AccountApiService; | |
| import org.jboss.resteasy.client.jaxrs.ResteasyClient; | |
| import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; | |
| import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; | |
| import org.keycloak.component.ComponentModel; | |
| import org.keycloak.models.KeycloakSession; | |
| import org.keycloak.storage.UserStorageProviderFactory; | |
| import org.springframework.beans.factory.annotation.Value; | |
| public class RemoteUserStorageProviderFactory implements UserStorageProviderFactory<RemoteUserStorageProvider> { | |
| // keycloak admin console에서 확인할 수 있는 값. | |
| // Enable UserStorageProvider for the realm. | |
| public static final String PROVIDER_NAME = "witherview-MySQL"; | |
| // @Value("${connect.server}") | |
| private String serviceUri = "http://localhost:8080"; | |
| @Override | |
| public RemoteUserStorageProvider create(KeycloakSession session, ComponentModel model) { | |
| return new RemoteUserStorageProvider(session, model, buildHttpClient(serviceUri)); | |
| } | |
| @Override | |
| public String getId() { return PROVIDER_NAME; } | |
| // External Web Service에 user 정보를 요청하기 위한 http Client. | |
| private AccountApiService buildHttpClient(String uri) { | |
| ResteasyClient client = new ResteasyClientBuilder().build(); | |
| ResteasyWebTarget target = client.target(uri); | |
| return target.proxyBuilder(AccountApiService.class) | |
| .classloader(AccountApiService.class.getClassLoader()) | |
| .build(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment