Compare commits

..

9 Commits

Author SHA1 Message Date
Lucio Lelii cb29bb3883 updated for release 2022-08-01 16:36:18 +02:00
Lucio Lelii 2f5091c517 commit for release 2022-08-01 16:35:11 +02:00
Lucio Lelii e876a4d9dd catches throwable instead of Exception 2022-08-01 16:34:27 +02:00
Lucio Lelii a71108f4ea updated 2022-07-26 17:22:24 +02:00
Lucio Lelii 663b3e7675 added d4s-user Header 2022-07-26 17:21:39 +02:00
lucio.lelii cb135d554a exception removed 2021-07-08 12:23:47 +02:00
lucio.lelii 32452f3c6a Changed UmaTokenProvider with AccessTokenProvider 2021-05-24 16:30:58 +02:00
user1 be74dac112 pom updated 2020-11-19 16:53:25 +01:00
user1 531356f85b Support for UmaToken added in the interceptor 2020-11-19 16:51:05 +01:00
16 changed files with 219 additions and 207 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
/target/

View File

@ -5,11 +5,21 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
@ -17,7 +27,10 @@
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="common-gcube-calls">
<wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
</wb-module>
</project-modules>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="1.8"/>
<installed facet="jst.utility" version="1.0"/>
</faceted-project>

View File

@ -1,8 +1,16 @@
# Changelog
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.0.0-SNAPSHOT] - [2022-05-13]
# Changelog for Common Smartgears
porting to new Secret Manager
## [v1.3.1] - 2020-11-18
- added "d4s-user" as header
## [v1.3.0] - 2020-11-18
- Changed UmaTokenProvider with AccessTokenProvider
## [v1.2.0] - 2020-11-18
- interceptor for UmaToken added

View File

@ -1,9 +1,10 @@
#European Union Public Licence V.1.2
##*EUPL © the European Community 2007*
# European Union Public Licence V. 1.1
This **European Union Public Licence** (the **“EUPL”**) applies to the Work or Software
EUPL © the European Community 2007
This European Union Public Licence (the “EUPL”) applies to the Work or Software
(as defined below) which is provided under the terms of this Licence. Any use of
the Work, other than as authorised under this Licence is prohibited (to the
extent such use is covered by a right of the copyright holder of the Work).
@ -12,13 +13,13 @@ The Original Work is provided under the terms of this Licence when the Licensor
(as defined below) has placed the following notice immediately following the
copyright notice for the Original Work:
**Licensed under the EUPL V.1.2**
Licensed under the EUPL V.1.1
or has expressed by any other mean his willingness to license under the EUPL.
##1. Definitions
## 1. Definitions
In this Licence, the following terms have the following meaning:
@ -59,7 +60,7 @@ In this Licence, the following terms have the following meaning:
##2. Scope of the rights granted by the Licence
## 2. Scope of the rights granted by the Licence
The Licensor hereby grants You a world-wide, royalty-free, non-exclusive,
sub-licensable licence to do the following, for the duration of copyright vested
@ -85,7 +86,7 @@ rights granted on the Work under this Licence.
##3. Communication of the Source Code
## 3. Communication of the Source Code
The Licensor may provide the Work either in its Source Code form, or as
Executable Code. If the Work is provided as Executable Code, the Licensor
@ -97,7 +98,7 @@ continues to distribute and/or communicate the Work.
##4. Limitations on copyright
## 4. Limitations on copyright
Nothing in this Licence is intended to deprive the Licensee of the benefits from
any exception or limitation to the exclusive rights of the rights owners in the
@ -106,7 +107,7 @@ applicable limitations thereto.
##5. Obligations of the Licensee
## 5. Obligations of the Licensee
The grant of the rights mentioned above is subject to some restrictions and
obligations imposed on the Licensee. Those obligations are the following:
@ -147,7 +148,7 @@ reproducing the content of the copyright notice.
##6. Chain of Authorship
## 6. Chain of Authorship
The original Licensor warrants that the copyright in the Original Work granted
hereunder is owned by him/her or licensed to him/her and that he/she has the
@ -163,7 +164,7 @@ terms of this Licence.
##7. Disclaimer of Warranty
## 7. Disclaimer of Warranty
The Work is a work in progress, which is continuously improved by numerous
contributors. It is not a finished work and may therefore contain defects or
@ -180,7 +181,7 @@ for the grant of any rights to the Work.
##8. Disclaimer of Liability
## 8. Disclaimer of Liability
Except in the cases of wilful misconduct or damages directly caused to natural
persons, the Licensor will in no event be liable for any direct or indirect,
@ -193,7 +194,7 @@ laws as far such laws apply to the Work.
##9. Additional agreements
## 9. Additional agreements
While distributing the Original Work or Derivative Works, You may choose to
conclude an additional agreement to offer, and charge a fee for, acceptance of
@ -207,7 +208,7 @@ any such warranty or additional liability.
##10. Acceptance of the Licence
## 10. Acceptance of the Licence
The provisions of this Licence can be accepted by clicking on an icon “I agree”
placed under the bottom of a window displaying the text of this Licence or by
@ -222,7 +223,7 @@ Distribution and/or Communication by You of the Work or copies thereof.
##11. Information to the public
## 11. Information to the public
In case of any Distribution and/or Communication of the Work by means of
electronic communication by You (for example, by offering to download the Work
@ -233,7 +234,7 @@ accessible, concluded, stored and reproduced by the Licensee.
##12. Termination of the Licence
## 12. Termination of the Licence
The Licence and the rights granted hereunder will terminate automatically upon
any breach by the Licensee of the terms of the Licence.
@ -244,7 +245,7 @@ remain in full compliance with the Licence.
##13. Miscellaneous
## 13. Miscellaneous
Without prejudice of Article 9 above, the Licence represents the complete
agreement between the Parties as to the Work licensed hereunder.
@ -265,7 +266,7 @@ their choice.
##14. Jurisdiction
## 14. Jurisdiction
Any litigation resulting from the interpretation of this License, arising
between the European Commission, as a Licensor, and any Licensee, will be
@ -279,7 +280,7 @@ conducts its primary business.
##15. Applicable Law
## 15. Applicable Law
This Licence shall be governed by the law of the European Union country where
the Licensor resides or has his registered office.
@ -291,13 +292,12 @@ This licence shall be governed by the Belgian law if:
- or registered office inside a European Union country.
---
## Appendix
##Appendix
**“Compatible Licences”** according to article 5 EUPL are:
“Compatible Licences” according to article 5 EUPL are:
- GNU General Public License (GNU GPL) v. 2
@ -309,3 +309,4 @@ This licence shall be governed by the Belgian law if:
- Eclipse Public License v. 1.0
- Cecill v. 2.0

View File

@ -1,23 +1,24 @@
# Common Gcube Calls
# Common GCube Calls
A library to allow client calls to smartgears
## Structure of the project
* The source code is present in the src folder.
A library for fws clients support
## Built With
* [OpenJDK](https://openjdk.java.net/) - The JDK used
* [Maven](https://maven.apache.org/) - Dependency Management
## Documentation
[SmartGears](https://wiki.gcube-system.org/gcube/SmartGears)
## Change log
See [Releases](https://code-repo.d4science.org/gCubeSystem/common-gcube-calls/releases).
## Authors
* **Lucio Lelii** ([ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience)
* **Lucio Lelii** - [ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience)
* **Fabio Simeoni** - FAO of the UN, Italy
## License
@ -34,9 +35,23 @@ by favouring the realisation of reuse oriented policies.
The projects leading to this software have received funding from a series of European Union programmes including:
- the Sixth Framework Programme for Research and Technological Development
- DILIGENT (grant no. 004260);
- DILIGENT (grant no. 004260).
- the Seventh Framework Programme for research, technological development and demonstration
- D4Science (grant no. 212488), D4Science-II (grant no.239019), ENVRI (grant no. 283465), EUBrazilOpenBio (grant no. 288754), iMarine(grant no. 283644);
- D4Science (grant no. 212488);
- D4Science-II (grant no.239019);
- ENVRI (grant no. 283465);
- iMarine(grant no. 283644);
- EUBrazilOpenBio (grant no. 288754).
- the H2020 research and innovation programme
- BlueBRIDGE (grant no. 675680), EGIEngage (grant no. 654142), ENVRIplus (grant no. 654182), Parthenos (grant no. 654119), SoBigData (grant no. 654024),DESIRA (grant no. 818194), ARIADNEplus (grant no. 823914), RISIS2 (grant no. 824091), PerformFish (grant no. 727610), AGINFRAplus (grant no. 731001);
- SoBigData (grant no. 654024);
- PARTHENOS (grant no. 654119);
- EGIEngage (grant no. 654142);
- ENVRIplus (grant no. 654182);
- BlueBRIDGE (grant no. 675680);
- PerformFish (grant no. 727610);
- AGINFRAplus (grant no. 731001);
- DESIRA (grant no. 818194);
- ARIADNEplus (grant no. 823914);
- RISIS2 (grant no. 824091);

View File

@ -1 +0,0 @@
${gcube.license}

View File

@ -1,62 +0,0 @@
The gCube System - ${name}
--------------------------------------------------
${description}
${gcube.description}
${gcube.funding}
Version
--------------------------------------------------
${version} (${buildDate})
Please see the file named "changelog.xml" in this directory for the release notes.
Authors
--------------------------------------------------
* Lucio Lelii (lucio.lelii-AT-isti.cnr.it), CNR, Italy
* Fabio Simeoni (fabio.simeoni-AT-fao.org), FAO of the UN, Italy
MAINTAINERS
--------------------------------------------------
* Lucio Lelii (lucio.lelii-AT-isti.cnr.it), CNR, Italy
Download information
--------------------------------------------------
Source code is available from SVN:
${scm.url}
Binaries can be downloaded from the gCube website:
${gcube.website}
Installation
--------------------------------------------------
Installation documentation is available on-line in the gCube Wiki:
${gcube.wikiRoot}
Documentation
--------------------------------------------------
Documentation is available on-line in the gCube Wiki:
${gcube.wikiRoot}
Support
--------------------------------------------------
Bugs and support requests can be reported in the gCube issue tracking tool:
${gcube.issueTracking}
Licensing
--------------------------------------------------
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

View File

@ -1,13 +0,0 @@
<ReleaseNotes>
<Changeset component="common-gcube-calls-2.0.0" date="2020-05-20">
<Change>MethodInterceptor added</Change>
<Change>AuthorizationInterceptor added</Change>
</Changeset>
<Changeset component="common-gcube-calls-1.0.2" date="2015-09-24">
<Change>MethodInterceptor added</Change>
<Change>AuthorizationInterceptor added</Change>
</Changeset>
<Changeset component="common-gcube-calls-1.0.0" date="2013-10-24">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

View File

@ -1,31 +0,0 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>profile.xml</include>
<include>changelog.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>target/${build.finalName}.jar</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

57
pom.xml
View File

@ -6,12 +6,12 @@
<parent>
<groupId>org.gcube.tools</groupId>
<artifactId>maven-parent</artifactId>
<version>1.2.0</version>
<version>1.1.0</version>
</parent>
<groupId>org.gcube.core</groupId>
<artifactId>common-gcube-calls</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>1.3.1</version>
<properties>
<distroDirectory>distro</distroDirectory>
@ -23,33 +23,27 @@
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>3.0.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-security</artifactId>
<artifactId>common-authorization</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope</artifactId>
<version>[1.1.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>gcube-jackson-databind</artifactId>
<version>2.8.11</version>
</dependency>
</dependencies>
@ -85,25 +79,6 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,15 +1,16 @@
package org.gcube.common.calls.interceptors;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Base64;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.calls.Call;
import org.gcube.common.calls.Interceptor;
import org.gcube.common.calls.Request;
import org.gcube.common.calls.Response;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.common.security.secrets.Secret;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -17,24 +18,56 @@ public class AuthorizationInterceptor implements Interceptor {
private Logger logger = LoggerFactory.getLogger(AuthorizationInterceptor.class);
public static final String token_header="gcube-token";
public static final String uma_token_header="Authorization";
public static final String user_header="d4s-user";
@Override
public void handleRequest(Request request, Call call) {
Secret secret = SecretManagerProvider.get();
String token = SecurityTokenProvider.instance.get();
String accessToken = AccessTokenProvider.instance.get();
if (secret!=null) {
try {
Map<String, String> header = secret.getHTTPAuthorizationHeaders();
Objects.requireNonNull(header);
for (Entry<String, String> entry : header.entrySet()) {
request.addHeader(entry.getKey(), entry.getValue());
logger.trace("setting {} : {}", entry.getKey(), entry.getValue());
}
}catch (Exception e) {
logger.error("error setting header for secret",e);
if (accessToken!=null) {
request.addHeader(uma_token_header, "Bearer "+accessToken);
logger.trace("uma token set");
try {
request.addHeader(user_header, getUserFromToken(accessToken) );
}catch (Throwable e) {
logger.warn("errror setting {} header", user_header );
}
} else logger.trace("secret is not set");
} else logger.warn("uma token is not set");
if (token==null)
logger.warn("security token is not set");
else{
request.addHeader(token_header, token);
logger.trace("security token set in the header is "+token);
}
}
@Override
public void handleResponse(Response context, Call callContext) {}
@JsonIgnoreProperties(ignoreUnknown = true)
private static class AccessTokenJSON {
@JsonProperty("preferred_username")
private String username;
public String getUsername() {
return username;
}
}
private static String getUserFromToken(String accessToken) throws Exception {
String realAccessTokenEncoded = accessToken.split("\\.")[1];
String decodedAccessPart = new String(Base64.getDecoder().decode(realAccessTokenEncoded.getBytes()));
ObjectMapper mapper = new ObjectMapper();
AccessTokenJSON tokenMapped = mapper.readValue(decodedAccessPart, AccessTokenJSON.class);
String userName = Base64.getEncoder().encodeToString(tokenMapped.getUsername().getBytes());
return userName;
}
}

View File

@ -0,0 +1,29 @@
package org.gcube.common.calls.interceptors;
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
import org.gcube.common.calls.Call;
import org.gcube.common.calls.Interceptor;
import org.gcube.common.calls.Request;
import org.gcube.common.calls.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CalledMethodInterceptor implements Interceptor {
private Logger logger = LoggerFactory.getLogger(CalledMethodInterceptor.class);
public static final String calledMethodHeader="gcube-method";
@Override
public void handleRequest(Request request, Call call) {
String calledMethod = CalledMethodProvider.instance.get();
request.addHeader(calledMethodHeader, calledMethod);
logger.trace("called method set in the header is "+calledMethod);
}
@Override
public void handleResponse(Response context, Call callContext) {}
}

View File

@ -0,0 +1,33 @@
package org.gcube.common.calls.interceptors;
import org.gcube.common.calls.Call;
import org.gcube.common.calls.Interceptor;
import org.gcube.common.calls.Request;
import org.gcube.common.calls.Response;
import org.gcube.common.scope.api.ScopeProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ScopeInterceptor implements Interceptor {
private Logger logger = LoggerFactory.getLogger(ScopeInterceptor.class);
public static final String scope_header="gcube-scope";
public void handleRequest(Request request, Call call) {
String scope = ScopeProvider.instance.get();
if (scope==null)
logger.warn("scope is not set in this call");
else{
request.addHeader(scope_header, scope);
logger.trace("scope set in the header is "+scope);
}
}
public void handleResponse(Response context, Call callContext) {}
}

View File

@ -1 +1,3 @@
org.gcube.common.calls.interceptors.AuthorizationInterceptor
org.gcube.common.calls.interceptors.ScopeInterceptor
org.gcube.common.calls.interceptors.AuthorizationInterceptor
org.gcube.common.calls.interceptors.CalledMethodInterceptor