From 558e8af575f3c8d8cfdcebe561acb86fbac4e2fb Mon Sep 17 00:00:00 2001 From: lucio lelii Date: Mon, 9 May 2022 10:03:16 +0200 Subject: [PATCH 01/11] pom updated --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c510f21..c70d7fe 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.core common-smartgears-app - 2.1.0 + 3.0.0-SNAPSHOT Smartgears Application @@ -56,7 +56,7 @@ org.gcube.core common-smartgears - [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) + [3.0.0-SNAPSHOT,4.0.0-SNAPSHOT) provided From 9f90b8372443f1f4eaac50a5d50d95fa5be23de5 Mon Sep 17 00:00:00 2001 From: lucio Date: Wed, 25 May 2022 18:58:02 +0200 Subject: [PATCH 02/11] removed ScopeProvier --- .classpath | 21 +++++++------- .settings/org.eclipse.wst.common.component | 3 +- CHANGELOG.md | 4 +++ pom.xml | 21 +++++++++++--- .../org/gcube/smartgears/ContextListener.java | 4 +-- .../org/gcube/smartgears/ContextProvider.java | 28 ++++++++++--------- .../application/manager/OnlineObserver.java | 2 +- 7 files changed, 50 insertions(+), 33 deletions(-) diff --git a/.classpath b/.classpath index 502bd4a..71e1373 100644 --- a/.classpath +++ b/.classpath @@ -1,5 +1,15 @@ + + + + + + + + + + @@ -13,16 +23,5 @@ - - - - - - - - - - - diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index cd2a88f..021e6ca 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,6 +1,7 @@ - + + diff --git a/CHANGELOG.md b/CHANGELOG.md index ae81762..c8b0b37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v3.0.0-SNAPSHOT] - [2022-05-13] + +porting to new IAM + ## [v2.1.0] - [2022-02-04] added OfflineObserver for test purpose diff --git a/pom.xml b/pom.xml index c70d7fe..b22fd59 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 @@ -12,7 +13,7 @@ common-smartgears-app 3.0.0-SNAPSHOT Smartgears Application - + distro @@ -24,6 +25,18 @@ https://code-repo.d4science.org/gCubeSystem/common-smartgears-app + + + + org.gcube.distribution + gcube-smartgears-bom + 3.0.0-SNAPSHOT + pom + import + + + + @@ -56,8 +69,8 @@ org.gcube.core common-smartgears - [3.0.0-SNAPSHOT,4.0.0-SNAPSHOT) - provided + + diff --git a/src/main/java/org/gcube/smartgears/ContextListener.java b/src/main/java/org/gcube/smartgears/ContextListener.java index 343f66c..b162b20 100644 --- a/src/main/java/org/gcube/smartgears/ContextListener.java +++ b/src/main/java/org/gcube/smartgears/ContextListener.java @@ -4,12 +4,10 @@ import java.net.URL; import java.util.Collection; import java.util.HashSet; import java.util.Set; - import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener; -import org.gcube.smartgears.Constants; import org.gcube.smartgears.annotations.ManagedBy; import org.gcube.smartgears.application.manager.AppManagerObserver; import org.gcube.smartgears.context.application.ApplicationContext; @@ -66,7 +64,7 @@ public class ContextListener implements ServletContextListener { } if (managers.size()>0){ observer = ApplicationManagerProvider.instance.getObserver(); - observer.setStartingTokens(context.configuration().startTokens()); + observer.setStartingTokens(context.configuration().authorizedContexts()); observer.setApplicationManagerClasses(managers); observer.register(); diff --git a/src/main/java/org/gcube/smartgears/ContextProvider.java b/src/main/java/org/gcube/smartgears/ContextProvider.java index 4398a32..3d0429e 100644 --- a/src/main/java/org/gcube/smartgears/ContextProvider.java +++ b/src/main/java/org/gcube/smartgears/ContextProvider.java @@ -3,12 +3,13 @@ package org.gcube.smartgears; import javax.servlet.ServletContext; import org.gcube.common.events.Hub; +import org.gcube.common.resources.gcore.GCoreEndpoint; import org.gcube.smartgears.configuration.application.ApplicationConfiguration; import org.gcube.smartgears.context.Properties; import org.gcube.smartgears.context.application.ApplicationContext; import org.gcube.smartgears.context.container.ContainerContext; import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle; -import org.gcube.smartgears.persistence.Persistence; +import org.gcube.smartgears.persistence.PersistenceWriter; /** * Embedded in an application, makes available its context as a gCube resource. @@ -56,12 +57,7 @@ public class ContextProvider { public ApplicationConfiguration configuration() { return delegate.configuration(); } - - @Override - public T profile(Class type) { - return delegate.profile(type); - } - + @Override public ApplicationLifecycle lifecycle() { return delegate.lifecycle(); @@ -71,12 +67,7 @@ public class ContextProvider { public Hub events() { return delegate.events(); } - - @Override - public Persistence persistence() { - return delegate.persistence(); - } - + @Override public ServletContext application() { return delegate.application(); @@ -96,6 +87,17 @@ public class ContextProvider { public String id() { return delegate.id(); } + + @Override + public GCoreEndpoint profile() { + return delegate.profile(); + } + + @Override + public PersistenceWriter persistence() { + // TODO Auto-generated method stub + return delegate.persistence(); + } } } diff --git a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java index 7463379..999d2a2 100644 --- a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java +++ b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java @@ -104,7 +104,7 @@ public class OnlineObserver implements AppManagerObserver{ public synchronized void onStop(ApplicationContext appContext){ - for (String token :appContext.configuration().startTokens()){ + for (String token :appContext.configuration().authorizedContexts()){ try { String context = authorizationService().get(token).getContext(); for (Future appManagerEntry: instanciatedManagerPerScope.get(context)){ From e076dc39dec6c4f450136b7c907ddae07c662734 Mon Sep 17 00:00:00 2001 From: lucio Date: Mon, 30 May 2022 18:30:17 +0200 Subject: [PATCH 03/11] removed ScopeProvider --- pom.xml | 8 +- .../ApplicationManagerProvider.java | 12 +- .../org/gcube/smartgears/ContextListener.java | 3 +- .../manager/AppManagerObserver.java | 4 +- .../application/manager/OfflineObserver.java | 10 +- .../application/manager/OfflineProvider.java | 2 +- .../application/manager/OnlineObserver.java | 137 +++++++----------- .../application/manager/OnlineProvider.java | 12 +- .../smartgears/stateful/ResourceBinder.java | 12 -- 9 files changed, 82 insertions(+), 118 deletions(-) delete mode 100644 src/test/java/org/gcube/smartgears/stateful/ResourceBinder.java diff --git a/pom.xml b/pom.xml index b22fd59..01ce1a1 100644 --- a/pom.xml +++ b/pom.xml @@ -69,10 +69,14 @@ org.gcube.core common-smartgears - - + + org.gcube.common + common-security + + + junit junit diff --git a/src/main/java/org/gcube/smartgears/ApplicationManagerProvider.java b/src/main/java/org/gcube/smartgears/ApplicationManagerProvider.java index 6877106..22c3ae2 100644 --- a/src/main/java/org/gcube/smartgears/ApplicationManagerProvider.java +++ b/src/main/java/org/gcube/smartgears/ApplicationManagerProvider.java @@ -32,16 +32,19 @@ public abstract class ApplicationManagerProvider { protected static synchronized void init(ApplicationContext appcontext) { if (!initialized) { - if (appcontext.container().configuration().mode()== Mode.offline) + if (appcontext.container().configuration().mode()== Mode.offline) instance = new OfflineProvider(); + else instance = new OnlineProvider(); + initialized =true; } } public static synchronized ApplicationManager get(final Class applicationManagerClass){ if (!initialized) throw new RuntimeException("ApplicationManagerProvider not yet initialized"); + logger.debug("retrieveing application manager of {} ",applicationManagerClass.getCanonicalName()); Object obj = instance.getApplicationManagerObject(applicationManagerClass); return applicationManagerClass.cast(obj); } @@ -59,13 +62,14 @@ public abstract class ApplicationManagerProvider { obj = _class.newInstance(); classProxyObjetMap.put(_class.getCanonicalName(), obj); } - + + logger.debug("proxy created for {} ",applicationManagerClass.getCanonicalName()); } catch (Exception e) { throw new RuntimeException("error creating proxy ", e); } - ((ProxyObject)obj).setHandler(getMethdoHandler(applicationManagerClass)); + ((ProxyObject)obj).setHandler(this.getMethodHandler(applicationManagerClass)); return obj; } @@ -108,7 +112,7 @@ public abstract class ApplicationManagerProvider { } protected abstract Future retrieveFuture(Class applicationManagerClass); - protected abstract MethodHandler getMethdoHandler(Class applicationManagerClass); + protected abstract MethodHandler getMethodHandler(Class applicationManagerClass); protected abstract AppManagerObserver getObserver(); } diff --git a/src/main/java/org/gcube/smartgears/ContextListener.java b/src/main/java/org/gcube/smartgears/ContextListener.java index b162b20..811a267 100644 --- a/src/main/java/org/gcube/smartgears/ContextListener.java +++ b/src/main/java/org/gcube/smartgears/ContextListener.java @@ -64,10 +64,9 @@ public class ContextListener implements ServletContextListener { } if (managers.size()>0){ observer = ApplicationManagerProvider.instance.getObserver(); - observer.setStartingTokens(context.configuration().authorizedContexts()); + observer.setAuthorizationProvider(context.container().configuration().authorizationProvider()); observer.setApplicationManagerClasses(managers); observer.register(); - context.events().subscribe(observer); } } diff --git a/src/main/java/org/gcube/smartgears/application/manager/AppManagerObserver.java b/src/main/java/org/gcube/smartgears/application/manager/AppManagerObserver.java index 13c1844..693d0cd 100644 --- a/src/main/java/org/gcube/smartgears/application/manager/AppManagerObserver.java +++ b/src/main/java/org/gcube/smartgears/application/manager/AppManagerObserver.java @@ -1,10 +1,10 @@ package org.gcube.smartgears.application.manager; -import java.util.Collection; import java.util.Set; import org.gcube.smartgears.ApplicationManager; import org.gcube.smartgears.context.application.ApplicationContext; +import org.gcube.smartgears.security.AuthorizationProvider; public interface AppManagerObserver { @@ -16,7 +16,7 @@ public interface AppManagerObserver { void unregister(); - void setStartingTokens(Collection startingTokens); + public void setAuthorizationProvider(AuthorizationProvider authProvider); void setApplicationManagerClasses(Set> managersClasses); diff --git a/src/main/java/org/gcube/smartgears/application/manager/OfflineObserver.java b/src/main/java/org/gcube/smartgears/application/manager/OfflineObserver.java index bd65043..f36a208 100644 --- a/src/main/java/org/gcube/smartgears/application/manager/OfflineObserver.java +++ b/src/main/java/org/gcube/smartgears/application/manager/OfflineObserver.java @@ -1,6 +1,5 @@ package org.gcube.smartgears.application.manager; -import java.util.Collection; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; @@ -13,6 +12,7 @@ import org.gcube.common.events.Observes.Kind; import org.gcube.smartgears.ApplicationManager; import org.gcube.smartgears.Constants; import org.gcube.smartgears.context.application.ApplicationContext; +import org.gcube.smartgears.security.AuthorizationProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -109,13 +109,15 @@ public class OfflineObserver implements AppManagerObserver { } } - @Override - public void setStartingTokens(Collection startingTokens) { - } + @Override public void setApplicationManagerClasses(Set> managerClasses) { this.managerClasses = managerClasses; } + + @Override + public void setAuthorizationProvider(AuthorizationProvider authProvider) { + } } diff --git a/src/main/java/org/gcube/smartgears/application/manager/OfflineProvider.java b/src/main/java/org/gcube/smartgears/application/manager/OfflineProvider.java index 49f915f..22f947a 100644 --- a/src/main/java/org/gcube/smartgears/application/manager/OfflineProvider.java +++ b/src/main/java/org/gcube/smartgears/application/manager/OfflineProvider.java @@ -27,7 +27,7 @@ public class OfflineProvider extends ApplicationManagerProvider { } @Override - protected MethodHandler getMethdoHandler(Class applicationManagerClass) { + protected MethodHandler getMethodHandler(Class applicationManagerClass) { MethodHandler handler = new MethodHandler() { @Override public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable { diff --git a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java index 999d2a2..d218d88 100644 --- a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java +++ b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java @@ -1,9 +1,6 @@ package org.gcube.smartgears.application.manager; -import static org.gcube.common.authorization.client.Constants.authorizationService; - import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -13,14 +10,14 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import org.gcube.common.authorization.client.exceptions.ObjectNotFound; -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.events.Observes; import org.gcube.common.events.Observes.Kind; -import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.security.providers.SecretManagerProvider; +import org.gcube.common.security.secrets.Secret; import org.gcube.smartgears.ApplicationManager; import org.gcube.smartgears.Constants; import org.gcube.smartgears.context.application.ApplicationContext; +import org.gcube.smartgears.security.AuthorizationProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,32 +30,36 @@ public class OnlineObserver implements AppManagerObserver{ private Map>> instanciatedManagerPerScope = new HashMap>>(); private OnlineProvider provider; - - private Collection startingTokens; - + + private AuthorizationProvider authProvider; + private Set> managersClasses; - + public OnlineObserver(OnlineProvider provider) { this.provider = provider; - + } public void register() { - for (String startingToken : startingTokens ) - this.onRegistration(startingToken); + for (String context : authProvider.getContexts()) { + this.onRegistration(context); + } } - + @Observes(value=Constants.token_registered, kind=Kind.safe) - public synchronized void onRegistration(final String securityToken){ - log.info("token registered called with token {}", securityToken); + public synchronized void onRegistration(String context){ + log.info("registration called in context {}", context); List> futureList = new ArrayList>(); try { - final String context = authorizationService().get(securityToken).getContext(); + + Secret secret = authProvider.getSecretForContext(context); for (Class appManager: managersClasses){ - Future appManagerFuture = service.submit(new InitAppManager(securityToken, context, appManager)); - log.info("intializing app in context {} with token {} ",context, securityToken); + + + Future appManagerFuture = service.submit(new InitAppManager(secret, appManager)); + log.info("intializing app using manager {} in context {}",appManager.getClass().getCanonicalName(),context); futureList.add(appManagerFuture); if (provider.getAppmanagerMap().containsKey(appManager.getCanonicalName())) @@ -71,31 +72,24 @@ public class OnlineObserver implements AppManagerObserver{ } if (!futureList.isEmpty()) instanciatedManagerPerScope.put(context, futureList); - } catch (ObjectNotFound e1) { - log.error("it should never happen (token has just been created)",e1); - throw new RuntimeException("it should never happen (token has just been created",e1); } catch (Exception e1) { - log.error("something failed getting token",e1); - throw new RuntimeException("something failed getting token",e1); + log.error("something failed getting authorization",e1); + throw new RuntimeException("something failed getting authorization",e1); } } @Observes(value=Constants.token_removed, kind=Kind.critical) - public synchronized void onRemove(final String securityToken){ + public synchronized void onRemove(String context){ try { - final String context = authorizationService().get(securityToken).getContext(); + + Secret secret = authProvider.getSecretForContext(context); for (Future appManager: instanciatedManagerPerScope.get(context)){ - service.execute(new ShutDownAppManager(securityToken, context, appManager)); + service.execute(new ShutDownAppManager(secret, appManager)); provider.getAppmanagerMap().get(appManager).remove(context); } - instanciatedManagerPerScope.remove(context); - SecurityTokenProvider.instance.reset(); - } catch (ObjectNotFound e1) { - log.error("it should never happen (token has just been created)",e1); - throw new RuntimeException("it should never happen (token has just been created",e1); } catch (Exception e1) { log.error("something failed getting token",e1); throw new RuntimeException("something failed getting token",e1); @@ -104,35 +98,9 @@ public class OnlineObserver implements AppManagerObserver{ public synchronized void onStop(ApplicationContext appContext){ - for (String token :appContext.configuration().authorizedContexts()){ - try { - String context = authorizationService().get(token).getContext(); - for (Future appManagerEntry: instanciatedManagerPerScope.get(context)){ - try{ - log.info("stoppping {} in context {} ",appContext.name(), context); + for (String context :appContext.configuration().authorizedContexts()) + this.onRemove(context); - SecurityTokenProvider.instance.set(token); - ScopeProvider.instance.set(context); - try { - appManagerEntry.get().onShutdown(); - log.info("manager {} correctly suhtdown on context {}",appContext.name(), context); - } catch (Exception e){ - log.warn("problem calling onShutdown for context {}", context, e); - } - }catch(Exception e){ - log.error("error retrieving token on shutdown on context {}", context,e); - throw new RuntimeException("error retrieving token on shutdown",e); - }finally{ - ScopeProvider.instance.reset(); - SecurityTokenProvider.instance.reset(); - } - } - } catch (ObjectNotFound e1) { - log.error("token not found : {}",token,e1); - } catch (Exception e1) { - log.error("something failed getting token {}",token,e1); - } - } unregister(); } @@ -143,28 +111,27 @@ public class OnlineObserver implements AppManagerObserver{ public class InitAppManager implements Callable{ private Class managerClass; - private String securityToken; - private String context; + private Secret secret; - public InitAppManager(String securityToken, String context, Class managerClass){ + public InitAppManager(Secret secret, Class managerClass){ this.managerClass = managerClass; - this.securityToken = securityToken; - this.context = context; + this.secret = secret; + } @Override public ApplicationManager call() throws Exception { - SecurityTokenProvider.instance.set(securityToken); - ScopeProvider.instance.set(context); - ApplicationManager manager = managerClass.newInstance(); + log.info("on init called"); + SecretManagerProvider.instance.set(secret); + ApplicationManager manager = null; try { - log.info("calling on onInit of {} on token {}",manager.getClass().getCanonicalName(), securityToken); + manager = managerClass.newInstance(); + log.info("calling on onInit on manager {} with secret {}",manager.getClass().getCanonicalName(),secret); manager.onInit(); } catch (Exception e) { - log.warn("error on onInit of {} on token {}",manager.getClass().getCanonicalName(), securityToken, e); + log.warn("error on onInit of {} on context {}",manager.getClass().getCanonicalName(), secret.getContext(), e); } finally{ - ScopeProvider.instance.reset(); - SecurityTokenProvider.instance.reset(); + SecretManagerProvider.instance.reset(); } return manager; } @@ -173,35 +140,31 @@ public class OnlineObserver implements AppManagerObserver{ public class ShutDownAppManager implements Runnable{ private Future appManager; - private String securityToken; - private String context; + private Secret secret; - public ShutDownAppManager(String securityToken, String context, Future appManager){ + public ShutDownAppManager(Secret secret, Future appManager){ this.appManager = appManager; - this.securityToken = securityToken; - this.context = context; + } @Override public void run() { - SecurityTokenProvider.instance.set(securityToken); - ScopeProvider.instance.set(context); + SecretManagerProvider.instance.set(secret); try { - log.info("calling on ShutDown of {} on token {}",appManager.getClass().getCanonicalName(), securityToken); + log.info("calling on ShutDown of {} on context {}",appManager.getClass().getCanonicalName(), secret.getContext()); appManager.get().onShutdown(); } catch (Exception e) { - log.warn("error on onShutdown of {} on token {}",appManager.getClass().getCanonicalName(), securityToken, e); + log.warn("error on onShutdown of {} on context {}",appManager.getClass().getCanonicalName(), secret.getContext(), e); } finally{ - ScopeProvider.instance.reset(); - SecurityTokenProvider.instance.reset(); + SecretManagerProvider.instance.reset(); } } } @Override - public void setStartingTokens(Collection startingTokens) { - this.startingTokens = startingTokens; - + public void setAuthorizationProvider(AuthorizationProvider authProvider) { + this.authProvider = authProvider; + } @Override @@ -209,5 +172,5 @@ public class OnlineObserver implements AppManagerObserver{ this.managersClasses = managersClasses; } - + } diff --git a/src/main/java/org/gcube/smartgears/application/manager/OnlineProvider.java b/src/main/java/org/gcube/smartgears/application/manager/OnlineProvider.java index 91f034b..6266646 100644 --- a/src/main/java/org/gcube/smartgears/application/manager/OnlineProvider.java +++ b/src/main/java/org/gcube/smartgears/application/manager/OnlineProvider.java @@ -5,7 +5,8 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.Future; -import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.security.providers.SecretManagerProvider; +import org.gcube.common.security.secrets.Secret; import org.gcube.smartgears.ApplicationManager; import org.gcube.smartgears.ApplicationManagerProvider; import org.slf4j.Logger; @@ -25,15 +26,18 @@ public class OnlineProvider extends ApplicationManagerProvider { @Override protected Future retrieveFuture(Class applicationManagerClass) { - return appManagerMap.get(applicationManagerClass.getCanonicalName()).get(ScopeProvider.instance.get()); + Secret secret = SecretManagerProvider.instance.get(); + String context = secret.getContext(); + logger.debug("retrieving appManager {} in context {}",applicationManagerClass.getCanonicalName(), context); + return appManagerMap.get(applicationManagerClass.getCanonicalName()).get(context); } @Override - protected MethodHandler getMethdoHandler(Class applicationManagerClass) { + protected MethodHandler getMethodHandler(Class applicationManagerClass) { MethodHandler handler = new MethodHandler() { @Override public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable { - if (ScopeProvider.instance.get()==null) throw new RuntimeException("error invoking application manager method, scope is not set in this thread"); + if (SecretManagerProvider.instance.get()==null) throw new Exception("error invoking application manager method, secret is not set in this thread"); logger.debug("applicationManagerClass is {}",applicationManagerClass.getCanonicalName()); Future appManagerFuture = retrieveFuture(applicationManagerClass); logger.debug("appmanager future is null? {}", appManagerFuture==null); diff --git a/src/test/java/org/gcube/smartgears/stateful/ResourceBinder.java b/src/test/java/org/gcube/smartgears/stateful/ResourceBinder.java deleted file mode 100644 index aef5694..0000000 --- a/src/test/java/org/gcube/smartgears/stateful/ResourceBinder.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.gcube.smartgears.stateful; - -import org.junit.Test; - -public class ResourceBinder { - - @Test - public void bind() throws Exception{ - - } - -} From b65fe507af1221d39221d1c7e7157ca45f6d7cce Mon Sep 17 00:00:00 2001 From: lucio Date: Fri, 10 Jun 2022 17:11:39 +0200 Subject: [PATCH 04/11] changes on OnlineObserver --- src/main/java/org/gcube/smartgears/ContextProvider.java | 6 ------ .../smartgears/application/manager/OnlineObserver.java | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/org/gcube/smartgears/ContextProvider.java b/src/main/java/org/gcube/smartgears/ContextProvider.java index 3d0429e..25a7e5d 100644 --- a/src/main/java/org/gcube/smartgears/ContextProvider.java +++ b/src/main/java/org/gcube/smartgears/ContextProvider.java @@ -3,7 +3,6 @@ package org.gcube.smartgears; import javax.servlet.ServletContext; import org.gcube.common.events.Hub; -import org.gcube.common.resources.gcore.GCoreEndpoint; import org.gcube.smartgears.configuration.application.ApplicationConfiguration; import org.gcube.smartgears.context.Properties; import org.gcube.smartgears.context.application.ApplicationContext; @@ -88,11 +87,6 @@ public class ContextProvider { return delegate.id(); } - @Override - public GCoreEndpoint profile() { - return delegate.profile(); - } - @Override public PersistenceWriter persistence() { // TODO Auto-generated method stub diff --git a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java index d218d88..6889abf 100644 --- a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java +++ b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java @@ -98,7 +98,7 @@ public class OnlineObserver implements AppManagerObserver{ public synchronized void onStop(ApplicationContext appContext){ - for (String context :appContext.configuration().authorizedContexts()) + for (String context :appContext.container().configuration().authorizationProvider().getContexts()) this.onRemove(context); unregister(); From bdbbd55d8cd2c4f1971f0a06cccbc3c42d092e61 Mon Sep 17 00:00:00 2001 From: lucio Date: Wed, 22 Jun 2022 18:26:37 +0200 Subject: [PATCH 05/11] logs improved --- src/main/java/org/gcube/smartgears/ContextListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/smartgears/ContextListener.java b/src/main/java/org/gcube/smartgears/ContextListener.java index 811a267..35270ab 100644 --- a/src/main/java/org/gcube/smartgears/ContextListener.java +++ b/src/main/java/org/gcube/smartgears/ContextListener.java @@ -59,7 +59,7 @@ public class ContextListener implements ServletContextListener { Set> managers = new HashSet>(); for (Class initializer: toInitialize ){ ManagedBy manageBy = initializer.getAnnotation(ManagedBy.class); - log.info("ApplicationManager added {} @ {}", manageBy.value().getSimpleName(), context.name()); + log.info("ApplicationManager added {} to {} @ {}", manageBy.value().getSimpleName(), initializer.getSimpleName(), context.name()); managers.add(manageBy.value()); } if (managers.size()>0){ From c20234af241017989c88f491290d902f3e56c352 Mon Sep 17 00:00:00 2001 From: lucio Date: Mon, 12 Sep 2022 15:32:57 +0200 Subject: [PATCH 06/11] solved bug on shutdown --- .../gcube/smartgears/application/manager/OnlineObserver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java index 6889abf..2da5322 100644 --- a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java +++ b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java @@ -87,7 +87,7 @@ public class OnlineObserver implements AppManagerObserver{ for (Future appManager: instanciatedManagerPerScope.get(context)){ service.execute(new ShutDownAppManager(secret, appManager)); - provider.getAppmanagerMap().get(appManager).remove(context); + provider.getAppmanagerMap().get(appManager.getClass().getCanonicalName()).remove(context); } instanciatedManagerPerScope.remove(context); } catch (Exception e1) { From c80f8896a1e7bcd7c4fd45048ed23beab9b8b3f0 Mon Sep 17 00:00:00 2001 From: lucio Date: Tue, 6 Dec 2022 14:50:36 +0100 Subject: [PATCH 07/11] solved bug on remove context --- .classpath | 6 +---- pom.xml | 3 ++- .../org/gcube/smartgears/ManagerPair.java | 26 +++++++++++++++++++ .../application/manager/OnlineObserver.java | 19 +++++++++----- 4 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 src/main/java/org/gcube/smartgears/ManagerPair.java diff --git a/.classpath b/.classpath index 71e1373..2497e80 100644 --- a/.classpath +++ b/.classpath @@ -5,11 +5,7 @@ - - - - - + diff --git a/pom.xml b/pom.xml index 01ce1a1..4d3f8e9 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,8 @@ distro + 1.8 + 1.8 @@ -49,7 +51,6 @@ org.reflections reflections - 0.9.10 diff --git a/src/main/java/org/gcube/smartgears/ManagerPair.java b/src/main/java/org/gcube/smartgears/ManagerPair.java new file mode 100644 index 0000000..cbd30af --- /dev/null +++ b/src/main/java/org/gcube/smartgears/ManagerPair.java @@ -0,0 +1,26 @@ +package org.gcube.smartgears; + +import java.util.concurrent.Future; + +public class ManagerPair { + + private Class clazz; + + private Future future; + + public ManagerPair(Class clazz, Future future) { + super(); + this.clazz = clazz; + this.future = future; + } + + public Class getImplementationClass() { + return clazz; + } + + public Future getFuture() { + return future; + } + + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java index 2da5322..1a354f6 100644 --- a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java +++ b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java @@ -16,6 +16,7 @@ import org.gcube.common.security.providers.SecretManagerProvider; import org.gcube.common.security.secrets.Secret; import org.gcube.smartgears.ApplicationManager; import org.gcube.smartgears.Constants; +import org.gcube.smartgears.ManagerPair; import org.gcube.smartgears.context.application.ApplicationContext; import org.gcube.smartgears.security.AuthorizationProvider; import org.slf4j.Logger; @@ -27,7 +28,7 @@ public class OnlineObserver implements AppManagerObserver{ private static ExecutorService service = Executors.newCachedThreadPool(); - private Map>> instanciatedManagerPerScope = new HashMap>>(); + private Map> instanciatedManagerPerScope = new HashMap>(); private OnlineProvider provider; @@ -49,7 +50,7 @@ public class OnlineObserver implements AppManagerObserver{ @Observes(value=Constants.token_registered, kind=Kind.safe) public synchronized void onRegistration(String context){ log.info("registration called in context {}", context); - List> futureList = new ArrayList>(); + List futureList = new ArrayList(); try { @@ -61,7 +62,7 @@ public class OnlineObserver implements AppManagerObserver{ Future appManagerFuture = service.submit(new InitAppManager(secret, appManager)); log.info("intializing app using manager {} in context {}",appManager.getClass().getCanonicalName(),context); - futureList.add(appManagerFuture); + futureList.add(new ManagerPair(appManager, appManagerFuture)); if (provider.getAppmanagerMap().containsKey(appManager.getCanonicalName())) provider.getAppmanagerMap().get(appManager.getCanonicalName()).put(context, appManagerFuture); else { @@ -85,10 +86,14 @@ public class OnlineObserver implements AppManagerObserver{ Secret secret = authProvider.getSecretForContext(context); - for (Future appManager: instanciatedManagerPerScope.get(context)){ - service.execute(new ShutDownAppManager(secret, appManager)); - provider.getAppmanagerMap().get(appManager.getClass().getCanonicalName()).remove(context); - } + if(instanciatedManagerPerScope.get(context) != null ) { + for (ManagerPair manager: instanciatedManagerPerScope.get(context)){ + service.execute(new ShutDownAppManager(secret, manager.getFuture())); + provider.getAppmanagerMap().get(manager.getImplementationClass().getCanonicalName()).remove(context); + } + instanciatedManagerPerScope.remove(context); + } + instanciatedManagerPerScope.remove(context); } catch (Exception e1) { log.error("something failed getting token",e1); From d04d5dafbf28fa9d78fad725c824cc1fb85153fd Mon Sep 17 00:00:00 2001 From: lucio Date: Thu, 19 Jan 2023 16:16:48 +0100 Subject: [PATCH 08/11] AuthorizationProvider moved from configuration to context --- src/main/java/org/gcube/smartgears/ContextListener.java | 2 +- src/main/java/org/gcube/smartgears/ContextProvider.java | 6 ++++++ .../smartgears/application/manager/OnlineObserver.java | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/smartgears/ContextListener.java b/src/main/java/org/gcube/smartgears/ContextListener.java index 35270ab..44df785 100644 --- a/src/main/java/org/gcube/smartgears/ContextListener.java +++ b/src/main/java/org/gcube/smartgears/ContextListener.java @@ -64,7 +64,7 @@ public class ContextListener implements ServletContextListener { } if (managers.size()>0){ observer = ApplicationManagerProvider.instance.getObserver(); - observer.setAuthorizationProvider(context.container().configuration().authorizationProvider()); + observer.setAuthorizationProvider(context.container().authorizationProvider()); observer.setApplicationManagerClasses(managers); observer.register(); context.events().subscribe(observer); diff --git a/src/main/java/org/gcube/smartgears/ContextProvider.java b/src/main/java/org/gcube/smartgears/ContextProvider.java index 25a7e5d..e98e1c6 100644 --- a/src/main/java/org/gcube/smartgears/ContextProvider.java +++ b/src/main/java/org/gcube/smartgears/ContextProvider.java @@ -9,6 +9,7 @@ import org.gcube.smartgears.context.application.ApplicationContext; import org.gcube.smartgears.context.container.ContainerContext; import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle; import org.gcube.smartgears.persistence.PersistenceWriter; +import org.gcube.smartgears.security.AuthorizationProvider; /** * Embedded in an application, makes available its context as a gCube resource. @@ -92,6 +93,11 @@ public class ContextProvider { // TODO Auto-generated method stub return delegate.persistence(); } + + @Override + public AuthorizationProvider authorizationProvider() { + return delegate.authorizationProvider(); + } } } diff --git a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java index 1a354f6..78c7fa0 100644 --- a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java +++ b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java @@ -103,7 +103,7 @@ public class OnlineObserver implements AppManagerObserver{ public synchronized void onStop(ApplicationContext appContext){ - for (String context :appContext.container().configuration().authorizationProvider().getContexts()) + for (String context :appContext.authorizationProvider().getContexts()) this.onRemove(context); unregister(); From 73cba3adc73f47698945426d275891c7a3c26fd8 Mon Sep 17 00:00:00 2001 From: lucio Date: Wed, 1 Feb 2023 14:41:47 +0100 Subject: [PATCH 09/11] updated --- .gitignore | 1 + .../java/org/gcube/smartgears/ApplicationManagerProvider.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/src/main/java/org/gcube/smartgears/ApplicationManagerProvider.java b/src/main/java/org/gcube/smartgears/ApplicationManagerProvider.java index 22c3ae2..b5bcae3 100644 --- a/src/main/java/org/gcube/smartgears/ApplicationManagerProvider.java +++ b/src/main/java/org/gcube/smartgears/ApplicationManagerProvider.java @@ -59,7 +59,7 @@ public abstract class ApplicationManagerProvider { logger.trace("getting object {} from cache ",_class.getCanonicalName()); return obj; } else { - obj = _class.newInstance(); + obj = _class.getDeclaredConstructor().newInstance(); classProxyObjetMap.put(_class.getCanonicalName(), obj); } From 7738b1ea1f1f0f720c20930cf43d6b2c04eb9793 Mon Sep 17 00:00:00 2001 From: lucio Date: Thu, 2 Feb 2023 11:14:56 +0100 Subject: [PATCH 10/11] warning removed --- .classpath | 7 ++++++- .settings/org.eclipse.wst.common.component | 6 +++++- .../smartgears/application/manager/OfflineObserver.java | 2 +- .../smartgears/application/manager/OnlineObserver.java | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.classpath b/.classpath index 2497e80..2e4d759 100644 --- a/.classpath +++ b/.classpath @@ -1,11 +1,16 @@ + + + + + + - diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 021e6ca..302f34a 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,7 +1,11 @@ + + + - + + diff --git a/src/main/java/org/gcube/smartgears/application/manager/OfflineObserver.java b/src/main/java/org/gcube/smartgears/application/manager/OfflineObserver.java index f36a208..e2ec55f 100644 --- a/src/main/java/org/gcube/smartgears/application/manager/OfflineObserver.java +++ b/src/main/java/org/gcube/smartgears/application/manager/OfflineObserver.java @@ -79,7 +79,7 @@ public class OfflineObserver implements AppManagerObserver { @Override public ApplicationManager call() throws Exception { - ApplicationManager manager = managerClass.newInstance(); + ApplicationManager manager = managerClass.getDeclaredConstructor().newInstance(); try { log.info("calling on onInit of {}",manager.getClass().getCanonicalName()); manager.onInit(); diff --git a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java index 78c7fa0..d997339 100644 --- a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java +++ b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java @@ -130,7 +130,7 @@ public class OnlineObserver implements AppManagerObserver{ SecretManagerProvider.instance.set(secret); ApplicationManager manager = null; try { - manager = managerClass.newInstance(); + manager = managerClass.getDeclaredConstructor().newInstance(); log.info("calling on onInit on manager {} with secret {}",manager.getClass().getCanonicalName(),secret); manager.onInit(); } catch (Exception e) { From 6b056664a99e43d7220a2317905ccb844c502c07 Mon Sep 17 00:00:00 2001 From: lucio Date: Tue, 4 Apr 2023 09:26:45 +0200 Subject: [PATCH 11/11] updated --- .classpath | 2 +- .settings/org.eclipse.jdt.core.prefs | 8 ++++---- .settings/org.eclipse.wst.common.project.facet.core.xml | 2 +- pom.xml | 5 +++-- src/main/java/org/gcube/smartgears/ContextProvider.java | 1 - 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.classpath b/.classpath index 2e4d759..40ed22b 100644 --- a/.classpath +++ b/.classpath @@ -6,7 +6,7 @@ - + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index db24ee7..ec55441 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,8 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.compliance=11 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -10,6 +10,6 @@ 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.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=1.8 +org.eclipse.jdt.core.compiler.source=11 diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index f4bf050..54a5299 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,5 +1,5 @@ - + diff --git a/pom.xml b/pom.xml index 4d3f8e9..4be0406 100644 --- a/pom.xml +++ b/pom.xml @@ -17,8 +17,9 @@ distro - 1.8 - 1.8 + UTF-8 + 11 + 11 diff --git a/src/main/java/org/gcube/smartgears/ContextProvider.java b/src/main/java/org/gcube/smartgears/ContextProvider.java index e98e1c6..a893f5e 100644 --- a/src/main/java/org/gcube/smartgears/ContextProvider.java +++ b/src/main/java/org/gcube/smartgears/ContextProvider.java @@ -90,7 +90,6 @@ public class ContextProvider { @Override public PersistenceWriter persistence() { - // TODO Auto-generated method stub return delegate.persistence(); }