Compare commits
4 Commits
master
...
smartgears
Author | SHA1 | Date |
---|---|---|
lucio | 600b3dab3d | |
lucio | 70da43e4a6 | |
Lucio Lelii | 32359123dd | |
Lucio Lelii | 94c7e884a2 |
|
@ -0,0 +1 @@
|
|||
/target/
|
13
.project
13
.project
|
@ -5,21 +5,11 @@
|
|||
<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>
|
||||
|
@ -27,10 +17,7 @@
|
|||
</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>
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
<?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>
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<installed facet="java" version="1.8"/>
|
||||
<installed facet="jst.utility" version="1.0"/>
|
||||
</faceted-project>
|
18
CHANGELOG.md
18
CHANGELOG.md
|
@ -1,16 +1,8 @@
|
|||
# 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).
|
||||
|
||||
# Changelog for Common Smartgears
|
||||
## [v2.0.0-SNAPSHOT] - [2022-05-13]
|
||||
|
||||
## [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
|
||||
porting to new Secret Manager
|
||||
|
|
49
LICENSE.md
49
LICENSE.md
|
@ -1,10 +1,9 @@
|
|||
# European Union Public Licence V. 1.1
|
||||
#European Union Public Licence V.1.2
|
||||
|
||||
##*EUPL © the European Community 2007*
|
||||
|
||||
|
||||
EUPL © the European Community 2007
|
||||
|
||||
|
||||
This European Union Public Licence (the “EUPL”) applies to the Work or Software
|
||||
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).
|
||||
|
@ -13,13 +12,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.1
|
||||
**Licensed under the EUPL V.1.2**
|
||||
|
||||
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:
|
||||
|
||||
|
@ -60,7 +59,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
|
||||
|
@ -86,7 +85,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
|
||||
|
@ -98,7 +97,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
|
||||
|
@ -107,7 +106,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:
|
||||
|
@ -148,7 +147,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
|
||||
|
@ -164,7 +163,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
|
||||
|
@ -181,7 +180,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,
|
||||
|
@ -194,7 +193,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
|
||||
|
@ -208,7 +207,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
|
||||
|
@ -223,7 +222,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
|
||||
|
@ -234,7 +233,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.
|
||||
|
@ -245,7 +244,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.
|
||||
|
@ -266,7 +265,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
|
||||
|
@ -280,7 +279,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.
|
||||
|
@ -292,12 +291,13 @@ 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,4 +309,3 @@ This licence shall be governed by the Belgian law if:
|
|||
- Eclipse Public License v. 1.0
|
||||
|
||||
- Cecill v. 2.0
|
||||
|
||||
|
|
35
README.md
35
README.md
|
@ -1,24 +1,23 @@
|
|||
# Common GCube Calls
|
||||
# Common Gcube Calls
|
||||
|
||||
A library for fws clients support
|
||||
A library to allow client calls to smartgears
|
||||
|
||||
## Structure of the project
|
||||
|
||||
* The source code is present in the src folder.
|
||||
|
||||
## 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)
|
||||
* **Fabio Simeoni** - FAO of the UN, Italy
|
||||
* **Lucio Lelii** ([ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience)
|
||||
|
||||
|
||||
## License
|
||||
|
@ -35,23 +34,9 @@ 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);
|
||||
- iMarine(grant no. 283644);
|
||||
- EUBrazilOpenBio (grant no. 288754).
|
||||
- D4Science (grant no. 212488), D4Science-II (grant no.239019), ENVRI (grant no. 283465), EUBrazilOpenBio (grant no. 288754), iMarine(grant no. 283644);
|
||||
- the H2020 research and innovation programme
|
||||
- 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);
|
||||
|
||||
- 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);
|
||||
|
|
@ -0,0 +1 @@
|
|||
${gcube.license}
|
|
@ -0,0 +1,62 @@
|
|||
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.
|
|
@ -0,0 +1,13 @@
|
|||
<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>
|
|
@ -0,0 +1,31 @@
|
|||
<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>
|
55
pom.xml
55
pom.xml
|
@ -6,12 +6,12 @@
|
|||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.2.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-gcube-calls</artifactId>
|
||||
<version>1.3.1</version>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<distroDirectory>distro</distroDirectory>
|
||||
|
@ -23,27 +23,33 @@
|
|||
<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-authorization</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||
<artifactId>common-security</artifactId>
|
||||
</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>
|
||||
|
||||
|
@ -79,6 +85,25 @@
|
|||
</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>
|
|
@ -1,16 +1,15 @@
|
|||
package org.gcube.common.calls.interceptors;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -18,56 +17,24 @@ 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) {
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
String accessToken = AccessTokenProvider.instance.get();
|
||||
Secret secret = SecretManagerProvider.get();
|
||||
|
||||
if (accessToken!=null) {
|
||||
request.addHeader(uma_token_header, "Bearer "+accessToken);
|
||||
logger.trace("uma token set");
|
||||
if (secret!=null) {
|
||||
try {
|
||||
request.addHeader(user_header, getUserFromToken(accessToken) );
|
||||
}catch (Throwable e) {
|
||||
logger.warn("errror setting {} header", user_header );
|
||||
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);
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
} else logger.trace("secret is not set");
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
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) {}
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
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) {}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,3 +1 @@
|
|||
org.gcube.common.calls.interceptors.ScopeInterceptor
|
||||
org.gcube.common.calls.interceptors.AuthorizationInterceptor
|
||||
org.gcube.common.calls.interceptors.CalledMethodInterceptor
|
Loading…
Reference in New Issue