updated web xml to servlet spec 2.4

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/gcube-loggedin@124969 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-03-11 15:36:08 +00:00
parent 2027646261
commit 50562130a9
8 changed files with 110 additions and 156 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/gcube-loggedin-2.7.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/gcube-loggedin-3.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
@ -31,5 +31,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/gcube-loggedin-2.7.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/gcube-loggedin-3.0.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -3,10 +3,7 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<dependent-module archiveName="gcube-widgets-1.9.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="session-checker-0.4.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/session-checker/session-checker">
<dependent-module archiveName="session-checker-0.5.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/session-checker/session-checker">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>

44
pom.xml
View File

@ -13,9 +13,9 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-loggedin</artifactId>
<packaging>war</packaging>
<version>2.7.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<name>gCube Loggedin Portlet</name>
<name>gCube Environment Home Portlet</name>
<description>
gCube Loggedin.
</description>
@ -32,7 +32,7 @@
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<liferay.version>6.2.5</liferay.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
@ -76,11 +76,11 @@
<dependency>
<groupId>com.github.gwtbootstrap</groupId>
<artifactId>gwt-bootstrap</artifactId>
<version>2.3.2.0</version>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -98,11 +98,6 @@
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-jcr</artifactId>
@ -113,6 +108,12 @@
<artifactId>home-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
@ -122,6 +123,25 @@
<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>
@ -129,6 +149,12 @@
<artifactId>portlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>

View File

@ -13,8 +13,6 @@ public interface LoggedinService extends RemoteService {
VObject getSelectedRE(String portalURL);
String getDefaultCommunityURL();
String removeUserFromVRE();
}

View File

@ -12,9 +12,5 @@ public interface LoggedinServiceAsync {
void getSelectedRE(String portalURL, AsyncCallback<VObject> callback);
void getDefaultCommunityURL(AsyncCallback<String> callback);
void removeUserFromVRE(AsyncCallback<String> callback);
}

View File

