diff --git a/.classpath b/.classpath
index 7bd7856..4c73e2c 100644
--- a/.classpath
+++ b/.classpath
@@ -20,6 +20,7 @@
+
diff --git a/.project b/.project
index ea1b8a8..1264c41 100644
--- a/.project
+++ b/.project
@@ -5,6 +5,11 @@
+
+ org.eclipse.wst.common.project.facet.core.builder
+
+
+
org.eclipse.jdt.core.javabuilder
@@ -15,9 +20,17 @@
+
+ org.eclipse.wst.validation.validationbuilder
+
+
+
+ org.eclipse.jem.workbench.JavaEMFNature
+ org.eclipse.wst.common.modulecore.ModuleCoreNature
org.eclipse.jdt.core.javanature
org.eclipse.m2e.core.maven2Nature
+ org.eclipse.wst.common.project.facet.core.nature
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index ec4300d..443e085 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -1,5 +1,8 @@
eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7
diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
new file mode 100644
index 0000000..d3c448c
--- /dev/null
+++ b/.settings/org.eclipse.wst.common.component
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml
new file mode 100644
index 0000000..1b22d70
--- /dev/null
+++ b/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index c62d29a..626ae00 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,6 +42,10 @@
+
+ org.gcube.resources.discovery
+ ic-client
+
org.gcube.common
authorization-client
diff --git a/src/main/java/org/gcube/portal/auth/AuthUtil.java b/src/main/java/org/gcube/portal/auth/AuthUtil.java
index ac09ad1..cc1800f 100644
--- a/src/main/java/org/gcube/portal/auth/AuthUtil.java
+++ b/src/main/java/org/gcube/portal/auth/AuthUtil.java
@@ -1,4 +1,7 @@
package org.gcube.portal.auth;
+import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
+import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@@ -6,7 +9,9 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.gcube.common.portal.PortalContext;
@@ -15,6 +20,9 @@ import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
import org.gcube.common.resources.gcore.utils.Group;
+import org.gcube.common.scope.api.ScopeProvider;
+import org.gcube.resources.discovery.client.api.DiscoveryClient;
+import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,7 +45,7 @@ public class AuthUtil {
public final static String ENDPOINT_CATEGORY = "OnlineService";
/**
- * look for the clientId AccessEndpoint passes as parameter
+ * look for the clientId passes as parameter
* @param clientId
* @return a RequestingApp
contanining the application name, the description and the application logo URL if any, or null
if non existent
*/
@@ -107,4 +115,58 @@ public class AuthUtil {
}
return map;
}
+
+ /**
+ * look for the clientId passes as parameter
+ * @param clientId
+ * @return a RequestingApp
contanining the application name, the description and the application logo URL if any, or null
if non existent
+ */
+ public static List getAuthorisedApplicationInfoFromIsICClient(String infrastructureName, String clientId) throws Exception {
+ String scope = "/" + infrastructureName;
+ String currScope = ScopeProvider.instance.get();
+ ScopeProvider.instance.set(scope);
+ String encodedClientId = URLEncoder.encode(clientId, "UTF-8").replaceAll("\\+", "%20");
+ SimpleQuery query = queryFor(ServiceEndpoint.class);
+ query.addCondition("$resource/ID/text() eq '"+ encodedClientId +"'");
+ DiscoveryClient client = clientFor(ServiceEndpoint.class);
+ List toReturn = client.submit(query);
+ ScopeProvider.instance.set(currScope);
+ return toReturn;
+ }
+ /**
+ * look for the clientId AccessEndpoint passes as parameter
+ * @param gatewayName
+ * @param clientId
+ * @return the client secret related to the id, or null if non existent
+ */
+ public static List getAuthorisedRedirectURLsFromIs(String clientId) {
+ PortalContext pContext = PortalContext.getConfiguration();
+ String scope = "/"+pContext.getInfrastructureName();
+ List autRedirectURLs = new ArrayList<>();
+ try {
+ List list = getAuthorisedApplicationInfoFromIsICClient(pContext.getInfrastructureName(), clientId);
+ if (list.size() > 1) {
+ _log.error("Too many Service Endpoints having name " + clientId +" in this scope having Category " + SERVICE_ENDPOINT_CATEGORY);
+ }
+ else if (list.size() == 0){
+ _log.warn("There is no Service Endpoint having name " + clientId +" and Category " + SERVICE_ENDPOINT_CATEGORY + " in this scope: " + scope);
+ }
+ else {
+ for (ServiceEndpoint res : list) {
+ Group apGroup = res.profile().accessPoints();
+ AccessPoint[] accessPoints = (AccessPoint[]) apGroup.toArray(new AccessPoint[apGroup.size()]);
+ for (int i = 0; i < accessPoints.length; i++) {
+ if (accessPoints[i].name().compareTo(REDIRECT_URL) == 0) {
+ AccessPoint found = accessPoints[i];
+ autRedirectURLs.add(found.address());
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return autRedirectURLs;
+ }
}
diff --git a/src/main/resources/clientlog4j.properties b/src/main/resources/clientlog4j.properties
new file mode 100644
index 0000000..574c7b1
--- /dev/null
+++ b/src/main/resources/clientlog4j.properties
@@ -0,0 +1,13 @@
+log4j.rootLogger=DEBUG, A1
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+
+# Print the date in ISO 8601 format
+log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
+
+# Print only messages of level TRACE or above in the package org.gcube
+log4j.logger.org.gcube=TRACE
+log4j.logger.org.gcube.application.framework.core.session=INFO
+log4j.logger.com.netflix.astyanax.connectionpool=ERROR
+log4j.logger.org.gcube.portal.databook.server.DBCassandraAstyanaxImpl=TRACE
+log4j.logger.org.gcube.common=ERROR
\ No newline at end of file
diff --git a/src/test/java/org/gcube/portal/auth/AppTest.java b/src/test/java/org/gcube/portal/auth/AppTest.java
index 9b584d3..7f66e90 100644
--- a/src/test/java/org/gcube/portal/auth/AppTest.java
+++ b/src/test/java/org/gcube/portal/auth/AppTest.java
@@ -1,5 +1,7 @@
package org.gcube.portal.auth;
+import java.util.List;
+
import org.gcube.portal.auth.AuthUtil;
import org.gcube.portal.auth.RequestingApp;
@@ -39,5 +41,15 @@ public class AppTest extends TestCase {
// System.out.println(app.getLogoURL());
// }
// assertTrue( app != null );
+ System.out.println("getAuthorisedRedirectURLsFromIs ... ");
+ try {
+ List authreds = AuthUtil.getAuthorisedRedirectURLsFromIs("c96d4477-236c-4f98-ba7d-7897991ef412");
+ for (String red : authreds) {
+ System.out.println(red);
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
}