2013-09-24 15:26:13 +02:00
package org.gcube.common.portal ;
2016-11-03 16:54:59 +01:00
import static org.gcube.common.authorization.client.Constants.authorizationService ;
2013-09-24 15:26:13 +02:00
import java.io.File ;
import java.io.FileInputStream ;
import java.io.IOException ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.Properties ;
2017-01-17 13:59:37 +01:00
import javax.portlet.RenderRequest ;
2016-03-23 18:33:58 +01:00
import javax.servlet.http.HttpServletRequest ;
2017-01-17 17:24:44 +01:00
import javax.servlet.http.HttpSession ;
2016-03-23 18:33:58 +01:00
2017-08-24 19:29:18 +02:00
import org.apache.commons.codec.binary.StringUtils ;
2016-11-17 11:15:23 +01:00
import org.gcube.common.authorization.client.exceptions.ObjectNotFound ;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider ;
2016-11-03 16:54:59 +01:00
import org.gcube.common.authorization.library.provider.UserInfo ;
import org.gcube.common.scope.api.ScopeProvider ;
2017-01-04 17:04:49 +01:00
import org.gcube.vomanagement.usermanagement.UserManager ;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException ;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault ;
2016-04-08 13:12:47 +02:00
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager ;
2016-11-03 16:54:59 +01:00
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager ;
2016-04-08 13:12:47 +02:00
import org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys ;
2016-11-03 16:54:59 +01:00
import org.gcube.vomanagement.usermanagement.model.Email ;
import org.gcube.vomanagement.usermanagement.model.GCubeUser ;
2013-09-24 15:26:13 +02:00
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
2016-03-24 12:19:28 +01:00
import com.liferay.portal.model.Group ;
import com.liferay.portal.model.VirtualHost ;
2016-04-08 15:02:24 +02:00
import com.liferay.portal.service.CompanyLocalServiceUtil ;
2016-03-24 12:19:28 +01:00
import com.liferay.portal.service.LayoutSetLocalServiceUtil ;
2016-11-03 16:54:59 +01:00
import com.liferay.portal.service.UserLocalServiceUtil ;
2016-03-24 12:19:28 +01:00
import com.liferay.portal.service.VirtualHostLocalServiceUtil ;
2016-04-08 15:02:24 +02:00
import com.liferay.portal.util.PortalUtil ;
2016-03-24 12:19:28 +01:00
2013-09-24 15:26:13 +02:00
/ * *
2017-01-04 17:04:49 +01:00
* < p >
2013-09-24 15:32:30 +02:00
* Clients can obtain the single instance of the { @link PortalContext } by invoking its static method { @link # getConfiguration ( ) } .
2013-09-24 15:26:13 +02:00
* The first invocation of the method triggers the initialisation of the instance .
*
2017-01-04 17:04:49 +01:00
* For documentation see the related < a href = " https://wiki.gcube-system.org/gcube/Portal_Context " > WIKI < / a >
* < / p >
2013-09-24 15:26:13 +02:00
* @author Massimiliano Assante ( ISTI - CNR )
*
* /
2013-09-24 15:32:30 +02:00
public class PortalContext {
private static final Logger _log = LoggerFactory . getLogger ( PortalContext . class ) ;
2016-11-04 18:42:16 +01:00
public static final String VRE_ID_ATTR_NAME = " gcube-vreid " ;
public static final String USER_ID_ATTR_NAME = " gcube-userId " ;
2016-11-03 16:54:59 +01:00
/ * *
* Scope separators used in linear syntax .
* /
protected static final String SCOPE_SEPARATOR = " / " ;
2017-08-24 19:29:18 +02:00
private static final String REGEX_ISNUMBER = " \\ d+ " ;
2016-11-03 16:54:59 +01:00
private final static String DEFAULT_ROLE = " OrganizationMember " ;
2017-05-15 18:44:22 +02:00
public static final String CONFIGURATION_FOLDER = " conf " ;
public static final String INFRA_PROPERTY_FILENAME = " infrastructure.properties " ;
2016-11-03 16:54:59 +01:00
private static final String GCUBE_DEV__CONTEXT_PROPERTY_FILENAME = " gcube-dev-context.properties " ;
private static final String DEV_USERNAME_ATTR = " user.username " ;
private static final String DEV_USER_NAME_ATTR = " user.name " ;
private static final String DEV_USER_LASTNAME_ATTR = " user.lastname " ;
private static final String DEV_USER_EMAIL_ATTR = " user.email " ;
2016-11-10 15:36:11 +01:00
private static final String DEV_SCOPE_ATTR = " development.context " ;
private static final String DEV_GROUP_NAME_ATTR = " development.groupname " ;
private static final String DEV_GROUP_ID_ATTR = " development.groupid " ;
2016-11-03 16:54:59 +01:00
private static final String DEV_TOKEN_ATTR = " user.token " ;
2016-04-08 13:12:47 +02:00
private static final String DEFAULT_INFRA_NAME = " gcube " ;
private static final String DEFAULT_VO_NAME = " devsec " ;
private static final String DEFAULT_GATEWAY_NAME = " D4science Gateway " ;
private static final String DEFAULT_GATEWAY_EMAIL = " do-not-reply@d4science.org " ;
2016-04-21 14:11:30 +02:00
2013-09-30 15:19:28 +02:00
private static PortalContext singleton = new PortalContext ( ) ;
2013-09-24 15:26:13 +02:00
2017-01-04 17:04:49 +01:00
private UserManager userManager ;
2017-01-12 11:52:20 +01:00
2013-09-24 15:26:13 +02:00
private String infra ;
private String vos ;
2013-09-24 15:32:30 +02:00
private PortalContext ( ) {
2013-09-24 15:26:13 +02:00
initialize ( ) ;
}
/ * *
*
* @return the instance
* /
2013-09-24 15:32:30 +02:00
public synchronized static PortalContext getConfiguration ( ) {
return singleton = = null ? new PortalContext ( ) : singleton ;
2013-09-24 15:26:13 +02:00
}
2016-04-21 14:11:30 +02:00
2013-09-24 15:26:13 +02:00
private void initialize ( ) {
Properties props = new Properties ( ) ;
try {
2016-11-03 16:54:59 +01:00
StringBuilder sb = new StringBuilder ( getCatalinaHome ( ) ) ;
sb . append ( File . separator )
. append ( CONFIGURATION_FOLDER )
. append ( File . separator )
. append ( INFRA_PROPERTY_FILENAME ) ;
String propertyfile = sb . toString ( ) ;
2013-09-24 15:26:13 +02:00
File propsFile = new File ( propertyfile ) ;
FileInputStream fis = new FileInputStream ( propsFile ) ;
props . load ( fis ) ;
2016-03-17 15:19:05 +01:00
infra = props . getProperty ( GCubePortalConstants . INFRASTRUCTURE_NAME ) ;
vos = props . getProperty ( GCubePortalConstants . SCOPES ) ;
2017-01-04 17:04:49 +01:00
userManager = new LiferayUserManager ( ) ;
2013-09-24 15:26:13 +02:00
}
catch ( IOException e ) {
2016-04-08 13:12:47 +02:00
infra = DEFAULT_INFRA_NAME ;
vos = DEFAULT_VO_NAME ;
2017-01-17 13:59:37 +01:00
userManager = new LiferayUserManager ( ) ;
2016-04-08 13:12:47 +02:00
_log . error ( " infrastructure.properties file not found under $CATALINA_HOME/conf/ dir, setting default infrastructure Name " + infra + " and VO Name " + vos ) ;
2013-09-24 15:26:13 +02:00
}
2016-11-03 16:54:59 +01:00
2013-09-24 15:32:30 +02:00
_log . info ( " PortalContext configurator correctly initialized on " + infra ) ;
2013-09-24 15:26:13 +02:00
}
2016-11-03 16:54:59 +01:00
2013-09-24 17:09:28 +02:00
/ * *
*
* @return the infrastructure name in which your client runs
* /
2013-09-24 15:26:13 +02:00
public String getInfrastructureName ( ) {
return this . infra ;
}
2013-09-24 17:09:28 +02:00
/ * *
*
* @return the value of the scopes as it is in the property file ( a string with comma separated vales )
* /
public String getVOsAsString ( ) {
return this . vos ;
}
2016-11-03 16:54:59 +01:00
/ * *
2017-01-04 17:04:49 +01:00
* < p >
* Please note that this method works with AJAX calls only ( i . e . XMLHttpRequest to exchange data with a server behind the scenes ) .
2017-01-17 17:27:44 +01:00
* If you use standard http servlet GET or POST to exchange data with a server , you must call the method PortalContext # setUserInSession in your portlet doView method .
2016-11-03 16:54:59 +01:00
*
2017-01-04 17:04:49 +01:00
* < / p >
*
* @param httpServletRequest the { @link HttpServletRequest } object
2017-01-17 17:24:44 +01:00
* @return the current user , or < code > null < / code > if a current user could not be found or session expired
2017-01-04 17:04:49 +01:00
* @see { @link GCubeUser }
2016-11-03 16:54:59 +01:00
* /
public GCubeUser getCurrentUser ( HttpServletRequest httpServletRequest ) {
2017-01-04 17:04:49 +01:00
String userIdNo = httpServletRequest . getHeader ( USER_ID_ATTR_NAME ) ;
2017-01-17 13:59:37 +01:00
long userId = - 1 ;
2017-08-24 19:29:18 +02:00
if ( userIdNo ! = null & & userIdNo . matches ( REGEX_ISNUMBER ) ) {
2016-11-03 16:54:59 +01:00
try {
2017-01-17 13:59:37 +01:00
_log . debug ( " The userIdNo is " + userIdNo ) ;
2017-01-04 17:04:49 +01:00
userId = Long . parseLong ( userIdNo ) ;
return userManager . getUserById ( userId ) ;
} catch ( NumberFormatException e ) {
_log . error ( " The userId is not a number -> " + userId ) ;
} catch ( Exception e ) {
2017-01-17 13:59:37 +01:00
_log . error ( " Could not read the current userid from header param, either session expired or user not logged in, exception: " + e . getMessage ( ) ) ;
2016-11-03 16:54:59 +01:00
}
} else {
2017-01-04 17:04:49 +01:00
if ( ! isWithinPortal ( ) ) {
2016-11-03 16:54:59 +01:00
GCubeUser toReturn = readUserFromPropertyFile ( ) ;
_log . debug ( " getCurrentUser devMode into IDE detected, returning testing user: " + toReturn . toString ( ) ) ;
return toReturn ;
2017-01-17 13:59:37 +01:00
} else { //must be a custom servlet
try {
2017-01-17 17:24:44 +01:00
HttpSession session = httpServletRequest . getSession ( false ) ;
userId = ( long ) session . getAttribute ( USER_ID_ATTR_NAME ) ;
_log . debug ( " read the current userid from the http session userId: " + userId + " sessionid= " + session . getId ( ) ) ;
2017-01-17 13:59:37 +01:00
return userManager . getUserById ( userId ) ;
} catch ( Exception e ) {
_log . error ( " Could not read the current userid from the http session, either session expired or user not logged in, exception: " + e . getMessage ( ) ) ;
2017-01-17 17:24:44 +01:00
return null ;
2017-01-17 13:59:37 +01:00
}
2016-11-03 16:54:59 +01:00
}
}
return null ;
}
2017-01-17 13:59:37 +01:00
/ * *
* < p >
* This method sets the current userid in the session so that it is possible to get the current user in custom servlets of the same WAR .
* Must be added in Portlet ' s doView ( ) method before dispatching the request .
* < / p >
*
* @param request the portlet { @link RenderRequest } object
* /
public static void setUserInSession ( RenderRequest request ) {
2017-01-17 17:24:44 +01:00
long userId = Long . parseLong ( request . getRemoteUser ( ) ) ;
HttpServletRequest httpServletRequest = PortalUtil . getHttpServletRequest ( request ) ;
HttpSession session = httpServletRequest . getSession ( ) ;
_log . debug ( " HttpSession#setUserInSession, set userId: " + userId + " sessionid= " + session . getId ( ) ) ;
session . setAttribute ( USER_ID_ATTR_NAME , userId ) ;
2017-01-17 13:59:37 +01:00
}
2016-11-03 16:54:59 +01:00
/ * *
2016-11-14 17:10:36 +01:00
* @param scopeGroupId the liferay groupid number ( as String ) of the VRE / VO
2016-11-10 15:36:11 +01:00
* @return the scope ( context )
2016-11-03 16:54:59 +01:00
* /
2016-11-14 17:10:36 +01:00
public String getCurrentScope ( String scopeGroupId ) {
2017-08-24 19:29:18 +02:00
if ( scopeGroupId ! = null & & scopeGroupId . matches ( REGEX_ISNUMBER ) ) {
2016-11-03 16:54:59 +01:00
long groupId = - 1 ;
try {
2016-11-14 17:10:36 +01:00
groupId = Long . parseLong ( scopeGroupId ) ;
2016-11-03 16:54:59 +01:00
LiferayGroupManager gm = new LiferayGroupManager ( ) ;
if ( gm . isRootVO ( groupId ) ) {
return SCOPE_SEPARATOR + getInfrastructureName ( ) ;
} else
return new LiferayGroupManager ( ) . getInfrastructureScope ( groupId ) ;
} catch ( NumberFormatException e ) {
_log . error ( " The groupId is not a number -> " + groupId ) ;
} catch ( Exception e ) {
_log . error ( " This groupId does not belong to any group in this portal -> " + groupId ) ;
}
} else {
2016-11-10 15:36:11 +01:00
if ( ! isWithinPortal ( ) ) {
String toReturn = readContextPropertyFile ( ) ;
2016-11-03 16:54:59 +01:00
_log . debug ( " getCurrentScope devMode into IDE detected, returning scope: " + toReturn . toString ( ) ) ;
_log . debug ( " The PortalBeanLocatorUtil stacktrace (java.lang.Exception) is acceptable in dev " ) ;
return toReturn ;
}
}
return null ;
}
2016-11-14 17:10:36 +01:00
/ * *
2017-01-04 17:04:49 +01:00
* < p >
* Please note that this method works with AJAX calls only ( i . e . XMLHttpRequest to exchange data with a server behind the scenes ) .
* If you use standard http servlet GET or POST to exchange data with a server , you must you must handle the infrastructure context information differently .
* Please see the following page for further information @see < a href = " https://wiki.gcube-system.org/gcube/ClientContextLibrary " > ClientContextLibrary WIKI < / a >
* < / p >
2016-11-14 17:10:36 +01:00
*
2017-01-04 17:04:49 +01:00
* @param httpServletRequest the { @link HttpServletRequest } object
* @return the infrastructure context ( scope )
2016-11-14 17:10:36 +01:00
* /
public String getCurrentScope ( HttpServletRequest httpServletRequest ) {
String scopeGroupId = httpServletRequest . getHeader ( VRE_ID_ATTR_NAME ) ;
return getCurrentScope ( scopeGroupId ) ;
}
2016-11-10 15:36:11 +01:00
/ * *
2017-01-04 17:04:49 +01:00
* < p >
* Please note that this method works with AJAX calls only ( i . e . XMLHttpRequest to exchange data with a server behind the scenes ) .
* If you use standard http servlet GET or POST to exchange data with a server , you must you must handle the infrastructure context information differently .
* Please see the following page for further information @see < a href = " https://wiki.gcube-system.org/gcube/ClientContextLibrary " > ClientContextLibrary WIKI < / a >
* < / p >
2016-11-10 15:36:11 +01:00
*
2017-01-04 17:04:49 +01:00
* @param httpServletRequest the { @link HttpServletRequest } object
* @return the current group name ( e . g . devVRE , BioDiversityLab , RStudioLab etc . )
2016-11-10 15:36:11 +01:00
* /
public String getCurrentGroupName ( HttpServletRequest httpServletRequest ) {
String groupIdNo = httpServletRequest . getHeader ( VRE_ID_ATTR_NAME ) ;
2017-08-24 19:29:18 +02:00
if ( groupIdNo ! = null & & groupIdNo . matches ( REGEX_ISNUMBER ) ) {
2016-11-10 15:36:11 +01:00
long groupId = - 1 ;
try {
groupId = Long . parseLong ( groupIdNo ) ;
LiferayGroupManager gm = new LiferayGroupManager ( ) ;
return gm . getGroup ( groupId ) . getGroupName ( ) ;
} catch ( NumberFormatException e ) {
_log . error ( " The groupId is not a number -> " + groupId ) ;
} catch ( Exception e ) {
_log . error ( " This groupId does not belong to any group in this portal -> " + groupId ) ;
}
} else {
if ( ! isWithinPortal ( ) ) {
String toReturn = readGroupNamePropertyFile ( ) ;
_log . debug ( " getCurrentGroupName devMode into IDE detected, returning group name: " + toReturn . toString ( ) ) ;
_log . debug ( " The PortalBeanLocatorUtil stacktrace (java.lang.Exception) is acceptable in dev " ) ;
return toReturn ;
}
}
return null ;
}
/ * *
2017-01-04 17:04:49 +01:00
* < p >
* Please note that this method works with AJAX calls only ( i . e . XMLHttpRequest to exchange data with a server behind the scenes ) .
* If you use standard http servlet GET or POST to exchange data with a server , you must you must handle the infrastructure context information differently .
* Please see the following page for further information @see < a href = " https://wiki.gcube-system.org/gcube/ClientContextLibrary " > ClientContextLibrary WIKI < / a >
* < / p >
2016-11-10 15:36:11 +01:00
*
2017-01-04 17:04:49 +01:00
* @param httpServletRequest the { @link HttpServletRequest } object
* @return the current group identifier as long
2016-11-10 15:36:11 +01:00
* /
public long getCurrentGroupId ( HttpServletRequest httpServletRequest ) {
String groupIdNo = httpServletRequest . getHeader ( VRE_ID_ATTR_NAME ) ;
2017-08-24 19:29:18 +02:00
if ( groupIdNo ! = null & & groupIdNo . matches ( REGEX_ISNUMBER ) ) {
2016-11-10 15:36:11 +01:00
long groupId = - 1 ;
try {
groupId = Long . parseLong ( groupIdNo ) ;
return groupId ;
} catch ( NumberFormatException e ) {
_log . error ( " The groupId is not a number -> " + groupId ) ;
} catch ( Exception e ) {
_log . error ( " This groupId does not belong to any group in this portal -> " + groupId ) ;
}
} else {
if ( ! isWithinPortal ( ) ) {
long toReturn = readGroupIdPropertyFile ( ) ;
_log . debug ( " getCurrentGroup devMode into IDE detected, returning groupid = " + toReturn ) ;
_log . debug ( " The PortalBeanLocatorUtil stacktrace (java.lang.Exception) is acceptable in dev " ) ;
return toReturn ;
}
}
return - 1 ;
}
2016-11-03 16:54:59 +01:00
/ * *
2017-01-04 17:04:49 +01:00
* < p >
* Returns the gCube authorisation token for the given user
* < / p >
* @param scope infrastrucure context ( scope )
* @param userId the GCubeUser user identifier ( userId ) @see { @link GCubeUser }
* @return the Token for the user in the context , or < code > null < / code > if a token for this user could not be found
2016-11-03 16:54:59 +01:00
* /
2017-01-04 17:04:49 +01:00
public String getCurrentUserToken ( String scope , long userId ) {
if ( isWithinPortal ( ) ) {
2016-11-03 16:54:59 +01:00
try {
2017-01-04 17:04:49 +01:00
String username = userManager . getUserById ( userId ) . getUsername ( ) ;
return getCurrentUserToken ( scope , username ) ;
} catch ( UserManagementSystemException | UserRetrievalFault e ) {
2016-11-03 16:54:59 +01:00
e . printStackTrace ( ) ;
}
}
2017-01-04 17:04:49 +01:00
else {
String toReturn = readTokenPropertyFile ( ) ;
2017-08-24 19:29:18 +02:00
_log . debug ( " getCurrentToken devMode into IDE detected, returning token: " + toReturn . toString ( ) ) ;
2017-01-04 17:04:49 +01:00
_log . debug ( " The PortalBeanLocatorUtil stacktrace (java.lang.Exception) is acceptable in dev " ) ;
return toReturn ;
}
return null ;
2016-11-03 16:54:59 +01:00
}
2016-11-29 15:10:57 +01:00
/ * *
2017-01-04 17:04:49 +01:00
* < p >
* Returns the gCube authorisation token for the given user
* < / p >
* @param scope infrastrucure context ( scope )
* @param username the GCubeUser username @see { @link GCubeUser }
* @return the Token for the user in the context , or < code > null < / code > if a token for this user could not be found
2016-11-29 15:10:57 +01:00
* /
2017-01-04 17:04:49 +01:00
public String getCurrentUserToken ( String scope , String username ) {
2016-11-29 15:10:57 +01:00
String userToken = null ;
if ( isWithinPortal ( ) ) {
try {
ScopeProvider . instance . set ( scope ) ;
userToken = authorizationService ( ) . resolveTokenByUserAndContext ( username , scope ) ;
SecurityTokenProvider . instance . set ( userToken ) ;
}
catch ( ObjectNotFound ex ) {
userToken = generateAuthorizationToken ( username , scope ) ;
SecurityTokenProvider . instance . set ( userToken ) ;
_log . debug ( " generateAuthorizationToken OK for " + username + " in scope " + scope ) ;
}
catch ( Exception e ) {
_log . error ( " Error while trying to generate token for user " + username + " in scope " + scope ) ;
e . printStackTrace ( ) ;
return null ;
}
} else {
String toReturn = readTokenPropertyFile ( ) ;
2018-06-25 15:46:56 +02:00
_log . debug ( " getCurrentToken devMode into IDE detected, returning token: " + toReturn . toString ( ) ) ;
2016-11-29 15:10:57 +01:00
_log . debug ( " The PortalBeanLocatorUtil stacktrace (java.lang.Exception) is acceptable in dev " ) ;
return toReturn ;
}
return userToken ;
}
2016-12-22 14:19:22 +01:00
/ * *
2017-01-04 17:04:49 +01:00
* @deprecated please use getCurrentUserToken ( String scope , String username ) or getCurrentUserToken ( String scope , long userId )
* < p >
* Please note that this method works with AJAX calls only ( i . e . XMLHttpRequest to exchange data with a server behind the scenes ) .
* < / p >
*
* @param httpServletRequest the { @link HttpServletRequest } object
* @return the Token for the user in the context , or < code > null < / code > if a token for this user could not be found
2016-12-22 14:19:22 +01:00
* /
2017-01-04 17:04:49 +01:00
public String getCurrentUserToken ( HttpServletRequest httpServletRequest ) {
String groupIdNo = httpServletRequest . getHeader ( VRE_ID_ATTR_NAME ) ;
2016-12-22 14:19:22 +01:00
String userToken = null ;
2017-08-24 19:29:18 +02:00
if ( groupIdNo ! = null & & groupIdNo . matches ( REGEX_ISNUMBER ) ) {
2017-01-04 17:04:49 +01:00
String scope = getCurrentScope ( httpServletRequest ) ;
String username = getCurrentUser ( httpServletRequest ) . getUsername ( ) ;
2016-12-22 14:19:22 +01:00
try {
ScopeProvider . instance . set ( scope ) ;
userToken = authorizationService ( ) . resolveTokenByUserAndContext ( username , scope ) ;
SecurityTokenProvider . instance . set ( userToken ) ;
}
catch ( ObjectNotFound ex ) {
userToken = generateAuthorizationToken ( username , scope ) ;
SecurityTokenProvider . instance . set ( userToken ) ;
_log . debug ( " generateAuthorizationToken OK for " + username + " in scope " + scope ) ;
}
catch ( Exception e ) {
_log . error ( " Error while trying to generate token for user " + username + " in scope " + scope ) ;
e . printStackTrace ( ) ;
return null ;
}
} else {
2017-01-04 17:04:49 +01:00
if ( isWithinPortal ( ) ) {
_log . warn ( " It seems your app is running in Liferay but not context was set on this (HttpServletRequest) request " ) ;
} else {
String toReturn = readTokenPropertyFile ( ) ;
_log . debug ( " getCurrentToken devMode into IDE detected, returning scope: " + toReturn . toString ( ) ) ;
_log . debug ( " The PortalBeanLocatorUtil stacktrace (java.lang.Exception) is acceptable in dev " ) ;
return toReturn ;
}
2016-12-22 14:19:22 +01:00
}
return userToken ;
}
2016-11-03 16:54:59 +01:00
/ * *
*
* @param username
* @param scope
* @throws Exception
* /
2016-11-17 11:15:23 +01:00
private static String generateAuthorizationToken ( String username , String scope ) {
2016-11-03 16:54:59 +01:00
List < String > userRoles = new ArrayList < > ( ) ;
userRoles . add ( DEFAULT_ROLE ) ;
2016-11-17 11:15:23 +01:00
String token ;
try {
token = authorizationService ( ) . generateUserToken ( new UserInfo ( username , userRoles ) , scope ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return null ;
}
2016-11-03 16:54:59 +01:00
return token ;
}
/ * *
*
* @return true if you ' re running into the portal , false if in development
* /
private boolean isWithinPortal ( ) {
try {
UserLocalServiceUtil . getService ( ) ;
return true ;
}
catch ( Exception ex ) {
_log . trace ( " Development Mode ON " ) ;
return false ;
}
}
2013-09-24 17:09:28 +02:00
/ * *
*
* @return the value of the scopes
* /
2013-09-24 15:26:13 +02:00
public List < String > getVOs ( ) {
List < String > toReturn = new ArrayList < String > ( ) ;
if ( vos = = null | | vos . equals ( " " ) )
return toReturn ;
String [ ] split = vos . split ( " , " ) ;
for ( int i = 0 ; i < split . length ; i + + ) {
toReturn . add ( split [ i ] . trim ( ) ) ;
}
return toReturn ;
}
2015-07-08 12:09:20 +02:00
/ * *
2016-02-25 15:55:46 +01:00
*
2016-04-21 14:11:30 +02:00
* @deprecated use getConfiguration ( ) . getGatewayName ( ) method
* read the portal instance name from a property file and returns it
2015-07-08 12:09:20 +02:00
* /
2016-02-25 15:55:46 +01:00
@Deprecated
2015-07-08 12:09:20 +02:00
public static String getPortalInstanceName ( ) {
2016-02-25 15:55:46 +01:00
return getConfiguration ( ) . getGatewayName ( ) ;
}
2016-03-23 18:33:58 +01:00
/ * *
*
2017-01-04 17:04:49 +01:00
* @param httpServletRequest the { @link HttpServletRequest } object
2016-03-23 18:33:58 +01:00
* @return the gateway URL until the first slash , e . g . http ( s ) : //mynode.d4science.org:8080, if the URL uses standard http(s) port like 80 or 443 the port is not returned.
* /
public String getGatewayURL ( HttpServletRequest httpServletRequest ) {
String serverName = httpServletRequest . getServerName ( ) ;
String toReturn = ( httpServletRequest . isSecure ( ) ) ? " https:// " : " http:// " ;
//server name
toReturn + = serverName ;
//port
if ( httpServletRequest . isSecure ( ) )
toReturn + = ( httpServletRequest . getServerPort ( ) = = 443 ) ? " " : " : " + httpServletRequest . getServerPort ( ) ;
else
toReturn + = ( httpServletRequest . getServerPort ( ) = = 80 ) ? " " : " : " + httpServletRequest . getServerPort ( ) ;
2016-07-21 15:26:46 +02:00
2016-03-23 18:33:58 +01:00
return toReturn ;
}
2016-07-21 15:26:46 +02:00
/ * *
*
* @param serverName e . g . myportal . mydomain . org
* @param serverPort
* @param secure
* @return the gateway URL until the first slash , e . g . http ( s ) : //mynode.d4science.org:8080, if the URL uses standard http(s) port like 80 or 443 the port is not returned.
* /
public String getGatewayURL ( String serverName , int serverPort , boolean secure ) {
return PortalUtil . getPortalURL ( serverName , serverPort , secure ) ;
}
2016-04-08 15:02:24 +02:00
/ * *
* @deprecated use getGatewayURL ( HttpServletRequest httpServletRequest )
* @return the basic gateway url
* /
@Deprecated
public String getGatewayURL ( ) {
Long defaultCompanyId = PortalUtil . getDefaultCompanyId ( ) ;
try {
CompanyLocalServiceUtil . getCompany ( defaultCompanyId ) ;
2016-04-21 14:11:30 +02:00
return PortalUtil . getPortalURL ( CompanyLocalServiceUtil . getCompany ( defaultCompanyId ) . getVirtualHostname ( ) , 443 , true ) ;
2016-07-28 12:48:27 +02:00
} catch ( Exception e ) {
2016-04-08 15:02:24 +02:00
e . printStackTrace ( ) ;
2016-07-28 12:48:27 +02:00
}
2016-04-08 15:02:24 +02:00
return " " ;
}
2016-03-24 12:19:28 +01:00
/ * *
*
2017-01-04 17:04:49 +01:00
* @param httpServletRequest the { @link HttpServletRequest } object
2016-03-24 12:19:28 +01:00
* @return the landing page path of the current Site e . g . " /group/i-marine "
* /
2016-04-21 14:11:30 +02:00
public String getSiteLandingPagePath ( final HttpServletRequest request ) {
2016-11-03 16:54:59 +01:00
String sitePath = " " ;
2016-04-21 14:11:30 +02:00
Group site ;
try {
site = getSiteFromServletRequest ( request ) ;
if ( site . getPrivateLayoutsPageCount ( ) > 0 ) {
2016-07-21 15:26:46 +02:00
sitePath = getGroupFriendlyURL ( site ) ;
} else {
_log . debug ( site . getName ( ) + " site doesn't have any private page. Default landing page will be used " ) ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
return sitePath ;
}
/ * *
*
* @param serverName e . g . myportal . mydomain . org
* @return the landing page path of the current Site e . g . " /group/i-marine "
* /
public String getSiteLandingPagePath ( final String serverName ) {
2016-11-03 16:54:59 +01:00
String sitePath = " " ;
2016-07-21 15:26:46 +02:00
Group site ;
try {
site = getSiteFromServerName ( serverName ) ;
if ( site . getPrivateLayoutsPageCount ( ) > 0 ) {
sitePath = getGroupFriendlyURL ( site ) ;
2016-04-21 14:11:30 +02:00
} else {
_log . debug ( site . getName ( ) + " site doesn't have any private page. Default landing page will be used " ) ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
2016-04-08 13:12:47 +02:00
return sitePath ;
}
/ * *
*
2017-01-04 17:04:49 +01:00
* @param request the { @link HttpServletRequest } object
2016-04-08 13:12:47 +02:00
* @return the current Group instance based on the request
* /
2016-07-28 12:48:27 +02:00
private Group getSiteFromServletRequest ( final HttpServletRequest request ) throws Exception {
2016-03-24 12:19:28 +01:00
String serverName = request . getServerName ( ) ;
2016-07-21 15:26:46 +02:00
Group site = null ;
List < VirtualHost > vHosts = VirtualHostLocalServiceUtil . getVirtualHosts ( 0 , VirtualHostLocalServiceUtil . getVirtualHostsCount ( ) ) ;
for ( VirtualHost virtualHost : vHosts ) {
if ( virtualHost . getHostname ( ) . compareTo ( " localhost " ) ! = 0 & &
virtualHost . getLayoutSetId ( ) ! = 0 & &
virtualHost . getHostname ( ) . compareTo ( serverName ) = = 0 ) {
long layoutSetId = virtualHost . getLayoutSetId ( ) ;
site = LayoutSetLocalServiceUtil . getLayoutSet ( layoutSetId ) . getGroup ( ) ;
return site ;
}
}
_log . warn ( " serverName is " + serverName + " but i could not find any virtualHost associated to it " ) ;
return null ;
}
/ * *
*
* @param serverName e . g . myportal . mydomain . org
2016-11-03 16:54:59 +01:00
* @return the Liferay Group instance responding to the servename passed as parameter
2016-07-21 15:26:46 +02:00
* /
2016-07-28 12:48:27 +02:00
private Group getSiteFromServerName ( final String serverName ) throws Exception {
2016-07-21 15:26:46 +02:00
_log . debug ( " serverName passed is " + serverName ) ;
2016-03-24 12:19:28 +01:00
Group site = null ;
List < VirtualHost > vHosts = VirtualHostLocalServiceUtil . getVirtualHosts ( 0 , VirtualHostLocalServiceUtil . getVirtualHostsCount ( ) ) ;
for ( VirtualHost virtualHost : vHosts ) {
_log . debug ( " Found " + virtualHost . getHostname ( ) ) ;
if ( virtualHost . getHostname ( ) . compareTo ( " localhost " ) ! = 0 & &
virtualHost . getLayoutSetId ( ) ! = 0 & &
virtualHost . getHostname ( ) . compareTo ( serverName ) = = 0 ) {
long layoutSetId = virtualHost . getLayoutSetId ( ) ;
site = LayoutSetLocalServiceUtil . getLayoutSet ( layoutSetId ) . getGroup ( ) ;
_log . debug ( " Found match! Your site is " + site . getName ( ) ) ;
2016-04-08 13:12:47 +02:00
return site ;
2016-03-24 12:19:28 +01:00
}
}
2016-04-08 13:12:47 +02:00
return null ;
2016-03-24 12:19:28 +01:00
}
/ * *
* @param currentGroup
2017-01-04 17:04:49 +01:00
* @return Returns the friendly u r l of this group .
2016-07-21 15:26:46 +02:00
* /
2016-07-28 12:48:27 +02:00
private static String getGroupFriendlyURL ( final Group currentGroup ) throws Exception {
2016-07-21 15:26:46 +02:00
String friendlyURL = GCubePortalConstants . PREFIX_GROUP_URL ;
2016-11-03 16:54:59 +01:00
StringBuffer sb = new StringBuffer ( ) ;
2016-07-21 15:26:46 +02:00
sb . append ( friendlyURL ) . append ( currentGroup . getFriendlyURL ( ) ) ;
return sb . toString ( ) ;
}
/ * *
*
* @param serverName e . g . myportal . mydomain . org
* @return the current Site Name based on the servername ( e . g . i - marine . d4science . org )
* /
public String getGatewayName ( final String serverName ) {
String toReturn = DEFAULT_GATEWAY_NAME ;
try {
Group currSite = getSiteFromServerName ( serverName ) ;
toReturn = currSite . getName ( ) ;
} catch ( Exception e ) {
toReturn = DEFAULT_GATEWAY_NAME ;
_log . error ( " Could not read Site Custom Attr: " + CustomAttributeKeys . GATEWAY_SITE_NAME . getKeyName ( ) + " , returning default Gateway Name " + toReturn ) ;
}
return toReturn ;
}
2016-04-08 13:12:47 +02:00
/ * *
*
2017-01-04 17:04:49 +01:00
* @param httpServletRequest the { @link HttpServletRequest } object
2016-04-08 13:12:47 +02:00
* @return the current Site Name based on the request
* /
public String getGatewayName ( HttpServletRequest request ) {
String toReturn = DEFAULT_GATEWAY_NAME ;
try {
Group currSite = getSiteFromServletRequest ( request ) ;
2016-07-21 15:26:46 +02:00
toReturn = currSite . getName ( ) ;
2016-04-08 13:12:47 +02:00
} catch ( Exception e ) {
toReturn = DEFAULT_GATEWAY_NAME ;
_log . error ( " Could not read Site Custom Attr: " + CustomAttributeKeys . GATEWAY_SITE_NAME . getKeyName ( ) + " , returning default Gateway Name " + toReturn ) ;
}
return toReturn ;
}
2016-04-21 14:11:30 +02:00
2016-02-25 15:55:46 +01:00
/ * *
* read the infrastructure gateway name from a property file and returns it
2016-04-08 13:12:47 +02:00
* @deprecated use getGatewayName ( HttpServletRequest request )
2016-02-25 15:55:46 +01:00
* /
2016-04-08 13:12:47 +02:00
@Deprecated
2016-02-25 15:55:46 +01:00
public String getGatewayName ( ) {
2015-07-08 12:09:20 +02:00
//get the portles to look for from the property file
Properties props = new Properties ( ) ;
String toReturn = " " ;
2015-06-22 15:24:39 +02:00
2015-07-08 12:09:20 +02:00
try {
String propertyfile = getCatalinaHome ( ) + File . separator + " conf " + File . separator + " gcube-data.properties " ;
File propsFile = new File ( propertyfile ) ;
FileInputStream fis = new FileInputStream ( propsFile ) ;
props . load ( fis ) ;
2016-03-17 15:19:05 +01:00
toReturn = props . getProperty ( GCubePortalConstants . GATEWAY_NAME ) ;
2015-07-08 12:09:20 +02:00
}
//catch exception in case properties file does not exist
catch ( IOException e ) {
2016-04-08 13:12:47 +02:00
toReturn = DEFAULT_GATEWAY_NAME ;
2015-07-08 12:09:20 +02:00
_log . error ( " gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default Portal Name " + toReturn ) ;
return toReturn ;
}
_log . debug ( " Returning Gateway Name: " + toReturn ) ;
return toReturn ;
}
2016-04-08 13:12:47 +02:00
/ * *
*
2017-01-04 17:04:49 +01:00
* @param request the { @link HttpServletRequest } object
2016-04-08 13:12:47 +02:00
* @return the sender ( from ) email address for the current Site based on the request
* /
public String getSenderEmail ( HttpServletRequest request ) {
String toReturn = DEFAULT_GATEWAY_EMAIL ;
try {
Group currSite = getSiteFromServletRequest ( request ) ;
toReturn = ( String ) new LiferayGroupManager ( ) . readCustomAttr ( currSite . getGroupId ( ) , CustomAttributeKeys . GATEWAY_SITE_EMAIL_SENDER . getKeyName ( ) ) ;
} catch ( Exception e ) {
toReturn = DEFAULT_GATEWAY_EMAIL ;
_log . error ( " Could not read Site Custom Attr: " + CustomAttributeKeys . GATEWAY_SITE_EMAIL_SENDER . getKeyName ( ) + " , returning default Gateway Email Sender " + toReturn ) ;
}
return toReturn ;
}
2016-07-21 15:26:46 +02:00
/ * *
*
* @param serverName e . g . myportal . mydomain . org
* @return the sender ( from ) email address for the current Site based on the request
* /
public String getSenderEmail ( final String serverName ) {
String toReturn = DEFAULT_GATEWAY_EMAIL ;
try {
Group currSite = getSiteFromServerName ( serverName ) ;
toReturn = ( String ) new LiferayGroupManager ( ) . readCustomAttr ( currSite . getGroupId ( ) , CustomAttributeKeys . GATEWAY_SITE_EMAIL_SENDER . getKeyName ( ) ) ;
} catch ( Exception e ) {
toReturn = DEFAULT_GATEWAY_EMAIL ;
_log . error ( " Could not read Site Custom Attr: " + CustomAttributeKeys . GATEWAY_SITE_EMAIL_SENDER . getKeyName ( ) + " , returning default Gateway Email Sender " + toReturn ) ;
}
return toReturn ;
}
2016-11-03 16:54:59 +01:00
2017-01-31 18:51:49 +01:00
/ * *
* < p >
* read the portal application token valid in the root Virtual Organisation into a property file
* < / p >
* @return the portal application token valid in the root Virtual Organisation or < code > null < / code > if the token could not be found
* /
public static String getPortalApplicationToken ( ) {
//get the portles to look for from the property file
Properties props = new Properties ( ) ;
String toReturn = " " ;
try {
String propertyfile = getCatalinaHome ( ) + File . separator + " conf " + File . separator + " gcube-data.properties " ;
File propsFile = new File ( propertyfile ) ;
FileInputStream fis = new FileInputStream ( propsFile ) ;
props . load ( fis ) ;
toReturn = props . getProperty ( GCubePortalConstants . PORTAL_APPLICATION_TOKEN ) ;
}
//catch exception in case properties file does not exist
catch ( IOException e ) {
toReturn = null ;
_log . error ( " gcube-data.properties file or portal app token not found under $CATALINA_HOME/conf dir, please add the property and or a valid token: " + GCubePortalConstants . PORTAL_APPLICATION_TOKEN ) ;
return toReturn ;
}
return toReturn ;
}
/ * *
* < p >
* read the IC Proxy endpoint from a property file , IC Proxy is needed to query the Information System via REST
* e . g . http : //dev.d4science.org:8080/icproxy/gcube/service
* < / p >
* @return the IC Proxy endpoint or < code > null < / code > if the IC Proxy could not be found
* /
public static String getICProxyEndPoint ( ) {
//get the portles to look for from the property file
Properties props = new Properties ( ) ;
String toReturn = " " ;
try {
String propertyfile = getCatalinaHome ( ) + File . separator + " conf " + File . separator + " gcube-data.properties " ;
File propsFile = new File ( propertyfile ) ;
FileInputStream fis = new FileInputStream ( propsFile ) ;
props . load ( fis ) ;
toReturn = props . getProperty ( GCubePortalConstants . ICPROXY_ENDPOINT_URL ) ;
}
//catch exception in case properties file does not exist
catch ( IOException e ) {
toReturn = null ;
_log . error ( " gcube-data.properties file or portal app token not found under $CATALINA_HOME/conf dir, please add the property and or a valid token: " + GCubePortalConstants . PORTAL_APPLICATION_TOKEN ) ;
return toReturn ;
}
return toReturn ;
}
2016-11-03 16:54:59 +01:00
2015-06-22 15:24:39 +02:00
/ * *
2015-07-08 12:09:20 +02:00
* read the sender ( from ) email address for notifications name from a property file and returns it
2016-04-08 13:12:47 +02:00
* @deprecated use getSenderEmail ( HttpServletRequest request )
2015-06-22 15:24:39 +02:00
* /
2016-04-08 13:12:47 +02:00
@Deprecated
2015-06-22 15:48:38 +02:00
public String getSenderEmail ( ) {
2015-06-22 15:24:39 +02:00
//get the portles to look for from the property file
Properties props = new Properties ( ) ;
String toReturn = " " ;
try {
String propertyfile = getCatalinaHome ( ) + File . separator + " conf " + File . separator + " gcube-data.properties " ;
File propsFile = new File ( propertyfile ) ;
FileInputStream fis = new FileInputStream ( propsFile ) ;
props . load ( fis ) ;
2016-03-17 15:19:05 +01:00
toReturn = props . getProperty ( GCubePortalConstants . SENDER_EMAIL ) ;
2015-06-22 15:24:39 +02:00
}
//catch exception in case properties file does not exist
catch ( IOException e ) {
2016-04-08 13:12:47 +02:00
toReturn = DEFAULT_GATEWAY_EMAIL ;
2015-06-22 15:24:39 +02:00
_log . error ( " gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default Email " + toReturn ) ;
return toReturn ;
}
_log . debug ( " Returning SENDER_EMAIL: " + toReturn ) ;
return toReturn ;
}
2016-02-25 15:55:46 +01:00
/ * *
2016-11-03 16:54:59 +01:00
* for development purposes only
2016-02-25 15:55:46 +01:00
* /
2016-11-25 12:36:55 +01:00
protected static GCubeUser readUserFromPropertyFile ( ) {
2016-02-25 15:55:46 +01:00
Properties props = new Properties ( ) ;
2016-11-03 16:54:59 +01:00
try {
2016-11-14 17:10:36 +01:00
StringBuilder sb = new StringBuilder ( getGCubeDevHome ( ) ) ;
2016-11-03 16:54:59 +01:00
sb . append ( File . separator )
. append ( GCUBE_DEV__CONTEXT_PROPERTY_FILENAME ) ;
String propertyfile = sb . toString ( ) ;
File propsFile = new File ( propertyfile ) ;
FileInputStream fis = new FileInputStream ( propsFile ) ;
props . load ( fis ) ;
long userId = - 1 ;
String username = props . getProperty ( DEV_USERNAME_ATTR ) ;
String email = props . getProperty ( DEV_USER_EMAIL_ATTR ) ;
String firstName = props . getProperty ( DEV_USER_NAME_ATTR ) ;
String middleName = " " ;
String lastName = props . getProperty ( DEV_USER_LASTNAME_ATTR ) ;
String fullname = firstName + lastName ;
long registrationDate = - 1 ;
String userAvatarId = " -1 " ;
boolean male = true ;
String jobTitle = " TestingAccount " ;
List < Email > emailAddresses = new ArrayList < > ( ) ;
2016-02-25 15:55:46 +01:00
2016-11-03 16:54:59 +01:00
return new GCubeUser ( userId , username , email , firstName , middleName , lastName , fullname , registrationDate , userAvatarId , male , jobTitle , emailAddresses ) ;
}
catch ( IOException e ) {
2016-11-14 17:10:36 +01:00
_log . error ( GCUBE_DEV__CONTEXT_PROPERTY_FILENAME + " file not found under $GCUBE_DEV_HOME dir " ) ;
2016-11-03 16:54:59 +01:00
return null ;
}
}
/ * *
* for development purposes only
* /
private static String readTokenPropertyFile ( ) {
Properties props = new Properties ( ) ;
2016-02-25 15:55:46 +01:00
try {
2016-11-14 17:10:36 +01:00
StringBuilder sb = new StringBuilder ( getGCubeDevHome ( ) ) ;
2016-11-03 16:54:59 +01:00
sb . append ( File . separator )
. append ( GCUBE_DEV__CONTEXT_PROPERTY_FILENAME ) ;
String propertyfile = sb . toString ( ) ;
2016-02-25 15:55:46 +01:00
File propsFile = new File ( propertyfile ) ;
FileInputStream fis = new FileInputStream ( propsFile ) ;
props . load ( fis ) ;
2016-11-03 16:54:59 +01:00
String token = props . getProperty ( DEV_TOKEN_ATTR ) ;
if ( token ! = null & & token . compareTo ( " " ) ! = 0 )
return token ;
else {
_log . error ( " Token property " + DEV_TOKEN_ATTR + " is missing or empty in the property file " + propertyfile ) ;
return null ;
}
2016-02-25 15:55:46 +01:00
}
catch ( IOException e ) {
2016-11-14 17:10:36 +01:00
_log . error ( GCUBE_DEV__CONTEXT_PROPERTY_FILENAME + " file not found under $GCUBE_DEV_HOME dir " ) ;
2016-11-03 16:54:59 +01:00
return null ;
}
2016-11-10 15:36:11 +01:00
}
2016-11-17 11:15:23 +01:00
2016-11-10 15:36:11 +01:00
/ * *
2016-11-03 16:54:59 +01:00
* for development purposes only
* /
2016-11-10 15:36:11 +01:00
private static String readContextPropertyFile ( ) {
2016-11-03 16:54:59 +01:00
Properties props = new Properties ( ) ;
try {
2016-11-14 17:10:36 +01:00
StringBuilder sb = new StringBuilder ( getGCubeDevHome ( ) ) ;
2016-11-03 16:54:59 +01:00
sb . append ( File . separator )
. append ( GCUBE_DEV__CONTEXT_PROPERTY_FILENAME ) ;
String propertyfile = sb . toString ( ) ;
File propsFile = new File ( propertyfile ) ;
FileInputStream fis = new FileInputStream ( propsFile ) ;
props . load ( fis ) ;
String scope = props . getProperty ( DEV_SCOPE_ATTR ) ;
if ( scope . startsWith ( SCOPE_SEPARATOR ) )
return scope ;
else {
_log . error ( " Scope is not valid, does not start with " + SCOPE_SEPARATOR ) ;
return null ;
}
2016-02-25 15:55:46 +01:00
}
2016-11-03 16:54:59 +01:00
catch ( IOException e ) {
2016-11-14 17:10:36 +01:00
_log . error ( GCUBE_DEV__CONTEXT_PROPERTY_FILENAME + " file not found under $GCUBE_DEV_HOME dir " ) ;
2016-11-03 16:54:59 +01:00
return null ;
}
2016-02-25 15:55:46 +01:00
}
2016-11-10 15:36:11 +01:00
/ * *
* for development purposes only
* /
private static String readGroupNamePropertyFile ( ) {
Properties props = new Properties ( ) ;
try {
2016-11-14 17:10:36 +01:00
StringBuilder sb = new StringBuilder ( getGCubeDevHome ( ) ) ;
2016-11-10 15:36:11 +01:00
sb . append ( File . separator )
. append ( GCUBE_DEV__CONTEXT_PROPERTY_FILENAME ) ;
String propertyfile = sb . toString ( ) ;
File propsFile = new File ( propertyfile ) ;
FileInputStream fis = new FileInputStream ( propsFile ) ;
props . load ( fis ) ;
String groupName = props . getProperty ( DEV_GROUP_NAME_ATTR ) ;
if ( groupName ! = null & & ! groupName . isEmpty ( ) )
return groupName ;
else {
_log . error ( " groupName is not valid, check property " + DEV_GROUP_NAME_ATTR ) ;
return null ;
}
}
catch ( IOException e ) {
2016-11-14 17:10:36 +01:00
_log . error ( GCUBE_DEV__CONTEXT_PROPERTY_FILENAME + " file not found under $GCUBE_DEV_HOME dir " ) ;
2016-11-10 15:36:11 +01:00
return null ;
}
}
2016-11-17 11:15:23 +01:00
2016-11-10 15:36:11 +01:00
/ * *
* for development purposes only
* /
private static long readGroupIdPropertyFile ( ) {
Properties props = new Properties ( ) ;
try {
2016-11-14 17:10:36 +01:00
StringBuilder sb = new StringBuilder ( getGCubeDevHome ( ) ) ;
2016-11-10 15:36:11 +01:00
sb . append ( File . separator )
. append ( GCUBE_DEV__CONTEXT_PROPERTY_FILENAME ) ;
String propertyfile = sb . toString ( ) ;
File propsFile = new File ( propertyfile ) ;
FileInputStream fis = new FileInputStream ( propsFile ) ;
props . load ( fis ) ;
String groupIdNo = props . getProperty ( DEV_GROUP_ID_ATTR ) ;
long groupId = - 1 ;
if ( groupIdNo ! = null ) {
try {
groupId = Long . parseLong ( groupIdNo ) ;
return groupId ;
} catch ( NumberFormatException e ) {
_log . error ( " The groupId is not a number -> " + groupIdNo ) ;
}
}
else {
_log . error ( " groupId is not valid, check property " + DEV_GROUP_ID_ATTR ) ;
return - 1L ;
}
}
catch ( IOException e ) {
2016-11-14 17:10:36 +01:00
_log . error ( GCUBE_DEV__CONTEXT_PROPERTY_FILENAME + " file not found under $GCUBE_DEV_HOME dir " ) ;
2016-11-10 15:36:11 +01:00
return - 1L ;
}
return - 1L ;
}
2017-01-31 18:51:49 +01:00
2016-11-17 11:15:23 +01:00
2015-06-22 15:24:39 +02:00
/ * *
2013-09-24 15:26:13 +02:00
*
* @return $CATALINA_HOME
* /
2013-10-01 15:11:45 +02:00
private static String getCatalinaHome ( ) {
return ( System . getenv ( " CATALINA_HOME " ) . endsWith ( " / " ) ? System . getenv ( " CATALINA_HOME " ) : System . getenv ( " CATALINA_HOME " ) + " / " ) ;
2013-09-24 15:26:13 +02:00
}
2016-11-17 11:15:23 +01:00
2016-11-14 17:10:36 +01:00
/ * *
*
* @return $GCUBE - DEV - HOME
* /
private static String getGCubeDevHome ( ) {
return ( System . getenv ( " GCUBE_DEV_HOME " ) . endsWith ( " / " ) ? System . getenv ( " GCUBE_DEV_HOME " ) : System . getenv ( " GCUBE_DEV_HOME " ) + " / " ) ;
}
2016-03-23 18:33:58 +01:00
2016-11-10 15:36:11 +01:00
2013-09-24 15:26:13 +02:00
}