rename FederationProvider to UserFederationProvider
This commit is contained in:
parent
245d83adce
commit
1b14444eba
27 changed files with 135 additions and 150 deletions
|
@ -4,7 +4,7 @@
|
|||
<artifactId>keycloak-authentication-parent</artifactId>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<version>1.0-beta-4-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>keycloak-authentication-parent</artifactId>
|
||||
<artifactId>keycloak-parent</artifactId>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<version>1.0-beta-4-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package org.keycloak.federation.ldap;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.models.FederationProvider;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.UserFederationProvider;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.ModelException;
|
||||
import org.keycloak.models.RealmModel;
|
||||
|
@ -15,7 +15,6 @@ import org.picketlink.idm.IdentityManager;
|
|||
import org.picketlink.idm.PartitionManager;
|
||||
import org.picketlink.idm.credential.Credentials;
|
||||
import org.picketlink.idm.credential.Password;
|
||||
import org.picketlink.idm.credential.TOTPCredential;
|
||||
import org.picketlink.idm.credential.UsernamePasswordCredentials;
|
||||
import org.picketlink.idm.model.basic.BasicModel;
|
||||
import org.picketlink.idm.model.basic.User;
|
||||
|
@ -25,18 +24,15 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.picketlink.common.util.StringUtil.isNullOrEmpty;
|
||||
import static org.picketlink.idm.IDMMessages.MESSAGES;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class LDAPFederationProvider implements FederationProvider {
|
||||
public class LDAPFederationProvider implements UserFederationProvider {
|
||||
private static final Logger logger = Logger.getLogger(LDAPFederationProvider.class);
|
||||
|
||||
protected KeycloakSession session;
|
||||
protected FederationProviderModel model;
|
||||
protected UserFederationProviderModel model;
|
||||
protected PartitionManager partitionManager;
|
||||
|
||||
protected static final Set<String> supportedCredentialTypes = new HashSet<String>();
|
||||
|
@ -46,7 +42,7 @@ public class LDAPFederationProvider implements FederationProvider {
|
|||
supportedCredentialTypes.add(UserCredentialModel.PASSWORD);
|
||||
}
|
||||
|
||||
public LDAPFederationProvider(KeycloakSession session, FederationProviderModel model, PartitionManager partitionManager) {
|
||||
public LDAPFederationProvider(KeycloakSession session, UserFederationProviderModel model, PartitionManager partitionManager) {
|
||||
this.session = session;
|
||||
this.model = model;
|
||||
this.partitionManager = partitionManager;
|
||||
|
@ -66,7 +62,7 @@ public class LDAPFederationProvider implements FederationProvider {
|
|||
return session;
|
||||
}
|
||||
|
||||
public FederationProviderModel getModel() {
|
||||
public UserFederationProviderModel getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,31 +1,27 @@
|
|||
package org.keycloak.federation.ldap;
|
||||
|
||||
import org.keycloak.Config;
|
||||
import org.keycloak.models.FederationProvider;
|
||||
import org.keycloak.models.FederationProviderFactory;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.UserFederationProvider;
|
||||
import org.keycloak.models.UserFederationProviderFactory;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.picketlink.idm.IdentityManager;
|
||||
import org.picketlink.idm.PartitionManager;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class LDAPFederationProviderFactory implements FederationProviderFactory {
|
||||
public class LDAPFederationProviderFactory implements UserFederationProviderFactory {
|
||||
public static final String PROVIDER_NAME = "ldap";
|
||||
PartitionManagerRegistry registry;
|
||||
|
||||
@Override
|
||||
public FederationProvider create(KeycloakSession session) {
|
||||
public UserFederationProvider create(KeycloakSession session) {
|
||||
throw new IllegalAccessError("Illegal to call this method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public FederationProvider getInstance(KeycloakSession session, FederationProviderModel model) {
|
||||
public UserFederationProvider getInstance(KeycloakSession session, UserFederationProviderModel model) {
|
||||
PartitionManager partition = registry.getPartitionManager(model);
|
||||
return new LDAPFederationProvider(session, model, partition);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.keycloak.federation.ldap;
|
|||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.AuthenticationLinkModel;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.ModelException;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package org.keycloak.federation.ldap;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.LDAPConstants;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.picketlink.idm.PartitionManager;
|
||||
import org.picketlink.idm.config.AbstractIdentityStoreConfiguration;
|
||||
import org.picketlink.idm.config.IdentityConfiguration;
|
||||
|
@ -30,7 +28,7 @@ public class PartitionManagerRegistry {
|
|||
|
||||
private Map<String, PartitionManagerContext> partitionManagers = new ConcurrentHashMap<String, PartitionManagerContext>();
|
||||
|
||||
public PartitionManager getPartitionManager(FederationProviderModel model) {
|
||||
public PartitionManager getPartitionManager(UserFederationProviderModel model) {
|
||||
PartitionManagerContext context = partitionManagers.get(model.getId());
|
||||
|
||||
// Ldap config might have changed for the realm. In this case, we must re-initialize
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
package org.keycloak.models;
|
||||
|
||||
import org.keycloak.provider.ProviderFactory;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public interface FederationProviderFactory extends ProviderFactory<FederationProvider> {
|
||||
FederationProvider getInstance(KeycloakSession session, FederationProviderModel model);
|
||||
}
|
|
@ -20,6 +20,8 @@ public interface KeycloakSession {
|
|||
|
||||
<T extends Provider> Set<T> getAllProviders(Class<T> clazz);
|
||||
|
||||
void enlistForClose(Provider provider);
|
||||
|
||||
KeycloakSessionFactory getKeycloakSessionFactory();
|
||||
|
||||
/**
|
||||
|
|
|
@ -165,9 +165,9 @@ public interface RealmModel extends RoleContainerModel {
|
|||
|
||||
void setAuthenticationProviders(List<AuthenticationProviderModel> authenticationProviders);
|
||||
|
||||
List<FederationProviderModel> getFederationProviders();
|
||||
List<UserFederationProviderModel> getFederationProviders();
|
||||
|
||||
void setFederationProviders(List<FederationProviderModel> providers);
|
||||
void setFederationProviders(List<UserFederationProviderModel> providers);
|
||||
|
||||
String getLoginTheme();
|
||||
|
||||
|
|
|
@ -10,25 +10,25 @@ import java.util.Set;
|
|||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class FederationManager implements UserProvider {
|
||||
public class UserFederationManager implements UserProvider {
|
||||
protected KeycloakSession session;
|
||||
|
||||
public FederationManager(KeycloakSession session) {
|
||||
public UserFederationManager(KeycloakSession session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserModel addUser(RealmModel realm, String id, String username, boolean addDefaultRoles) {
|
||||
UserModel user = session.userStorage().addUser(realm, id, username, addDefaultRoles);
|
||||
for (FederationProviderModel federation : realm.getFederationProviders()) {
|
||||
FederationProvider fed = session.getProvider(FederationProvider.class, federation.getProviderName());
|
||||
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
|
||||
UserFederationProvider fed = session.getProvider(UserFederationProvider.class, federation.getProviderName());
|
||||
return fed.addUser(realm, user);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
protected FederationProvider getFederationProvider(FederationProviderModel model) {
|
||||
FederationProviderFactory factory = (FederationProviderFactory)session.getKeycloakSessionFactory().getProviderFactory(FederationProvider.class, model.getProviderName());
|
||||
protected UserFederationProvider getFederationProvider(UserFederationProviderModel model) {
|
||||
UserFederationProviderFactory factory = (UserFederationProviderFactory)session.getKeycloakSessionFactory().getProviderFactory(UserFederationProvider.class, model.getProviderName());
|
||||
return factory.getInstance(session, model);
|
||||
|
||||
}
|
||||
|
@ -36,16 +36,16 @@ public class FederationManager implements UserProvider {
|
|||
@Override
|
||||
public UserModel addUser(RealmModel realm, String username) {
|
||||
UserModel user = session.userStorage().addUser(realm, username);
|
||||
for (FederationProviderModel federation : realm.getFederationProviders()) {
|
||||
FederationProvider fed = getFederationProvider(federation);
|
||||
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
|
||||
UserFederationProvider fed = getFederationProvider(federation);
|
||||
return fed.addUser(realm, user);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
protected FederationProvider getFederationLink(RealmModel realm, UserModel user) {
|
||||
protected UserFederationProvider getFederationLink(RealmModel realm, UserModel user) {
|
||||
if (user.getFederationLink() == null) return null;
|
||||
for (FederationProviderModel fed : realm.getFederationProviders()) {
|
||||
for (UserFederationProviderModel fed : realm.getFederationProviders()) {
|
||||
if (fed.getId().equals(user.getFederationLink())) {
|
||||
return getFederationProvider(fed);
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class FederationManager implements UserProvider {
|
|||
public boolean removeUser(RealmModel realm, String name) {
|
||||
UserModel user = session.userStorage().getUserByUsername(name, realm);
|
||||
if (user == null) return false;
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
return link.removeUser(realm, user);
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public class FederationManager implements UserProvider {
|
|||
|
||||
@Override
|
||||
public void addSocialLink(RealmModel realm, UserModel user, SocialLinkModel socialLink) {
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
link.addSocialLink(realm, user, socialLink);
|
||||
return;
|
||||
|
@ -78,7 +78,7 @@ public class FederationManager implements UserProvider {
|
|||
|
||||
@Override
|
||||
public boolean removeSocialLink(RealmModel realm, UserModel user, String socialProvider) {
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
return link.removeSocialLink(realm, user, socialProvider);
|
||||
}
|
||||
|
@ -89,14 +89,14 @@ public class FederationManager implements UserProvider {
|
|||
public UserModel getUserById(String id, RealmModel realm) {
|
||||
UserModel user = session.userStorage().getUserById(id, realm);
|
||||
if (user != null) {
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
return link.proxy(user);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
for (FederationProviderModel federation : realm.getFederationProviders()) {
|
||||
FederationProvider fed = getFederationProvider(federation);
|
||||
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
|
||||
UserFederationProvider fed = getFederationProvider(federation);
|
||||
user = fed.getUserById(id, realm);
|
||||
if (user != null) return user;
|
||||
}
|
||||
|
@ -107,14 +107,14 @@ public class FederationManager implements UserProvider {
|
|||
public UserModel getUserByUsername(String username, RealmModel realm) {
|
||||
UserModel user = session.userStorage().getUserByUsername(username, realm);
|
||||
if (user != null) {
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
return link.proxy(user);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
for (FederationProviderModel federation : realm.getFederationProviders()) {
|
||||
FederationProvider fed = getFederationProvider(federation);
|
||||
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
|
||||
UserFederationProvider fed = getFederationProvider(federation);
|
||||
user = fed.getUserByUsername(username, realm);
|
||||
if (user != null) return user;
|
||||
}
|
||||
|
@ -125,14 +125,14 @@ public class FederationManager implements UserProvider {
|
|||
public UserModel getUserByEmail(String email, RealmModel realm) {
|
||||
UserModel user = session.userStorage().getUserByEmail(email, realm);
|
||||
if (user != null) {
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
return link.proxy(user);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
for (FederationProviderModel federation : realm.getFederationProviders()) {
|
||||
FederationProvider fed = getFederationProvider(federation);
|
||||
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
|
||||
UserFederationProvider fed = getFederationProvider(federation);
|
||||
user = fed.getUserByEmail(email, realm);
|
||||
if (user != null) return user;
|
||||
}
|
||||
|
@ -143,14 +143,14 @@ public class FederationManager implements UserProvider {
|
|||
public UserModel getUserBySocialLink(SocialLinkModel socialLink, RealmModel realm) {
|
||||
UserModel user = session.userStorage().getUserBySocialLink(socialLink, realm);
|
||||
if (user != null) {
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
return link.proxy(user);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
for (FederationProviderModel federation : realm.getFederationProviders()) {
|
||||
FederationProvider fed = getFederationProvider(federation);
|
||||
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
|
||||
UserFederationProvider fed = getFederationProvider(federation);
|
||||
user = fed.getUserBySocialLink(socialLink, realm);
|
||||
if (user != null) return user;
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ public class FederationManager implements UserProvider {
|
|||
Map<String, UserModel> users = new HashMap<String, UserModel>();
|
||||
List<UserModel> query = session.userStorage().getUsers(realm, firstResult, maxResults);
|
||||
for (UserModel user : query) {
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
users.put(user.getUsername(), link.proxy(user));
|
||||
} else {
|
||||
|
@ -185,10 +185,10 @@ public class FederationManager implements UserProvider {
|
|||
results.addAll(users.values());
|
||||
return results;
|
||||
}
|
||||
List<FederationProviderModel> federationProviders = realm.getFederationProviders();
|
||||
List<UserFederationProviderModel> federationProviders = realm.getFederationProviders();
|
||||
for (int i = federationProviders.size() - 1; i >= 0; i--) {
|
||||
FederationProviderModel federation = federationProviders.get(i);
|
||||
FederationProvider fed = getFederationProvider(federation);
|
||||
UserFederationProviderModel federation = federationProviders.get(i);
|
||||
UserFederationProvider fed = getFederationProvider(federation);
|
||||
query = fed.getUsers(realm, firstResult, maxResults);
|
||||
for (UserModel user : query) users.put(user.getUsername(), user);
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ public class FederationManager implements UserProvider {
|
|||
Map<String, UserModel> users = new HashMap<String, UserModel>();
|
||||
List<UserModel> query = session.userStorage().searchForUser(search, realm, firstResult, maxResults);
|
||||
for (UserModel user : query) {
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
users.put(user.getUsername(), link.proxy(user));
|
||||
} else {
|
||||
|
@ -219,10 +219,10 @@ public class FederationManager implements UserProvider {
|
|||
results.addAll(users.values());
|
||||
return results;
|
||||
}
|
||||
List<FederationProviderModel> federationProviders = realm.getFederationProviders();
|
||||
List<UserFederationProviderModel> federationProviders = realm.getFederationProviders();
|
||||
for (int i = federationProviders.size() - 1; i >= 0; i--) {
|
||||
FederationProviderModel federation = federationProviders.get(i);
|
||||
FederationProvider fed = getFederationProvider(federation);
|
||||
UserFederationProviderModel federation = federationProviders.get(i);
|
||||
UserFederationProvider fed = getFederationProvider(federation);
|
||||
query = fed.searchForUser(search, realm, firstResult, maxResults);
|
||||
for (UserModel user : query) users.put(user.getUsername(), user);
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ public class FederationManager implements UserProvider {
|
|||
Map<String, UserModel> users = new HashMap<String, UserModel>();
|
||||
List<UserModel> query = session.userStorage().searchForUserByAttributes(attributes, realm, firstResult, maxResults);
|
||||
for (UserModel user : query) {
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
users.put(user.getUsername(), link.proxy(user));
|
||||
} else {
|
||||
|
@ -253,10 +253,10 @@ public class FederationManager implements UserProvider {
|
|||
results.addAll(users.values());
|
||||
return results;
|
||||
}
|
||||
List<FederationProviderModel> federationProviders = realm.getFederationProviders();
|
||||
List<UserFederationProviderModel> federationProviders = realm.getFederationProviders();
|
||||
for (int i = federationProviders.size() - 1; i >= 0; i--) {
|
||||
FederationProviderModel federation = federationProviders.get(i);
|
||||
FederationProvider fed = getFederationProvider(federation);
|
||||
UserFederationProviderModel federation = federationProviders.get(i);
|
||||
UserFederationProvider fed = getFederationProvider(federation);
|
||||
query = fed.searchForUserByAttributes(attributes, realm, firstResult, maxResults);
|
||||
for (UserModel user : query) users.put(user.getUsername(), user);
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ public class FederationManager implements UserProvider {
|
|||
|
||||
@Override
|
||||
public Set<SocialLinkModel> getSocialLinks(UserModel user, RealmModel realm) {
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
return link.getSocialLinks(user, realm);
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ public class FederationManager implements UserProvider {
|
|||
|
||||
@Override
|
||||
public SocialLinkModel getSocialLink(UserModel user, String socialProvider, RealmModel realm) {
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
return link.getSocialLink(user, socialProvider, realm);
|
||||
}
|
||||
|
@ -285,8 +285,8 @@ public class FederationManager implements UserProvider {
|
|||
|
||||
@Override
|
||||
public void preRemove(RealmModel realm) {
|
||||
for (FederationProviderModel federation : realm.getFederationProviders()) {
|
||||
FederationProvider fed = getFederationProvider(federation);
|
||||
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
|
||||
UserFederationProvider fed = getFederationProvider(federation);
|
||||
fed.preRemove(realm);
|
||||
}
|
||||
session.userStorage().preRemove(realm);
|
||||
|
@ -294,8 +294,8 @@ public class FederationManager implements UserProvider {
|
|||
|
||||
@Override
|
||||
public void preRemove(RealmModel realm, RoleModel role) {
|
||||
for (FederationProviderModel federation : realm.getFederationProviders()) {
|
||||
FederationProvider fed = getFederationProvider(federation);
|
||||
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
|
||||
UserFederationProvider fed = getFederationProvider(federation);
|
||||
fed.preRemove(realm, role);
|
||||
}
|
||||
session.userStorage().preRemove(realm, role);
|
||||
|
@ -303,7 +303,7 @@ public class FederationManager implements UserProvider {
|
|||
|
||||
@Override
|
||||
public boolean validCredentials(RealmModel realm, UserModel user, List<UserCredentialModel> input) {
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
if (link.getSupportedCredentialTypes().size() > 0) {
|
||||
List<UserCredentialModel> fedCreds = new ArrayList<UserCredentialModel>();
|
||||
|
@ -326,7 +326,7 @@ public class FederationManager implements UserProvider {
|
|||
|
||||
@Override
|
||||
public boolean validCredentials(RealmModel realm, UserModel user, UserCredentialModel... input) {
|
||||
FederationProvider link = getFederationLink(realm, user);
|
||||
UserFederationProvider link = getFederationLink(realm, user);
|
||||
if (link != null) {
|
||||
Set<String> supportedCredentialTypes = link.getSupportedCredentialTypes();
|
||||
if (supportedCredentialTypes.size() > 0) {
|
|
@ -7,7 +7,7 @@ import java.util.Set;
|
|||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public interface FederationProvider extends UserProvider {
|
||||
public interface UserFederationProvider extends UserProvider {
|
||||
UserModel proxy(UserModel local);
|
||||
UserModel addUser(RealmModel realm, UserModel user);
|
||||
boolean removeUser(RealmModel realm, UserModel user);
|
|
@ -0,0 +1,11 @@
|
|||
package org.keycloak.models;
|
||||
|
||||
import org.keycloak.provider.ProviderFactory;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public interface UserFederationProviderFactory extends ProviderFactory<UserFederationProvider> {
|
||||
UserFederationProvider getInstance(KeycloakSession session, UserFederationProviderModel model);
|
||||
}
|
|
@ -7,15 +7,15 @@ import java.util.Map;
|
|||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
* @author <a href="mailto:bburke@redhat.com">Bill Burke</a>
|
||||
*/
|
||||
public class FederationProviderModel {
|
||||
public class UserFederationProviderModel {
|
||||
|
||||
private String id;
|
||||
private String providerName;
|
||||
private Map<String, String> config = new HashMap<String, String>();
|
||||
|
||||
public FederationProviderModel() {};
|
||||
public UserFederationProviderModel() {};
|
||||
|
||||
public FederationProviderModel(String id, String providerName, Map<String, String> config) {
|
||||
public UserFederationProviderModel(String id, String providerName, Map<String, String> config) {
|
||||
this.id = id;
|
||||
this.providerName = providerName;
|
||||
if (config != null) {
|
|
@ -7,21 +7,21 @@ import org.keycloak.provider.Spi;
|
|||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
public class FederationSpi implements Spi {
|
||||
public class UserFederationSpi implements Spi {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "federation";
|
||||
return "userFederation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Provider> getProviderClass() {
|
||||
return FederationProvider.class;
|
||||
return UserFederationProvider.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends ProviderFactory> getProviderFactoryClass() {
|
||||
return FederationProviderFactory.class;
|
||||
return UserFederationProviderFactory.class;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@ import org.keycloak.models.AuthenticationProviderModel;
|
|||
import org.keycloak.models.ClaimMask;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RequiredCredentialModel;
|
||||
|
@ -143,10 +143,10 @@ public class ModelToRepresentation {
|
|||
}
|
||||
rep.setAuthenticationProviders(authProviderReps);
|
||||
}
|
||||
List<FederationProviderModel> fedProviderModels = realm.getFederationProviders();
|
||||
List<UserFederationProviderModel> fedProviderModels = realm.getFederationProviders();
|
||||
if (fedProviderModels.size() > 0) {
|
||||
List<FederationProviderRepresentation> fedProviderReps = new ArrayList<FederationProviderRepresentation>();
|
||||
for (FederationProviderModel model : fedProviderModels) {
|
||||
for (UserFederationProviderModel model : fedProviderModels) {
|
||||
FederationProviderRepresentation fedProvRep = new FederationProviderRepresentation();
|
||||
fedProvRep.setId(model.getId());
|
||||
fedProvRep.setProviderName(model.getProviderName());
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.keycloak.models.AuthenticationLinkModel;
|
|||
import org.keycloak.models.AuthenticationProviderModel;
|
||||
import org.keycloak.models.ClaimMask;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
|
@ -216,7 +216,7 @@ public class RepresentationToModel {
|
|||
}
|
||||
|
||||
if (rep.getFederationProviders() != null) {
|
||||
List<FederationProviderModel> providerModels = convertFederationProviders(rep.getFederationProviders());
|
||||
List<UserFederationProviderModel> providerModels = convertFederationProviders(rep.getFederationProviders());
|
||||
newRealm.setFederationProviders(providerModels);
|
||||
}
|
||||
|
||||
|
@ -288,7 +288,7 @@ public class RepresentationToModel {
|
|||
}
|
||||
|
||||
if (rep.getFederationProviders() != null) {
|
||||
List<FederationProviderModel> providerModels = convertFederationProviders(rep.getFederationProviders());
|
||||
List<UserFederationProviderModel> providerModels = convertFederationProviders(rep.getFederationProviders());
|
||||
realm.setFederationProviders(providerModels);
|
||||
}
|
||||
|
||||
|
@ -315,11 +315,11 @@ public class RepresentationToModel {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static List<FederationProviderModel> convertFederationProviders(List<FederationProviderRepresentation> providers) {
|
||||
List<FederationProviderModel> result = new ArrayList<FederationProviderModel>();
|
||||
private static List<UserFederationProviderModel> convertFederationProviders(List<FederationProviderRepresentation> providers) {
|
||||
List<UserFederationProviderModel> result = new ArrayList<UserFederationProviderModel>();
|
||||
|
||||
for (FederationProviderRepresentation representation : providers) {
|
||||
FederationProviderModel model = new FederationProviderModel(representation.getId(), representation.getProviderName(),
|
||||
UserFederationProviderModel model = new UserFederationProviderModel(representation.getId(), representation.getProviderName(),
|
||||
representation.getConfig());
|
||||
result.add(model);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
org.keycloak.models.FederationSpi
|
||||
org.keycloak.models.UserFederationSpi
|
||||
org.keycloak.models.RealmSpi
|
||||
org.keycloak.models.UserSessionSpi
|
||||
org.keycloak.models.UserSpi
|
|
@ -4,19 +4,14 @@ import org.keycloak.Config;
|
|||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.AuthenticationProviderModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.utils.CredentialValidation;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RequiredCredentialModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
import org.keycloak.models.UserCredentialValueModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.cache.entities.CachedRealm;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
import org.keycloak.models.utils.TimeBasedOTP;
|
||||
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
|
@ -611,13 +606,13 @@ public class RealmAdapter implements RealmModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<FederationProviderModel> getFederationProviders() {
|
||||
public List<UserFederationProviderModel> getFederationProviders() {
|
||||
if (updated != null) return updated.getFederationProviders();
|
||||
return cached.getFederationProviders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFederationProviders(List<FederationProviderModel> providers) {
|
||||
public void setFederationProviders(List<UserFederationProviderModel> providers) {
|
||||
getDelegateForUpdate();
|
||||
updated.setFederationProviders(providers);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.keycloak.models.cache;
|
|||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.AuthenticationLinkModel;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleContainerModel;
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.keycloak.models.cache.entities;
|
|||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.AuthenticationProviderModel;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
|
@ -65,7 +65,7 @@ public class CachedRealm {
|
|||
|
||||
private List<RequiredCredentialModel> requiredCredentials = new ArrayList<RequiredCredentialModel>();
|
||||
private List<AuthenticationProviderModel> authenticationProviders = new ArrayList<AuthenticationProviderModel>();
|
||||
private List<FederationProviderModel> federationProviders = new ArrayList<FederationProviderModel>();
|
||||
private List<UserFederationProviderModel> federationProviders = new ArrayList<UserFederationProviderModel>();
|
||||
|
||||
private Map<String, String> smtpConfig = new HashMap<String, String>();
|
||||
private Map<String, String> socialConfig = new HashMap<String, String>();
|
||||
|
@ -331,7 +331,7 @@ public class CachedRealm {
|
|||
return auditListeners;
|
||||
}
|
||||
|
||||
public List<FederationProviderModel> getFederationProviders() {
|
||||
public List<UserFederationProviderModel> getFederationProviders() {
|
||||
return federationProviders;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.keycloak.models.cache.entities;
|
||||
|
||||
import org.keycloak.models.AuthenticationLinkModel;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserCredentialValueModel;
|
||||
|
|
|
@ -3,27 +3,21 @@ package org.keycloak.models.jpa;
|
|||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.AuthenticationProviderModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.jpa.entities.FederationProviderEntity;
|
||||
import org.keycloak.models.utils.CredentialValidation;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RequiredCredentialModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
import org.keycloak.models.UserCredentialValueModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.jpa.entities.ApplicationEntity;
|
||||
import org.keycloak.models.jpa.entities.AuthenticationProviderEntity;
|
||||
import org.keycloak.models.jpa.entities.OAuthClientEntity;
|
||||
import org.keycloak.models.jpa.entities.RealmEntity;
|
||||
import org.keycloak.models.jpa.entities.RequiredCredentialEntity;
|
||||
import org.keycloak.models.jpa.entities.RoleEntity;
|
||||
import org.keycloak.models.jpa.entities.ScopeMappingEntity;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
import org.keycloak.models.utils.TimeBasedOTP;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
@ -733,7 +727,7 @@ public class RealmAdapter implements RealmModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<FederationProviderModel> getFederationProviders() {
|
||||
public List<UserFederationProviderModel> getFederationProviders() {
|
||||
List<FederationProviderEntity> entities = realm.getFederationProviders();
|
||||
List<FederationProviderEntity> copy = new ArrayList<FederationProviderEntity>();
|
||||
for (FederationProviderEntity entity : entities) {
|
||||
|
@ -748,19 +742,19 @@ public class RealmAdapter implements RealmModel {
|
|||
}
|
||||
|
||||
});
|
||||
List<FederationProviderModel> result = new ArrayList<FederationProviderModel>();
|
||||
List<UserFederationProviderModel> result = new ArrayList<UserFederationProviderModel>();
|
||||
for (FederationProviderEntity entity : copy) {
|
||||
result.add(new FederationProviderModel(entity.getId(), entity.getProviderName(), entity.getConfig()));
|
||||
result.add(new UserFederationProviderModel(entity.getId(), entity.getProviderName(), entity.getConfig()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFederationProviders(List<FederationProviderModel> providers) {
|
||||
public void setFederationProviders(List<UserFederationProviderModel> providers) {
|
||||
List<FederationProviderEntity> newEntities = new ArrayList<FederationProviderEntity>();
|
||||
int counter = 1;
|
||||
for (FederationProviderModel model : providers) {
|
||||
for (UserFederationProviderModel model : providers) {
|
||||
FederationProviderEntity entity = new FederationProviderEntity();
|
||||
entity.setId(KeycloakModelUtils.generateId());
|
||||
entity.setRealm(realm);
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.keycloak.models.jpa;
|
|||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.AuthenticationLinkModel;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleContainerModel;
|
||||
|
@ -12,7 +11,6 @@ import org.keycloak.models.UserCredentialValueModel;
|
|||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.jpa.entities.AuthenticationLinkEntity;
|
||||
import org.keycloak.models.jpa.entities.CredentialEntity;
|
||||
import org.keycloak.models.jpa.entities.FederationProviderEntity;
|
||||
import org.keycloak.models.jpa.entities.UserAttributeEntity;
|
||||
import org.keycloak.models.jpa.entities.UserEntity;
|
||||
import org.keycloak.models.jpa.entities.UserRequiredActionEntity;
|
||||
|
|
|
@ -7,9 +7,8 @@ import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext;
|
|||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.AuthenticationProviderModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.entities.FederationProviderEntity;
|
||||
import org.keycloak.models.utils.CredentialValidation;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
|
@ -17,9 +16,6 @@ import org.keycloak.models.PasswordPolicy;
|
|||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RequiredCredentialModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
import org.keycloak.models.UserCredentialValueModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.entities.AuthenticationProviderEntity;
|
||||
import org.keycloak.models.entities.RequiredCredentialEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoApplicationEntity;
|
||||
|
@ -27,7 +23,6 @@ import org.keycloak.models.mongo.keycloak.entities.MongoOAuthClientEntity;
|
|||
import org.keycloak.models.mongo.keycloak.entities.MongoRealmEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoRoleEntity;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
import org.keycloak.models.utils.TimeBasedOTP;
|
||||
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
|
@ -796,20 +791,20 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
|||
updateRealm();
|
||||
}
|
||||
@Override
|
||||
public List<FederationProviderModel> getFederationProviders() {
|
||||
public List<UserFederationProviderModel> getFederationProviders() {
|
||||
List<FederationProviderEntity> entities = realm.getFederationProviders();
|
||||
List<FederationProviderModel> result = new ArrayList<FederationProviderModel>();
|
||||
List<UserFederationProviderModel> result = new ArrayList<UserFederationProviderModel>();
|
||||
for (FederationProviderEntity entity : entities) {
|
||||
result.add(new FederationProviderModel(entity.getId(), entity.getProviderName(), entity.getConfig()));
|
||||
result.add(new UserFederationProviderModel(entity.getId(), entity.getProviderName(), entity.getConfig()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFederationProviders(List<FederationProviderModel> providers) {
|
||||
public void setFederationProviders(List<UserFederationProviderModel> providers) {
|
||||
List<FederationProviderEntity> entities = new ArrayList<FederationProviderEntity>();
|
||||
for (FederationProviderModel model : providers) {
|
||||
for (UserFederationProviderModel model : providers) {
|
||||
FederationProviderEntity entity = new FederationProviderEntity();
|
||||
entity.setId(KeycloakModelUtils.generateId());
|
||||
entity.setProviderName(model.getProviderName());
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.keycloak.services;
|
||||
|
||||
import org.keycloak.models.FederationManager;
|
||||
import org.keycloak.models.UserFederationManager;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.models.KeycloakTransactionManager;
|
||||
|
@ -14,6 +14,8 @@ import org.keycloak.provider.ProviderFactory;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -24,16 +26,17 @@ public class DefaultKeycloakSession implements KeycloakSession {
|
|||
|
||||
private final DefaultKeycloakSessionFactory factory;
|
||||
private final Map<Integer, Provider> providers = new HashMap<Integer, Provider>();
|
||||
private final List<Provider> closable = new LinkedList<Provider>();
|
||||
private final DefaultKeycloakTransactionManager transactionManager;
|
||||
private RealmProvider model;
|
||||
private UserProvider userModel;
|
||||
private UserSessionProvider sessionProvider;
|
||||
private FederationManager federationManager;
|
||||
private UserFederationManager federationManager;
|
||||
|
||||
public DefaultKeycloakSession(DefaultKeycloakSessionFactory factory) {
|
||||
this.factory = factory;
|
||||
this.transactionManager = new DefaultKeycloakTransactionManager();
|
||||
federationManager = new FederationManager(this);
|
||||
federationManager = new UserFederationManager(this);
|
||||
}
|
||||
|
||||
private RealmProvider getRealmProvider() {
|
||||
|
@ -52,6 +55,11 @@ public class DefaultKeycloakSession implements KeycloakSession {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enlistForClose(Provider provider) {
|
||||
closable.add(provider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeycloakTransactionManager getTransaction() {
|
||||
return transactionManager;
|
||||
|
@ -133,7 +141,16 @@ public class DefaultKeycloakSession implements KeycloakSession {
|
|||
|
||||
public void close() {
|
||||
for (Provider p : providers.values()) {
|
||||
try {
|
||||
p.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
for (Provider p : closable) {
|
||||
try {
|
||||
p.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,15 +9,12 @@ import org.junit.rules.RuleChain;
|
|||
import org.junit.rules.TestRule;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.keycloak.OAuth2Constants;
|
||||
import org.keycloak.authentication.AuthProviderConstants;
|
||||
import org.keycloak.federation.ldap.LDAPFederationProviderFactory;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.testsuite.LDAPEmbeddedServer;
|
||||
import org.keycloak.testsuite.LDAPTestUtils;
|
||||
import org.keycloak.models.AuthenticationProviderModel;
|
||||
import org.keycloak.models.FederationProviderModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.LDAPConstants;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
|
@ -64,7 +61,7 @@ public class FederationProvidersIntegrationTest {
|
|||
ldapConfig.put(LDAPConstants.VENDOR, ldapServer.getVendor());
|
||||
|
||||
|
||||
FederationProviderModel ldapProvider = new FederationProviderModel(null, LDAPFederationProviderFactory.PROVIDER_NAME, ldapConfig);
|
||||
UserFederationProviderModel ldapProvider = new UserFederationProviderModel(null, LDAPFederationProviderFactory.PROVIDER_NAME, ldapConfig);
|
||||
appRealm.setFederationProviders(Arrays.asList(ldapProvider));
|
||||
|
||||
// Configure LDAP
|
||||
|
|
Loading…
Reference in a new issue