commit
3631635487
6 changed files with 96 additions and 31 deletions
|
@ -26,9 +26,10 @@ public class DefaultMongoConnectionFactoryProvider implements MongoConnectionPro
|
||||||
"org.keycloak.models.mongo.keycloak.entities.MongoRealmEntity",
|
"org.keycloak.models.mongo.keycloak.entities.MongoRealmEntity",
|
||||||
"org.keycloak.models.mongo.keycloak.entities.MongoUserEntity",
|
"org.keycloak.models.mongo.keycloak.entities.MongoUserEntity",
|
||||||
"org.keycloak.models.mongo.keycloak.entities.MongoRoleEntity",
|
"org.keycloak.models.mongo.keycloak.entities.MongoRoleEntity",
|
||||||
|
"org.keycloak.models.entities.IdentityProviderEntity",
|
||||||
"org.keycloak.models.entities.RequiredCredentialEntity",
|
"org.keycloak.models.entities.RequiredCredentialEntity",
|
||||||
"org.keycloak.models.entities.CredentialEntity",
|
"org.keycloak.models.entities.CredentialEntity",
|
||||||
"org.keycloak.models.entities.SocialLinkEntity",
|
"org.keycloak.models.entities.FederatedIdentityEntity",
|
||||||
"org.keycloak.models.mongo.keycloak.entities.MongoApplicationEntity",
|
"org.keycloak.models.mongo.keycloak.entities.MongoApplicationEntity",
|
||||||
"org.keycloak.models.mongo.keycloak.entities.MongoOAuthClientEntity",
|
"org.keycloak.models.mongo.keycloak.entities.MongoOAuthClientEntity",
|
||||||
"org.keycloak.models.sessions.mongo.entities.MongoUsernameLoginFailureEntity",
|
"org.keycloak.models.sessions.mongo.entities.MongoUsernameLoginFailureEntity",
|
||||||
|
|
|
@ -25,19 +25,13 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class IdentityProviderEntity {
|
public class IdentityProviderEntity {
|
||||||
|
|
||||||
private String id;
|
|
||||||
private String name;
|
private String name;
|
||||||
private String iconUrl;
|
private boolean enabled;
|
||||||
|
private boolean updateProfileFirstLogin;
|
||||||
|
private String providerId;
|
||||||
|
private String id;
|
||||||
private Map<String, String> config = new HashMap<String, String>();
|
private Map<String, String> config = new HashMap<String, String>();
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
@ -46,12 +40,36 @@ public class IdentityProviderEntity {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIconUrl() {
|
public boolean isEnabled() {
|
||||||
return this.iconUrl;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIconUrl(String iconUrl) {
|
public void setEnabled(boolean enabled) {
|
||||||
this.iconUrl = iconUrl;
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUpdateProfileFirstLogin() {
|
||||||
|
return updateProfileFirstLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdateProfileFirstLogin(boolean updateProfileFirstLogin) {
|
||||||
|
this.updateProfileFirstLogin = updateProfileFirstLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProviderId() {
|
||||||
|
return providerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProviderId(String providerId) {
|
||||||
|
this.providerId = providerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String providerNonimalId) {
|
||||||
|
this.id = providerNonimalId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getConfig() {
|
public Map<String, String> getConfig() {
|
||||||
|
|
|
@ -18,7 +18,6 @@ public class RealmEntity extends AbstractIdentifiableEntity {
|
||||||
private boolean verifyEmail;
|
private boolean verifyEmail;
|
||||||
private boolean passwordCredentialGrantAllowed;
|
private boolean passwordCredentialGrantAllowed;
|
||||||
private boolean resetPasswordAllowed;
|
private boolean resetPasswordAllowed;
|
||||||
private boolean social;
|
|
||||||
private String passwordPolicy;
|
private String passwordPolicy;
|
||||||
//--- brute force settings
|
//--- brute force settings
|
||||||
private boolean bruteForceProtected;
|
private boolean bruteForceProtected;
|
||||||
|
@ -52,6 +51,7 @@ public class RealmEntity extends AbstractIdentifiableEntity {
|
||||||
|
|
||||||
private List<RequiredCredentialEntity> requiredCredentials = new ArrayList<RequiredCredentialEntity>();
|
private List<RequiredCredentialEntity> requiredCredentials = new ArrayList<RequiredCredentialEntity>();
|
||||||
private List<UserFederationProviderEntity> userFederationProviders = new ArrayList<UserFederationProviderEntity>();
|
private List<UserFederationProviderEntity> userFederationProviders = new ArrayList<UserFederationProviderEntity>();
|
||||||
|
private List<IdentityProviderEntity> identityProviders = new ArrayList<IdentityProviderEntity>();
|
||||||
|
|
||||||
private Map<String, String> browserSecurityHeaders = new HashMap<String, String>();
|
private Map<String, String> browserSecurityHeaders = new HashMap<String, String>();
|
||||||
private Map<String, String> smtpConfig = new HashMap<String, String>();
|
private Map<String, String> smtpConfig = new HashMap<String, String>();
|
||||||
|
@ -375,6 +375,14 @@ public class RealmEntity extends AbstractIdentifiableEntity {
|
||||||
this.userFederationProviders = userFederationProviders;
|
this.userFederationProviders = userFederationProviders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<IdentityProviderEntity> getIdentityProviders() {
|
||||||
|
return identityProviders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdentityProviders(List<IdentityProviderEntity> identityProviders) {
|
||||||
|
this.identityProviders = identityProviders;
|
||||||
|
}
|
||||||
|
|
||||||
public String getCertificatePem() {
|
public String getCertificatePem() {
|
||||||
return certificatePem;
|
return certificatePem;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class UserEntity extends AbstractIdentifiableEntity {
|
||||||
private Map<String, String> attributes;
|
private Map<String, String> attributes;
|
||||||
private List<UserModel.RequiredAction> requiredActions;
|
private List<UserModel.RequiredAction> requiredActions;
|
||||||
private List<CredentialEntity> credentials = new ArrayList<CredentialEntity>();
|
private List<CredentialEntity> credentials = new ArrayList<CredentialEntity>();
|
||||||
private List<FederatedIdentityEntity> socialLinks;
|
private List<FederatedIdentityEntity> federatedIdentities;
|
||||||
private String federationLink;
|
private String federationLink;
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
|
@ -125,12 +125,12 @@ public class UserEntity extends AbstractIdentifiableEntity {
|
||||||
this.credentials = credentials;
|
this.credentials = credentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FederatedIdentityEntity> getSocialLinks() {
|
public List<FederatedIdentityEntity> getFederatedIdentities() {
|
||||||
return socialLinks;
|
return federatedIdentities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSocialLinks(List<FederatedIdentityEntity> socialLinks) {
|
public void setFederatedIdentities(List<FederatedIdentityEntity> federatedIdentities) {
|
||||||
this.socialLinks = socialLinks;
|
this.federatedIdentities = federatedIdentities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFederationLink() {
|
public String getFederationLink() {
|
||||||
|
|
|
@ -216,7 +216,7 @@ public class MongoUserProvider implements UserProvider {
|
||||||
public Set<FederatedIdentityModel> getFederatedIdentities(UserModel userModel, RealmModel realm) {
|
public Set<FederatedIdentityModel> getFederatedIdentities(UserModel userModel, RealmModel realm) {
|
||||||
UserModel user = getUserById(userModel.getId(), realm);
|
UserModel user = getUserById(userModel.getId(), realm);
|
||||||
MongoUserEntity userEntity = ((UserAdapter) user).getUser();
|
MongoUserEntity userEntity = ((UserAdapter) user).getUser();
|
||||||
List<FederatedIdentityEntity> linkEntities = userEntity.getSocialLinks();
|
List<FederatedIdentityEntity> linkEntities = userEntity.getFederatedIdentities();
|
||||||
|
|
||||||
if (linkEntities == null) {
|
if (linkEntities == null) {
|
||||||
return Collections.EMPTY_SET;
|
return Collections.EMPTY_SET;
|
||||||
|
@ -234,7 +234,7 @@ public class MongoUserProvider implements UserProvider {
|
||||||
private FederatedIdentityEntity findSocialLink(UserModel userModel, String socialProvider, RealmModel realm) {
|
private FederatedIdentityEntity findSocialLink(UserModel userModel, String socialProvider, RealmModel realm) {
|
||||||
UserModel user = getUserById(userModel.getId(), realm);
|
UserModel user = getUserById(userModel.getId(), realm);
|
||||||
MongoUserEntity userEntity = ((UserAdapter) user).getUser();
|
MongoUserEntity userEntity = ((UserAdapter) user).getUser();
|
||||||
List<FederatedIdentityEntity> linkEntities = userEntity.getSocialLinks();
|
List<FederatedIdentityEntity> linkEntities = userEntity.getFederatedIdentities();
|
||||||
if (linkEntities == null) {
|
if (linkEntities == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -311,21 +311,21 @@ public class MongoUserProvider implements UserProvider {
|
||||||
public boolean removeFederatedIdentity(RealmModel realm, UserModel userModel, String socialProvider) {
|
public boolean removeFederatedIdentity(RealmModel realm, UserModel userModel, String socialProvider) {
|
||||||
UserModel user = getUserById(userModel.getId(), realm);
|
UserModel user = getUserById(userModel.getId(), realm);
|
||||||
MongoUserEntity userEntity = ((UserAdapter) user).getUser();
|
MongoUserEntity userEntity = ((UserAdapter) user).getUser();
|
||||||
FederatedIdentityEntity federatedIdentityEntity = findSocialLink(userEntity, socialProvider);
|
FederatedIdentityEntity federatedIdentityEntity = findFederatedIdentityLink(userEntity, socialProvider);
|
||||||
if (federatedIdentityEntity == null) {
|
if (federatedIdentityEntity == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return getMongoStore().pullItemFromList(userEntity, "federatedIdentities", federatedIdentityEntity, invocationContext);
|
return getMongoStore().pullItemFromList(userEntity, "federatedIdentities", federatedIdentityEntity, invocationContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FederatedIdentityEntity findSocialLink(MongoUserEntity userEntity, String socialProvider) {
|
private FederatedIdentityEntity findFederatedIdentityLink(MongoUserEntity userEntity, String identityProvider) {
|
||||||
List<FederatedIdentityEntity> linkEntities = userEntity.getSocialLinks();
|
List<FederatedIdentityEntity> linkEntities = userEntity.getFederatedIdentities();
|
||||||
if (linkEntities == null) {
|
if (linkEntities == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FederatedIdentityEntity federatedIdentityEntity : linkEntities) {
|
for (FederatedIdentityEntity federatedIdentityEntity : linkEntities) {
|
||||||
if (federatedIdentityEntity.getIdentityProvider().equals(socialProvider)) {
|
if (federatedIdentityEntity.getIdentityProvider().equals(identityProvider)) {
|
||||||
return federatedIdentityEntity;
|
return federatedIdentityEntity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.keycloak.models.RealmProvider;
|
||||||
import org.keycloak.models.RequiredCredentialModel;
|
import org.keycloak.models.RequiredCredentialModel;
|
||||||
import org.keycloak.models.RoleModel;
|
import org.keycloak.models.RoleModel;
|
||||||
import org.keycloak.models.UserFederationProviderModel;
|
import org.keycloak.models.UserFederationProviderModel;
|
||||||
|
import org.keycloak.models.entities.IdentityProviderEntity;
|
||||||
import org.keycloak.models.entities.RequiredCredentialEntity;
|
import org.keycloak.models.entities.RequiredCredentialEntity;
|
||||||
import org.keycloak.models.entities.UserFederationProviderEntity;
|
import org.keycloak.models.entities.UserFederationProviderEntity;
|
||||||
import org.keycloak.models.mongo.keycloak.entities.MongoApplicationEntity;
|
import org.keycloak.models.mongo.keycloak.entities.MongoApplicationEntity;
|
||||||
|
@ -783,22 +784,60 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IdentityProviderModel> getIdentityProviders() {
|
public List<IdentityProviderModel> getIdentityProviders() {
|
||||||
return null;
|
List<IdentityProviderModel> identityProviders = new ArrayList<IdentityProviderModel>();
|
||||||
|
|
||||||
|
for (IdentityProviderEntity entity: realm.getIdentityProviders()) {
|
||||||
|
IdentityProviderModel identityProviderModel = new IdentityProviderModel(entity.getProviderId(), entity.getId(), entity.getName(),
|
||||||
|
entity.getConfig());
|
||||||
|
|
||||||
|
identityProviderModel.setEnabled(entity.isEnabled());
|
||||||
|
identityProviderModel.setUpdateProfileFirstLogin(entity.isUpdateProfileFirstLogin());
|
||||||
|
|
||||||
|
identityProviders.add(identityProviderModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return identityProviders;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addIdentityProvider(IdentityProviderModel identityProvider) {
|
public void addIdentityProvider(IdentityProviderModel identityProvider) {
|
||||||
|
IdentityProviderEntity entity = new IdentityProviderEntity();
|
||||||
|
|
||||||
|
entity.setId(identityProvider.getId());
|
||||||
|
entity.setProviderId(identityProvider.getProviderId());
|
||||||
|
entity.setName(identityProvider.getName());
|
||||||
|
entity.setEnabled(identityProvider.isEnabled());
|
||||||
|
entity.setUpdateProfileFirstLogin(identityProvider.isUpdateProfileFirstLogin());
|
||||||
|
entity.setConfig(identityProvider.getConfig());
|
||||||
|
|
||||||
|
realm.getIdentityProviders().add(entity);
|
||||||
|
updateRealm();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeIdentityProviderById(String providerId) {
|
public void removeIdentityProviderById(String providerId) {
|
||||||
|
IdentityProviderEntity toRemove;
|
||||||
|
for (IdentityProviderEntity entity : realm.getIdentityProviders()) {
|
||||||
|
if (entity.getId().equals(providerId)) {
|
||||||
|
realm.getIdentityProviders().remove(entity);
|
||||||
|
updateRealm();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateIdentityProvider(IdentityProviderModel identityProvider) {
|
public void updateIdentityProvider(IdentityProviderModel identityProvider) {
|
||||||
|
for (IdentityProviderEntity entity : this.realm.getIdentityProviders()) {
|
||||||
|
if (entity.getId().equals(identityProvider.getId())) {
|
||||||
|
entity.setName(identityProvider.getName());
|
||||||
|
entity.setEnabled(identityProvider.isEnabled());
|
||||||
|
entity.setUpdateProfileFirstLogin(identityProvider.isUpdateProfileFirstLogin());
|
||||||
|
entity.setConfig(identityProvider.getConfig());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateRealm();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -963,8 +1002,7 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isIdentityFederationEnabled() {
|
public boolean isIdentityFederationEnabled() {
|
||||||
//TODO: support identity federation storage for mongo
|
return this.realm.getIdentityProviders() != null && !this.realm.getIdentityProviders().isEmpty();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue