git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-library@129386 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
68ceb8f9fd
commit
a58e5ec3f7
|
@ -13,7 +13,7 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
|
||||||
@XmlAttribute
|
@XmlAttribute
|
||||||
private int priority = 0;
|
private int priority = 0;
|
||||||
|
|
||||||
@XmlElement
|
@XmlAttribute
|
||||||
private String infrastructure;
|
private String infrastructure;
|
||||||
|
|
||||||
@XmlElement
|
@XmlElement
|
||||||
|
@ -52,6 +52,10 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getPriority() {
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(AuthorizationEndpoint o) {
|
public int compareTo(AuthorizationEndpoint o) {
|
||||||
return this.priority-o.priority;
|
return this.priority-o.priority;
|
||||||
|
@ -101,6 +105,4 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package org.gcube.common.authorization.library.enpoints;
|
package org.gcube.common.authorization.library.enpoints;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.HashMap;
|
||||||
import java.util.Collections;
|
import java.util.Map;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
@ -19,7 +18,7 @@ public class AuthorizationEndpointScanner {
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(AuthorizationEndpointScanner.class);
|
private static Logger log = LoggerFactory.getLogger(AuthorizationEndpointScanner.class);
|
||||||
|
|
||||||
private static List<AuthorizationEndpoint> endpoints;
|
private static Map<Integer, AuthorizationEndpoint> endpoints;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The path used to find service map configuration files.
|
* The path used to find service map configuration files.
|
||||||
|
@ -29,10 +28,10 @@ public class AuthorizationEndpointScanner {
|
||||||
/**
|
/**
|
||||||
* Scans the classpath for {@link ServiceMap}s.
|
* Scans the classpath for {@link ServiceMap}s.
|
||||||
*/
|
*/
|
||||||
public static synchronized List<AuthorizationEndpoint> endpoints() {
|
public static synchronized Map<Integer, AuthorizationEndpoint> endpoints() {
|
||||||
|
|
||||||
if (endpoints==null || endpoints.size()==0){
|
if (endpoints==null || endpoints.size()==0){
|
||||||
endpoints = new ArrayList<AuthorizationEndpoint>();
|
endpoints = new HashMap<Integer, AuthorizationEndpoint>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -42,7 +41,10 @@ public class AuthorizationEndpointScanner {
|
||||||
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());
|
||||||
endpoints.add(endpoint);
|
if (!endpoints.containsKey(endpoint.getInfrastructure())
|
||||||
|
|| endpoints.get(endpoint.getInfrastructure()).getPriority()> endpoint.getPriority())
|
||||||
|
endpoints.put(endpoint.getInfrastructure().hashCode(), endpoint);
|
||||||
|
|
||||||
log.info("loaded endpoint {} ",endpoint.toString());
|
log.info("loaded endpoint {} ",endpoint.toString());
|
||||||
}
|
}
|
||||||
if (endpoints.size()==0)
|
if (endpoints.size()==0)
|
||||||
|
@ -51,7 +53,7 @@ public class AuthorizationEndpointScanner {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("could not load authorization endpoints", e);
|
throw new RuntimeException("could not load authorization endpoints", e);
|
||||||
}
|
}
|
||||||
Collections.sort(endpoints);
|
|
||||||
}
|
}
|
||||||
return endpoints;
|
return endpoints;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package org.gcube.common.authorization.library.policies;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
@XmlRootElement
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
public class ExternalService extends UserEntity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserEntityType getType() {
|
||||||
|
return UserEntityType.EXTERNALSERVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSubsetOf(UserEntity entity) {
|
||||||
|
if (entity.getType()== UserEntityType.EXTERNALSERVICE)
|
||||||
|
return entity.getIdentifier()==null || this.getIdentifier().equals(entity.getIdentifier());
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.common.authorization.library.policies;
|
package org.gcube.common.authorization.library.policies;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -20,6 +22,10 @@ public abstract class Policy {
|
||||||
|
|
||||||
public abstract ServiceAccess getServiceAccess();
|
public abstract ServiceAccess getServiceAccess();
|
||||||
|
|
||||||
|
public abstract Calendar getCreationTime();
|
||||||
|
|
||||||
|
public abstract Calendar getLastUpdateTime();
|
||||||
|
|
||||||
public abstract String getContext();
|
public abstract String getContext();
|
||||||
|
|
||||||
public abstract Action getMode();
|
public abstract Action getMode();
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.common.authorization.library.policies;
|
package org.gcube.common.authorization.library.policies;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -10,6 +12,8 @@ public class Service2ServicePolicy extends Policy{
|
||||||
|
|
||||||
private ServiceEntity client;
|
private ServiceEntity client;
|
||||||
private String context;
|
private String context;
|
||||||
|
private Calendar lastUpdateTime;
|
||||||
|
private Calendar creationTime;
|
||||||
private ServiceAccess serviceAccess;
|
private ServiceAccess serviceAccess;
|
||||||
private Action mode = Action.ALL;
|
private Action mode = Action.ALL;
|
||||||
|
|
||||||
|
@ -103,6 +107,16 @@ public class Service2ServicePolicy extends Policy{
|
||||||
return this.mode;
|
return this.mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Calendar getCreationTime() {
|
||||||
|
return creationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Calendar getLastUpdateTime() {
|
||||||
|
return lastUpdateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.common.authorization.library.policies;
|
package org.gcube.common.authorization.library.policies;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
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.XmlElementRef;
|
import javax.xml.bind.annotation.XmlElementRef;
|
||||||
|
@ -17,6 +19,8 @@ public class User2ServicePolicy extends Policy {
|
||||||
private UserEntity entity;
|
private UserEntity entity;
|
||||||
private String context;
|
private String context;
|
||||||
private ServiceAccess serviceAccess;
|
private ServiceAccess serviceAccess;
|
||||||
|
private Calendar lastUpdateTime;
|
||||||
|
private Calendar creationTime;
|
||||||
|
|
||||||
private Action mode = Action.ALL;
|
private Action mode = Action.ALL;
|
||||||
|
|
||||||
|
@ -55,6 +59,14 @@ public class User2ServicePolicy extends Policy {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Calendar getLastUpdateTime() {
|
||||||
|
return lastUpdateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Calendar getCreationTime() {
|
||||||
|
return creationTime;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
|
|
|
@ -18,7 +18,7 @@ public abstract class UserEntity {
|
||||||
private List<String> excludes = new ArrayList<String>();
|
private List<String> excludes = new ArrayList<String>();
|
||||||
|
|
||||||
public enum UserEntityType {
|
public enum UserEntityType {
|
||||||
ROLE , USER
|
ROLE , USER, EXTERNALSERVICE
|
||||||
}
|
}
|
||||||
|
|
||||||
protected UserEntity() {
|
protected UserEntity() {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import javax.xml.bind.annotation.XmlSeeAlso;
|
||||||
|
|
||||||
@XmlRootElement
|
@XmlRootElement
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
@XmlSeeAlso(value={UserInfo.class, ServiceInfo.class})
|
@XmlSeeAlso(value={UserInfo.class, ServiceInfo.class, ExternalServiceInfo.class})
|
||||||
public abstract class ClientInfo implements Serializable{
|
public abstract class ClientInfo implements Serializable{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,6 +22,4 @@ public abstract class ClientInfo implements Serializable{
|
||||||
|
|
||||||
public abstract List<String> getRoles();
|
public abstract List<String> getRoles();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
package org.gcube.common.authorization.library.provider;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
@XmlRootElement
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
public class ExternalServiceInfo extends ClientInfo{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private String generatedBy;
|
||||||
|
|
||||||
|
public ExternalServiceInfo(String id, String generatedBy) {
|
||||||
|
super();
|
||||||
|
this.id = id;
|
||||||
|
this.generatedBy = generatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ExternalServiceInfo() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGeneratedBy() {
|
||||||
|
return generatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getRoles() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1 +1 @@
|
||||||
<authorization-endpoint priority="10"><host>node7.d.d4science.research-infrastructures.eu</host><port>9000</port></authorization-endpoint>
|
<authorization-endpoint priority="10" infrastructure="gcube"><host>node7.d.d4science.research-infrastructures.eu</host><port>9000</port></authorization-endpoint>
|
|
@ -3,7 +3,7 @@ package org.gcube.common.authorization.library.binder;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
|
@ -25,25 +25,26 @@ public class EndpointBinder {
|
||||||
public void bind() throws Exception{
|
public void bind() throws Exception{
|
||||||
JAXBContext context = getContext();
|
JAXBContext context = getContext();
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
AuthorizationEndpoint ae1 = new AuthorizationEndpoint("/myInfra", 2, "146.48.85.179", 8080);
|
AuthorizationEndpoint ae1 = new AuthorizationEndpoint("myInfra", 2, "146.48.85.179", 8080);
|
||||||
context.createMarshaller().marshal(ae1, sw);
|
context.createMarshaller().marshal(ae1, sw);
|
||||||
|
System.out.println(sw);
|
||||||
AuthorizationEndpoint ae2 = (AuthorizationEndpoint)context.createUnmarshaller().unmarshal(new StringReader(sw.toString()));
|
AuthorizationEndpoint ae2 = (AuthorizationEndpoint)context.createUnmarshaller().unmarshal(new StringReader(sw.toString()));
|
||||||
Assert.assertEquals(ae1, ae2);
|
Assert.assertEquals(ae1, ae2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compare(){
|
public void compare(){
|
||||||
AuthorizationEndpoint ae1 = new AuthorizationEndpoint("/myInfra", 2, "146.48.85.179", 8080);
|
AuthorizationEndpoint ae1 = new AuthorizationEndpoint("myInfra", 2, "146.48.85.179", 8080);
|
||||||
AuthorizationEndpoint ae2 = new AuthorizationEndpoint("/myInfra", 1, "146.48.85.179", 8080);
|
AuthorizationEndpoint ae2 = new AuthorizationEndpoint("myInfra", 1, "146.48.85.179", 8080);
|
||||||
|
|
||||||
Assert.assertTrue(ae1.compareTo(ae2)>0);
|
Assert.assertTrue(ae1.compareTo(ae2)>0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void order(){
|
public void order(){
|
||||||
AuthorizationEndpoint ae1 = new AuthorizationEndpoint("/myInfra" ,2, "146.48.85.179", 8080);
|
AuthorizationEndpoint ae1 = new AuthorizationEndpoint("myInfra" ,2, "146.48.85.179", 8080);
|
||||||
AuthorizationEndpoint ae2 = new AuthorizationEndpoint("/myInfra" ,1, "146.48.85.179", 8080);
|
AuthorizationEndpoint ae2 = new AuthorizationEndpoint("myInfra" ,1, "146.48.85.179", 8080);
|
||||||
AuthorizationEndpoint ae3 = new AuthorizationEndpoint("/myInfra", 3, "146.48.85.179", 8080);
|
AuthorizationEndpoint ae3 = new AuthorizationEndpoint("myInfra", 3, "146.48.85.179", 8080);
|
||||||
|
|
||||||
AuthorizationEndpoint[] arr1 = new AuthorizationEndpoint[]{ae1, ae2, ae3};
|
AuthorizationEndpoint[] arr1 = new AuthorizationEndpoint[]{ae1, ae2, ae3};
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ public class EndpointBinder {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void scan(){
|
public void scan(){
|
||||||
List<AuthorizationEndpoint> endpoints = AuthorizationEndpointScanner.endpoints();
|
Map<Integer, AuthorizationEndpoint> endpoints = AuthorizationEndpointScanner.endpoints();
|
||||||
System.out.println(endpoints);
|
System.out.println(endpoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue