diff --git a/CHANGELOG.md b/CHANGELOG.md index 1903517..dfb80c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm # Changelog for Common Smartgears +## [v3.1.4] - 2022-03-29 + +- fixes issue [#23075] + ## [v3.1.3] - 2022-03-21 - fixed bug on policies diff --git a/pom.xml b/pom.xml index d0e70c7..b4ed984 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.gcube.core common-smartgears - 3.1.3 + 3.1.4 SmartGears diff --git a/src/main/java/org/gcube/smartgears/handlers/application/request/RequestContextRetriever.java b/src/main/java/org/gcube/smartgears/handlers/application/request/RequestContextRetriever.java index 37fac3d..6a04c78 100644 --- a/src/main/java/org/gcube/smartgears/handlers/application/request/RequestContextRetriever.java +++ b/src/main/java/org/gcube/smartgears/handlers/application/request/RequestContextRetriever.java @@ -15,6 +15,8 @@ import org.gcube.common.authorization.client.exceptions.ObjectNotFound; import org.gcube.common.authorization.library.AuthorizationEntry; import org.gcube.common.authorization.library.provider.AccessTokenProvider; import org.gcube.common.authorization.library.provider.AuthorizationProvider; +import org.gcube.common.authorization.library.provider.ClientInfo; +import org.gcube.common.authorization.library.provider.ExternalServiceInfo; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.UserInfo; import org.gcube.common.authorization.library.utils.Caller; @@ -140,7 +142,14 @@ public class RequestContextRetriever extends RequestHandler { internal_server_error.fire("invalid context in access token"); } - AuthorizationProvider.instance.set(new Caller(new UserInfo(jwt.getUsername(), jwt.getRoles(), jwt.getEmail(), jwt.getFirstName(), jwt.getLastName()), "token")); + ClientInfo clientInfo; + if (!jwt.isExternalService()) + clientInfo = new UserInfo(jwt.getUsername(), jwt.getRoles(), jwt.getEmail(), jwt.getFirstName(), jwt.getLastName()); + else + clientInfo = new ExternalServiceInfo(jwt.getUsername(), "unknown"); + + log.info("caller type is {}",clientInfo.getType()); + AuthorizationProvider.instance.set(new Caller(clientInfo, "token")); ScopeProvider.instance.set(scopeBean.toString()); diff --git a/src/main/java/org/gcube/smartgears/utils/GcubeJwt.java b/src/main/java/org/gcube/smartgears/utils/GcubeJwt.java index b86540c..0d3af5d 100644 --- a/src/main/java/org/gcube/smartgears/utils/GcubeJwt.java +++ b/src/main/java/org/gcube/smartgears/utils/GcubeJwt.java @@ -32,6 +32,9 @@ public class GcubeJwt { @JsonProperty("family_name") private String lastName; + @JsonProperty("clientId") + private String clientId; + @JsonProperty("email") private String email; @@ -51,6 +54,10 @@ public class GcubeJwt { return username; } + public boolean isExternalService() { + return clientId != null; + } + public String getFirstName() { return firstName; }