add logic for sync
This commit is contained in:
parent
0dee393071
commit
49ba71fd8f
3 changed files with 29 additions and 5 deletions
|
@ -81,7 +81,7 @@ public class UserStorageSyncManager {
|
|||
|
||||
public SynchronizationResult syncAllUsers(final KeycloakSessionFactory sessionFactory, final String realmId, final UserStorageProviderModel provider) {
|
||||
UserStorageProviderFactory factory = (UserStorageProviderFactory) sessionFactory.getProviderFactory(UserStorageProvider.class, provider.getProviderId());
|
||||
if (!(factory instanceof ImportSynchronization) || !provider.isImportEnabled()) {
|
||||
if (!(factory instanceof ImportSynchronization) || !provider.isImportEnabled() || !provider.isEnabled()) {
|
||||
return SynchronizationResult.ignored();
|
||||
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public class UserStorageSyncManager {
|
|||
|
||||
public SynchronizationResult syncChangedUsers(final KeycloakSessionFactory sessionFactory, final String realmId, final UserStorageProviderModel provider) {
|
||||
UserStorageProviderFactory factory = (UserStorageProviderFactory) sessionFactory.getProviderFactory(UserStorageProvider.class, provider.getProviderId());
|
||||
if (!(factory instanceof ImportSynchronization) || !provider.isImportEnabled()) {
|
||||
if (!(factory instanceof ImportSynchronization) || !provider.isImportEnabled() || !provider.isEnabled()) {
|
||||
return SynchronizationResult.ignored();
|
||||
|
||||
}
|
||||
|
|
|
@ -62,7 +62,11 @@ public class FailableHardcodedStorageProvider implements UserStorageProvider, Us
|
|||
public FailableHardcodedStorageProvider(ComponentModel model, KeycloakSession session) {
|
||||
this.model = model;
|
||||
this.session = session;
|
||||
componentFail = model.getConfig().getFirst("fail") != null && model.getConfig().getFirst("fail").equalsIgnoreCase("true");
|
||||
componentFail = isInFailMode(model);
|
||||
}
|
||||
|
||||
public static boolean isInFailMode(ComponentModel model) {
|
||||
return model.getConfig().getFirst("fail") != null && model.getConfig().getFirst("fail").equalsIgnoreCase("true");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -206,7 +210,11 @@ public class FailableHardcodedStorageProvider implements UserStorageProvider, Us
|
|||
}
|
||||
|
||||
protected void checkForceFail() {
|
||||
if (fail || componentFail) throw new RuntimeException("FORCED FAILURE");
|
||||
if (fail || componentFail) throwFailure();
|
||||
}
|
||||
|
||||
public static void throwFailure() {
|
||||
throw new RuntimeException("FORCED FAILURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,9 +18,14 @@ package org.keycloak.testsuite.federation.storage;
|
|||
|
||||
import org.keycloak.component.ComponentModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.provider.ProviderConfigProperty;
|
||||
import org.keycloak.storage.UserStorageProviderFactory;
|
||||
import org.keycloak.storage.UserStorageProviderModel;
|
||||
import org.keycloak.storage.user.ImportSynchronization;
|
||||
import org.keycloak.storage.user.SynchronizationResult;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -28,7 +33,7 @@ import java.util.List;
|
|||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class FailableHardcodedStorageProviderFactory implements UserStorageProviderFactory<FailableHardcodedStorageProvider> {
|
||||
public class FailableHardcodedStorageProviderFactory implements UserStorageProviderFactory<FailableHardcodedStorageProvider>, ImportSynchronization {
|
||||
|
||||
public static final String PROVIDER_ID = "failable-hardcoded-storage";
|
||||
|
||||
|
@ -52,4 +57,15 @@ public class FailableHardcodedStorageProviderFactory implements UserStorageProvi
|
|||
return OPTIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SynchronizationResult sync(KeycloakSessionFactory sessionFactory, String realmId, UserStorageProviderModel model) {
|
||||
if (FailableHardcodedStorageProvider.isInFailMode(model)) FailableHardcodedStorageProvider.throwFailure();
|
||||
return SynchronizationResult.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SynchronizationResult syncSince(Date lastSync, KeycloakSessionFactory sessionFactory, String realmId, UserStorageProviderModel model) {
|
||||
if (FailableHardcodedStorageProvider.isInFailMode(model)) FailableHardcodedStorageProvider.throwFailure();
|
||||
return SynchronizationResult.empty();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue