diff --git a/.classpath b/.classpath index e43402f..002ad57 100644 --- a/.classpath +++ b/.classpath @@ -15,14 +15,16 @@ + + - + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 6249222..db24ee7 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,15 @@ 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.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/distro/gcube-app.xml b/distro/gcube-app.xml index d9cecd6..fcfff7c 100644 --- a/distro/gcube-app.xml +++ b/distro/gcube-app.xml @@ -1,8 +1,7 @@ - + WhnManager VREManagement ${version} Web Hosting Node Service - diff --git a/pom.xml b/pom.xml index cbd2aee..6ceef1f 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 @@ -41,11 +42,16 @@ 4.0.1 provided - - org.gcube.core - common-smartgears-app - - + + org.gcube.core + common-smartgears-app + + + + org.gcube.common + gxHTTP + + com.sun.xml.ws jaxws-rt diff --git a/src/main/java/org/gcube/vremanagement/whnmanager/jaxws/ws/WhnManagerImpl.java b/src/main/java/org/gcube/vremanagement/whnmanager/jaxws/ws/WhnManagerImpl.java index 225827f..535d99f 100644 --- a/src/main/java/org/gcube/vremanagement/whnmanager/jaxws/ws/WhnManagerImpl.java +++ b/src/main/java/org/gcube/vremanagement/whnmanager/jaxws/ws/WhnManagerImpl.java @@ -1,7 +1,13 @@ package org.gcube.vremanagement.whnmanager.jaxws.ws; -import javax.jws.WebService; +import java.net.HttpURLConnection; +import java.util.Map.Entry; +import javax.jws.WebService; +import javax.ws.rs.core.Response.Status; + +import org.gcube.common.gxhttp.request.GXHTTPStringRequest; +import org.gcube.common.gxhttp.util.ContentUtils; import org.gcube.common.security.providers.SecretManagerProvider; import org.gcube.common.security.secrets.Secret; import org.gcube.resourcemanagement.whnmanager.api.WhnManager; @@ -9,6 +15,8 @@ import org.gcube.resourcemanagement.whnmanager.api.exception.GCUBEUnrecoverableE import org.gcube.smartgears.ContextProvider; import org.gcube.smartgears.context.application.ApplicationContext; import org.gcube.smartgears.managers.ContextEvents; +import org.gcube.smartgears.security.SimpleCredentials; +import org.gcube.smartgears.security.defaults.DefaultAuthorizationProvider; import org.gcube.vremanagement.whnmanager.utils.ValidationUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,7 +31,7 @@ public class WhnManagerImpl implements WhnManager{ private static Logger logger=LoggerFactory.getLogger(WhnManagerImpl.class); - + /** * Add a scope to the ghn profile and publish it on IS */ @@ -34,7 +42,34 @@ public class WhnManagerImpl implements WhnManager{ ValidationUtils.valid("context", context); ApplicationContext appContext = ContextProvider.get(); if(context!=null){ - //TODO must add client id to new context + + GXHTTPStringRequest request = GXHTTPStringRequest.newRequest("https://conductor.dev.d4science.org/api"); + try { + + request = request.path("workflow"); + for(Entry entry : secret.getHTTPAuthorizationHeaders().entrySet()) + request = request.header(entry.getKey(), entry.getValue()); + + + SimpleCredentials credentials = ((DefaultAuthorizationProvider) appContext.container().configuration().authorizationProvider()).getCredentials(); + + HttpURLConnection response = request.post(String.format(" \"name\": \"ghn_client_add_to_contexts\",\n" + + " \"input\" : {\n" + + " \"client_id\" : \"%s\",\n" + + " \"context_list\" : [\"%s\"] }", credentials.getClientID(), context)) ; + + if(response.getResponseCode() == Status.CREATED.getStatusCode()) { + String body = ContentUtils.toString(ContentUtils.toByteArray(response.getInputStream())); + logger.info("Returned response for remove scope {} ",body); + } + + appContext.container().events().fire(context, ContextEvents.REMOVE_CONTEXT_FROM_CONTAINER); + } catch (Exception e) { + logger.error("error removing context {}", context, e); + return false; + } + + appContext.container().events().fire(context, ContextEvents.ADD_CONTEXT_TO_CONTAINER); }else{ logger.error("context is null"); @@ -54,7 +89,34 @@ public class WhnManagerImpl implements WhnManager{ ApplicationContext appContext = ContextProvider.get(); if(context!=null){ logger.trace("allowed container in context are {} ",appContext.container().configuration().authorizationProvider().getContexts()); - appContext.container().events().fire(context, ContextEvents.REMOVE_CONTEXT_FROM_CONTAINER); + + GXHTTPStringRequest request = GXHTTPStringRequest.newRequest("https://conductor.dev.d4science.org/api"); + try { + + request = request.path("workflow"); + for(Entry entry : secret.getHTTPAuthorizationHeaders().entrySet()) + request = request.header(entry.getKey(), entry.getValue()); + + + SimpleCredentials credentials = ((DefaultAuthorizationProvider) appContext.container().configuration().authorizationProvider()).getCredentials(); + + HttpURLConnection response = request.post(String.format(" \"name\": \"ghn_client_remove_from_contexts\",\n" + + " \"input\" : {\n" + + " \"client_id\" : \"%s\",\n" + + " \"context_list\" : [\"%s\"] }", credentials.getClientID(), context)) ; + + if(response.getResponseCode() == Status.CREATED.getStatusCode()) { + String body = ContentUtils.toString(ContentUtils.toByteArray(response.getInputStream())); + logger.info("Returned response for remove scope {} ",body); + } + + appContext.container().events().fire(context, ContextEvents.REMOVE_CONTEXT_FROM_CONTAINER); + } catch (Exception e) { + logger.error("error removing context {}", context, e); + return false; + } + + }else{ logger.error("context is null"); return false; diff --git a/src/main/webapp/WEB-INF/gcube-app.xml b/src/main/webapp/WEB-INF/gcube-app.xml index 333b81e..67a1c96 100644 --- a/src/main/webapp/WEB-INF/gcube-app.xml +++ b/src/main/webapp/WEB-INF/gcube-app.xml @@ -1,8 +1,7 @@ - + WhnManager VREManagement 3.0.0-SNAPSHOT Web Hosting Node Service -