From f96a8a4f6cb926e303c0d7706e5bb4d32c08a774 Mon Sep 17 00:00:00 2001 From: "costantino.perciante" Date: Fri, 27 Jan 2017 15:19:39 +0000 Subject: [PATCH] added scope as value of the bean in the cache for a faster retrieval git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/oauth@141875 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../org/gcube/portal/oauth/OauthService.java | 7 +++--- .../gcube/portal/oauth/cache/CacheBean.java | 24 +++++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gcube/portal/oauth/OauthService.java b/src/main/java/org/gcube/portal/oauth/OauthService.java index 8ca4c36..1d73e56 100644 --- a/src/main/java/org/gcube/portal/oauth/OauthService.java +++ b/src/main/java/org/gcube/portal/oauth/OauthService.java @@ -19,6 +19,7 @@ import org.gcube.common.authorization.library.ClientType; 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.gcube.portal.oauth.cache.CacheBean; import org.gcube.portal.oauth.cache.CacheCleaner; import org.gcube.portal.oauth.input.PushCodeBean; @@ -91,7 +92,7 @@ public class OauthService { }else{ logger.info("Saving entry defined by " + bean + " in cache, token is " + token.substring(0, 10)); - entries.put(bean.getCode(), new CacheBean(token, bean.getRedirectUri(), bean.getClientId(), System.currentTimeMillis())); + entries.put(bean.getCode(), new CacheBean(token, ScopeProvider.instance.get(), bean.getRedirectUri(), bean.getClientId(), System.currentTimeMillis())); return Response.status(status).build(); } @@ -132,8 +133,9 @@ public class OauthService { }else{ logger.info("The request is ok"); String tokenToReturn = entries.get(code).getToken(); + String scope = entries.get(code).getScope(); status = Status.OK; - return Response.status(status).entity(new AccessTokenBeanResponse(tokenToReturn, authorizationService().get(tokenToReturn).getContext())).build(); + return Response.status(status).entity(new AccessTokenBeanResponse(tokenToReturn, scope)).build(); } }catch(Exception e){ logger.error("Failed to perform this operation", e); @@ -153,7 +155,6 @@ public class OauthService { */ private String checkRequest(String clientId, String clientSecret, String redirectUri, String code, String grantType) { - try{ if(clientId == null || clientSecret == null || redirectUri == null || code == null || grantType == null) return "invalid_request"; diff --git a/src/main/java/org/gcube/portal/oauth/cache/CacheBean.java b/src/main/java/org/gcube/portal/oauth/cache/CacheBean.java index 5201ef9..7c5cc72 100644 --- a/src/main/java/org/gcube/portal/oauth/cache/CacheBean.java +++ b/src/main/java/org/gcube/portal/oauth/cache/CacheBean.java @@ -8,6 +8,7 @@ package org.gcube.portal.oauth.cache; public class CacheBean { private String token; + private String scope; private String redirectUri; private String clientId; private Long insertTime; @@ -15,19 +16,31 @@ public class CacheBean { /** * @param token + * @param scope * @param redirectUri * @param clientId * @param insertTime */ - public CacheBean(String token, String redirectUri, String clientId, - Long insertTime) { + public CacheBean(String token, String scope, String redirectUri, + String clientId, Long insertTime) { super(); this.token = token; + this.scope = scope; this.redirectUri = redirectUri; this.clientId = clientId; this.insertTime = insertTime; } + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + + public String getToken() { return token; } @@ -59,11 +72,12 @@ public class CacheBean { public void setClientId(String clientId) { this.clientId = clientId; } - + @Override public String toString() { - return "CacheBean [token=" + token + ", redirectUri=" + redirectUri - + ", clientId=" + clientId + ", insertTime=" + insertTime + "]"; + return "CacheBean [token=" + token + ", scope=" + scope + + ", redirectUri=" + redirectUri + ", clientId=" + clientId + + ", insertTime=" + insertTime + "]"; } /**