JSON migration
This commit is contained in:
parent
91283878ac
commit
7badd3d5e5
2 changed files with 26 additions and 11 deletions
|
@ -266,6 +266,10 @@ public class RealmRepresentation {
|
||||||
this.codeSecret = codeSecret;
|
this.codeSecret = codeSecret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean isPasswordCredentialGrantAllowed() {
|
||||||
|
return passwordCredentialGrantAllowed;
|
||||||
|
}
|
||||||
|
|
||||||
public Boolean isRegistrationAllowed() {
|
public Boolean isRegistrationAllowed() {
|
||||||
return registrationAllowed;
|
return registrationAllowed;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.LDAPConstants;
|
import org.keycloak.models.LDAPConstants;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.UserFederationEventAwareProviderFactory;
|
import org.keycloak.models.UserFederationEventAwareProviderFactory;
|
||||||
|
import org.keycloak.models.UserFederationMapperModel;
|
||||||
import org.keycloak.models.UserFederationProvider;
|
import org.keycloak.models.UserFederationProvider;
|
||||||
import org.keycloak.models.UserFederationProviderFactory;
|
import org.keycloak.models.UserFederationProviderFactory;
|
||||||
import org.keycloak.models.UserFederationProviderModel;
|
import org.keycloak.models.UserFederationProviderModel;
|
||||||
|
@ -12,6 +13,7 @@ import org.keycloak.models.utils.DefaultAuthenticationFlows;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.naming.directory.SearchControls;
|
import javax.naming.directory.SearchControls;
|
||||||
|
|
||||||
|
@ -43,29 +45,38 @@ public class MigrateTo1_3_0_Beta1 {
|
||||||
Map<String, String> config = fedProvider.getConfig();
|
Map<String, String> config = fedProvider.getConfig();
|
||||||
|
|
||||||
// Update config properties for LDAP federation provider
|
// Update config properties for LDAP federation provider
|
||||||
config.put(LDAPConstants.SEARCH_SCOPE, String.valueOf(SearchControls.SUBTREE_SCOPE));
|
if (config.get(LDAPConstants.SEARCH_SCOPE) == null) {
|
||||||
|
config.put(LDAPConstants.SEARCH_SCOPE, String.valueOf(SearchControls.SUBTREE_SCOPE));
|
||||||
|
}
|
||||||
|
|
||||||
String usersDn = config.remove("userDnSuffix");
|
String usersDn = config.remove("userDnSuffix");
|
||||||
config.put(LDAPConstants.USERS_DN, usersDn);
|
if (usersDn != null && config.get(LDAPConstants.USERS_DN) == null) {
|
||||||
|
config.put(LDAPConstants.USERS_DN, usersDn);
|
||||||
|
}
|
||||||
|
|
||||||
String rdnLdapAttribute = config.get(LDAPConstants.USERNAME_LDAP_ATTRIBUTE);
|
String usernameLdapAttribute = config.get(LDAPConstants.USERNAME_LDAP_ATTRIBUTE);
|
||||||
if (rdnLdapAttribute != null) {
|
if (usernameLdapAttribute != null && config.get(LDAPConstants.RDN_LDAP_ATTRIBUTE) == null) {
|
||||||
if (rdnLdapAttribute.equalsIgnoreCase(LDAPConstants.SAM_ACCOUNT_NAME)) {
|
if (usernameLdapAttribute.equalsIgnoreCase(LDAPConstants.SAM_ACCOUNT_NAME)) {
|
||||||
config.put(LDAPConstants.RDN_LDAP_ATTRIBUTE, LDAPConstants.CN);
|
config.put(LDAPConstants.RDN_LDAP_ATTRIBUTE, LDAPConstants.CN);
|
||||||
} else {
|
} else {
|
||||||
config.put(LDAPConstants.RDN_LDAP_ATTRIBUTE, rdnLdapAttribute);
|
config.put(LDAPConstants.RDN_LDAP_ATTRIBUTE, usernameLdapAttribute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String uuidAttrName = LDAPConstants.getUuidAttributeName(config.get(LDAPConstants.VENDOR));
|
if (config.get(LDAPConstants.UUID_LDAP_ATTRIBUTE) == null) {
|
||||||
config.put(LDAPConstants.UUID_LDAP_ATTRIBUTE, uuidAttrName);
|
String uuidAttrName = LDAPConstants.getUuidAttributeName(config.get(LDAPConstants.VENDOR));
|
||||||
|
config.put(LDAPConstants.UUID_LDAP_ATTRIBUTE, uuidAttrName);
|
||||||
|
}
|
||||||
|
|
||||||
realm.updateUserFederationProvider(fedProvider);
|
realm.updateUserFederationProvider(fedProvider);
|
||||||
|
|
||||||
// Create default mappers for LDAP
|
// Create default mappers for LDAP
|
||||||
UserFederationProviderFactory ldapFactory = (UserFederationProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(UserFederationProvider.class, LDAPConstants.LDAP_PROVIDER);
|
Set<UserFederationMapperModel> mappers = realm.getUserFederationMappersByFederationProvider(fedProvider.getId());
|
||||||
if (ldapFactory != null) {
|
if (mappers.isEmpty()) {
|
||||||
((UserFederationEventAwareProviderFactory) ldapFactory).onProviderModelCreated(realm, fedProvider);
|
UserFederationProviderFactory ldapFactory = (UserFederationProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(UserFederationProvider.class, LDAPConstants.LDAP_PROVIDER);
|
||||||
|
if (ldapFactory != null) {
|
||||||
|
((UserFederationEventAwareProviderFactory) ldapFactory).onProviderModelCreated(realm, fedProvider);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue