From d2aaf739ee4788fdae3afd0a51fe93372eb25a64 Mon Sep 17 00:00:00 2001
From: lucio <lucio@192.168.1.66>
Date: Wed, 2 Oct 2024 11:45:44 +0200
Subject: [PATCH] moved Authorization interfaces to common security

---
 CHANGELOG.md                                    |  2 +-
 pom.xml                                         |  2 +-
 .../AuthorizationProviderConfiguration.java     |  2 +-
 .../container/ContainerConfigurationBinder.java |  2 +-
 .../context/application/ApplicationContext.java |  2 +-
 .../application/DefaultApplicationContext.java  |  2 +-
 .../context/container/ContainerContext.java     |  2 +-
 .../container/DefaultContainerContext.java      |  2 +-
 .../smartgears/provider/DefaultProvider.java    |  4 ++--
 .../security/AuthorizationProvider.java         | 17 -----------------
 .../security/AuthorizationProviderFactory.java  |  9 ---------
 .../defaults/DefaultAuthorizationProvider.java  |  2 +-
 .../DefaultAuthorizationProviderFactory.java    |  2 +-
 13 files changed, 12 insertions(+), 38 deletions(-)
 delete mode 100644 src/main/java/org/gcube/smartgears/security/AuthorizationProvider.java
 delete mode 100644 src/main/java/org/gcube/smartgears/security/AuthorizationProviderFactory.java

diff --git a/CHANGELOG.md b/CHANGELOG.md
index c5bb9d1..ee099e0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
 
 # Changelog for Common Smartgears
 
-## [v4.0.0]
+## [v4.0.0-SNAPSHOT]
 
 - porting to keycloak
 - moved to jakarta and servlet6
diff --git a/pom.xml b/pom.xml
index 741c24a..074356e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
 	</parent>
 	<groupId>org.gcube.core</groupId>
 	<artifactId>common-smartgears</artifactId>
-	<version>4.0.0</version>
+	<version>4.0.0-SNAPSHOT</version>
 	<name>SmartGears</name>
 	<dependencyManagement>
 		<dependencies>
diff --git a/src/main/java/org/gcube/smartgears/configuration/AuthorizationProviderConfiguration.java b/src/main/java/org/gcube/smartgears/configuration/AuthorizationProviderConfiguration.java
index 9f87397..963fa4a 100644
--- a/src/main/java/org/gcube/smartgears/configuration/AuthorizationProviderConfiguration.java
+++ b/src/main/java/org/gcube/smartgears/configuration/AuthorizationProviderConfiguration.java
@@ -1,9 +1,9 @@
 package org.gcube.smartgears.configuration;
 
 import org.gcube.common.security.credentials.Credentials;
+import org.gcube.common.security.factories.AuthorizationProviderFactory;
 import org.gcube.common.validator.annotations.IsValid;
 import org.gcube.common.validator.annotations.NotNull;
-import org.gcube.smartgears.security.AuthorizationProviderFactory;
 
 public class AuthorizationProviderConfiguration {
 
diff --git a/src/main/java/org/gcube/smartgears/configuration/container/ContainerConfigurationBinder.java b/src/main/java/org/gcube/smartgears/configuration/container/ContainerConfigurationBinder.java
index f24928a..e6a4ea0 100644
--- a/src/main/java/org/gcube/smartgears/configuration/container/ContainerConfigurationBinder.java
+++ b/src/main/java/org/gcube/smartgears/configuration/container/ContainerConfigurationBinder.java
@@ -9,6 +9,7 @@ import java.util.Map.Entry;
 import java.util.stream.Collectors;
 
 import org.gcube.common.security.credentials.Credentials;
+import org.gcube.common.security.factories.AuthorizationProviderFactory;
 import org.gcube.smartgears.configuration.AuthorizationProviderConfiguration;
 import org.gcube.smartgears.configuration.ComponentConfiguration;
 import org.gcube.smartgears.configuration.ConfiguredWith;
@@ -21,7 +22,6 @@ import org.gcube.smartgears.handlers.container.lifecycle.ContainerProfileManager
 import org.gcube.smartgears.persistence.LocalWriter;
 import org.gcube.smartgears.persistence.LocalWriterConfiguration;
 import org.gcube.smartgears.persistence.PersistenceWriter;
-import org.gcube.smartgears.security.AuthorizationProviderFactory;
 import org.gcube.smartgears.security.defaults.DefaultAuthorizationProviderFactory;
 import org.gcube.smartgears.utils.Utils;
 import org.ini4j.Ini;
diff --git a/src/main/java/org/gcube/smartgears/context/application/ApplicationContext.java b/src/main/java/org/gcube/smartgears/context/application/ApplicationContext.java
index f6b06a5..9fea259 100644
--- a/src/main/java/org/gcube/smartgears/context/application/ApplicationContext.java
+++ b/src/main/java/org/gcube/smartgears/context/application/ApplicationContext.java
@@ -4,13 +4,13 @@ import java.nio.file.Path;
 import java.util.List;
 
 import org.gcube.common.events.Hub;
+import org.gcube.common.security.factories.AuthorizationProvider;
 import org.gcube.common.security.secrets.Secret;
 import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
 import org.gcube.smartgears.context.Properties;
 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;
 import org.gcube.smartgears.security.secrets.SecretFactory;
 
 import jakarta.servlet.ServletContext;
diff --git a/src/main/java/org/gcube/smartgears/context/application/DefaultApplicationContext.java b/src/main/java/org/gcube/smartgears/context/application/DefaultApplicationContext.java
index ad85dcf..eb41380 100644
--- a/src/main/java/org/gcube/smartgears/context/application/DefaultApplicationContext.java
+++ b/src/main/java/org/gcube/smartgears/context/application/DefaultApplicationContext.java
@@ -14,6 +14,7 @@ import java.util.List;
 import java.util.UUID;
 
 import org.gcube.common.events.Hub;
+import org.gcube.common.security.factories.AuthorizationProvider;
 import org.gcube.common.security.secrets.Secret;
 import org.gcube.smartgears.configuration.PersistenceConfiguration;
 import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
@@ -21,7 +22,6 @@ import org.gcube.smartgears.context.Properties;
 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;
 import org.gcube.smartgears.security.secrets.GCubeKeyCloakSecretFactory;
 import org.gcube.smartgears.security.secrets.LegacyGCubeTokenSecretFactory;
 import org.gcube.smartgears.security.secrets.SecretFactory;
diff --git a/src/main/java/org/gcube/smartgears/context/container/ContainerContext.java b/src/main/java/org/gcube/smartgears/context/container/ContainerContext.java
index e3729a9..c1bee54 100644
--- a/src/main/java/org/gcube/smartgears/context/container/ContainerContext.java
+++ b/src/main/java/org/gcube/smartgears/context/container/ContainerContext.java
@@ -1,11 +1,11 @@
 package org.gcube.smartgears.context.container;
 
 import org.gcube.common.events.Hub;
+import org.gcube.common.security.factories.AuthorizationProvider;
 import org.gcube.smartgears.configuration.container.ContainerConfiguration;
 import org.gcube.smartgears.context.Properties;
 import org.gcube.smartgears.lifecycle.container.ContainerLifecycle;
 import org.gcube.smartgears.persistence.PersistenceWriter;
-import org.gcube.smartgears.security.AuthorizationProvider;
 
 /**
  * The management context of the container.
diff --git a/src/main/java/org/gcube/smartgears/context/container/DefaultContainerContext.java b/src/main/java/org/gcube/smartgears/context/container/DefaultContainerContext.java
index cde9c96..f372a56 100644
--- a/src/main/java/org/gcube/smartgears/context/container/DefaultContainerContext.java
+++ b/src/main/java/org/gcube/smartgears/context/container/DefaultContainerContext.java
@@ -8,12 +8,12 @@ import java.io.ObjectInputStream;
 import java.util.UUID;
 
 import org.gcube.common.events.Hub;
+import org.gcube.common.security.factories.AuthorizationProvider;
 import org.gcube.smartgears.configuration.PersistenceConfiguration;
 import org.gcube.smartgears.configuration.container.ContainerConfiguration;
 import org.gcube.smartgears.context.Properties;
 import org.gcube.smartgears.lifecycle.container.ContainerLifecycle;
 import org.gcube.smartgears.persistence.PersistenceWriter;
-import org.gcube.smartgears.security.AuthorizationProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
diff --git a/src/main/java/org/gcube/smartgears/provider/DefaultProvider.java b/src/main/java/org/gcube/smartgears/provider/DefaultProvider.java
index 65cd64b..b35b54f 100644
--- a/src/main/java/org/gcube/smartgears/provider/DefaultProvider.java
+++ b/src/main/java/org/gcube/smartgears/provider/DefaultProvider.java
@@ -18,6 +18,8 @@ import jakarta.servlet.ServletContext;
 import org.gcube.common.events.Hub;
 import org.gcube.common.events.impl.DefaultHub;
 import org.gcube.common.security.credentials.Credentials;
+import org.gcube.common.security.factories.AuthorizationProvider;
+import org.gcube.common.security.factories.AuthorizationProviderFactory;
 import org.gcube.smartgears.configuration.SmartgearsConfiguration;
 import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
 import org.gcube.smartgears.configuration.application.ApplicationConfigurationBinder;
@@ -36,8 +38,6 @@ import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle;
 import org.gcube.smartgears.lifecycle.container.ContainerLifecycle;
 import org.gcube.smartgears.publishing.Publisher;
 import org.gcube.smartgears.publishing.SmartgearsProfilePublisher;
-import org.gcube.smartgears.security.AuthorizationProvider;
-import org.gcube.smartgears.security.AuthorizationProviderFactory;
 import org.gcube.smartgears.utils.Utils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
diff --git a/src/main/java/org/gcube/smartgears/security/AuthorizationProvider.java b/src/main/java/org/gcube/smartgears/security/AuthorizationProvider.java
deleted file mode 100644
index c2a94aa..0000000
--- a/src/main/java/org/gcube/smartgears/security/AuthorizationProvider.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.gcube.smartgears.security;
-
-import java.util.Set;
-
-import org.gcube.common.security.credentials.Credentials;
-import org.gcube.common.security.secrets.Secret;
-
-public interface AuthorizationProvider {
-
-	Set<String> getContexts();
-	
-	Secret getSecretForContext(String context);
-	
-	@Deprecated
-	Credentials getCredentials();
-
-}
diff --git a/src/main/java/org/gcube/smartgears/security/AuthorizationProviderFactory.java b/src/main/java/org/gcube/smartgears/security/AuthorizationProviderFactory.java
deleted file mode 100644
index 63d9eda..0000000
--- a/src/main/java/org/gcube/smartgears/security/AuthorizationProviderFactory.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.gcube.smartgears.security;
-
-import org.gcube.common.security.credentials.Credentials;
-
-public interface AuthorizationProviderFactory<T extends AuthorizationProvider> {
-
-	T connect(Credentials credentials);
-	
-}
diff --git a/src/main/java/org/gcube/smartgears/security/defaults/DefaultAuthorizationProvider.java b/src/main/java/org/gcube/smartgears/security/defaults/DefaultAuthorizationProvider.java
index 88eb3fe..8c0adae 100644
--- a/src/main/java/org/gcube/smartgears/security/defaults/DefaultAuthorizationProvider.java
+++ b/src/main/java/org/gcube/smartgears/security/defaults/DefaultAuthorizationProvider.java
@@ -12,9 +12,9 @@ import org.gcube.common.keycloak.model.AccessToken.Access;
 import org.gcube.common.keycloak.model.ModelUtils;
 import org.gcube.common.keycloak.model.TokenResponse;
 import org.gcube.common.security.ContextBean;
+import org.gcube.common.security.factories.AuthorizationProvider;
 import org.gcube.common.security.secrets.Secret;
 import org.gcube.common.security.secrets.UmaTokenSecret;
-import org.gcube.smartgears.security.AuthorizationProvider;
 import org.gcube.smartgears.security.SimpleCredentials;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
diff --git a/src/main/java/org/gcube/smartgears/security/defaults/DefaultAuthorizationProviderFactory.java b/src/main/java/org/gcube/smartgears/security/defaults/DefaultAuthorizationProviderFactory.java
index 87b34c9..e1ed0f4 100644
--- a/src/main/java/org/gcube/smartgears/security/defaults/DefaultAuthorizationProviderFactory.java
+++ b/src/main/java/org/gcube/smartgears/security/defaults/DefaultAuthorizationProviderFactory.java
@@ -3,10 +3,10 @@ package org.gcube.smartgears.security.defaults;
 import java.util.List;
 
 import org.gcube.common.security.credentials.Credentials;
+import org.gcube.common.security.factories.AuthorizationProviderFactory;
 import org.gcube.common.validator.ValidationError;
 import org.gcube.common.validator.ValidatorFactory;
 import org.gcube.common.validator.annotations.NotEmpty;
-import org.gcube.smartgears.security.AuthorizationProviderFactory;
 import org.gcube.smartgears.security.SimpleCredentials;
 
 public class DefaultAuthorizationProviderFactory implements AuthorizationProviderFactory<DefaultAuthorizationProvider>{