git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-library@131607 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e97e7585c3
commit
eb941576f5
|
@ -16,6 +16,9 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
|
||||||
@XmlAttribute
|
@XmlAttribute
|
||||||
private String infrastructure;
|
private String infrastructure;
|
||||||
|
|
||||||
|
@XmlAttribute(name="cacheValidityInMillis")
|
||||||
|
long clientCacheValidity = 10*60*1000; //10 minutes
|
||||||
|
|
||||||
@XmlElement
|
@XmlElement
|
||||||
private String host;
|
private String host;
|
||||||
|
|
||||||
|
@ -56,6 +59,10 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
|
||||||
return priority;
|
return priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getClientCacheValidity() {
|
||||||
|
return clientCacheValidity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(AuthorizationEndpoint o) {
|
public int compareTo(AuthorizationEndpoint o) {
|
||||||
return this.priority-o.priority;
|
return this.priority-o.priority;
|
||||||
|
|
|
@ -17,38 +17,47 @@ public class AuthorizationEndpointScanner {
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(AuthorizationEndpointScanner.class);
|
private static Logger log = LoggerFactory.getLogger(AuthorizationEndpointScanner.class);
|
||||||
|
|
||||||
private static Map<Integer, AuthorizationEndpoint> endpoints;
|
private static EndpointsContainer endpoints;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The path used to find service map configuration files.
|
* The path used to find service map configuration files.
|
||||||
*/
|
*/
|
||||||
static final String configurationPattern = "authorization-endpoint.xml";
|
static final String configurationPattern = ".*\\.authorization";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scans the classpath for {@link ServiceMap}s.
|
* Scans the classpath for {@link ServiceMap}s.
|
||||||
*/
|
*/
|
||||||
public static synchronized Map<Integer, AuthorizationEndpoint> endpoints() {
|
public static synchronized EndpointsContainer endpoints() {
|
||||||
|
|
||||||
if (endpoints==null || endpoints.size()==0){
|
if (endpoints==null || endpoints.getEndpoints().size()==0){
|
||||||
endpoints = new HashMap<Integer, AuthorizationEndpoint>();
|
Map<Integer, AuthorizationEndpoint> endpointsMap = new HashMap<Integer, AuthorizationEndpoint>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
JAXBContext context = JAXBContext.newInstance(AuthorizationEndpoint.class);
|
JAXBContext context = JAXBContext.newInstance(AuthorizationEndpoint.class);
|
||||||
Unmarshaller um = context.createUnmarshaller();
|
Unmarshaller um = context.createUnmarshaller();
|
||||||
|
|
||||||
|
String defaultInfrastructure = null;
|
||||||
|
|
||||||
ClasspathScanner scanner = ClasspathScannerFactory.scanner();
|
ClasspathScanner scanner = ClasspathScannerFactory.scanner();
|
||||||
for (ClasspathResource r : scanner.scan(new NameMatcher(configurationPattern))){
|
for (ClasspathResource r : scanner.scan(new NameMatcher(configurationPattern))){
|
||||||
AuthorizationEndpoint endpoint = (AuthorizationEndpoint)um.unmarshal(r.stream());
|
AuthorizationEndpoint endpoint = (AuthorizationEndpoint)um.unmarshal(r.stream());
|
||||||
if (!endpoints.containsKey(endpoint.getInfrastructure())
|
if (defaultInfrastructure==null)
|
||||||
|| endpoints.get(endpoint.getInfrastructure()).getPriority()> endpoint.getPriority())
|
defaultInfrastructure = endpoint.getInfrastructure();
|
||||||
endpoints.put(endpoint.getInfrastructure().hashCode(), endpoint);
|
|
||||||
|
if (!endpointsMap.containsKey(endpoint.getInfrastructure())
|
||||||
|
|| endpointsMap.get(endpoint.getInfrastructure()).getPriority()> endpoint.getPriority()){
|
||||||
|
if ((r.name()).startsWith("default"))
|
||||||
|
defaultInfrastructure = endpoint.getInfrastructure();
|
||||||
|
endpointsMap.put(endpoint.getInfrastructure().hashCode(), endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
log.info("loaded endpoint {} ",endpoint.toString());
|
log.info("loaded endpoint {} ",endpoint.toString());
|
||||||
}
|
}
|
||||||
if (endpoints.size()==0)
|
|
||||||
throw new Exception("no endpoints retreived");
|
|
||||||
|
|
||||||
|
if (endpointsMap.size()==0)
|
||||||
|
throw new Exception("no endpoints retreived");
|
||||||
|
endpoints = new EndpointsContainer(endpointsMap, defaultInfrastructure);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("could not load authorization endpoints", e);
|
throw new RuntimeException("could not load authorization endpoints", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package org.gcube.common.authorization.library.enpoints;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class EndpointsContainer {
|
||||||
|
|
||||||
|
private Map<Integer, AuthorizationEndpoint> endpoints;
|
||||||
|
private String defaultInfrastructure;
|
||||||
|
protected EndpointsContainer(Map<Integer, AuthorizationEndpoint> endpoints,
|
||||||
|
String defaultInfrastructure) {
|
||||||
|
super();
|
||||||
|
this.endpoints = endpoints;
|
||||||
|
this.defaultInfrastructure = defaultInfrastructure;
|
||||||
|
}
|
||||||
|
public Map<Integer, AuthorizationEndpoint> getEndpoints() {
|
||||||
|
return endpoints;
|
||||||
|
}
|
||||||
|
public String getDefaultInfrastructure() {
|
||||||
|
return defaultInfrastructure;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.common.authorization.library.policies;
|
package org.gcube.common.authorization.library.policies;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
@ -16,6 +18,10 @@ public class User extends UserEntity {
|
||||||
super(identifier);
|
super(identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected User(List<String> excludes) {
|
||||||
|
super(excludes);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserEntityType getType() {
|
public UserEntityType getType() {
|
||||||
return UserEntityType.USER;
|
return UserEntityType.USER;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.common.authorization.library.policies;
|
package org.gcube.common.authorization.library.policies;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|
||||||
public class Users {
|
public class Users {
|
||||||
|
|
||||||
|
@ -11,4 +13,8 @@ public class Users {
|
||||||
return new User();
|
return new User();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static User allExcept(String ... identifiers){
|
||||||
|
return new User(Arrays.asList(identifiers));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class EndpointBinder {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void scan(){
|
public void scan(){
|
||||||
Map<Integer, AuthorizationEndpoint> endpoints = AuthorizationEndpointScanner.endpoints();
|
Map<Integer, AuthorizationEndpoint> endpoints = AuthorizationEndpointScanner.endpoints().getEndpoints();
|
||||||
System.out.println(endpoints);
|
System.out.println(endpoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue