Issue
I have implemented my user-storage-provider like this:
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() {
}
}
and its factory 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() {
}
}
and the org.keycloak.storage.UserStorageProviderFactory
file is located on META-INF/services/
and the its content is:
com.kian.neshan.userfederation.UserStorageProviderFactory
So I make the jar by mvn clean package
and put it in deplyment folder of keycloak but when I go to admin panel, my provider is not added to user-federation option
Where is wrong?
Solution
The whole of my module is correct.
The problem is the local-keycloak-docker-image shuold be removed after any changes of the module
Keycloak is started by docker-compose and its images is built by Dockerfile, so after any changes of my module, the local-keycloak-image should be removed by sudo docker rmi [local-image-name]
to rebuild the image to get the newest my jar file and put it to deployment folder of local-docker-image.
Answered By - reza ramezani matin
Answer Checked By - Robin (JavaFixing Admin)