Lucio Lelii 2015-12-22 18:38:57 +00:00
parent 839a4e8403
commit e554641431
4 changed files with 97 additions and 4 deletions

View File

@ -20,12 +20,12 @@
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-configuration-scanner</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<version>[1.0.1-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>junit</groupId>

View File

@ -5,9 +5,12 @@ import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementRefs;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.common.scope.api.ServiceMap;
import org.gcube.common.scope.impl.DefaultServiceMap;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@ -16,6 +19,7 @@ public class AuthorizationEntry {
private String clientId;
private List<String> roles;
private String context;
@XmlElementRefs({@XmlElementRef(type=DefaultServiceMap.class)})
private ServiceMap map;
private List<CalledService> bannedServices = new ArrayList<CalledService>();
@ -63,10 +67,64 @@ public class AuthorizationEntry {
this.bannedServices = bannedServices;
}
@Override
public String toString() {
return "AuthorizationEntry [clientId=" + clientId + ", roles=" + roles
+ ", context=" + context + " bannedServices "+ bannedServices+"]";
+ ", context=" + context + ", map=" + map + ", bannedServices="
+ bannedServices + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((bannedServices == null) ? 0 : bannedServices.hashCode());
result = prime * result
+ ((clientId == null) ? 0 : clientId.hashCode());
result = prime * result + ((context == null) ? 0 : context.hashCode());
result = prime * result + ((map == null) ? 0 : map.hashCode());
result = prime * result + ((roles == null) ? 0 : roles.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AuthorizationEntry other = (AuthorizationEntry) obj;
if (bannedServices == null) {
if (other.bannedServices != null)
return false;
} else if (!bannedServices.equals(other.bannedServices))
return false;
if (clientId == null) {
if (other.clientId != null)
return false;
} else if (!clientId.equals(other.clientId))
return false;
if (context == null) {
if (other.context != null)
return false;
} else if (!context.equals(other.context))
return false;
if (map == null) {
if (other.map != null)
return false;
} else if (!map.equals(other.map))
return false;
if (roles == null) {
if (other.roles != null)
return false;
} else if (!roles.equals(other.roles))
return false;
return true;
}

View File

@ -1 +1 @@
<auhtorization-endpoint priority="10"><host>146.48.85.179</host><port>8080</port></auhtorization-endpoint>
<auhtorization-endpoint priority="10"><host>node7.d.d4science.research-infrastructures.eu</host><port>9000</port></auhtorization-endpoint>

View File

@ -0,0 +1,35 @@
package org.gcube.common.authorization.library.binder;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.scope.impl.DefaultServiceMap;
import org.junit.Assert;
import org.junit.Test;
public class AuthorizationEntryBinder {
public static JAXBContext getContext() throws JAXBException{
return JAXBContext.newInstance(AuthorizationEntry.class);
}
@Test
public void bind() throws Exception{
JAXBContext context = getContext();
StringWriter sw = new StringWriter();
AuthorizationEntry ae1 = new AuthorizationEntry("clientId", null, "scope");
Map<String, String> services = new HashMap<String, String>();
services.put("service", "endpoint");
ae1.setMap(new DefaultServiceMap("scope","versione", services ));
context.createMarshaller().marshal(ae1, sw);
System.out.println(sw.toString());
AuthorizationEntry ae2 = (AuthorizationEntry)context.createUnmarshaller().unmarshal(new StringReader(sw.toString()));
Assert.assertEquals(ae1, ae2);
}
}