Search in sources :

Example 6 with LDAPStorageMapper

use of org.keycloak.storage.ldap.mappers.LDAPStorageMapper in project keycloak by keycloak.

the class UserStorageProviderResource method syncMapperData.

/**
 * Trigger sync of mapper data related to ldap mapper (roles, groups, ...)
 *
 * direction is "fedToKeycloak" or "keycloakToFed"
 *
 * @return
 */
@POST
@Path("{parentId}/mappers/{id}/sync")
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public SynchronizationResult syncMapperData(@PathParam("parentId") String parentId, @PathParam("id") String mapperId, @QueryParam("direction") String direction) {
    auth.users().requireManage();
    ComponentModel parentModel = realm.getComponent(parentId);
    if (parentModel == null)
        throw new NotFoundException("Parent model not found");
    ComponentModel mapperModel = realm.getComponent(mapperId);
    if (mapperModel == null)
        throw new NotFoundException("Mapper model not found");
    LDAPStorageProvider ldapProvider = (LDAPStorageProvider) session.getProvider(UserStorageProvider.class, parentModel);
    LDAPStorageMapper mapper = session.getProvider(LDAPStorageMapper.class, mapperModel);
    ServicesLogger.LOGGER.syncingDataForMapper(mapperModel.getName(), mapperModel.getProviderId(), direction);
    SynchronizationResult syncResult;
    if ("fedToKeycloak".equals(direction)) {
        syncResult = mapper.syncDataFromFederationProviderToKeycloak(realm);
    } else if ("keycloakToFed".equals(direction)) {
        syncResult = mapper.syncDataFromKeycloakToFederationProvider(realm);
    } else {
        throw new BadRequestException("Unknown direction: " + direction);
    }
    Map<String, Object> eventRep = new HashMap<>();
    eventRep.put("action", direction);
    eventRep.put("result", syncResult);
    adminEvent.operation(OperationType.ACTION).resourcePath(session.getContext().getUri()).representation(eventRep).success();
    return syncResult;
}
Also used : LDAPStorageMapper(org.keycloak.storage.ldap.mappers.LDAPStorageMapper) UserStorageProvider(org.keycloak.storage.UserStorageProvider) HashMap(java.util.HashMap) ComponentModel(org.keycloak.component.ComponentModel) NotFoundException(javax.ws.rs.NotFoundException) LDAPStorageProvider(org.keycloak.storage.ldap.LDAPStorageProvider) BadRequestException(javax.ws.rs.BadRequestException) SynchronizationResult(org.keycloak.storage.user.SynchronizationResult) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Aggregations

LDAPStorageMapper (org.keycloak.storage.ldap.mappers.LDAPStorageMapper)6 ComponentModel (org.keycloak.component.ComponentModel)3 ModelException (org.keycloak.models.ModelException)3 UserModel (org.keycloak.models.UserModel)3 LDAPObject (org.keycloak.storage.ldap.idm.model.LDAPObject)3 LDAPMappersComparator (org.keycloak.storage.ldap.mappers.LDAPMappersComparator)3 CachedUserModel (org.keycloak.models.cache.CachedUserModel)2 UserStorageProvider (org.keycloak.storage.UserStorageProvider)2 LDAPIdentityStore (org.keycloak.storage.ldap.idm.store.ldap.LDAPIdentityStore)2 SynchronizationResult (org.keycloak.storage.user.SynchronizationResult)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 NamingException (javax.naming.NamingException)1 BadRequestException (javax.ws.rs.BadRequestException)1