This commit is contained in:
Bill Burke 2014-07-25 10:40:46 -04:00
parent 81dfea4052
commit b1cd37814a
12 changed files with 48 additions and 50 deletions

View file

@ -1,7 +1,5 @@
package org.keycloak.representations.idm;
import org.keycloak.representations.FederationProviderRepresentation;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -58,7 +56,7 @@ public class RealmRepresentation {
protected Map<String, String> smtpServer;
protected Map<String, String> ldapServer;
protected List<AuthenticationProviderRepresentation> authenticationProviders;
protected List<FederationProviderRepresentation> federationProviders;
protected List<UserFederationProviderRepresentation> userFederationProviders;
protected String loginTheme;
protected String accountTheme;
protected String adminTheme;
@ -471,11 +469,11 @@ public class RealmRepresentation {
this.auditListeners = auditListeners;
}
public List<FederationProviderRepresentation> getFederationProviders() {
return federationProviders;
public List<UserFederationProviderRepresentation> getUserFederationProviders() {
return userFederationProviders;
}
public void setFederationProviders(List<FederationProviderRepresentation> federationProviders) {
this.federationProviders = federationProviders;
public void setUserFederationProviders(List<UserFederationProviderRepresentation> userFederationProviders) {
this.userFederationProviders = userFederationProviders;
}
}

View file

@ -1,11 +1,11 @@
package org.keycloak.representations;
package org.keycloak.representations.idm;
import java.util.Map;
/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
public class FederationProviderRepresentation {
public class UserFederationProviderRepresentation {
private String id;
private String providerName;
@ -41,7 +41,7 @@ public class FederationProviderRepresentation {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FederationProviderRepresentation that = (FederationProviderRepresentation) o;
UserFederationProviderRepresentation that = (UserFederationProviderRepresentation) o;
if (!id.equals(that.id)) return false;

View file

@ -267,12 +267,12 @@ public class LDAPFederationProvider implements UserFederationProvider {
@Override
public void preRemove(RealmModel realm) {
//To change body of implemented methods use File | Settings | File Templates.
// complete Don't think we have to do anything
}
@Override
public void preRemove(RealmModel realm, RoleModel role) {
//To change body of implemented methods use File | Settings | File Templates.
// complete I don't think we have to do anything here
}
public boolean validPassword(String username, String password) {

View file

@ -165,9 +165,9 @@ public interface RealmModel extends RoleContainerModel {
void setAuthenticationProviders(List<AuthenticationProviderModel> authenticationProviders);
List<UserFederationProviderModel> getFederationProviders();
List<UserFederationProviderModel> getUserFederationProviders();
void setFederationProviders(List<UserFederationProviderModel> providers);
void setUserFederationProviders(List<UserFederationProviderModel> providers);
String getLoginTheme();

View file

@ -20,7 +20,7 @@ public class UserFederationManager implements UserProvider {
@Override
public UserModel addUser(RealmModel realm, String id, String username, boolean addDefaultRoles) {
UserModel user = session.userStorage().addUser(realm, id, username, addDefaultRoles);
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
for (UserFederationProviderModel federation : realm.getUserFederationProviders()) {
UserFederationProvider fed = session.getProvider(UserFederationProvider.class, federation.getProviderName());
return fed.addUser(realm, user);
}
@ -36,7 +36,7 @@ public class UserFederationManager implements UserProvider {
@Override
public UserModel addUser(RealmModel realm, String username) {
UserModel user = session.userStorage().addUser(realm, username);
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
for (UserFederationProviderModel federation : realm.getUserFederationProviders()) {
UserFederationProvider fed = getFederationProvider(federation);
return fed.addUser(realm, user);
}
@ -45,7 +45,7 @@ public class UserFederationManager implements UserProvider {
protected UserFederationProvider getFederationLink(RealmModel realm, UserModel user) {
if (user.getFederationLink() == null) return null;
for (UserFederationProviderModel fed : realm.getFederationProviders()) {
for (UserFederationProviderModel fed : realm.getUserFederationProviders()) {
if (fed.getId().equals(user.getFederationLink())) {
return getFederationProvider(fed);
}
@ -95,7 +95,7 @@ public class UserFederationManager implements UserProvider {
}
return user;
}
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
for (UserFederationProviderModel federation : realm.getUserFederationProviders()) {
UserFederationProvider fed = getFederationProvider(federation);
user = fed.getUserById(id, realm);
if (user != null) return user;
@ -113,7 +113,7 @@ public class UserFederationManager implements UserProvider {
}
return user;
}
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
for (UserFederationProviderModel federation : realm.getUserFederationProviders()) {
UserFederationProvider fed = getFederationProvider(federation);
user = fed.getUserByUsername(username, realm);
if (user != null) return user;
@ -131,7 +131,7 @@ public class UserFederationManager implements UserProvider {
}
return user;
}
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
for (UserFederationProviderModel federation : realm.getUserFederationProviders()) {
UserFederationProvider fed = getFederationProvider(federation);
user = fed.getUserByEmail(email, realm);
if (user != null) return user;
@ -149,7 +149,7 @@ public class UserFederationManager implements UserProvider {
}
return user;
}
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
for (UserFederationProviderModel federation : realm.getUserFederationProviders()) {
UserFederationProvider fed = getFederationProvider(federation);
user = fed.getUserBySocialLink(socialLink, realm);
if (user != null) return user;
@ -185,7 +185,7 @@ public class UserFederationManager implements UserProvider {
results.addAll(users.values());
return results;
}
List<UserFederationProviderModel> federationProviders = realm.getFederationProviders();
List<UserFederationProviderModel> federationProviders = realm.getUserFederationProviders();
for (int i = federationProviders.size() - 1; i >= 0; i--) {
UserFederationProviderModel federation = federationProviders.get(i);
UserFederationProvider fed = getFederationProvider(federation);
@ -219,7 +219,7 @@ public class UserFederationManager implements UserProvider {
results.addAll(users.values());
return results;
}
List<UserFederationProviderModel> federationProviders = realm.getFederationProviders();
List<UserFederationProviderModel> federationProviders = realm.getUserFederationProviders();
for (int i = federationProviders.size() - 1; i >= 0; i--) {
UserFederationProviderModel federation = federationProviders.get(i);
UserFederationProvider fed = getFederationProvider(federation);
@ -253,7 +253,7 @@ public class UserFederationManager implements UserProvider {
results.addAll(users.values());
return results;
}
List<UserFederationProviderModel> federationProviders = realm.getFederationProviders();
List<UserFederationProviderModel> federationProviders = realm.getUserFederationProviders();
for (int i = federationProviders.size() - 1; i >= 0; i--) {
UserFederationProviderModel federation = federationProviders.get(i);
UserFederationProvider fed = getFederationProvider(federation);
@ -285,7 +285,7 @@ public class UserFederationManager implements UserProvider {
@Override
public void preRemove(RealmModel realm) {
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
for (UserFederationProviderModel federation : realm.getUserFederationProviders()) {
UserFederationProvider fed = getFederationProvider(federation);
fed.preRemove(realm);
}
@ -294,7 +294,7 @@ public class UserFederationManager implements UserProvider {
@Override
public void preRemove(RealmModel realm, RoleModel role) {
for (UserFederationProviderModel federation : realm.getFederationProviders()) {
for (UserFederationProviderModel federation : realm.getUserFederationProviders()) {
UserFederationProvider fed = getFederationProvider(federation);
fed.preRemove(realm, role);
}

View file

@ -14,7 +14,7 @@ import org.keycloak.models.SocialLinkModel;
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.UserSessionModel;
import org.keycloak.representations.FederationProviderRepresentation;
import org.keycloak.representations.idm.UserFederationProviderRepresentation;
import org.keycloak.representations.idm.ApplicationRepresentation;
import org.keycloak.representations.idm.AuthenticationProviderRepresentation;
import org.keycloak.representations.idm.ClaimRepresentation;
@ -143,17 +143,17 @@ public class ModelToRepresentation {
}
rep.setAuthenticationProviders(authProviderReps);
}
List<UserFederationProviderModel> fedProviderModels = realm.getFederationProviders();
List<UserFederationProviderModel> fedProviderModels = realm.getUserFederationProviders();
if (fedProviderModels.size() > 0) {
List<FederationProviderRepresentation> fedProviderReps = new ArrayList<FederationProviderRepresentation>();
List<UserFederationProviderRepresentation> fedProviderReps = new ArrayList<UserFederationProviderRepresentation>();
for (UserFederationProviderModel model : fedProviderModels) {
FederationProviderRepresentation fedProvRep = new FederationProviderRepresentation();
UserFederationProviderRepresentation fedProvRep = new UserFederationProviderRepresentation();
fedProvRep.setId(model.getId());
fedProvRep.setProviderName(model.getProviderName());
fedProvRep.setConfig(model.getConfig());
fedProviderReps.add(fedProvRep);
}
rep.setFederationProviders(fedProviderReps);
rep.setUserFederationProviders(fedProviderReps);
}
return rep;
}

View file

@ -17,7 +17,7 @@ import org.keycloak.models.SocialLinkModel;
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserCredentialValueModel;
import org.keycloak.models.UserModel;
import org.keycloak.representations.FederationProviderRepresentation;
import org.keycloak.representations.idm.UserFederationProviderRepresentation;
import org.keycloak.representations.idm.ApplicationRepresentation;
import org.keycloak.representations.idm.AuthenticationLinkRepresentation;
import org.keycloak.representations.idm.AuthenticationProviderRepresentation;
@ -215,9 +215,9 @@ public class RepresentationToModel {
newRealm.setAuthenticationProviders(authProviderModels);
}
if (rep.getFederationProviders() != null) {
List<UserFederationProviderModel> providerModels = convertFederationProviders(rep.getFederationProviders());
newRealm.setFederationProviders(providerModels);
if (rep.getUserFederationProviders() != null) {
List<UserFederationProviderModel> providerModels = convertFederationProviders(rep.getUserFederationProviders());
newRealm.setUserFederationProviders(providerModels);
}
// create users and their role mappings and social mappings
@ -287,9 +287,9 @@ public class RepresentationToModel {
realm.setAuthenticationProviders(authProviderModels);
}
if (rep.getFederationProviders() != null) {
List<UserFederationProviderModel> providerModels = convertFederationProviders(rep.getFederationProviders());
realm.setFederationProviders(providerModels);
if (rep.getUserFederationProviders() != null) {
List<UserFederationProviderModel> providerModels = convertFederationProviders(rep.getUserFederationProviders());
realm.setUserFederationProviders(providerModels);
}
if ("GENERATE".equals(rep.getPublicKey())) {
@ -315,10 +315,10 @@ public class RepresentationToModel {
return result;
}
private static List<UserFederationProviderModel> convertFederationProviders(List<FederationProviderRepresentation> providers) {
private static List<UserFederationProviderModel> convertFederationProviders(List<UserFederationProviderRepresentation> providers) {
List<UserFederationProviderModel> result = new ArrayList<UserFederationProviderModel>();
for (FederationProviderRepresentation representation : providers) {
for (UserFederationProviderRepresentation representation : providers) {
UserFederationProviderModel model = new UserFederationProviderModel(representation.getId(), representation.getProviderName(),
representation.getConfig());
result.add(model);

View file

@ -606,15 +606,15 @@ public class RealmAdapter implements RealmModel {
}
@Override
public List<UserFederationProviderModel> getFederationProviders() {
if (updated != null) return updated.getFederationProviders();
public List<UserFederationProviderModel> getUserFederationProviders() {
if (updated != null) return updated.getUserFederationProviders();
return cached.getFederationProviders();
}
@Override
public void setFederationProviders(List<UserFederationProviderModel> providers) {
public void setUserFederationProviders(List<UserFederationProviderModel> providers) {
getDelegateForUpdate();
updated.setFederationProviders(providers);
updated.setUserFederationProviders(providers);
}
@Override

View file

@ -122,7 +122,7 @@ public class CachedRealm {
requiredCredentials = model.getRequiredCredentials();
authenticationProviders = model.getAuthenticationProviders();
federationProviders = model.getFederationProviders();
federationProviders = model.getUserFederationProviders();
smtpConfig.putAll(model.getSmtpConfig());
socialConfig.putAll(model.getSocialConfig());

View file

@ -727,7 +727,7 @@ public class RealmAdapter implements RealmModel {
}
@Override
public List<UserFederationProviderModel> getFederationProviders() {
public List<UserFederationProviderModel> getUserFederationProviders() {
List<FederationProviderEntity> entities = realm.getFederationProviders();
List<FederationProviderEntity> copy = new ArrayList<FederationProviderEntity>();
for (FederationProviderEntity entity : entities) {
@ -751,7 +751,7 @@ public class RealmAdapter implements RealmModel {
}
@Override
public void setFederationProviders(List<UserFederationProviderModel> providers) {
public void setUserFederationProviders(List<UserFederationProviderModel> providers) {
List<FederationProviderEntity> newEntities = new ArrayList<FederationProviderEntity>();
int counter = 1;
for (UserFederationProviderModel model : providers) {

View file

@ -791,7 +791,7 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
updateRealm();
}
@Override
public List<UserFederationProviderModel> getFederationProviders() {
public List<UserFederationProviderModel> getUserFederationProviders() {
List<FederationProviderEntity> entities = realm.getFederationProviders();
List<UserFederationProviderModel> result = new ArrayList<UserFederationProviderModel>();
for (FederationProviderEntity entity : entities) {
@ -802,7 +802,7 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
}
@Override
public void setFederationProviders(List<UserFederationProviderModel> providers) {
public void setUserFederationProviders(List<UserFederationProviderModel> providers) {
List<FederationProviderEntity> entities = new ArrayList<FederationProviderEntity>();
for (UserFederationProviderModel model : providers) {
FederationProviderEntity entity = new FederationProviderEntity();

View file

@ -62,7 +62,7 @@ public class FederationProvidersIntegrationTest {
UserFederationProviderModel ldapProvider = new UserFederationProviderModel(null, LDAPFederationProviderFactory.PROVIDER_NAME, ldapConfig);
appRealm.setFederationProviders(Arrays.asList(ldapProvider));
appRealm.setUserFederationProviders(Arrays.asList(ldapProvider));
// Configure LDAP
ldapRule.getEmbeddedServer().setupLdapInRealm(appRealm);