Merge remote-tracking branch 'origin/road_to_smartgears_4'
This commit is contained in:
commit
6a4629eaea
|
@ -26,6 +26,7 @@
|
|||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
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).
|
||||
|
||||
## [v2.5.1]
|
||||
|
||||
- Added library to support Java 11 JDK
|
||||
|
||||
## [v3.0.0-SNAPSHOT] - [2022-06-06]
|
||||
|
||||
- removed common-scope from the dependencies
|
||||
|
||||
## [v2.5.0] - [2022-04-20]
|
||||
|
||||
|
|
43
pom.xml
43
pom.xml
|
@ -1,59 +1,56 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-authorization</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<name>authorization service common library</name>
|
||||
<parent>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<version>1.1.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-authorization</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<name>authorization service common library</name>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/common-authorization.git</connection>
|
||||
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/common-authorization.git</developerConnection>
|
||||
<url>https://code-repo.d4science.org/gCubeSystem/common-authorization</url>
|
||||
</scm>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>2.1.0</version>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-configuration-scanner</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Added to support Java 11 JDK -->
|
||||
<dependency>
|
||||
<groupId>javax.xml.ws</groupId>
|
||||
<artifactId>jaxws-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-impl</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- END Added to support Java 11 JDK -->
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -18,8 +18,6 @@ import org.gcube.common.authorization.library.provider.ContainerInfo;
|
|||
import org.gcube.common.authorization.library.provider.ExternalServiceInfo;
|
||||
import org.gcube.common.authorization.library.provider.ServiceInfo;
|
||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||
import org.gcube.common.scope.api.ServiceMap;
|
||||
import org.gcube.common.scope.impl.DefaultServiceMap;
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
|
@ -35,9 +33,6 @@ public class AuthorizationEntry {
|
|||
|
||||
private String context;
|
||||
|
||||
@XmlElementRef(type = DefaultServiceMap.class)
|
||||
private ServiceMap map;
|
||||
|
||||
@XmlElementRefs({
|
||||
@XmlElementRef(type = Service2ServicePolicy.class),
|
||||
@XmlElementRef(type = User2ServicePolicy.class),
|
||||
|
@ -68,18 +63,11 @@ public class AuthorizationEntry {
|
|||
return context;
|
||||
}
|
||||
|
||||
public ServiceMap getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public String getQualifier() {
|
||||
return qualifier;
|
||||
}
|
||||
|
||||
public void setMap(ServiceMap map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public List<Policy> getPolicies() {
|
||||
return policies;
|
||||
}
|
||||
|
@ -128,7 +116,7 @@ public class AuthorizationEntry {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "AuthorizationEntry [clientInfo=" + clientInfo + ", context="
|
||||
+ context + ", map=" + map + ", qualifier=" + qualifier
|
||||
+ context + ", qualifier=" + qualifier
|
||||
+ ", policies=" + policies + "]";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
package org.gcube.common.authorization.library;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.authorization.library.utils.Caller;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class AuthorizedTasks {
|
||||
|
||||
private static Logger logger= LoggerFactory.getLogger(AuthorizedTasks.class);
|
||||
|
||||
/**
|
||||
* Binds a {@link Callable} task to the current scope and user.
|
||||
* @param task the task
|
||||
* @return an equivalent {@link Callable} task bound to the current scope and user
|
||||
*/
|
||||
static public <V> Callable<V> bind(final Callable<V> task) {
|
||||
|
||||
|
||||
final Caller userCall = AuthorizationProvider.instance.get();
|
||||
|
||||
final String token = SecurityTokenProvider.instance.get();
|
||||
|
||||
final String scope = ScopeProvider.instance.get();
|
||||
|
||||
final String accessToken = AccessTokenProvider.instance.get();
|
||||
|
||||
return new Callable<V>() {
|
||||
@Override
|
||||
public V call() throws Exception {
|
||||
|
||||
|
||||
AuthorizationProvider.instance.set(userCall);
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
ScopeProvider.instance.set(scope);
|
||||
AccessTokenProvider.instance.set(accessToken);
|
||||
|
||||
try {
|
||||
logger.info("setting on authorized task scope {} and token {}", scope, token);
|
||||
return task.call();
|
||||
}
|
||||
finally {
|
||||
AuthorizationProvider.instance.reset();
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a {@link Runnable} task to the current scope and user.
|
||||
* @param task the task
|
||||
* @return an equivalent {@link Runnable} task bound to the current scope and user
|
||||
*/
|
||||
static public <V> Runnable bind(final Runnable task) {
|
||||
|
||||
|
||||
final Caller userCall = AuthorizationProvider.instance.get();
|
||||
|
||||
final String token = SecurityTokenProvider.instance.get();
|
||||
|
||||
final String scope = ScopeProvider.instance.get();
|
||||
|
||||
final String accessToken = AccessTokenProvider.instance.get();
|
||||
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
AuthorizationProvider.instance.set(userCall);
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
ScopeProvider.instance.set(scope);
|
||||
AccessTokenProvider.instance.set(accessToken);
|
||||
|
||||
try {
|
||||
logger.info("setting on authorized task scope {} and token {}", scope, token);
|
||||
task.run();
|
||||
}
|
||||
finally {
|
||||
AuthorizationProvider.instance.reset();
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.common.authorization.library.enpoints;
|
||||
package org.gcube.common.authorization.library.endpoints;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.common.authorization.library.enpoints;
|
||||
package org.gcube.common.authorization.library.endpoints;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.common.authorization.library.enpoints;
|
||||
package org.gcube.common.authorization.library.endpoints;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
package org.gcube.common.authorization.library.provider;
|
||||
|
||||
@Deprecated
|
||||
public class AccessTokenProvider {
|
||||
|
||||
public static AccessTokenProvider instance = new AccessTokenProvider();
|
||||
|
||||
private static final InheritableThreadLocal<String> threadToken = new InheritableThreadLocal<String>() {
|
||||
|
||||
@Override
|
||||
protected String initialValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private AccessTokenProvider() {
|
||||
}
|
||||
|
||||
public String get() {
|
||||
return threadToken.get();
|
||||
}
|
||||
|
||||
public void set(String jwt) {
|
||||
threadToken.set(jwt);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
threadToken.remove();
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package org.gcube.common.authorization.library.provider;
|
||||
|
||||
import org.gcube.common.authorization.library.utils.Caller;
|
||||
|
||||
@Deprecated
|
||||
public class AuthorizationProvider {
|
||||
|
||||
public static AuthorizationProvider instance = new AuthorizationProvider();
|
||||
|
||||
// Thread local variable containing each thread's ID
|
||||
private static final InheritableThreadLocal<Caller> threadAuth =
|
||||
new InheritableThreadLocal<Caller>() {
|
||||
|
||||
@Override protected Caller initialValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private AuthorizationProvider(){}
|
||||
|
||||
public Caller get(){
|
||||
Caller info = threadAuth.get();
|
||||
return info;
|
||||
}
|
||||
|
||||
public void set(Caller info){
|
||||
threadAuth.set(info);
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
threadAuth.remove();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package org.gcube.common.authorization.library.provider;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CalledMethodProvider {
|
||||
|
||||
public static CalledMethodProvider instance = new CalledMethodProvider();
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(CalledMethodProvider.class);
|
||||
|
||||
// Thread local variable containing each thread's ID
|
||||
private static final InheritableThreadLocal<String> threadMethod =
|
||||
new InheritableThreadLocal<String>() {
|
||||
|
||||
@Override protected String initialValue() {
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private CalledMethodProvider(){}
|
||||
|
||||
public String get(){
|
||||
String calledMethod = threadMethod.get();
|
||||
logger.trace("getting calledMethod as "+calledMethod+" in thread "+Thread.currentThread().getId() );
|
||||
return calledMethod;
|
||||
}
|
||||
|
||||
public void set(String calledMethod){
|
||||
if (calledMethod==null) return;
|
||||
threadMethod.set(calledMethod);
|
||||
logger.trace("setting calledMethod as "+calledMethod+" in thread "+Thread.currentThread().getId() );
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
threadMethod.remove();
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package org.gcube.common.authorization.library.provider;
|
||||
|
||||
@Deprecated
|
||||
public class SecurityTokenProvider {
|
||||
|
||||
public static SecurityTokenProvider instance = new SecurityTokenProvider();
|
||||
|
||||
//private static Logger logger = LoggerFactory.getLogger(SecurityTokenProvider.class);
|
||||
|
||||
// Thread local variable containing each thread's ID
|
||||
private static final InheritableThreadLocal<String> threadToken =
|
||||
new InheritableThreadLocal<String>() {
|
||||
|
||||
@Override protected String initialValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private SecurityTokenProvider(){}
|
||||
|
||||
public String get(){
|
||||
return threadToken.get();
|
||||
}
|
||||
|
||||
public void set(String authorizationToken){
|
||||
threadToken.set(authorizationToken);
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
threadToken.remove();
|
||||
}
|
||||
}
|
|
@ -8,8 +8,8 @@ import java.util.Map;
|
|||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.gcube.common.authorization.library.enpoints.AuthorizationEndpoint;
|
||||
import org.gcube.common.authorization.library.enpoints.AuthorizationEndpointScanner;
|
||||
import org.gcube.common.authorization.library.endpoints.AuthorizationEndpoint;
|
||||
import org.gcube.common.authorization.library.endpoints.AuthorizationEndpointScanner;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
Loading…
Reference in New Issue