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
This commit is contained in:
costantino.perciante 2017-01-27 15:19:39 +00:00
parent 3510c04a0e
commit f96a8a4f6c
2 changed files with 23 additions and 8 deletions

View File

@ -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";

View File

@ -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 + "]";
}
/**