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:
parent
3510c04a0e
commit
f96a8a4f6c
|
@ -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.AuthorizationProvider;
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
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.CacheBean;
|
||||||
import org.gcube.portal.oauth.cache.CacheCleaner;
|
import org.gcube.portal.oauth.cache.CacheCleaner;
|
||||||
import org.gcube.portal.oauth.input.PushCodeBean;
|
import org.gcube.portal.oauth.input.PushCodeBean;
|
||||||
|
@ -91,7 +92,7 @@ public class OauthService {
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
logger.info("Saving entry defined by " + bean + " in cache, token is " + token.substring(0, 10));
|
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();
|
return Response.status(status).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,8 +133,9 @@ public class OauthService {
|
||||||
}else{
|
}else{
|
||||||
logger.info("The request is ok");
|
logger.info("The request is ok");
|
||||||
String tokenToReturn = entries.get(code).getToken();
|
String tokenToReturn = entries.get(code).getToken();
|
||||||
|
String scope = entries.get(code).getScope();
|
||||||
status = Status.OK;
|
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){
|
}catch(Exception e){
|
||||||
logger.error("Failed to perform this operation", e);
|
logger.error("Failed to perform this operation", e);
|
||||||
|
@ -153,7 +155,6 @@ public class OauthService {
|
||||||
*/
|
*/
|
||||||
private String checkRequest(String clientId, String clientSecret,
|
private String checkRequest(String clientId, String clientSecret,
|
||||||
String redirectUri, String code, String grantType) {
|
String redirectUri, String code, String grantType) {
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if(clientId == null || clientSecret == null || redirectUri == null || code == null || grantType == null)
|
if(clientId == null || clientSecret == null || redirectUri == null || code == null || grantType == null)
|
||||||
return "invalid_request";
|
return "invalid_request";
|
||||||
|
|
|
@ -8,6 +8,7 @@ package org.gcube.portal.oauth.cache;
|
||||||
public class CacheBean {
|
public class CacheBean {
|
||||||
|
|
||||||
private String token;
|
private String token;
|
||||||
|
private String scope;
|
||||||
private String redirectUri;
|
private String redirectUri;
|
||||||
private String clientId;
|
private String clientId;
|
||||||
private Long insertTime;
|
private Long insertTime;
|
||||||
|
@ -15,19 +16,31 @@ public class CacheBean {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param token
|
* @param token
|
||||||
|
* @param scope
|
||||||
* @param redirectUri
|
* @param redirectUri
|
||||||
* @param clientId
|
* @param clientId
|
||||||
* @param insertTime
|
* @param insertTime
|
||||||
*/
|
*/
|
||||||
public CacheBean(String token, String redirectUri, String clientId,
|
public CacheBean(String token, String scope, String redirectUri,
|
||||||
Long insertTime) {
|
String clientId, Long insertTime) {
|
||||||
super();
|
super();
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
this.scope = scope;
|
||||||
this.redirectUri = redirectUri;
|
this.redirectUri = redirectUri;
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
this.insertTime = insertTime;
|
this.insertTime = insertTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getScope() {
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScope(String scope) {
|
||||||
|
this.scope = scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
@ -59,11 +72,12 @@ public class CacheBean {
|
||||||
public void setClientId(String clientId) {
|
public void setClientId(String clientId) {
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "CacheBean [token=" + token + ", redirectUri=" + redirectUri
|
return "CacheBean [token=" + token + ", scope=" + scope
|
||||||
+ ", clientId=" + clientId + ", insertTime=" + insertTime + "]";
|
+ ", redirectUri=" + redirectUri + ", clientId=" + clientId
|
||||||
|
+ ", insertTime=" + insertTime + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue