From 1b14444eba1e28c751d3a173d4268ff532fe788b Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Thu, 24 Jul 2014 11:11:21 -0400 Subject: [PATCH] rename FederationProvider to UserFederationProvider --- .../authentication-picketlink/pom.xml | 2 +- federation/ldap/pom.xml | 2 +- .../ldap/LDAPFederationProvider.java | 16 ++-- .../ldap/LDAPFederationProviderFactory.java | 16 ++-- .../ldap/LDAPUserModelDelegate.java | 1 - .../ldap/PartitionManagerRegistry.java | 6 +- ...loak.models.UserFederationProviderFactory} | 0 .../models/FederationProviderFactory.java | 11 --- .../org/keycloak/models/KeycloakSession.java | 2 + .../java/org/keycloak/models/RealmModel.java | 4 +- ...anager.java => UserFederationManager.java} | 90 +++++++++---------- ...vider.java => UserFederationProvider.java} | 2 +- .../models/UserFederationProviderFactory.java | 11 +++ ....java => UserFederationProviderModel.java} | 6 +- ...erationSpi.java => UserFederationSpi.java} | 8 +- .../models/utils/ModelToRepresentation.java | 6 +- .../models/utils/RepresentationToModel.java | 12 +-- .../services/org.keycloak.provider.Spi | 2 +- .../keycloak/models/cache/RealmAdapter.java | 11 +-- .../keycloak/models/cache/UserAdapter.java | 1 - .../models/cache/entities/CachedRealm.java | 6 +- .../models/cache/entities/CachedUser.java | 1 - .../org/keycloak/models/jpa/RealmAdapter.java | 18 ++-- .../org/keycloak/models/jpa/UserAdapter.java | 2 - .../mongo/keycloak/adapters/RealmAdapter.java | 17 ++-- .../services/DefaultKeycloakSession.java | 25 +++++- .../FederationProvidersIntegrationTest.java | 7 +- 27 files changed, 135 insertions(+), 150 deletions(-) rename federation/ldap/src/main/resources/META-INF/services/{org.keycloak.models.FederationProviderFactory => org.keycloak.models.UserFederationProviderFactory} (100%) delete mode 100755 model/api/src/main/java/org/keycloak/models/FederationProviderFactory.java rename model/api/src/main/java/org/keycloak/models/{FederationManager.java => UserFederationManager.java} (73%) rename model/api/src/main/java/org/keycloak/models/{FederationProvider.java => UserFederationProvider.java} (83%) create mode 100755 model/api/src/main/java/org/keycloak/models/UserFederationProviderFactory.java rename model/api/src/main/java/org/keycloak/models/{FederationProviderModel.java => UserFederationProviderModel.java} (82%) rename model/api/src/main/java/org/keycloak/models/{FederationSpi.java => UserFederationSpi.java} (71%) diff --git a/authentication/authentication-picketlink/pom.xml b/authentication/authentication-picketlink/pom.xml index 37ae937785..3ca1a10a88 100755 --- a/authentication/authentication-picketlink/pom.xml +++ b/authentication/authentication-picketlink/pom.xml @@ -4,7 +4,7 @@ keycloak-authentication-parent org.keycloak 1.0-beta-4-SNAPSHOT - ../../pom.xml + ../pom.xml 4.0.0 diff --git a/federation/ldap/pom.xml b/federation/ldap/pom.xml index 5f8f887c99..0ce4c2e9c5 100755 --- a/federation/ldap/pom.xml +++ b/federation/ldap/pom.xml @@ -1,7 +1,7 @@ - keycloak-authentication-parent + keycloak-parent org.keycloak 1.0-beta-4-SNAPSHOT ../../pom.xml diff --git a/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPFederationProvider.java b/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPFederationProvider.java index 4215948965..f99af8286a 100755 --- a/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPFederationProvider.java +++ b/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPFederationProvider.java @@ -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 Bill Burke * @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 supportedCredentialTypes = new HashSet(); @@ -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; } diff --git a/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPFederationProviderFactory.java b/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPFederationProviderFactory.java index 6a0c57d64a..b656d7ac26 100755 --- a/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPFederationProviderFactory.java +++ b/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPFederationProviderFactory.java @@ -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 Bill Burke * @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); } diff --git a/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPUserModelDelegate.java b/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPUserModelDelegate.java index a2936d5d57..2a7fad51a9 100755 --- a/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPUserModelDelegate.java +++ b/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPUserModelDelegate.java @@ -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; diff --git a/federation/ldap/src/main/java/org/keycloak/federation/ldap/PartitionManagerRegistry.java b/federation/ldap/src/main/java/org/keycloak/federation/ldap/PartitionManagerRegistry.java index 860fb2e753..5c83bdaca0 100755 --- a/federation/ldap/src/main/java/org/keycloak/federation/ldap/PartitionManagerRegistry.java +++ b/federation/ldap/src/main/java/org/keycloak/federation/ldap/PartitionManagerRegistry.java @@ -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 partitionManagers = new ConcurrentHashMap(); - 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 diff --git a/federation/ldap/src/main/resources/META-INF/services/org.keycloak.models.FederationProviderFactory b/federation/ldap/src/main/resources/META-INF/services/org.keycloak.models.UserFederationProviderFactory similarity index 100% rename from federation/ldap/src/main/resources/META-INF/services/org.keycloak.models.FederationProviderFactory rename to federation/ldap/src/main/resources/META-INF/services/org.keycloak.models.UserFederationProviderFactory diff --git a/model/api/src/main/java/org/keycloak/models/FederationProviderFactory.java b/model/api/src/main/java/org/keycloak/models/FederationProviderFactory.java deleted file mode 100755 index 214b5b565c..0000000000 --- a/model/api/src/main/java/org/keycloak/models/FederationProviderFactory.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.keycloak.models; - -import org.keycloak.provider.ProviderFactory; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public interface FederationProviderFactory extends ProviderFactory { - FederationProvider getInstance(KeycloakSession session, FederationProviderModel model); -} diff --git a/model/api/src/main/java/org/keycloak/models/KeycloakSession.java b/model/api/src/main/java/org/keycloak/models/KeycloakSession.java index 908093ef21..506d211b25 100755 --- a/model/api/src/main/java/org/keycloak/models/KeycloakSession.java +++ b/model/api/src/main/java/org/keycloak/models/KeycloakSession.java @@ -20,6 +20,8 @@ public interface KeycloakSession { Set getAllProviders(Class clazz); + void enlistForClose(Provider provider); + KeycloakSessionFactory getKeycloakSessionFactory(); /** diff --git a/model/api/src/main/java/org/keycloak/models/RealmModel.java b/model/api/src/main/java/org/keycloak/models/RealmModel.java index 3117584e1c..c1afcf53eb 100755 --- a/model/api/src/main/java/org/keycloak/models/RealmModel.java +++ b/model/api/src/main/java/org/keycloak/models/RealmModel.java @@ -165,9 +165,9 @@ public interface RealmModel extends RoleContainerModel { void setAuthenticationProviders(List authenticationProviders); - List getFederationProviders(); + List getFederationProviders(); - void setFederationProviders(List providers); + void setFederationProviders(List providers); String getLoginTheme(); diff --git a/model/api/src/main/java/org/keycloak/models/FederationManager.java b/model/api/src/main/java/org/keycloak/models/UserFederationManager.java similarity index 73% rename from model/api/src/main/java/org/keycloak/models/FederationManager.java rename to model/api/src/main/java/org/keycloak/models/UserFederationManager.java index 8e79ba1ff2..b94803b6ad 100755 --- a/model/api/src/main/java/org/keycloak/models/FederationManager.java +++ b/model/api/src/main/java/org/keycloak/models/UserFederationManager.java @@ -10,25 +10,25 @@ import java.util.Set; * @author Bill Burke * @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 users = new HashMap(); List 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 federationProviders = realm.getFederationProviders(); + List 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 users = new HashMap(); List 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 federationProviders = realm.getFederationProviders(); + List 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 users = new HashMap(); List 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 federationProviders = realm.getFederationProviders(); + List 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 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 input) { - FederationProvider link = getFederationLink(realm, user); + UserFederationProvider link = getFederationLink(realm, user); if (link != null) { if (link.getSupportedCredentialTypes().size() > 0) { List fedCreds = new ArrayList(); @@ -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 supportedCredentialTypes = link.getSupportedCredentialTypes(); if (supportedCredentialTypes.size() > 0) { diff --git a/model/api/src/main/java/org/keycloak/models/FederationProvider.java b/model/api/src/main/java/org/keycloak/models/UserFederationProvider.java similarity index 83% rename from model/api/src/main/java/org/keycloak/models/FederationProvider.java rename to model/api/src/main/java/org/keycloak/models/UserFederationProvider.java index a70cb252b6..9c25bbace9 100755 --- a/model/api/src/main/java/org/keycloak/models/FederationProvider.java +++ b/model/api/src/main/java/org/keycloak/models/UserFederationProvider.java @@ -7,7 +7,7 @@ import java.util.Set; * @author Bill Burke * @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); diff --git a/model/api/src/main/java/org/keycloak/models/UserFederationProviderFactory.java b/model/api/src/main/java/org/keycloak/models/UserFederationProviderFactory.java new file mode 100755 index 0000000000..b723f3dd74 --- /dev/null +++ b/model/api/src/main/java/org/keycloak/models/UserFederationProviderFactory.java @@ -0,0 +1,11 @@ +package org.keycloak.models; + +import org.keycloak.provider.ProviderFactory; + +/** + * @author Bill Burke + * @version $Revision: 1 $ + */ +public interface UserFederationProviderFactory extends ProviderFactory { + UserFederationProvider getInstance(KeycloakSession session, UserFederationProviderModel model); +} diff --git a/model/api/src/main/java/org/keycloak/models/FederationProviderModel.java b/model/api/src/main/java/org/keycloak/models/UserFederationProviderModel.java similarity index 82% rename from model/api/src/main/java/org/keycloak/models/FederationProviderModel.java rename to model/api/src/main/java/org/keycloak/models/UserFederationProviderModel.java index 075d75d4e2..35fd727aa6 100755 --- a/model/api/src/main/java/org/keycloak/models/FederationProviderModel.java +++ b/model/api/src/main/java/org/keycloak/models/UserFederationProviderModel.java @@ -7,15 +7,15 @@ import java.util.Map; * @author Marek Posolda * @author Bill Burke */ -public class FederationProviderModel { +public class UserFederationProviderModel { private String id; private String providerName; private Map config = new HashMap(); - public FederationProviderModel() {}; + public UserFederationProviderModel() {}; - public FederationProviderModel(String id, String providerName, Map config) { + public UserFederationProviderModel(String id, String providerName, Map config) { this.id = id; this.providerName = providerName; if (config != null) { diff --git a/model/api/src/main/java/org/keycloak/models/FederationSpi.java b/model/api/src/main/java/org/keycloak/models/UserFederationSpi.java similarity index 71% rename from model/api/src/main/java/org/keycloak/models/FederationSpi.java rename to model/api/src/main/java/org/keycloak/models/UserFederationSpi.java index c427ec924d..6a22337f3e 100755 --- a/model/api/src/main/java/org/keycloak/models/FederationSpi.java +++ b/model/api/src/main/java/org/keycloak/models/UserFederationSpi.java @@ -7,21 +7,21 @@ import org.keycloak.provider.Spi; /** * @author Stian Thorgersen */ -public class FederationSpi implements Spi { +public class UserFederationSpi implements Spi { @Override public String getName() { - return "federation"; + return "userFederation"; } @Override public Class getProviderClass() { - return FederationProvider.class; + return UserFederationProvider.class; } @Override public Class getProviderFactoryClass() { - return FederationProviderFactory.class; + return UserFederationProviderFactory.class; } } diff --git a/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java b/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java index 227218343d..2fc5893446 100755 --- a/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java +++ b/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java @@ -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 fedProviderModels = realm.getFederationProviders(); + List fedProviderModels = realm.getFederationProviders(); if (fedProviderModels.size() > 0) { List fedProviderReps = new ArrayList(); - for (FederationProviderModel model : fedProviderModels) { + for (UserFederationProviderModel model : fedProviderModels) { FederationProviderRepresentation fedProvRep = new FederationProviderRepresentation(); fedProvRep.setId(model.getId()); fedProvRep.setProviderName(model.getProviderName()); diff --git a/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java b/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java index 5aa8888eff..51a5ce73c7 100755 --- a/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java +++ b/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java @@ -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 providerModels = convertFederationProviders(rep.getFederationProviders()); + List providerModels = convertFederationProviders(rep.getFederationProviders()); newRealm.setFederationProviders(providerModels); } @@ -288,7 +288,7 @@ public class RepresentationToModel { } if (rep.getFederationProviders() != null) { - List providerModels = convertFederationProviders(rep.getFederationProviders()); + List providerModels = convertFederationProviders(rep.getFederationProviders()); realm.setFederationProviders(providerModels); } @@ -315,11 +315,11 @@ public class RepresentationToModel { return result; } - private static List convertFederationProviders(List providers) { - List result = new ArrayList(); + private static List convertFederationProviders(List providers) { + List result = new ArrayList(); 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); } diff --git a/model/api/src/main/resources/META-INF/services/org.keycloak.provider.Spi b/model/api/src/main/resources/META-INF/services/org.keycloak.provider.Spi index 58ccc7bbf0..e0718949e4 100755 --- a/model/api/src/main/resources/META-INF/services/org.keycloak.provider.Spi +++ b/model/api/src/main/resources/META-INF/services/org.keycloak.provider.Spi @@ -1,4 +1,4 @@ -org.keycloak.models.FederationSpi +org.keycloak.models.UserFederationSpi org.keycloak.models.RealmSpi org.keycloak.models.UserSessionSpi org.keycloak.models.UserSpi \ No newline at end of file diff --git a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/RealmAdapter.java b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/RealmAdapter.java index deed00b702..d280a20131 100755 --- a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/RealmAdapter.java +++ b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/RealmAdapter.java @@ -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 getFederationProviders() { + public List getFederationProviders() { if (updated != null) return updated.getFederationProviders(); return cached.getFederationProviders(); } @Override - public void setFederationProviders(List providers) { + public void setFederationProviders(List providers) { getDelegateForUpdate(); updated.setFederationProviders(providers); } diff --git a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/UserAdapter.java b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/UserAdapter.java index a431ff95c0..9f4ffe3d48 100755 --- a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/UserAdapter.java +++ b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/UserAdapter.java @@ -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; diff --git a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedRealm.java b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedRealm.java index cfd6018812..292b174764 100755 --- a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedRealm.java +++ b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedRealm.java @@ -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 requiredCredentials = new ArrayList(); private List authenticationProviders = new ArrayList(); - private List federationProviders = new ArrayList(); + private List federationProviders = new ArrayList(); private Map smtpConfig = new HashMap(); private Map socialConfig = new HashMap(); @@ -331,7 +331,7 @@ public class CachedRealm { return auditListeners; } - public List getFederationProviders() { + public List getFederationProviders() { return federationProviders; } } diff --git a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedUser.java b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedUser.java index 83f432d978..a376012373 100755 --- a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedUser.java +++ b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/entities/CachedUser.java @@ -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; diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java index 9c988d19cc..4312ce7814 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java @@ -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 getFederationProviders() { + public List getFederationProviders() { List entities = realm.getFederationProviders(); List copy = new ArrayList(); for (FederationProviderEntity entity : entities) { @@ -748,19 +742,19 @@ public class RealmAdapter implements RealmModel { } }); - List result = new ArrayList(); + List result = new ArrayList(); 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 providers) { + public void setFederationProviders(List providers) { List newEntities = new ArrayList(); int counter = 1; - for (FederationProviderModel model : providers) { + for (UserFederationProviderModel model : providers) { FederationProviderEntity entity = new FederationProviderEntity(); entity.setId(KeycloakModelUtils.generateId()); entity.setRealm(realm); diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/UserAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/UserAdapter.java index 4687908a33..949efba293 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/UserAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/UserAdapter.java @@ -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; diff --git a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java index 713d08c983..003523599a 100755 --- a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java +++ b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java @@ -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 impleme updateRealm(); } @Override - public List getFederationProviders() { + public List getFederationProviders() { List entities = realm.getFederationProviders(); - List result = new ArrayList(); + List result = new ArrayList(); 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 providers) { + public void setFederationProviders(List providers) { List entities = new ArrayList(); - for (FederationProviderModel model : providers) { + for (UserFederationProviderModel model : providers) { FederationProviderEntity entity = new FederationProviderEntity(); entity.setId(KeycloakModelUtils.generateId()); entity.setProviderName(model.getProviderName()); diff --git a/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java b/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java index 73299bf91f..b6b55c8514 100755 --- a/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java +++ b/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java @@ -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 providers = new HashMap(); + private final List closable = new LinkedList(); 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()) { - p.close(); + try { + p.close(); + } catch (Exception e) { + } + } + for (Provider p : closable) { + try { + p.close(); + } catch (Exception e) { + } } } diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/forms/FederationProvidersIntegrationTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/forms/FederationProvidersIntegrationTest.java index 56221f822c..b1c3fd1674 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/forms/FederationProvidersIntegrationTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/forms/FederationProvidersIntegrationTest.java @@ -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