kill cleaner thread on service stop

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/oauth@141891 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
costantino.perciante 2017-01-29 17:54:43 +00:00
parent 807cea8e60
commit cd61182ac6
1 changed files with 14 additions and 3 deletions

View File

@ -43,6 +43,11 @@ public class OauthService {
*/
private Map<String, CacheBean> entries;
/**
* Cleaner thread
*/
CacheCleaner cleaner;
/**
* Since this is a singleton sub-service, there will be just one call to this constructor and one running thread
* to clean up expired codes.
@ -50,10 +55,16 @@ public class OauthService {
public OauthService() {
logger.info("Singleton gcube-oauth service built.");
entries = new ConcurrentHashMap<String, CacheBean>();
CacheCleaner cleaner = new CacheCleaner(entries);
cleaner = new CacheCleaner(entries);
cleaner.start();
}
@Override
protected void finalize(){
if(cleaner != null)
cleaner.interrupt();
}
/**
* Used to check that the token type is of type user
* @param clientType
@ -73,7 +84,7 @@ public class OauthService {
private boolean checkIsapplicationTokenType(ClientType clientType){
return clientType.equals(ClientType.EXTERNALSERVICE);
}
@GET
@Path("check")
@Produces(MediaType.TEXT_PLAIN)
@ -136,7 +147,7 @@ public class OauthService {
Status status = Status.BAD_REQUEST;
logger.info("Request to exchange code for token");
logger.info("Params are client_id = " + clientId + ", client_secret = " + clientSecret.substring(0, 10) +
"*******************"+ ", redirect_uri = " +redirectUri + ", code = " + code.substring(0, 10) + "*******************" + ", grant_type = " + grantType);
"*******************"+ ", redirect_uri = " +redirectUri + ", code = " + code.substring(0, 10) + "*******************" + ", grant_type = " + grantType);
try{
// check if something is missing