added thread for removing the token

This commit is contained in:
Massimiliano Assante 2020-01-17 17:07:49 +01:00
parent 67eeafea13
commit 1a037c10da
1 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,45 @@
package org.gcube.portal.removeaccount.thread;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
/**
*
* @author Massimiliano Assante ISTI-CNR
*
*/
public class RemoveUserTokenFromInfraThread implements Runnable {
private static Log _log = LogFactoryUtil.getLog(RemoveUserTokenFromInfraThread.class);
private String username;
/**
*
* @param username
* @param scope
*/
public RemoveUserTokenFromInfraThread(String username) {
super();
this.username = username;
}
@Override
public void run() {
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
ScopeProvider.instance.set(infraContext);
try {
String userToken = authorizationService().resolveTokenByUserAndContext(username, infraContext);
SecurityTokenProvider.instance.set(userToken);
authorizationService().removeAllReleatedToken(username, infraContext);
_log.info("*** Removed user token " + username + " in " + infraContext);
} catch (Exception e) {
_log.error("Could not remove user token " + username + " in " + infraContext, e);
}
}
}