Merge pull request #1984 from mstruk/providers-init

Prevent ProviderFactories being loaded twice
This commit is contained in:
Stian Thorgersen 2016-01-07 11:57:12 +01:00
commit 77962ec896

View file

@ -3,6 +3,7 @@ package org.keycloak.provider;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import java.util.HashMap; import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -52,10 +53,17 @@ public class ProviderManager {
List<ProviderFactory> factories = cache.get(spi.getName()); List<ProviderFactory> factories = cache.get(spi.getName());
if (factories == null) { if (factories == null) {
factories = new LinkedList<ProviderFactory>(); factories = new LinkedList<ProviderFactory>();
IdentityHashMap factoryClasses = new IdentityHashMap();
for (ProviderLoader loader : loaders) { for (ProviderLoader loader : loaders) {
List<ProviderFactory> f = loader.load(spi); List<ProviderFactory> f = loader.load(spi);
if (f != null) { if (f != null) {
factories.addAll(f); for (ProviderFactory pf: f) {
// make sure there are no duplicates
if (!factoryClasses.containsKey(pf.getClass())) {
factories.add(pf);
factoryClasses.put(pf.getClass(), pf);
}
}
} }
} }
} }