fix for bug #712 and assigning the wrong username found in session
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/custom-portal-handler@119375 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
2c0d46ffa7
commit
3fcb1a254f
|
@ -20,7 +20,7 @@
|
|||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="owner.project.facets" value="java"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
|
|
14
pom.xml
14
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>custom-portal-handler</artifactId>
|
||||
<version>1.7.0-SNAPSHOT</version>
|
||||
<version>1.8.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Custom Portal Handler</name>
|
||||
<description>
|
||||
|
@ -42,6 +42,16 @@
|
|||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-authorization</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common.portal</groupId>
|
||||
<artifactId>portal-manager</artifactId>
|
||||
|
@ -69,7 +79,7 @@
|
|||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</dependency>
|
||||
|
|
|
@ -205,7 +205,7 @@ public class OrganizationsUtil {
|
|||
* @throws PortalException .
|
||||
* @throws SystemException .
|
||||
*/
|
||||
protected long createLayout(Group group, User user, GCUBESiteLayout siteLayout) throws PortalException, SystemException {
|
||||
protected static long createLayout(Group group, User user, GCUBESiteLayout siteLayout) throws PortalException, SystemException {
|
||||
|
||||
Layout layout = null;
|
||||
|
||||
|
@ -253,7 +253,7 @@ public class OrganizationsUtil {
|
|||
* @throws SystemException .
|
||||
* @throws PortalException .
|
||||
*/
|
||||
private void removePortletFrame(GCUBELayoutTab tab, Layout layout) throws PortalException, SystemException {
|
||||
private static void removePortletFrame(GCUBELayoutTab tab, Layout layout) throws PortalException, SystemException {
|
||||
if (tab == null || layout == null) return;
|
||||
for (GCUBEPortlet gPortlet : tab.getPortlets()) {
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.portal.custom.communitymanager.OrganizationManager;
|
||||
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
||||
import org.gcube.portal.custom.communitymanager.PortletsIdManager;
|
||||
import org.gcube.portal.custom.communitymanager.components.GCUBELayoutTab;
|
||||
|
@ -46,7 +44,7 @@ import com.liferay.portal.service.UserLocalServiceUtil;
|
|||
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
|
||||
*
|
||||
*/
|
||||
public class OrganizationManagerImpl extends OrganizationsUtil implements OrganizationManager {
|
||||
public class OrganizationManagerImpl extends OrganizationsUtil {
|
||||
|
||||
private static Log _log = LogFactoryUtil.getLog(OrganizationManagerImpl.class);
|
||||
|
||||
|
@ -54,50 +52,24 @@ public class OrganizationManagerImpl extends OrganizationsUtil implements Organi
|
|||
* FIXME public as generic resource
|
||||
*/
|
||||
protected static final String ORGANIZATION_DEFAULT_LOGO = "/org/gcube/portal/custom/communitymanager/resources/default_logo.png";
|
||||
|
||||
ASLSession session = null;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String screenName;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static OrganizationManagerImpl singleton;
|
||||
/**
|
||||
*
|
||||
* @param session the ASL session
|
||||
*/
|
||||
private OrganizationManagerImpl(ASLSession session) {
|
||||
this.session = session;
|
||||
this.screenName = session.getUsername();
|
||||
singleton = this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param session the session
|
||||
* @return the singleton
|
||||
*/
|
||||
public static OrganizationManagerImpl getInstance(ASLSession session) {
|
||||
if (singleton == null)
|
||||
singleton = new OrganizationManagerImpl(session);
|
||||
return singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param rootVoName the voName
|
||||
* @param voDesc -
|
||||
* @return the organizationid of the created VO
|
||||
*/
|
||||
public long createVO(String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
|
||||
public static long createVO(String username, String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
|
||||
String email = "";
|
||||
Group voToCreate = null;
|
||||
try {
|
||||
email = validateUser(screenName).getEmailAddress();
|
||||
email = validateUser(username).getEmailAddress();
|
||||
|
||||
//create the Group
|
||||
User creator = validateUser(screenName);
|
||||
User creator = validateUser(username);
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
GroupModel groupModel = null;
|
||||
_log.info("createVO " + voName + " with parentid " + parentid);
|
||||
|
@ -106,7 +78,7 @@ public class OrganizationManagerImpl extends OrganizationsUtil implements Organi
|
|||
voToCreate = OrganizationLocalServiceUtil.getOrganization(groupModelid).getGroup();
|
||||
|
||||
//associate the layout to the group
|
||||
createLayout(voToCreate, validateUser(screenName), siteLayout);
|
||||
createLayout(voToCreate, validateUser(username), siteLayout);
|
||||
|
||||
Theme themeToApply = ThemeLocalServiceUtil.getTheme(getCompany().getCompanyId(), themeid, false);
|
||||
|
||||
|
@ -122,17 +94,17 @@ public class OrganizationManagerImpl extends OrganizationsUtil implements Organi
|
|||
_log.debug("Adding the Admin Role VO-Admin for this VO");
|
||||
//add the role ADMIN
|
||||
UserManager uman = new LiferayUserManager();
|
||||
long uid = Long.parseLong(uman.getUserId(screenName));
|
||||
long uid = Long.parseLong(uman.getUserId(username));
|
||||
Role created = OrganizationsUtil.createRole("VO-Admin", voName, uid);
|
||||
_log.debug("Admin Role VO-Admin Created Successfully");
|
||||
|
||||
uman.assignUserToGroup(""+voToCreate.getClassPK(), ""+uid);
|
||||
_log.debug("Added user " + screenName + " to group " + voName + " with Success");
|
||||
_log.debug("Added user " + username + " to group " + voName + " with Success");
|
||||
|
||||
_log.debug("Assigning Role: VO-Admin");
|
||||
RoleManager rm = new LiferayRoleManager();
|
||||
rm.assignRoleToUser(""+voToCreate.getClassPK(), ""+created.getRoleId(), ""+uid);
|
||||
_log.debug("Admin Role VO-Admin Associated to user " + screenName + " .... returning ...");
|
||||
_log.debug("Admin Role VO-Admin Associated to user " + username + " .... returning ...");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -148,8 +120,8 @@ public class OrganizationManagerImpl extends OrganizationsUtil implements Organi
|
|||
* @param voDesc -
|
||||
* @return the id of the created VO
|
||||
*/
|
||||
public long createVO(String voName, String voDesc, GCUBESiteLayout siteLayout, String themeid) {
|
||||
return createVO(voName, voDesc, 0, siteLayout, themeid);
|
||||
public static long createVO(String username, String voName, String voDesc, GCUBESiteLayout siteLayout, String themeid) {
|
||||
return createVO(username, voName, voDesc, 0, siteLayout, themeid);
|
||||
}
|
||||
/**
|
||||
*
|
||||
|
@ -157,14 +129,12 @@ public class OrganizationManagerImpl extends OrganizationsUtil implements Organi
|
|||
* @param voDesc -
|
||||
* @return the organizationid of the created VO
|
||||
*/
|
||||
public long createVRE(String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
|
||||
String email = "";
|
||||
public static long createVRE(String username, String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
|
||||
|
||||
Group voToCreate = null;
|
||||
try {
|
||||
email = validateUser(screenName).getEmailAddress();
|
||||
|
||||
//create the Group
|
||||
User creator = validateUser(screenName);
|
||||
User creator = validateUser(username);
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
GroupModel groupModel = null;
|
||||
_log.info("createVRE " + voName + " with parentid " + parentid);
|
||||
|
@ -173,7 +143,7 @@ public class OrganizationManagerImpl extends OrganizationsUtil implements Organi
|
|||
voToCreate = OrganizationLocalServiceUtil.getOrganization(groupModelid).getGroup();
|
||||
|
||||
//associate the layout to the group
|
||||
createLayout(voToCreate, validateUser(screenName), siteLayout);
|
||||
createLayout(voToCreate, validateUser(username), siteLayout);
|
||||
|
||||
Theme themeToApply = ThemeLocalServiceUtil.getTheme(getCompany().getCompanyId(), themeid, false);
|
||||
|
||||
|
@ -189,17 +159,17 @@ public class OrganizationManagerImpl extends OrganizationsUtil implements Organi
|
|||
_log.debug("Adding the MANAGER Role VRE-Manager for this VRE");
|
||||
//add the role ADMIN
|
||||
UserManager uman = new LiferayUserManager();
|
||||
long uid = Long.parseLong(uman.getUserId(screenName));
|
||||
long uid = Long.parseLong(uman.getUserId(username));
|
||||
Role created = OrganizationsUtil.createRole("VRE-Manager", voName, uid);
|
||||
_log.debug("Admin Role VRE-Manager Created Successfully");
|
||||
|
||||
uman.assignUserToGroup(""+voToCreate.getClassPK(), ""+uid);
|
||||
_log.debug("Added user " + screenName + " to group " + voName + " with Success");
|
||||
_log.debug("Added user " + username + " to group " + voName + " with Success");
|
||||
|
||||
_log.debug("Assigning Role: VRE-Manager");
|
||||
RoleManager rm = new LiferayRoleManager();
|
||||
rm.assignRoleToUser(""+voToCreate.getClassPK(), ""+created.getRoleId(), ""+uid);
|
||||
_log.debug("Admin Role VRE-Manager Associated to user " + screenName + " .... returning ...");
|
||||
_log.debug("Admin Role VRE-Manager Associated to user " + username + " .... returning ...");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -214,7 +184,7 @@ public class OrganizationManagerImpl extends OrganizationsUtil implements Organi
|
|||
* @throws SystemException .
|
||||
* @throws PortalException .
|
||||
*/
|
||||
public static GCUBESiteLayout getBaseLayout(String voName, OrganizationManagerImpl orgManager, boolean isVO, String username) throws PortalException, SystemException {
|
||||
public static GCUBESiteLayout getBaseLayout(String voName, boolean isVO, String username) throws PortalException, SystemException {
|
||||
GCUBESiteLayout siteLayout = null;
|
||||
String email = validateUser(username).getEmailAddress();
|
||||
siteLayout = new GCUBESiteLayout(OrganizationManagerImpl.getCompany(), voName, email);
|
||||
|
@ -250,7 +220,7 @@ public class OrganizationManagerImpl extends OrganizationsUtil implements Organi
|
|||
* @param inputStream
|
||||
* @return
|
||||
*/
|
||||
private File writeTempLogo(InputStream inputStream) {
|
||||
private static File writeTempLogo(InputStream inputStream) {
|
||||
try {
|
||||
File temp = File.createTempFile("logoimage", ".png");
|
||||
// write the inputStream to a FileOutputStream
|
||||
|
|
|
@ -1,17 +1,22 @@
|
|||
package org.gcube.portal.custom.scopemanager.scopehelper;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.portlet.PortletSession;
|
||||
import javax.portlet.RenderRequest;
|
||||
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.application.framework.core.session.SessionManager;
|
||||
import org.gcube.application.framework.core.util.GenderType;
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
||||
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
|
@ -132,6 +137,7 @@ public class ScopeHelper {
|
|||
SessionManager.getInstance().getASLSession(sessionID, username).setUserAvatarId(thumbnailURL);
|
||||
SessionManager.getInstance().getASLSession(sessionID, username).setUserGender(isMale? GenderType.MALE : GenderType.FEMALE);
|
||||
|
||||
setAuthorizationToken(SessionManager.getInstance().getASLSession(sessionID, username));
|
||||
|
||||
} catch (PortalException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -140,6 +146,28 @@ public class ScopeHelper {
|
|||
}
|
||||
|
||||
}
|
||||
private final static String DEFAULT_ROLE = "OrganizationMember";
|
||||
private final static String TEST_USER = "test.user";
|
||||
|
||||
private static void setAuthorizationToken(ASLSession session) {
|
||||
|
||||
String username = session.getUsername();
|
||||
_log.debug("Generating token");
|
||||
String managerName = "lucio.lelii";
|
||||
if (username.compareTo(TEST_USER) == 0)
|
||||
return;
|
||||
String scope = session.getScope();
|
||||
ScopeProvider.instance.set(scope);
|
||||
_log.debug("calling service token on scope " + scope);
|
||||
List<String> userRoles = new ArrayList<>();
|
||||
userRoles.add(DEFAULT_ROLE);
|
||||
if (username.compareTo("lucio.lelii")==0)
|
||||
userRoles.add("VRE-Manager");
|
||||
String token = authorizationService().build().generate(session.getUsername(), userRoles);
|
||||
_log.debug("received token: "+token);
|
||||
session.setSecurityToken(token);
|
||||
_log.info("Security token set in session for: "+username + " on " + scope);
|
||||
}
|
||||
/**
|
||||
* read the root VO name from a property file and retuns it
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue