From e554641431100f9061d5c4eaf3b9b9b04eacb22e Mon Sep 17 00:00:00 2001 From: "lucio.lelii" Date: Tue, 22 Dec 2015 18:38:57 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-library@122080 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 4 +- .../library/AuthorizationEntry.java | 60 ++++++++++++++++++- src/main/resources/authorization-endpoint.xml | 2 +- .../binder/AuthorizationEntryBinder.java | 35 +++++++++++ 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 src/test/java/org/gcube/common/authorization/library/binder/AuthorizationEntryBinder.java diff --git a/pom.xml b/pom.xml index 201f94e..31b3a8d 100644 --- a/pom.xml +++ b/pom.xml @@ -20,12 +20,12 @@ org.gcube.core common-scope - [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) org.gcube.core common-configuration-scanner - [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + [1.0.1-SNAPSHOT,2.0.0-SNAPSHOT) junit diff --git a/src/main/java/org/gcube/common/authorization/library/AuthorizationEntry.java b/src/main/java/org/gcube/common/authorization/library/AuthorizationEntry.java index 0224c0e..f568e9e 100644 --- a/src/main/java/org/gcube/common/authorization/library/AuthorizationEntry.java +++ b/src/main/java/org/gcube/common/authorization/library/AuthorizationEntry.java @@ -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 roles; private String context; + @XmlElementRefs({@XmlElementRef(type=DefaultServiceMap.class)}) private ServiceMap map; private List bannedServices = new ArrayList(); @@ -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; } diff --git a/src/main/resources/authorization-endpoint.xml b/src/main/resources/authorization-endpoint.xml index 1421f9d..f81e043 100644 --- a/src/main/resources/authorization-endpoint.xml +++ b/src/main/resources/authorization-endpoint.xml @@ -1 +1 @@ -146.48.85.1798080 \ No newline at end of file +node7.d.d4science.research-infrastructures.eu9000 \ No newline at end of file diff --git a/src/test/java/org/gcube/common/authorization/library/binder/AuthorizationEntryBinder.java b/src/test/java/org/gcube/common/authorization/library/binder/AuthorizationEntryBinder.java new file mode 100644 index 0000000..f7cc6f4 --- /dev/null +++ b/src/test/java/org/gcube/common/authorization/library/binder/AuthorizationEntryBinder.java @@ -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 services = new HashMap(); + 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); + } +}