@ -86,14 +86,7 @@ public class AboutView extends Composite {
@UiHandler("backButton")
void onClick(ClickEvent e) {
loggedinService.getDefaultCommunityURL(new AsyncCallback<String>() {
public void onSuccess(String url) {
Window.open(url, "_self", "");
}
public void onFailure(Throwable arg0) {
Window.alert("We're sorry we couldn't reach the server, try again later ... " + arg0.getMessage());
}
});
}
@UiHandler("leaveButton")

View File

@ -6,18 +6,19 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.custom.communitymanager.SiteManagerUtil;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.user.gcubeloggedin.client.LoggedinService;
import org.gcube.portlets.user.gcubeloggedin.shared.VObject;
@ -27,10 +28,11 @@ import org.gcube.portlets.user.gcubewidgets.server.ScopeServiceImpl;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.RoleModel;
import org.gcube.vomanagement.usermanagement.model.UserModel;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -38,11 +40,13 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.kernel.bean.BeanLocatorException;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.servlet.ImageServletTokenUtil;
import com.liferay.portal.kernel.management.PortalManager;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.Organization;
import com.liferay.portal.model.RoleModel;
import com.liferay.portal.model.User;
import com.liferay.portal.model.UserModel;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
import com.liferay.portal.security.permission.PermissionThreadLocal;
@ -107,18 +111,18 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
"", "", "", UserBelongingClient.BELONGING, false, true);
}
_log.trace("getting Selected Research Environment");
Organization currOrg = null;
try {
List<Group> groups = GroupLocalServiceUtil.getGroups(0, GroupLocalServiceUtil.getGroupsCount());
for (Group g : groups) {
if (g.isOrganization() || g.isCommunity())
if (g.getFriendlyURL().compareTo(friendlyURL) == 0) {
long organizationId = g.getClassPK();
currOrg = OrganizationLocalServiceUtil.getOrganization(organizationId);
String scopeToSet = ScopeServiceImpl.buildScope(g);
getASLSession().setScope(scopeToSet);
_log.info("GOT Selected Research Environment: " + scopeToSet);
}
GroupManager gm = new LiferayGroupManager();
GCubeGroup currSite = null;
try {
List<GCubeGroup> groups = gm.listGroups();
for (GCubeGroup g : groups) {
if (g.getFriendlyURL().compareTo(friendlyURL) == 0) {
long groupId = g.getGroupId();
String scopeToSet = gm.getInfrastructureScope(groupId);
getASLSession().setScope(scopeToSet);
_log.info("GOT Selected Research Environment: " + scopeToSet);
currSite = g;
}
}
} catch (Exception e) {
e.printStackTrace();
@ -127,42 +131,48 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
/**
* set the current ORG bean in session
*/
aslSession.setAttribute(ScopeHelper.CURR_ORG, currOrg);
aslSession.setAttribute(ScopeHelper.CURR_ORG, currSite);
aslSession.setGroupModelInfos(currOrg.getName(), currOrg.getOrganizationId());
aslSession.setGroupModelInfos(currSite.getGroupName(), currSite.getGroupId());
_log.trace("CURRENT ORG SET IN SESSION: " + currOrg.getName());
_log.trace("CURRENT ORG SET IN SESSION: " + currSite.getGroupName());
String name = currOrg.getName();
long logoId = currOrg.getLogoId();
ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY);
String logoURL = themeDisplay.getPathImage()+"/organization_logo?img_id="+ logoId +"&t" + ImageServletTokenUtil.getToken(logoId);
String name = currSite.getGroupName();
String logoURL = "/image/layout_set_logo?img_id="+currSite.getLogoId();
String desc = "";
//set the description for the vre
if (currOrg.getComments() != null)
desc = currOrg.getComments();
VREClient vre = new VREClient(name, "", desc, logoURL, "", UserBelongingClient.BELONGING, isEnabled(username, currOrg, MANDATORY_GROUP), isEnabled(username, currOrg, REQUEST_BASED_GROUP));
if (currSite.getDescription() != null)
desc = currSite.getDescription();
Group currGroup = null;
try {
currGroup = GroupLocalServiceUtil.getGroup(currSite.getGroupId());
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
VREClient vre = new VREClient(name, "", desc, logoURL, "", UserBelongingClient.BELONGING, isEnabled(username, currGroup, MANDATORY_GROUP), isEnabled(username, currGroup, REQUEST_BASED_GROUP));
return vre;
}
private Boolean isEnabled(String username, Organization currOrg, String attrToCheck) {
private Boolean isEnabled(String username, Group currOrg, String attrToCheck) {
Boolean isEnabled = false;
if (username.compareTo("test.user") == 0) {
_log.warn("Found test.user maybe you are in dev mode, returning ... ");
return true;
}
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);
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);
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);
@ -174,10 +184,10 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
}
_log.trace("Setting Thread Permission back to regular");
permissionChecker = PermissionCheckerFactoryUtil.create(currentUser, false);
permissionChecker = PermissionCheckerFactoryUtil.create(currentUser);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
_log.trace("Setting Permission ok! returning ...");
System.out.println(" returning *********** isEnabled=" + isEnabled);
_log.debug(" returning *********** isEnabled=" + isEnabled);
return isEnabled;
} catch (BeanLocatorException ex) {
ex.printStackTrace();
@ -194,17 +204,17 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
* @param username
* @param attribute2Set
*/
private void setOrgCustomAttribute(String username, Organization currOrg, String attribute2Set) {
private void setOrgCustomAttribute(String username, Group currGroup, String attribute2Set) {
User currUser = null;
if (username.compareTo("test.user") == 0) {
_log.warn("Found Test User, returning ... ");
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);
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
_log.trace("Setting Permission ok!");
@ -212,15 +222,15 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
//add the custom attrs
currUser = UserLocalServiceUtil.getUserByScreenName(companyId, username);
if (! currOrg.getExpandoBridge().hasAttribute(attribute2Set))
currOrg.getExpandoBridge().addAttribute(attribute2Set);
if (! currGroup.getExpandoBridge().hasAttribute(attribute2Set))
currGroup.getExpandoBridge().addAttribute(attribute2Set);
currOrg.getExpandoBridge().setAttribute(attribute2Set, "true");
currGroup.getExpandoBridge().setAttribute(attribute2Set, "true");
_log.trace("setAttribute true");
_log.trace("Setting Thread Permission back to regular");
permissionChecker = PermissionCheckerFactoryUtil.create(currUser, false);
permissionChecker = PermissionCheckerFactoryUtil.create(currUser);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
}
catch (Exception e) {
@ -228,49 +238,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
}
}
/**
* The Default Community is a community where all portal user belong to
* @return the default community URL
* @throws SystemException
* @throws PortalException
*/
public String getDefaultCommunityURL() {
//get the portles to look for from the property file
Properties props = new Properties();
String comName = "";
try {
String propertyfile = this.getServletContext().getRealPath("")+"/config/resources.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis);
comName = props.getProperty("defaultcommunity");
}
//catch exception in case properties file does not exist
catch(IOException e) {
_log.error("/config/resources.properties not found, Returning \"Data e-Infrastructure gateway\" as default Community");
}
String toReturn = "";
_log.trace("Default Community Read from config file: " + comName);
Group myPlace = null;
try {
myPlace = GroupLocalServiceUtil.getGroup(OrganizationsUtil.getCompany().getCompanyId(), comName);
if(myPlace.isCommunity()) {
ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY);
toReturn = myPlace.getPathFriendlyURL(true, themeDisplay) + myPlace.getFriendlyURL();
}
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
toReturn = getPortalBasicUrl()+toReturn;
_log.trace("RETURNING Default Community URL: " + toReturn);
return toReturn;
}
/**
*
@ -306,8 +274,8 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
try {
userM.dismissUserFromGroup(getCurrentGroupID(), userM.getUserId(username));
removeUserFromHLGroup(username, getASLSession().getScope());
sendUserUnregisteredNotification(username, getASLSession().getScope(), getPortalBasicUrl(), readGatewayName());
return getDefaultCommunityURL();
sendUserUnregisteredNotification(username, getASLSession().getScope(), getPortalBasicUrl(), PortalContext.getConfiguration().getGatewayName());
return "/";
} catch (Exception e) {
e.printStackTrace();
return null;
@ -320,7 +288,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
* @return the current group ID or null if an exception is thrown
* @throws Exception
*/
private String getCurrentGroupID(){
private long getCurrentGroupID(){
ASLSession session = getASLSession();
_log.debug("The current group NAME is --> " + session.getGroupName());
try {
@ -333,7 +301,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
} catch (Exception e) {
e.printStackTrace();
}
return null;
return -1;
}
private void removeUserFromHLGroup(String username, String group) {
@ -350,14 +318,14 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
protected static ArrayList<String> getAdministratorsEmails(String scope) {
LiferayUserManager userManager = new LiferayUserManager();
LiferayGroupManager groupManager = new LiferayGroupManager();
String groupId = null;
long groupId = -1;
try {
List<org.gcube.vomanagement.usermanagement.model.GroupModel> allGroups = groupManager.listGroups();
List<GCubeGroup> allGroups = groupManager.listGroups();
_log.debug("Number of groups retrieved: " + allGroups.size());
for (int i = 0; i < allGroups.size(); i++) {
String grId = allGroups.get(i).getGroupId();
long grId = allGroups.get(i).getGroupId();
String groupScope = groupManager.getScope(grId);
System.out.println("Comparing: " + groupScope + " " + scope);
_log.debug("Comparing: " + groupScope + " " + scope);
if (groupScope.equals(scope)) {
groupId = allGroups.get(i).getGroupId();
break;
@ -366,16 +334,16 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
} catch (Exception e) {
e.printStackTrace();
}
HashMap<UserModel, List<RoleModel>> usersAndRoles = null;
Map<GCubeUser, List<GCubeRole>> usersAndRoles = null;
try {
usersAndRoles = userManager.listUsersAndRolesByGroup(groupId);
} catch (Exception e) {
e.printStackTrace();
}
Set<UserModel> users = usersAndRoles.keySet();
Set<GCubeUser> users = usersAndRoles.keySet();
ArrayList<String> adminEmailsList = new ArrayList<String>();
for (UserModel usr:users) {
List<RoleModel> roles = usersAndRoles.get(usr);
for (GCubeUser usr:users) {
List<GCubeRole> roles = usersAndRoles.get(usr);
for (int i = 0; i < roles.size(); i++) {
if (roles.get(i).getRoleName().equals("VO-Admin") || roles.get(i).getRoleName().equals("VRE-Manager")) {
adminEmailsList.add(usr.getEmail());
@ -394,10 +362,10 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
*/
public static void sendUserUnregisteredNotification(String username, String scope, String portalbasicurl, String gatewayName) {
ArrayList<String> adminEmails = getAdministratorsEmails(scope);
User currUser = null;
UserManager um = new LiferayUserManager();
GCubeUser currUser = null;
try {
currUser = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username);
currUser = um.getUserByUsername(username);
} catch (Exception e) {
}
@ -415,7 +383,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
body.append("<br />");
body.append("<b>Username: </b>" + username);
body.append("<br />");
body.append("<b>e-mail: </b>" + currUser.getEmailAddress());
body.append("<b>e-mail: </b>" + currUser.getEmail());
body.append("</p>");
body.append("<p>");
body.append("WARNING / LEGAL TEXT: This message is intended only for the use of the individual or entity to which it is addressed and may contain"+
@ -433,24 +401,4 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
}
private String readGatewayName() {
//get the portles to look for from the property file
Properties props = new Properties();
String gatewayLabel = "gCube Gateway";
try {
String propertyfile = System.getenv("CATALINA_HOME")+"/conf/gcube-data.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis);
//set the gateway label in the session
gatewayLabel = props.getProperty("portalinstancename");
}
//catch exception in case properties file does not exist
catch(IOException e) {
_log.warn("$CATALINA_HOME/conf/gcube-data.properties not found, Returning gateway name: " + gatewayLabel);
}
return gatewayLabel;
}
}

View File

@ -1,9 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- Servlets -->
<servlet>