Merge pull request #1984 from mstruk/providers-init
Prevent ProviderFactories being loaded twice
This commit is contained in:
commit
77962ec896
1 changed files with 9 additions and 1 deletions
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue