test KEYCLOAK-4013

This commit is contained in:
Bill Burke 2017-01-05 11:27:17 -05:00
parent 4934fe5a8e
commit f9eeecf836
2 changed files with 23 additions and 8 deletions

View file

@ -125,7 +125,7 @@ public class UserCredentialStoreManager implements UserCredentialManager, OnUser
if (toValidate.isEmpty()) return true; if (toValidate.isEmpty()) return true;
List<CredentialInputValidator> credentialProviders = getCredentialProviders(realm, CredentialInputValidator.class); List<CredentialInputValidator> credentialProviders = getCredentialProviders(session, realm, CredentialInputValidator.class);
for (CredentialInputValidator validator : credentialProviders) { for (CredentialInputValidator validator : credentialProviders) {
validate(realm, user, toValidate, validator); validate(realm, user, toValidate, validator);
@ -143,7 +143,7 @@ public class UserCredentialStoreManager implements UserCredentialManager, OnUser
} }
} }
protected <T> List<T> getCredentialProviders(RealmModel realm, Class<T> type) { public static <T> List<T> getCredentialProviders(KeycloakSession session, RealmModel realm, Class<T> type) {
List<T> list = new LinkedList<T>(); List<T> list = new LinkedList<T>();
for (ProviderFactory f : session.getKeycloakSessionFactory().getProviderFactories(CredentialProvider.class)) { for (ProviderFactory f : session.getKeycloakSessionFactory().getProviderFactories(CredentialProvider.class)) {
if (!Types.supports(type, f, CredentialProviderFactory.class)) continue; if (!Types.supports(type, f, CredentialProviderFactory.class)) continue;
@ -173,7 +173,7 @@ public class UserCredentialStoreManager implements UserCredentialManager, OnUser
} }
} }
List<CredentialInputUpdater> credentialProviders = getCredentialProviders(realm, CredentialInputUpdater.class); List<CredentialInputUpdater> credentialProviders = getCredentialProviders(session, realm, CredentialInputUpdater.class);
for (CredentialInputUpdater updater : credentialProviders) { for (CredentialInputUpdater updater : credentialProviders) {
if (!updater.supportsCredentialType(input.getType())) continue; if (!updater.supportsCredentialType(input.getType())) continue;
if (updater.updateCredential(realm, user, input)) return; if (updater.updateCredential(realm, user, input)) return;
@ -201,7 +201,7 @@ public class UserCredentialStoreManager implements UserCredentialManager, OnUser
} }
List<CredentialInputUpdater> credentialProviders = getCredentialProviders(realm, CredentialInputUpdater.class); List<CredentialInputUpdater> credentialProviders = getCredentialProviders(session, realm, CredentialInputUpdater.class);
for (CredentialInputUpdater updater : credentialProviders) { for (CredentialInputUpdater updater : credentialProviders) {
if (!updater.supportsCredentialType(credentialType)) continue; if (!updater.supportsCredentialType(credentialType)) continue;
updater.disableCredentialType(realm, user, credentialType); updater.disableCredentialType(realm, user, credentialType);
@ -231,7 +231,7 @@ public class UserCredentialStoreManager implements UserCredentialManager, OnUser
} }
List<CredentialInputUpdater> credentialProviders = getCredentialProviders(realm, CredentialInputUpdater.class); List<CredentialInputUpdater> credentialProviders = getCredentialProviders(session, realm, CredentialInputUpdater.class);
for (CredentialInputUpdater updater : credentialProviders) { for (CredentialInputUpdater updater : credentialProviders) {
types.addAll(updater.getDisableableCredentialTypes(realm, user)); types.addAll(updater.getDisableableCredentialTypes(realm, user));
} }
@ -264,7 +264,7 @@ public class UserCredentialStoreManager implements UserCredentialManager, OnUser
@Override @Override
public boolean isConfiguredLocally(RealmModel realm, UserModel user, String type) { public boolean isConfiguredLocally(RealmModel realm, UserModel user, String type) {
List<CredentialInputValidator> credentialProviders = getCredentialProviders(realm, CredentialInputValidator.class); List<CredentialInputValidator> credentialProviders = getCredentialProviders(session, realm, CredentialInputValidator.class);
for (CredentialInputValidator validator : credentialProviders) { for (CredentialInputValidator validator : credentialProviders) {
if (validator.supportsCredentialType(type) && validator.isConfiguredFor(realm, user, type)) { if (validator.supportsCredentialType(type) && validator.isConfiguredFor(realm, user, type)) {
return true; return true;
@ -284,7 +284,7 @@ public class UserCredentialStoreManager implements UserCredentialManager, OnUser
} }
} }
list = getCredentialProviders(realm, CredentialAuthentication.class); list = getCredentialProviders(session, realm, CredentialAuthentication.class);
for (CredentialAuthentication auth : list) { for (CredentialAuthentication auth : list) {
if (auth.supportsCredentialAuthenticationFor(input.getType())) { if (auth.supportsCredentialAuthenticationFor(input.getType())) {
CredentialValidationOutput output = auth.authenticate(realm, input); CredentialValidationOutput output = auth.authenticate(realm, input);
@ -297,7 +297,7 @@ public class UserCredentialStoreManager implements UserCredentialManager, OnUser
@Override @Override
public void onCache(RealmModel realm, CachedUserModel user, UserModel delegate) { public void onCache(RealmModel realm, CachedUserModel user, UserModel delegate) {
List<OnUserCache> credentialProviders = getCredentialProviders(realm, OnUserCache.class); List<OnUserCache> credentialProviders = getCredentialProviders(session, realm, OnUserCache.class);
for (OnUserCache validator : credentialProviders) { for (OnUserCache validator : credentialProviders) {
validator.onCache(realm, user, delegate); validator.onCache(realm, user, delegate);
} }

View file

@ -24,6 +24,8 @@ import org.junit.Test;
import org.keycloak.OAuth2Constants; import org.keycloak.OAuth2Constants;
import org.keycloak.common.util.Time; import org.keycloak.common.util.Time;
import org.keycloak.component.ComponentModel; import org.keycloak.component.ComponentModel;
import org.keycloak.credential.CredentialAuthentication;
import org.keycloak.credential.UserCredentialStoreManager;
import org.keycloak.models.GroupModel; import org.keycloak.models.GroupModel;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
@ -137,6 +139,19 @@ public class UserStorageTest {
Thread.sleep(100000000); Thread.sleep(100000000);
} }
/**
* KEYCLOAK-4013
*
* @throws Exception
*/
@Test
public void testCast() throws Exception {
KeycloakSession session = keycloakRule.startSession();
List<CredentialAuthentication> list = UserCredentialStoreManager.getCredentialProviders(session, null, CredentialAuthentication.class);
keycloakRule.stopSession(session, true);
}
@Test @Test
public void testDailyEviction() { public void testDailyEviction() {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();