git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-library@131733 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
2f2620b800
commit
69994e0bca
|
@ -1,7 +1,10 @@
|
|||
package org.gcube.common.authorization.library.enpoints;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
@ -10,6 +13,7 @@ import org.gcube.common.scan.ClasspathScanner;
|
|||
import org.gcube.common.scan.ClasspathScannerFactory;
|
||||
import org.gcube.common.scan.matchers.NameMatcher;
|
||||
import org.gcube.common.scan.resources.ClasspathResource;
|
||||
import org.gcube.common.scope.api.ServiceMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -30,6 +34,7 @@ public class AuthorizationEndpointScanner {
|
|||
public static synchronized EndpointsContainer endpoints() {
|
||||
|
||||
if (endpoints==null || endpoints.getEndpoints().size()==0){
|
||||
log.trace("starting authorization endpoint retrieving");
|
||||
Map<Integer, AuthorizationEndpoint> endpointsMap = new HashMap<Integer, AuthorizationEndpoint>();
|
||||
|
||||
try {
|
||||
|
@ -40,28 +45,32 @@ public class AuthorizationEndpointScanner {
|
|||
String defaultInfrastructure = null;
|
||||
int defaultInfraPriority= Integer.MAX_VALUE;
|
||||
|
||||
ClasspathScanner scanner = ClasspathScannerFactory.scanner();
|
||||
for (ClasspathResource r : scanner.scan(new NameMatcher(configurationPattern))){
|
||||
AuthorizationEndpoint endpoint = (AuthorizationEndpoint)um.unmarshal(r.stream());
|
||||
for (String r :getEnpointResourceNames()){
|
||||
|
||||
URL url = Thread.currentThread().getContextClassLoader().getResource(r);
|
||||
|
||||
|
||||
AuthorizationEndpoint endpoint = (AuthorizationEndpoint)um.unmarshal(url);
|
||||
if (defaultInfrastructure==null)
|
||||
defaultInfrastructure = endpoint.getInfrastructure();
|
||||
|
||||
|
||||
if (!endpointsMap.containsKey(endpoint.getInfrastructure())
|
||||
|| endpointsMap.get(endpoint.getInfrastructure()).getPriority()> endpoint.getPriority()){
|
||||
if ((r.name()).startsWith("default") && endpoint.getPriority()<defaultInfraPriority ){
|
||||
if (r.startsWith("default") && endpoint.getPriority()<defaultInfraPriority ){
|
||||
defaultInfrastructure = endpoint.getInfrastructure();
|
||||
defaultInfraPriority = endpoint.getPriority();
|
||||
}
|
||||
endpointsMap.put(endpoint.getInfrastructure().hashCode(), endpoint);
|
||||
}
|
||||
|
||||
|
||||
log.info("loaded endpoint {} ",endpoint.toString());
|
||||
}
|
||||
|
||||
if (endpointsMap.size()==0)
|
||||
throw new Exception("no endpoints retreived");
|
||||
endpoints = new EndpointsContainer(endpointsMap, defaultInfrastructure);
|
||||
log.trace("authorization endpoint retrieving finished");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("could not load authorization endpoints", e);
|
||||
}
|
||||
|
@ -69,5 +78,14 @@ public class AuthorizationEndpointScanner {
|
|||
}
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
private static Set<String> getEnpointResourceNames() {
|
||||
|
||||
ClasspathScanner scanner = ClasspathScannerFactory.scanner();
|
||||
Set<String> names = new HashSet<String>();
|
||||
for (ClasspathResource r : scanner.scan(new NameMatcher(configurationPattern)))
|
||||
names.add(r.name());
|
||||
return names;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue