user-registration-hook/src/main/java/org/gcube/portal/usersaccount/WorkspaceCreateAccountThrea...

39 lines
1.6 KiB
Java
Raw Normal View History

package org.gcube.portal.usersaccount;
2020-06-22 11:54:41 +02:00
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
2020-06-22 11:54:41 +02:00
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class WorkspaceCreateAccountThread implements Runnable {
2020-06-22 11:54:41 +02:00
private static Logger _log = LoggerFactory.getLogger(WorkspaceCreateAccountThread.class);
2020-06-22 11:54:41 +02:00
private String newUserUserName;
2020-06-22 11:54:41 +02:00
public WorkspaceCreateAccountThread(String newUserUserName, String newUserFullName, String newUserEmailAddress) {
super();
this.newUserUserName = newUserUserName;
_log.info("Calling SHUB for Workspace creation to new user: " + newUserUserName + " (" + newUserFullName + ")");
}
2020-06-22 11:54:41 +02:00
@Override
public void run() {
String context = "/" + PortalContext.getConfiguration().getInfrastructureName();
String authorizationToken = PortalContext.getConfiguration().getCurrentUserToken(context, newUserUserName);
SecurityTokenProvider.instance.set(authorizationToken);
ScopeProvider.instance.set(context);
OIDCUmaUtil.provideConfiguredPortalClientUMATokenInThreadLocal(context);
try {
StorageHubClient shc = new StorageHubClient();
shc.createUserAccount(newUserUserName);
_log.info("Done Workspace creation for user: " + newUserUserName);
} catch (Exception e) {
_log.error("Creating new account on the storage HUB", e);
}
}
}