minor fixes

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/oauth@141979 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
costantino.perciante 2017-02-01 15:03:48 +00:00
parent ff6c10ac46
commit c0f720aa71
4 changed files with 28 additions and 14 deletions

View File

@ -39,7 +39,7 @@ public class OauthService {
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(OauthService.class); private static final org.slf4j.Logger logger = LoggerFactory.getLogger(OauthService.class);
/** /**
* This map contains couples <code, {qualifier-token, insert time}> * This map contains couples <code, {qualifier-token, insert time, scope, redirect uri, client id}>
*/ */
private Map<String, CacheBean> entries; private Map<String, CacheBean> entries;
@ -115,8 +115,25 @@ public class OauthService {
return Response.status(status).entity("{\"error\"=\"Trying to access push-authentication-code method via a token different than USER is not allowed\"").build(); return Response.status(status).entity("{\"error\"=\"Trying to access push-authentication-code method via a token different than USER is not allowed\"").build();
}else{ }else{
logger.info("Saving entry defined by " + bean + " in cache, token is " + token.substring(0, 10)); // check parameters
entries.put(bean.getCode(), new CacheBean(token, ScopeProvider.instance.get(), bean.getRedirectUri(), bean.getClientId(), System.currentTimeMillis())); String code = bean.getCode();
String clientId = bean.getClientId();
String redirectUri = bean.getRedirectUri();
if(code == null || code.isEmpty())
return Response.status(Status.BAD_REQUEST).
entity("{\"error\"=\"'code' cannot be null or missing\"").build();
if(clientId == null || clientId.isEmpty())
return Response.status(Status.BAD_REQUEST).
entity("{\"error\"=\"'client_id' cannot be null or missing\"").build();
if(redirectUri == null || redirectUri.isEmpty())
return Response.status(Status.BAD_REQUEST).
entity("{\"error\"=\"'redirect_uri' cannot be null or missing\"").build();
logger.info("Saving entry defined by " + bean + " in cache, token is " + token.substring(0, 10) + "***************");
entries.put(code, new CacheBean(token, ScopeProvider.instance.get(), redirectUri, clientId, System.currentTimeMillis()));
return Response.status(status).build(); return Response.status(status).build();
} }

View File

@ -39,8 +39,6 @@ public class CacheBean {
this.scope = scope; this.scope = scope;
} }
public String getToken() { public String getToken() {
return token; return token;
} }

View File

@ -50,7 +50,7 @@ public class CacheCleaner extends Thread {
} }
} }
logger.info("Going to sleep . Number of removed entries is " + removedEntries + " [" + new Date() + "]"); logger.info("Going to sleep. Number of removed entries is " + removedEntries + " [" + new Date() + "]");
} catch (InterruptedException e) { } catch (InterruptedException e) {
logger.warn("Exception was " + e.getMessage()); logger.warn("Exception was " + e.getMessage());

View File

@ -1,7 +1,5 @@
package org.gcube.portal.oauth.input; package org.gcube.portal.oauth.input;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
/** /**
@ -11,17 +9,18 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class PushCodeBean { public class PushCodeBean {
@JsonProperty("code") @JsonProperty("code")
@NotNull(message="code cannot be null")
private String code; private String code;
@JsonProperty("redirect_uri") @JsonProperty("redirect_uri")
@NotNull(message="redirect_uri cannot be null")
private String redirectUri; private String redirectUri;
@JsonProperty("client_id") @JsonProperty("client_id")
@NotNull(message="client_id cannot be null")
private String clientId; private String clientId;
public PushCodeBean() {
super();
}
/** /**
* @param code * @param code
* @param redirectUri * @param redirectUri
@ -41,7 +40,7 @@ public class PushCodeBean {
public void setCode(String code) { public void setCode(String code) {
this.code = code; this.code = code;
} }
public String getRedirectUri() { public String getRedirectUri() {
return redirectUri; return redirectUri;
} }