federation/ldap/src/main/java/org/keycloak/federation/ldap/mappers/RoleLDAPFederationMapper.java
// Sync roles from LDAP tree and create them in local Keycloak DB (if they don't exist here yet)
Sync roles from LDAP tree and create them in local Keycloak DB (if they don't exist here yet)
Sync roles from LDAP tree and create them in local Keycloak DB ( if they don ' t exist here yet )
protected void syncRolesFromLDAP(UserFederationMapperModel mapperModel, LDAPFederationProvider ldapProvider, RealmModel realm) {
        if (!rolesSyncedModels.contains(mapperModel.getId())) {
            logger.debugf("Syncing roles from LDAP into Keycloak DB. Mapper is [%s], LDAP provider is [%s]", mapperModel.getName(), ldapProvider.getModel().getDisplayName());
            LDAPIdentityQuery ldapQuery = createRoleQuery(mapperModel, ldapProvider);
            List<LDAPObject> ldapRoles = ldapQuery.getResultList();
            RoleContainerModel roleContainer = getTargetRoleContainer(mapperModel, realm);
            String rolesRdnAttr = getRoleNameLdapAttribute(mapperModel);
            for (LDAPObject ldapRole : ldapRoles) {
                String roleName = ldapRole.getAttributeAsString(rolesRdnAttr);
                if (roleContainer.getRole(roleName) == null) {
                    logger.infof("Syncing role [%s] from LDAP to keycloak DB", roleName);
                    roleContainer.addRole(roleName);
                }
            }
            rolesSyncedModels.add(mapperModel.getId());
        }
    }
protected void syncRolesFromLDAP ( UserFederationMapperModel mapperModel , LDAPFederationProvider ldapProvider , RealmModel realm ) { if ( ! rolesSyncedModels . contains ( mapperModel . getId ( ) ) ) { logger . debugf ( "Syncing roles from LDAP into Keycloak DB. Mapper is [%s], LDAP provider is [%s]" , mapperModel . getName ( ) , ldapProvider . getModel ( ) . getDisplayName ( ) ) ; LDAPIdentityQuery ldapQuery = createRoleQuery ( mapperModel , ldapProvider ) ; List < LDAPObject > ldapRoles = ldapQuery . getResultList ( ) ; RoleContainerModel roleContainer = getTargetRoleContainer ( mapperModel , realm ) ; String rolesRdnAttr = getRoleNameLdapAttribute ( mapperModel ) ; for ( LDAPObject ldapRole : ldapRoles ) { String roleName = ldapRole . getAttributeAsString ( rolesRdnAttr ) ; if ( roleContainer . getRole ( roleName ) == null ) { logger . infof ( "Syncing role [%s] from LDAP to keycloak DB" , roleName ) ; roleContainer . addRole ( roleName ) ; } } rolesSyncedModels . add ( mapperModel . getId ( ) ) ; } }
Sync roles from LDAP tree and create them in local Keycloak DB (if they don't exist here yet)
Sync roles from LDAP tree and create them in local Keycloak DB ( if they don ' t exist here yet )
// Send query