moved to version 2.0
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/custom-portal-handler@125277 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
cac2c2dc1b
commit
e8d6da2814
|
@ -15,8 +15,6 @@
|
|||
<includes>
|
||||
<include>README</include>
|
||||
<include>LICENSE</include>
|
||||
<include>INSTALL</include>
|
||||
<include>MAINTAINERS</include>
|
||||
<include>changelog.xml</include>
|
||||
</includes>
|
||||
<fileMode>755</fileMode>
|
||||
|
@ -39,10 +37,5 @@
|
|||
<source>target/${build.finalName}.jar</source>
|
||||
<outputDirectory>/${artifactId}</outputDirectory>
|
||||
</file>
|
||||
<file>
|
||||
<source>${distroDirectory}/svnpath.txt</source>
|
||||
<outputDirectory>/${artifactId}</outputDirectory>
|
||||
<filtered>true</filtered>
|
||||
</file>
|
||||
</files>
|
||||
</assembly>
|
26
pom.xml
26
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>custom-portal-handler</artifactId>
|
||||
<version>1.8.0-SNAPSHOT</version>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Custom Portal Handler</name>
|
||||
<description>
|
||||
|
@ -26,7 +26,7 @@
|
|||
<distroDirectory>distro</distroDirectory>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
|
||||
<liferay.version>6.2.5</liferay.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
|
@ -55,6 +55,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.common.portal</groupId>
|
||||
<artifactId>portal-manager</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -65,10 +66,31 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.dvos</groupId>
|
||||
<artifactId>usermanagement-core</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
<artifactId>portal-service</artifactId>
|
||||
<version>${liferay.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
<artifactId>util-bridges</artifactId>
|
||||
<version>${liferay.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
<artifactId>util-taglib</artifactId>
|
||||
<version>${liferay.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
<artifactId>util-java</artifactId>
|
||||
<version>${liferay.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.portlet</groupId>
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package org.gcube.portal.custom.communitymanager;
|
||||
|
||||
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
|
||||
|
||||
import com.liferay.portal.model.Organization;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
|
||||
*
|
||||
*/
|
||||
public interface GCubeSiteManager {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param rootVoName the voName
|
||||
* @param voDesc -
|
||||
* @return the id of the created VO
|
||||
*/
|
||||
long createVO(String rootVoName, String voDesc, GCUBESiteLayout siteLayout, String themeid);
|
||||
/**
|
||||
*
|
||||
* @param voName the voName
|
||||
* @param voDesc -
|
||||
* @return the id of the created VO
|
||||
*/
|
||||
long createVO(String voName, String voDesc, long parentID, GCUBESiteLayout siteLayout, String themeid);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param rootVoName the voName
|
||||
* @param voDesc -
|
||||
* @return the organizationid of the created VO
|
||||
*/
|
||||
long createVRE(String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid);
|
||||
/**
|
||||
*
|
||||
* @param username the screenname of the current user
|
||||
* @param currOrg the organization in which to check the custom attribute
|
||||
* @param attrToCheck the key to check
|
||||
* @return true or false
|
||||
*/
|
||||
Boolean readOrganizationCustomAttribute(String username, Organization currOrg, String attrToCheck);
|
||||
|
||||
}
|
|
@ -128,7 +128,7 @@ public final class PortletsIdManager {
|
|||
Properties props = new Properties();
|
||||
String toReturn = "";
|
||||
try {
|
||||
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-portlets.properties";
|
||||
String propertyfile = SiteManagerUtil.getTomcatFolder()+"conf/gcube-portlets.properties";
|
||||
File propsFile = new File(propertyfile);
|
||||
FileInputStream fis = new FileInputStream(propsFile);
|
||||
props.load( fis );
|
||||
|
|
|
@ -4,17 +4,15 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.portal.custom.communitymanager.components.GCUBELayoutTab;
|
||||
import org.gcube.portal.custom.communitymanager.components.GCUBEPortlet;
|
||||
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
|
||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
import com.liferay.portal.kernel.exception.SystemException;
|
||||
|
@ -33,15 +31,14 @@ import com.liferay.portal.service.CompanyLocalServiceUtil;
|
|||
import com.liferay.portal.service.LayoutLocalServiceUtil;
|
||||
import com.liferay.portal.service.PortletLocalServiceUtil;
|
||||
import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
|
||||
import com.liferay.portal.service.RoleLocalServiceUtil;
|
||||
import com.liferay.portal.service.ServiceContext;
|
||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
|
||||
public class OrganizationsUtil {
|
||||
public class SiteManagerUtil {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static Log _log = LogFactoryUtil.getLog(OrganizationManager.class);
|
||||
private static Log _log = LogFactoryUtil.getLog(GCubeSiteManager.class);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -150,38 +147,6 @@ public class OrganizationsUtil {
|
|||
toReturn.add(new GCUBEPortlet(PortletsIdManager.LR_ACTIVITIES, PortletsIdManager.getLRPortletId(PortletsIdManager.LR_ACTIVITIES)));
|
||||
return toReturn;
|
||||
}
|
||||
/**
|
||||
* Create a Regular Manager Role for the community/Organization
|
||||
* @param vreName
|
||||
* @return
|
||||
* @throws SystemException
|
||||
* @throws PortalException
|
||||
*/
|
||||
public static Role addManagerRole(String vreName, String username) throws PortalException, SystemException {
|
||||
Company company = getCompany();
|
||||
User user = validateUser(username);
|
||||
String roleName = "VRE-Manager-" + vreName.replaceAll(" ", "-");
|
||||
Locale english = new Locale("en");
|
||||
HashMap<Locale, String> roleNames = new HashMap<Locale, String>();
|
||||
roleNames.put(english, roleName);
|
||||
return RoleLocalServiceUtil.addRole(user.getUserId(), company.getCompanyId(), roleName, roleNames, "VRE Manager of " + vreName, LIFERAY_REGULAR_ROLE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Regular Manager Role for the community/Organization
|
||||
* @param vreName
|
||||
* @return
|
||||
* @throws SystemException
|
||||
* @throws PortalException
|
||||
*/
|
||||
public static Role addManagerRole(String roleName, String vreName, long userid) throws PortalException, SystemException {
|
||||
Company company = getCompany();
|
||||
Locale english = new Locale("en");
|
||||
HashMap<Locale, String> roleNames = new HashMap<Locale, String>();
|
||||
roleNames.put(english, roleName);
|
||||
return RoleLocalServiceUtil.addRole(userid, company.getCompanyId(), roleName, roleNames, "VRE Manager of " + vreName, LIFERAY_REGULAR_ROLE_ID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -288,34 +253,13 @@ public class OrganizationsUtil {
|
|||
public boolean addUserToGroup(long groupid, String username) {
|
||||
UserManager uman = new LiferayUserManager();
|
||||
try {
|
||||
uman.assignUserToGroup(""+groupid, uman.getUserId(username));
|
||||
uman.assignUserToGroup(groupid, uman.getUserId(username));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Regular Manager Role for the community
|
||||
* @param vreName
|
||||
* @return
|
||||
* @throws PortalException
|
||||
* @throws SystemException
|
||||
*/
|
||||
protected static Role createRole(String roleName, String vreName, long userid){
|
||||
try {
|
||||
Company company = getCompany();
|
||||
String roletoAdd = roleName+"-" + vreName.replaceAll(" ", "-");
|
||||
return RoleLocalServiceUtil.addRole(userid, company.getCompanyId(), roletoAdd, null, roleName +" of " + vreName, LIFERAY_REGULAR_ROLE_ID);
|
||||
} catch (PortalException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SystemException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* read the root VO name from a property file and retuns it
|
||||
*/
|
||||
|
@ -325,7 +269,7 @@ public class OrganizationsUtil {
|
|||
String toReturn = "";
|
||||
|
||||
try {
|
||||
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties";
|
||||
String propertyfile = SiteManagerUtil.getTomcatFolder()+"conf/gcube-data.properties";
|
||||
File propsFile = new File(propertyfile);
|
||||
FileInputStream fis = new FileInputStream(propsFile);
|
||||
props.load( fis);
|
||||
|
@ -340,20 +284,5 @@ public class OrganizationsUtil {
|
|||
_log.debug("Returning Root VO Name: " + toReturn );
|
||||
return toReturn;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param rolename
|
||||
* @param organizationName
|
||||
* @param user
|
||||
* @return
|
||||
* @throws SystemException
|
||||
*/
|
||||
private boolean hasRole(String rolename, String organizationName, User user) throws SystemException {
|
||||
for (Role role : user.getRoles()) {
|
||||
//_log.trace("COMPARING ROLE: " +role.getName() + " -> " + rolename + "-" + organizationName);
|
||||
if (role.getName().compareTo( rolename + "-" + organizationName) == 0 )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,195 +0,0 @@
|
|||
package org.gcube.portal.custom.communitymanager.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.portal.custom.communitymanager.CommunityManager;
|
||||
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
||||
import org.gcube.portal.custom.communitymanager.PortletsIdManager;
|
||||
import org.gcube.portal.custom.communitymanager.components.GCUBELayoutTab;
|
||||
import org.gcube.portal.custom.communitymanager.components.GCUBEPortlet;
|
||||
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
|
||||
import org.gcube.portal.custom.communitymanager.types.GCUBELayoutType;
|
||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GroupModel;
|
||||
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
import com.liferay.portal.kernel.exception.SystemException;
|
||||
import com.liferay.portal.kernel.log.Log;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
import com.liferay.portal.model.Group;
|
||||
import com.liferay.portal.model.Portlet;
|
||||
import com.liferay.portal.model.User;
|
||||
import com.liferay.portal.service.OrganizationLocalServiceUtil;
|
||||
/**
|
||||
*
|
||||
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
|
||||
* @version 1.0
|
||||
*
|
||||
*/
|
||||
public class CommunityManagerImpl extends OrganizationsUtil implements CommunityManager {
|
||||
|
||||
private static Log _log = LogFactoryUtil.getLog(CommunityManagerImpl.class);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final String CURR_ORG = "CURR_RE_NAME";
|
||||
|
||||
|
||||
ASLSession session = null;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String screenName;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static CommunityManagerImpl singleton;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the singleton
|
||||
*/
|
||||
public static CommunityManagerImpl get() {
|
||||
return singleton;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param session the ASL session
|
||||
*/
|
||||
private CommunityManagerImpl(ASLSession session) {
|
||||
this.session = session;
|
||||
this.screenName = session.getUsername();
|
||||
singleton = this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param session the session
|
||||
* @return the singleton
|
||||
*/
|
||||
public static CommunityManagerImpl getInstance(ASLSession session) {
|
||||
return new CommunityManagerImpl(session);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method for creating VRE programmatically and associate a default layout to it
|
||||
*
|
||||
* @param communityName -
|
||||
* @param communityDesc -
|
||||
* @param parentID -
|
||||
* @return the community created id
|
||||
*/
|
||||
public long createCommunity(String communityName, String communityDesc, long parentID) {
|
||||
String username = "";
|
||||
String email = "";
|
||||
GCUBESiteLayout siteLayout = null;
|
||||
try {
|
||||
username = validateUser(screenName).getScreenName();
|
||||
email = validateUser(screenName).getEmailAddress();
|
||||
|
||||
siteLayout = new GCUBESiteLayout(getCompany(), communityName, email);
|
||||
siteLayout.addTab(new GCUBELayoutTab("Home", GCUBELayoutType.ONE_COL,
|
||||
new GCUBEPortlet("gCube Loggedin", PortletsIdManager.getLRPortletId(PortletsIdManager.GCUBE_LOGGEDIN))));
|
||||
siteLayout.addTab(new GCUBELayoutTab("Workspace", GCUBELayoutType.ONE_COL,
|
||||
new GCUBEPortlet("gCube Workspace", PortletsIdManager.getLRPortletId(PortletsIdManager.WORKSPACE))));
|
||||
} catch (PortalException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SystemException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return createCommunity(username, communityName, communityDesc, siteLayout, parentID);
|
||||
|
||||
}
|
||||
/**
|
||||
* Use this method for creating VRE programmatically and associate it a layout
|
||||
*
|
||||
* @param usernameCreator -
|
||||
* @param communityName -
|
||||
* @param communityDesc -
|
||||
* @param siteLayout a <class>GCUBESiteLayout</class> instance to associate to it
|
||||
* @param parentID the organization parent
|
||||
* @return the community created id
|
||||
*/
|
||||
public long createCommunity(String usernameCreator, String communityName, String communityDesc, GCUBESiteLayout siteLayout, long parentID) {
|
||||
String username;
|
||||
Group tocreate = null;
|
||||
try {
|
||||
username = usernameCreator;
|
||||
//create the group
|
||||
tocreate = createVRE(communityName, communityDesc, parentID);
|
||||
|
||||
// associate a layout to the group
|
||||
createLayout(tocreate, validateUser(username), siteLayout);
|
||||
} catch (PortalException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SystemException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
_log.debug("Returning Organization ID " + tocreate.getClassPK());
|
||||
return tocreate.getClassPK();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create the group in the database
|
||||
*
|
||||
* @return
|
||||
* @throws SystemException
|
||||
* @throws PortalException
|
||||
*/
|
||||
private Group createVRE(String communityName, String communityDesc, long parentID) throws PortalException, SystemException {
|
||||
|
||||
User creator = validateUser(screenName);
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
|
||||
long groupid = parentID;
|
||||
|
||||
|
||||
GroupModel currOrg = null;
|
||||
try {
|
||||
currOrg = gm.getGroup(""+groupid);
|
||||
} catch (UserManagementSystemException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
} catch (GroupRetrievalFault e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
_log.info("Creating VRE " + communityName + " SUBORG OF " +currOrg.getGroupName());
|
||||
GroupModel groupModel = null;
|
||||
try {
|
||||
groupModel = gm.createVRE(communityName, ""+groupid, ""+creator.getUserId(), "Description for "+communityName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
_log.trace("Calling groupModel.getGroupId() ");
|
||||
long curGroupid = Long.parseLong(groupModel.getGroupId());
|
||||
_log.trace("curGroupid " + curGroupid );
|
||||
|
||||
Group toReturn = OrganizationLocalServiceUtil.getOrganization(curGroupid).getGroup();
|
||||
_log.debug("GROUP created id:" + toReturn.getGroupId());
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param communityName -
|
||||
* @return list of belonging portlet
|
||||
*/
|
||||
public List<Portlet> getGCubePortlets(String communityName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -2,15 +2,14 @@ package org.gcube.portal.custom.communitymanager.impl;
|
|||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
||||
import org.gcube.portal.custom.communitymanager.PortletsIdManager;
|
||||
import org.gcube.portal.custom.communitymanager.SiteManagerUtil;
|
||||
import org.gcube.portal.custom.communitymanager.components.GCUBELayoutTab;
|
||||
import org.gcube.portal.custom.communitymanager.components.GCUBEPortlet;
|
||||
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
|
||||
|
@ -19,10 +18,11 @@ import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
|||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.RoleManager;
|
||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayRoleManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GroupModel;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
||||
|
||||
import com.liferay.portal.kernel.bean.BeanLocatorException;
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
|
@ -31,14 +31,14 @@ import com.liferay.portal.kernel.log.Log;
|
|||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
import com.liferay.portal.model.Group;
|
||||
import com.liferay.portal.model.Organization;
|
||||
import com.liferay.portal.model.Role;
|
||||
import com.liferay.portal.model.Theme;
|
||||
import com.liferay.portal.model.User;
|
||||
import com.liferay.portal.security.auth.PrincipalThreadLocal;
|
||||
import com.liferay.portal.security.permission.PermissionChecker;
|
||||
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
|
||||
import com.liferay.portal.security.permission.PermissionThreadLocal;
|
||||
import com.liferay.portal.service.GroupLocalServiceUtil;
|
||||
import com.liferay.portal.service.LayoutSetLocalServiceUtil;
|
||||
import com.liferay.portal.service.OrganizationLocalServiceUtil;
|
||||
import com.liferay.portal.service.ThemeLocalServiceUtil;
|
||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
import com.liferay.portlet.expando.model.ExpandoBridge;
|
||||
|
@ -48,19 +48,19 @@ import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
|
|||
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
|
||||
*
|
||||
*/
|
||||
public class OrganizationManagerImpl extends OrganizationsUtil {
|
||||
public class GCubeSiteManagerImpl extends SiteManagerUtil {
|
||||
|
||||
private static Log _log = LogFactoryUtil.getLog(OrganizationManagerImpl.class);
|
||||
private static Log _log = LogFactoryUtil.getLog(GCubeSiteManagerImpl.class);
|
||||
|
||||
/**
|
||||
* FIXME public as generic resource
|
||||
*/
|
||||
protected static final String ORGANIZATION_DEFAULT_LOGO = "/org/gcube/portal/custom/communitymanager/resources/default_logo.png";
|
||||
public static final String SITE_DEFAULT_LOGO = "/org/gcube/portal/custom/communitymanager/resources/default_logo.png";
|
||||
private static final String CATEGORY = "Virtualgroup";
|
||||
|
||||
public static List<String> getVirtualGroups() throws PortalException, SystemException {
|
||||
try {
|
||||
ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(OrganizationsUtil.getCompany().getCompanyId(), Organization.class.getName());
|
||||
ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(SiteManagerUtil.getCompany().getCompanyId(), Organization.class.getName());
|
||||
String[] groups = (String[]) expandoBridge.getAttributeDefault("Virtualgroup");
|
||||
return Arrays.asList(groups);
|
||||
} catch (Exception e) {
|
||||
|
@ -70,20 +70,19 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
|||
}
|
||||
|
||||
|
||||
public static String getVirtualGroupName(Organization organization){
|
||||
public static String getVirtualGroupName(Group site){
|
||||
try {
|
||||
long companyId = OrganizationsUtil.getCompany().getCompanyId();
|
||||
_log.debug("Setting Thread Permission");
|
||||
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
|
||||
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
|
||||
long userId = LiferayUserManager.getAdmin().getUserId();
|
||||
PrincipalThreadLocal.setName(userId);
|
||||
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId), false);
|
||||
PermissionThreadLocal.setPermissionChecker(permissionChecker);
|
||||
_log.debug("Setting Permission ok!");
|
||||
|
||||
if (organization.getExpandoBridge().getAttribute(CATEGORY) == null || organization.getExpandoBridge().getAttribute(CATEGORY).equals("")) {
|
||||
if (site.getExpandoBridge().getAttribute(CATEGORY) == null || site.getExpandoBridge().getAttribute(CATEGORY).equals("")) {
|
||||
_log.warn(String.format("Attribute %s not initialized.", CATEGORY));
|
||||
return null;
|
||||
} else {
|
||||
String[] values = (String[]) organization.getExpandoBridge().getAttribute(CATEGORY);
|
||||
String[] values = (String[]) site.getExpandoBridge().getAttribute(CATEGORY);
|
||||
return values[0];
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -101,14 +100,15 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
|||
public static long createVO(String username, String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
|
||||
Group voToCreate = null;
|
||||
try {
|
||||
//create the Group
|
||||
User creator = validateUser(username);
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
GroupModel groupModel = null;
|
||||
GCubeGroup groupModel = null;
|
||||
_log.info("createVO " + voName + " with parentid " + parentid);
|
||||
groupModel = gm.createVRE(voName, ""+parentid, ""+creator.getUserId(), "Description for "+voName);
|
||||
long groupModelid = Long.parseLong(groupModel.getGroupId());
|
||||
voToCreate = OrganizationLocalServiceUtil.getOrganization(groupModelid).getGroup();
|
||||
if (parentid == 0)
|
||||
groupModel = gm.createRootVO(voName, voDesc);
|
||||
else
|
||||
groupModel = gm.createVO(voName, parentid, voDesc);
|
||||
long groupModelid = groupModel.getGroupId();
|
||||
voToCreate = GroupLocalServiceUtil.getGroup(groupModelid);
|
||||
|
||||
//associate the layout to the group
|
||||
createLayout(voToCreate, validateUser(username), siteLayout);
|
||||
|
@ -120,30 +120,36 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
|||
_log.debug("LayoutSet Theme with id " + themeid + " Applied Correctly");
|
||||
|
||||
//update logo
|
||||
InputStream is = OrganizationManagerImpl.class.getResourceAsStream(ORGANIZATION_DEFAULT_LOGO);
|
||||
FileInputStream fis = new FileInputStream(writeTempLogo(is));
|
||||
LayoutSetLocalServiceUtil.updateLogo(voToCreate.getGroupId(), true, true, fis);
|
||||
InputStream is = GCubeSiteManagerImpl.class.getResourceAsStream(SITE_DEFAULT_LOGO);
|
||||
//FileInputStream fis = new FileInputStream(writeTempLogo(is));
|
||||
LayoutSetLocalServiceUtil.updateLogo(voToCreate.getGroupId(), true, true, is);
|
||||
|
||||
_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(username));
|
||||
Role created = OrganizationsUtil.createRole("VO-Admin", voName, uid);
|
||||
_log.debug("Admin Role VO-Admin Created Successfully");
|
||||
long uid = uman.getUserId(username);
|
||||
|
||||
uman.assignUserToGroup(""+voToCreate.getClassPK(), ""+uid);
|
||||
|
||||
uman.assignUserToGroup(groupModel.getGroupId(), uid);
|
||||
_log.debug("Added user " + username + " to group " + voName + " with Success");
|
||||
|
||||
_log.debug("Assigning Role: VO-Admin");
|
||||
_log.debug("Assigning Role: " + GCubeRole.VO_ADMIN_LABEL);
|
||||
RoleManager rm = new LiferayRoleManager();
|
||||
rm.assignRoleToUser(""+voToCreate.getClassPK(), ""+created.getRoleId(), ""+uid);
|
||||
long roleId = -1;
|
||||
for (GCubeRole role : rm.listAllGroupRoles()) {
|
||||
if (role.getRoleName().compareTo(GCubeRole.VO_ADMIN_LABEL) == 0) {
|
||||
roleId = role.getRoleId();
|
||||
break;
|
||||
}
|
||||
}
|
||||
rm.assignRoleToUser(uid, groupModel.getGroupId(), roleId);
|
||||
_log.debug("Admin Role VO-Admin Associated to user " + username + " .... returning ...");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
_log.info("Created" + voName + " with id " + voToCreate.getOrganizationId());
|
||||
return voToCreate.getOrganizationId();
|
||||
_log.info("Created" + voName + " with id " + voToCreate.getGroupId());
|
||||
return voToCreate.getGroupId();
|
||||
}
|
||||
|
||||
|
||||
|
@ -153,7 +159,7 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
|||
* @param voDesc -
|
||||
* @return the id of the created VO
|
||||
*/
|
||||
public static long createVO(String username, String voName, String voDesc, GCUBESiteLayout siteLayout, String themeid) {
|
||||
public static long createRootVO(String username, String voName, String voDesc, GCUBESiteLayout siteLayout, String themeid) {
|
||||
return createVO(username, voName, voDesc, 0, siteLayout, themeid);
|
||||
}
|
||||
/**
|
||||
|
@ -162,53 +168,54 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
|||
* @param voDesc -
|
||||
* @return the organizationid of the created VO
|
||||
*/
|
||||
public static long createVRE(String username, String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
|
||||
|
||||
Group voToCreate = null;
|
||||
public static long createVRE(String username, String vreName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
|
||||
Group vreToCreate = null;
|
||||
try {
|
||||
//create the Group
|
||||
User creator = validateUser(username);
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
GroupModel groupModel = null;
|
||||
_log.info("createVRE " + voName + " with parentid " + parentid);
|
||||
groupModel = gm.createVRE(voName, ""+parentid, ""+creator.getUserId(), voDesc);
|
||||
long groupModelid = Long.parseLong(groupModel.getGroupId());
|
||||
voToCreate = OrganizationLocalServiceUtil.getOrganization(groupModelid).getGroup();
|
||||
|
||||
GCubeGroup groupModel = null;
|
||||
_log.info("createVRE " + vreName + " with parentid " + parentid);
|
||||
groupModel = gm.createVRE(vreName, parentid, voDesc);
|
||||
long groupModelid = groupModel.getGroupId();
|
||||
vreToCreate = GroupLocalServiceUtil.getGroup(groupModelid);
|
||||
//associate the layout to the group
|
||||
createLayout(voToCreate, validateUser(username), siteLayout);
|
||||
createLayout(vreToCreate, validateUser(username), siteLayout);
|
||||
|
||||
Theme themeToApply = ThemeLocalServiceUtil.getTheme(getCompany().getCompanyId(), themeid, false);
|
||||
|
||||
//update theme
|
||||
LayoutSetLocalServiceUtil.updateLookAndFeel(voToCreate.getGroupId(), themeToApply.getThemeId(), "", "", false);
|
||||
LayoutSetLocalServiceUtil.updateLookAndFeel(vreToCreate.getGroupId(), themeToApply.getThemeId(), "", "", false);
|
||||
_log.debug("LayoutSet Theme with id " + themeid + " Applied Correctly");
|
||||
|
||||
//update logo
|
||||
InputStream is = OrganizationManagerImpl.class.getResourceAsStream(ORGANIZATION_DEFAULT_LOGO);
|
||||
FileInputStream fis = new FileInputStream(writeTempLogo(is));
|
||||
LayoutSetLocalServiceUtil.updateLogo(voToCreate.getGroupId(), true, true, fis);
|
||||
InputStream is = GCubeSiteManagerImpl.class.getResourceAsStream(SITE_DEFAULT_LOGO);
|
||||
//FileInputStream fis = new FileInputStream(writeTempLogo(is));
|
||||
LayoutSetLocalServiceUtil.updateLogo(vreToCreate.getGroupId(), true, true, is);
|
||||
|
||||
_log.debug("Adding the MANAGER Role VRE-Manager for this VRE");
|
||||
_log.debug("Adding the Admin Role VRE-Admin for this VRE");
|
||||
//add the role ADMIN
|
||||
UserManager uman = new LiferayUserManager();
|
||||
long uid = Long.parseLong(uman.getUserId(username));
|
||||
Role created = OrganizationsUtil.createRole("VRE-Manager", voName, uid);
|
||||
_log.debug("Admin Role VRE-Manager Created Successfully");
|
||||
long uid = uman.getUserId(username);
|
||||
|
||||
uman.assignUserToGroup(""+voToCreate.getClassPK(), ""+uid);
|
||||
_log.debug("Added user " + username + " to group " + voName + " with Success");
|
||||
|
||||
_log.debug("Assigning Role: VRE-Manager");
|
||||
uman.assignUserToGroup(groupModel.getGroupId(), uid);
|
||||
_log.debug("Added user " + username + " to group " + vreName + " with Success");
|
||||
|
||||
_log.debug("Assigning Role: " + GCubeRole.VRE_MANAGER_LABEL);
|
||||
RoleManager rm = new LiferayRoleManager();
|
||||
rm.assignRoleToUser(""+voToCreate.getClassPK(), ""+created.getRoleId(), ""+uid);
|
||||
long roleId = -1;
|
||||
for (GCubeRole role : rm.listAllGroupRoles()) {
|
||||
if (role.getRoleName().compareTo(GCubeRole.VRE_MANAGER_LABEL) == 0) {
|
||||
roleId = role.getRoleId();
|
||||
break;
|
||||
}
|
||||
}
|
||||
rm.assignRoleToUser(uid, groupModel.getGroupId(), roleId);
|
||||
_log.debug("Admin Role VRE-Manager Associated to user " + username + " .... returning ...");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
_log.info("Created" + voName + " with id " + voToCreate.getOrganizationId());
|
||||
return voToCreate.getOrganizationId();
|
||||
_log.info("Created" + vreName + " with id " + vreToCreate.getGroupId());
|
||||
return vreToCreate.getOrganizationId();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -220,7 +227,7 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
|||
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);
|
||||
siteLayout = new GCUBESiteLayout(GCubeSiteManagerImpl.getCompany(), voName, email);
|
||||
siteLayout.addTab(new GCUBELayoutTab(voName, GCUBELayoutType.ONE_COL,
|
||||
new GCUBEPortlet("gCube Loggedin", PortletsIdManager.getLRPortletId(PortletsIdManager.GCUBE_LOGGEDIN))));
|
||||
|
||||
|
@ -281,14 +288,14 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
|||
}
|
||||
try {
|
||||
|
||||
long companyId = OrganizationsUtil.getCompany().getCompanyId();
|
||||
long companyId = SiteManagerUtil.getCompany().getCompanyId();
|
||||
_log.trace("Setting Thread Permission");
|
||||
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
|
||||
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
|
||||
PermissionThreadLocal.setPermissionChecker(permissionChecker);
|
||||
_log.trace("Setting Permission ok!");
|
||||
|
||||
User currentUser = OrganizationsUtil.validateUser(username);
|
||||
User currentUser = SiteManagerUtil.validateUser(username);
|
||||
if (currOrg.getExpandoBridge().getAttribute(attrToCheck) == null || currOrg.getExpandoBridge().getAttribute(attrToCheck).equals("")) {
|
||||
_log.trace("Attribute " + attrToCheck + " must be initialized");
|
||||
setOrgCustomAttribute(username, currOrg, attrToCheck);
|
||||
|
@ -328,7 +335,7 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
long companyId = OrganizationsUtil.getCompany().getCompanyId();
|
||||
long companyId = SiteManagerUtil.getCompany().getCompanyId();
|
||||
_log.trace("Setting Thread Permission");
|
||||
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
|
||||
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
|
Binary file not shown.
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 8.2 KiB |
|
@ -1,11 +1,8 @@
|
|||
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;
|
||||
|
||||
|
@ -16,20 +13,20 @@ 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 org.gcube.portal.custom.communitymanager.SiteManagerUtil;
|
||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
import com.liferay.portal.kernel.exception.SystemException;
|
||||
import com.liferay.portal.kernel.log.Log;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
import com.liferay.portal.kernel.util.WebKeys;
|
||||
import com.liferay.portal.model.Group;
|
||||
import com.liferay.portal.model.Organization;
|
||||
import com.liferay.portal.model.Role;
|
||||
import com.liferay.portal.model.User;
|
||||
import com.liferay.portal.service.GroupLocalServiceUtil;
|
||||
import com.liferay.portal.service.OrganizationLocalServiceUtil;
|
||||
import com.liferay.portal.service.RoleLocalServiceUtil;
|
||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
import com.liferay.portal.theme.ThemeDisplay;
|
||||
|
@ -38,7 +35,7 @@ import com.liferay.portal.theme.ThemeDisplay;
|
|||
public class ScopeHelper {
|
||||
|
||||
public static final String USERNAME_ATTRIBUTE = "username";
|
||||
|
||||
public static final String CURR_ORG = "CURR_RE_NAME";
|
||||
public static final String USER_FULL_NAME_ATTRIBUTE = "USER_FULL_NAME";
|
||||
public static final String USER_EMAIL_ATTRIBUTE = "USER_EMAIL";
|
||||
public static final String USER_AVATAR_ID_ATTRIBUTE = "USER_AVATAR_ID";
|
||||
|
@ -49,9 +46,9 @@ public class ScopeHelper {
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public static final String ROOT_ORG = "rootorganization";
|
||||
public static final String ROOT_VO = "rootVO";
|
||||
|
||||
public static final String CURR_ORG = "CURR_RE_NAME";
|
||||
public static final String CURR_RESEARCH_ENV = "CURR_RE_NAME";
|
||||
|
||||
public static final String MAIL = "notificationSenderEmail";
|
||||
|
||||
|
@ -72,30 +69,25 @@ public class ScopeHelper {
|
|||
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
|
||||
request.getPortletSession().setAttribute(WebKeys.THEME_DISPLAY, themeDisplay, PortletSession.APPLICATION_SCOPE);
|
||||
User user = null;
|
||||
Group currentGroup = null;
|
||||
Organization curOrg = null;
|
||||
|
||||
GCubeGroup currentGroup = null;
|
||||
try {
|
||||
user = UserLocalServiceUtil.getUser(userid);
|
||||
|
||||
currentGroup = GroupLocalServiceUtil.getGroup(themeDisplay.getLayout().getGroup().getGroupId());
|
||||
|
||||
// the group MUST BE an Organization
|
||||
if (currentGroup.isOrganization()) {
|
||||
long organizationId = currentGroup.getClassPK();
|
||||
curOrg = OrganizationLocalServiceUtil.getOrganization(organizationId);
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
long groupId = themeDisplay.getLayout().getGroup().getGroupId();
|
||||
currentGroup = gm.getGroup(groupId);
|
||||
|
||||
if (curOrg.isRoot()) {
|
||||
scopeToSet = "/"+curOrg.getName();
|
||||
} else if (isVO(curOrg)) {
|
||||
scopeToSet = "/"+curOrg.getParentOrganization().getName()+"/"+curOrg.getName();
|
||||
} else { //is a VRE
|
||||
Organization vo = curOrg.getParentOrganization();
|
||||
scopeToSet = "/"+vo.getParentOrganization().getName()+"/"+vo.getName()+"/"+curOrg.getName();
|
||||
boolean isInfrastructureScope = false;
|
||||
if (gm.isRootVO(groupId)) {
|
||||
scopeToSet = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
||||
}
|
||||
} else { //
|
||||
else if (gm.isVO(groupId) || gm.isVRE(groupId)) {
|
||||
scopeToSet = gm.getInfrastructureScope(groupId);
|
||||
isInfrastructureScope = true;
|
||||
} else {
|
||||
scopeToSet = "PORTAL";
|
||||
_log.info("Not an organization, scopeToSet set to PORTAL");
|
||||
_log.info("Not a VO or VRE, scopeToSet set to PORTAL");
|
||||
}
|
||||
|
||||
|
||||
|
@ -108,18 +100,17 @@ public class ScopeHelper {
|
|||
|
||||
|
||||
request.getPortletSession().setAttribute(username_attr, username, PortletSession.APPLICATION_SCOPE);
|
||||
request.getPortletSession().setAttribute(CURR_ORG, curOrg, PortletSession.APPLICATION_SCOPE);
|
||||
request.getPortletSession().setAttribute(CURR_RESEARCH_ENV, currentGroup, PortletSession.APPLICATION_SCOPE);
|
||||
|
||||
|
||||
if (curOrg != null) {
|
||||
SessionManager.getInstance().getASLSession(sessionID, username).setGroupModelInfos(curOrg.getName(), curOrg.getOrganizationId());
|
||||
if (isInfrastructureScope) {
|
||||
SessionManager.getInstance().getASLSession(sessionID, username).setGroupModelInfos(currentGroup.getGroupName(), groupId);
|
||||
SessionManager.getInstance().getASLSession(sessionID, username).setScope(scopeToSet);
|
||||
_log.info("CONTEXT INITIALIZED CORRECTLY SCOPE: " + scopeToSet);
|
||||
}
|
||||
else {
|
||||
String rootVO = getRootConfigFromGCore();
|
||||
_log.info("CONTEXT INITIALIZED CORRECTLY OUTSIDE VREs, setting rootvo as scope: " + rootVO);
|
||||
scopeToSet = "/"+rootVO;
|
||||
scopeToSet = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
||||
_log.info("CONTEXT INITIALIZED CORRECTLY OUTSIDE VREs, set rootvo as scope: " + scopeToSet);
|
||||
SessionManager.getInstance().getASLSession(sessionID, username).setScope(scopeToSet);
|
||||
}
|
||||
//add the social information needed by apps
|
||||
|
@ -134,7 +125,10 @@ public class ScopeHelper {
|
|||
SessionManager.getInstance().getASLSession(sessionID, username).setUserGender(isMale? GenderType.MALE : GenderType.FEMALE);
|
||||
|
||||
setAuthorizationToken(SessionManager.getInstance().getASLSession(sessionID, username));
|
||||
|
||||
} catch (UserManagementSystemException e) {
|
||||
e.printStackTrace();
|
||||
} catch (GroupRetrievalFault e) {
|
||||
e.printStackTrace();
|
||||
} catch (PortalException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SystemException e) {
|
||||
|
@ -146,24 +140,24 @@ public class ScopeHelper {
|
|||
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");
|
||||
session.setSecurityToken(null);
|
||||
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);
|
||||
//TODO:
|
||||
// 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");
|
||||
// session.setSecurityToken(null);
|
||||
// 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
|
||||
|
@ -174,7 +168,7 @@ public class ScopeHelper {
|
|||
String toReturn = "";
|
||||
|
||||
try {
|
||||
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties";
|
||||
String propertyfile = SiteManagerUtil.getTomcatFolder()+"conf/gcube-data.properties";
|
||||
File propsFile = new File(propertyfile);
|
||||
FileInputStream fis = new FileInputStream(propsFile);
|
||||
props.load( fis);
|
||||
|
@ -193,19 +187,6 @@ public class ScopeHelper {
|
|||
}
|
||||
return toReturn;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param currentGroup
|
||||
* @return true id the organization is a VO
|
||||
* @throws SystemException
|
||||
* @throws PortalException
|
||||
* @throws SystemException .
|
||||
* @throws PortalException .
|
||||
*/
|
||||
private static boolean isVO(Organization currentOrg) throws PortalException, SystemException {
|
||||
return (currentOrg.getParentOrganization().getParentOrganization() == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the infrastructure name
|
||||
*/
|
||||
|
@ -221,10 +202,16 @@ public class ScopeHelper {
|
|||
String toReturn = "";
|
||||
|
||||
try {
|
||||
Role adminRole = RoleLocalServiceUtil.getRole(OrganizationsUtil.getCompany().getCompanyId(),"Administrator");
|
||||
Role adminRole = RoleLocalServiceUtil.getRole(SiteManagerUtil.getCompany().getCompanyId(),"Administrator");
|
||||
List<User> adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());
|
||||
if (adminUsers != null && adminUsers.size() > 0)
|
||||
if (adminUsers != null && adminUsers.size() > 0) {
|
||||
for (User user : adminUsers) {
|
||||
if (user.isActive()) {
|
||||
toReturn = adminUsers.get(0).getScreenName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
_log.warn("No users with Administrator Role in this portal!");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue