自定义用户联合不会添加到 keycloak 管理面板
Custom-user-federation does not add to keycloak admin panel
我已经像这样实现了我的用户存储提供程序:
public class UserStorageProvider implements org.keycloak.storage.UserStorageProvider, UserLookupProvider, CredentialInputValidator {
public UserStorageProvider(KeycloakSession session) {
this.session = session;
}
public UserStorageProvider(KeycloakSession session, ComponentModel model) {
this.session = session;
this.model = model;
}
protected KeycloakSession session;
protected ComponentModel model;
@Override
public boolean isConfiguredFor(RealmModel realm, UserModel user, String credentialType) {
return true;
}
@Override
public boolean supportsCredentialType(String credentialType) {
return true;
}
@Override
public boolean isValid(RealmModel realm, UserModel user, CredentialInput input) {
return true;
}
@Override
public UserModel getUserByUsername(String username, RealmModel realm) {
//here to fetch user from my DB.
return null;
}
@Override
public UserModel getUserById(String id, RealmModel realm) {
StorageId storageId = new StorageId(id);
String username = storageId.getExternalId();
return getUserByUsername(username, realm);
}
@Override
public UserModel getUserByEmail(String email, RealmModel realm) {
return null;
}
public void close() {
}
}
及其工厂class:
public class UserStorageProviderFactory implements org.keycloak.storage.UserStorageProviderFactory<UserStorageProvider> {
public static final String PROVIDER_NAME = "user-provider";
@Override
public String getHelpText() {
return "JPA Example User Storage Provider";
}
@Override
public List<ProviderConfigProperty> getConfigProperties() {
return null;
}
@Override
public UserStorageProvider create(KeycloakSession keycloakSession) {
return new UserStorageProvider(keycloakSession);
}
@Override
public UserStorageProvider create(KeycloakSession keycloakSession, ComponentModel componentModel) {
UserStorageProvider provider = new UserStorageProvider(keycloakSession, componentModel);
provider.session = keycloakSession;
provider.model = componentModel;
return provider;
}
@Override
public String getId() {
return PROVIDER_NAME;
}
@Override
public void init(Config.Scope config) {
}
@Override
public void postInit(KeycloakSessionFactory factory) {
}
@Override
public void close() {
}
}
并且 org.keycloak.storage.UserStorageProviderFactory
文件位于 META-INF/services/
并且其内容是:
com.kian.neshan.userfederation.UserStorageProviderFactory
所以我通过 mvn clean package
制作了 jar 并将其放在 keycloak 的 deplyment 文件夹中但是当我进入管理面板时,我的提供者没有添加到用户联合选项
哪里错了?
我的整个模块都是正确的。
问题是 local-keycloak-docker-image 应该在模块发生任何更改后删除
Keycloak 由 docker-compose 启动,其图像由 Dockerfile 构建,因此在我的模块发生任何更改后,local-keycloak-image 应由 sudo docker rmi [local-image-name]
删除以重建图像获取最新的我的 jar 文件并将其放入 local-docker-image.
的部署文件夹
我已经像这样实现了我的用户存储提供程序:
public class UserStorageProvider implements org.keycloak.storage.UserStorageProvider, UserLookupProvider, CredentialInputValidator {
public UserStorageProvider(KeycloakSession session) {
this.session = session;
}
public UserStorageProvider(KeycloakSession session, ComponentModel model) {
this.session = session;
this.model = model;
}
protected KeycloakSession session;
protected ComponentModel model;
@Override
public boolean isConfiguredFor(RealmModel realm, UserModel user, String credentialType) {
return true;
}
@Override
public boolean supportsCredentialType(String credentialType) {
return true;
}
@Override
public boolean isValid(RealmModel realm, UserModel user, CredentialInput input) {
return true;
}
@Override
public UserModel getUserByUsername(String username, RealmModel realm) {
//here to fetch user from my DB.
return null;
}
@Override
public UserModel getUserById(String id, RealmModel realm) {
StorageId storageId = new StorageId(id);
String username = storageId.getExternalId();
return getUserByUsername(username, realm);
}
@Override
public UserModel getUserByEmail(String email, RealmModel realm) {
return null;
}
public void close() {
}
}
及其工厂class:
public class UserStorageProviderFactory implements org.keycloak.storage.UserStorageProviderFactory<UserStorageProvider> {
public static final String PROVIDER_NAME = "user-provider";
@Override
public String getHelpText() {
return "JPA Example User Storage Provider";
}
@Override
public List<ProviderConfigProperty> getConfigProperties() {
return null;
}
@Override
public UserStorageProvider create(KeycloakSession keycloakSession) {
return new UserStorageProvider(keycloakSession);
}
@Override
public UserStorageProvider create(KeycloakSession keycloakSession, ComponentModel componentModel) {
UserStorageProvider provider = new UserStorageProvider(keycloakSession, componentModel);
provider.session = keycloakSession;
provider.model = componentModel;
return provider;
}
@Override
public String getId() {
return PROVIDER_NAME;
}
@Override
public void init(Config.Scope config) {
}
@Override
public void postInit(KeycloakSessionFactory factory) {
}
@Override
public void close() {
}
}
并且 org.keycloak.storage.UserStorageProviderFactory
文件位于 META-INF/services/
并且其内容是:
com.kian.neshan.userfederation.UserStorageProviderFactory
所以我通过 mvn clean package
制作了 jar 并将其放在 keycloak 的 deplyment 文件夹中但是当我进入管理面板时,我的提供者没有添加到用户联合选项
哪里错了?
我的整个模块都是正确的。
问题是 local-keycloak-docker-image 应该在模块发生任何更改后删除
Keycloak 由 docker-compose 启动,其图像由 Dockerfile 构建,因此在我的模块发生任何更改后,local-keycloak-image 应由 sudo docker rmi [local-image-name]
删除以重建图像获取最新的我的 jar 文件并将其放入 local-docker-image.