OIDC UMA in threadlocal changes

This commit is contained in:
Mauro Mugnaini 2020-06-22 11:54:41 +02:00
parent 1d3e125819
commit f6ff974022
4 changed files with 37 additions and 35 deletions

View File

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

View File

@ -2,6 +2,8 @@ package org.gcube.portal.removeaccount.thread;
import java.util.List; 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.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -33,6 +35,7 @@ public class RemovedUserAccountThread implements Runnable {
@Override @Override
public void run() { public void run() {
OIDCUmaUtil.provideConfiguredPortalClientUMATokenInThreadLocal("/" + PortalContext.getConfiguration().getInfrastructureName());
try { try {
_log.info("Trying to remove user " + userNameToDelete + " from JCR first, using storageHub with role: "+GatewayRolesNames.INFRASTRUCTURE_MANAGER.getRoleName()); _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); 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.portal.removeaccount.thread.RemovedUserFromLDAPThread;
import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.RoleManager; 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.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; 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); private static final Logger _log = LoggerFactory.getLogger(MyCreateUserAccountListener.class);
final String SUBJECT = "New user account notification"; final String SUBJECT = "New user account notification";
private GroupManager gm; private GroupManager gm;
private UserManager uMan; // private UserManager uMan;
private RoleManager rm; private RoleManager rm;
@Override @Override
@ -52,7 +51,7 @@ public class MyCreateUserAccountListener extends BaseModelListener<User> {
@Override @Override
public void onBeforeRemove(User user) throws ModelListenerException { public void onBeforeRemove(User user) throws ModelListenerException {
gm = new LiferayGroupManager(); gm = new LiferayGroupManager();
uMan = new LiferayUserManager(); // uMan = new LiferayUserManager();
rm = new LiferayRoleManager(); rm = new LiferayRoleManager();
_log.info("onBeforeRemove userAccount listener for: " + user.getScreenName() + " / " + user.getFullName()); _log.info("onBeforeRemove userAccount listener for: " + user.getScreenName() + " / " + user.getFullName());

View File

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