Merge pull request 'OIDC UMA token in threadlocal changes' (#1) from mauro.mugnaini/user-registration-hook:master into master

This commit is contained in:
Massimiliano Assante 2020-06-24 11:46:39 +02:00
commit 5e9ea488e9
4 changed files with 37 additions and 35 deletions

View File

@ -1,5 +1,4 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
@ -80,6 +79,12 @@
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>oidc-library-portal</artifactId>
<version>[0.1.0,)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>

View File

@ -2,6 +2,8 @@ package org.gcube.portal.removeaccount.thread;
import java.util.List;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -33,6 +35,7 @@ public class RemovedUserAccountThread implements Runnable {
@Override
public void run() {
OIDCUmaUtil.provideConfiguredPortalClientUMATokenInThreadLocal("/" + PortalContext.getConfiguration().getInfrastructureName());
try {
_log.info("Trying to remove user " + userNameToDelete + " from JCR first, using storageHub with role: "+GatewayRolesNames.INFRASTRUCTURE_MANAGER.getRoleName());
RemoveUserFromJCR rmJCR = new RemoveUserFromJCR(userNameToDelete, theAdminToken, theAdminRolesString);

View File

@ -10,7 +10,6 @@ import org.gcube.portal.removeaccount.thread.RemovedUserAccountThread;
import org.gcube.portal.removeaccount.thread.RemovedUserFromLDAPThread;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
@ -36,7 +35,7 @@ public class MyCreateUserAccountListener extends BaseModelListener<User> {
private static final Logger _log = LoggerFactory.getLogger(MyCreateUserAccountListener.class);
final String SUBJECT = "New user account notification";
private GroupManager gm;
private UserManager uMan;
// private UserManager uMan;
private RoleManager rm;
@Override
@ -52,7 +51,7 @@ public class MyCreateUserAccountListener extends BaseModelListener<User> {
@Override
public void onBeforeRemove(User user) throws ModelListenerException {
gm = new LiferayGroupManager();
uMan = new LiferayUserManager();
// uMan = new LiferayUserManager();
rm = new LiferayRoleManager();
_log.info("onBeforeRemove userAccount listener for: " + user.getScreenName() + " / " + user.getFullName());

View File

@ -1,43 +1,38 @@
package org.gcube.portal.usersaccount;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
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 {
private static Logger _log = LoggerFactory.getLogger(WorkspaceCreateAccountThread.class);
private String newUserUserName;
private static Logger _log = LoggerFactory.getLogger(WorkspaceCreateAccountThread.class);
public WorkspaceCreateAccountThread(String newUserUserName, String newUserFullName, String newUserEmailAddress) {
super();
this.newUserUserName = newUserUserName;
_log.info("Calling HomeLibrary for Workspace creation to new user: " + newUserUserName + " ("+newUserFullName+")");
}
private String newUserUserName;
@Override
public void run() {
getWS(newUserUserName, "/"+PortalContext.getConfiguration().getInfrastructureName());
}
public static Workspace getWS(String currentUsername, String context) {
String username = currentUsername;
String authorizationToken = PortalContext.getConfiguration().getCurrentUserToken(context, username);
SecurityTokenProvider.instance.set(authorizationToken);
ScopeProvider.instance.set(context);
try {
Workspace toReturn = HomeLibrary.getUserWorkspace(username);
_log.info("Done Workspace creation for user: " + currentUsername);
return toReturn;
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
public WorkspaceCreateAccountThread(String newUserUserName, String newUserFullName, String newUserEmailAddress) {
super();
this.newUserUserName = newUserUserName;
_log.info("Calling SHUB for Workspace creation to new user: " + newUserUserName + " (" + newUserFullName + ")");
}
@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);
}
}
}