Compare commits

...

44 Commits

Author SHA1 Message Date
Massimiliano Assante 110b24282d updated bom 2021-06-24 17:32:40 +02:00
Massimiliano Assante 651bb173e1 ready to release 2021-06-24 10:37:06 +02:00
Massimiliano Assante 0ef38bfbcd #21503 Update threadlocal-vars-cleaner to support AccessTokenProvider 2021-05-25 16:29:28 +02:00
Massimiliano Assante 58641ac4a4 removed snapshot from bom 2021-05-03 14:04:22 +02:00
Massimiliano Assante e995002708 ready to release 2021-05-03 12:42:19 +02:00
Massimiliano Assante 10313013e8 just updated the message session is null 2021-05-03 12:30:47 +02:00
Massimiliano Assante 5f066da115 Merge pull request 'Restored session existance check before OIDC/UMA ticket related checks' (#9) from mauro.mugnaini/threadlocal-vars-cleaner:master into master
Reviewed-on: #9
2021-05-03 11:33:16 +02:00
Mauro Mugnaini 99b38ef4b7 Wrong extra return if session is null at check 2021-04-30 08:27:46 +02:00
Mauro Mugnaini 760448c7db Restored session existance check before OIDC/UMA ticket related checks 2021-04-29 19:18:52 +02:00
Massimiliano Assante d1ce7ef5c9 updated pom for release 2021-04-12 16:30:42 +02:00
Massimiliano Assante 7219cf69fe updated pom 2021-04-12 16:29:50 +02:00
Massimiliano Assante 2c45fb1549 Fix Bug #20591 portlet calls in landing page have not UMA token set 2021-04-12 16:29:25 +02:00
Massimiliano Assante 4f402e1821 Merge pull request 'Extracted the UMA issuing code' (#8) from mauro.mugnaini/threadlocal-vars-cleaner:master into master 2021-03-19 12:23:53 +01:00
Mauro Mugnaini eb383671aa Extracted the UMA issuing code for logged user from the Valve in the `threadlocal-vars-cleaner` project to be used also after the login process for UMA issue in the context, since the Valve has already finished its work at that moment. (#20591) 2021-03-17 19:09:28 +01:00
Mauro Mugnaini 3b54a86bc8 Prepared for new version SNAPSHOT 2021-02-15 17:58:49 +01:00
Massimiliano Assante 6e67b8dae2 lowered the level of log "OIDC token is null in cache proxy" 2021-02-10 15:56:46 +01:00
Massimiliano Assante 62a6375372 Merge pull request 'The UMA refresh token flow is skipped by the specific setting (constant in the class) and a new token is requested if the old is expired.' (#7) from mauro.mugnaini/threadlocal-vars-cleaner:master into master 2021-01-22 15:01:57 +01:00
Mauro Mugnaini 07c8a1219e The UMA refresh token flow is skipped by the specific setting (constant in the class) and a new token is requested if the old is expired. 2021-01-22 14:59:19 +01:00
Massimiliano Assante f67c570402 Merge pull request 'Porting to master repo of the changes that seems to resolves issues related to ticket #20445' (#6) from mauro.mugnaini/threadlocal-vars-cleaner:master into master 2021-01-20 12:35:51 +01:00
Mauro Mugnaini 8e28d139b5 Revised implementation that rely completely on cache proxy and ignore the several session objects (with same session ID) that are involved in different calls and threads. In addition to avoid also multiple thread collision that refreshes/requests the same object several times at each call, a specific mutex (per user) has been put in place. 2021-01-20 00:56:27 +01:00
Mauro Mugnaini f5479d8f58 Fixed wrong log messages 2021-01-19 18:00:39 +01:00
Mauro Mugnaini fc18dda68e Remove the user of the session to store objects and rely on cache proxy only adding a mutex to avoid concurrency problems 2021-01-19 17:54:06 +01:00
Mauro Mugnaini 1a0f9b5086 A lot of logs added and rationalized loop 2021-01-19 15:04:31 +01:00
Massimiliano Assante 6c7961c7b0 Merge pull request 'Moved out synch from method to session object and added checks for response messages from Keycloak. Added also redirection to logout URI in case of revoked or invalid OIDC token.' (#5) from mauro.mugnaini/threadlocal-vars-cleaner:master into master 2021-01-11 16:45:41 +01:00
Mauro Mugnaini 9a25509add Moved out synch from method to session object and added checks for response messages from Keycloak. Added also redirection to logout URI in case of revoked or invalid OIDC token. 2021-01-11 16:08:53 +01:00
Massimiliano Assante 52433442c2 Merge pull request 'Rewrote the flow according to last tests and strange LR behavior in session management' (#4) from mauro.mugnaini/threadlocal-vars-cleaner:master into master 2020-12-22 11:13:02 +01:00
Mauro Mugnaini b110e21b3f Rewrote the flow according to last tests and strange LR behavior in session management 2020-12-21 18:14:00 +01:00
Massimiliano Assante fbe94b6fd1 updated date of last commit in changelog 2020-12-17 10:16:13 +01:00
Massimiliano Assante 91465f9a8e Merge pull request 'Forced refresh of access token when current scope changes' (#3) from mauro.mugnaini/threadlocal-vars-cleaner:master into master 2020-12-16 16:03:02 +01:00
Mauro Mugnaini fa407f471a Forced refresh of access token when current scope changes 2020-12-16 15:53:26 +01:00
Massimiliano Assante e4e7352e2c removed snapshot from pom version 2020-11-17 10:57:28 +01:00
Massimiliano Assante d2508827e9 applied necessary changes to supplementary files for release 2020-11-17 10:52:33 +01:00
Massimiliano Assante 561d278f15 Merge pull request 'Finalization of the enabling of the portal to send the user's UMA token in the HTTP services invokation' (#2) from mauro.mugnaini/threadlocal-vars-cleaner:master into master 2020-07-07 12:14:16 +02:00
Mauro Mugnaini 3a4fee1fd4 Added range dependency according to CI rules for DEV 2020-07-07 12:01:19 +02:00
Mauro Mugnaini de67ba9d22 Added range dependency according to CI rules 2020-07-07 10:51:33 +02:00
Mauro Mugnaini 6b86a0700b Changed according to renamed classes method names 2020-07-03 18:45:41 +02:00
Mauro Mugnaini be0860d928 Fixed wrong token put in cache after refresh. Rationalized logs. 2020-07-03 18:38:58 +02:00
Mauro Mugnaini 3f965a9143 Implemented the token refresh on expired access-token validity 2020-07-01 19:42:10 +02:00
Mauro Mugnaini 081e3dd257 Specific version required. Range removed 2020-07-01 19:40:32 +02:00
Massimiliano Assante 7c2c755e6f added -SNAPSHOT 2020-06-25 10:07:49 +02:00
Massimiliano Assante 2b5733d6ff fixed wrong method name call 2020-06-24 12:02:48 +02:00
Massimiliano Assante 02cc26dacb Merge pull request 'Porting of OIDC related modifications' (#1) from mauro.mugnaini/threadlocal-vars-cleaner:master into master 2020-06-24 11:55:07 +02:00
Mauro Mugnaini b156114d3d Changed the proxy class name and renamed packages from com.nubisware.* to org.gcube.* 2020-06-18 12:32:03 +02:00
Mauro Mugnaini ee7a088be2 Beta version 2020-05-29 13:06:55 +02:00
10 changed files with 208 additions and 213 deletions

View File

@ -1,5 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
@ -10,18 +21,8 @@
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -1,5 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -1,4 +1,4 @@
activeProfiles=
activeProfiles=gcube-developer
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

33
CHANGELOG.md Normal file
View File

@ -0,0 +1,33 @@
# Changelog for / threadlocal-vars-cleaner
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v2.3.1] - 2021-05-25
- Feature #21503 Update threadlocal-vars-cleaner to support AccessTokenProvider
## [v2.3.0] - 2021-05-03
- Fix Bug #20591 Keycloak-LR 6.2 Integration: portlet calls in landing page have not UMA token set
## [v2.2.1] - 2020-12-17
- Added support for OIDC related communications
- Fixed wrong token put in cache after refresh. Rationalized logs.
- Ported to git
## [v2.1.1] - 2020-03-26
- Small fix which checks if the current Liferay Site is a valid context and avoid to call auth if it is not
## [v2.1.0] - 2015-02-22
- Added automatic injection of context and token of any AJAX calls
## [v2.0.0] - 2016-06-23
- First release after switch to new liferay version (6.2.6)

26
FUNDING.md Normal file
View File

@ -0,0 +1,26 @@
# Acknowledgments
The projects leading to this software have received funding from a series of European Union programmes including:
- the Sixth Framework Programme for Research and Technological Development
- [DILIGENT](https://cordis.europa.eu/project/id/004260) (grant no. 004260).
- the Seventh Framework Programme for research, technological development and demonstration
- [D4Science](https://cordis.europa.eu/project/id/212488) (grant no. 212488);
- [D4Science-II](https://cordis.europa.eu/project/id/239019) (grant no.239019);
- [ENVRI](https://cordis.europa.eu/project/id/283465) (grant no. 283465);
- [iMarine](https://cordis.europa.eu/project/id/283644) (grant no. 283644);
- [EUBrazilOpenBio](https://cordis.europa.eu/project/id/288754) (grant no. 288754).
- the H2020 research and innovation programme
- [SoBigData](https://cordis.europa.eu/project/id/654024) (grant no. 654024);
- [PARTHENOS](https://cordis.europa.eu/project/id/654119) (grant no. 654119);
- [EGI-Engage](https://cordis.europa.eu/project/id/654142) (grant no. 654142);
- [ENVRI PLUS](https://cordis.europa.eu/project/id/654182) (grant no. 654182);
- [BlueBRIDGE](https://cordis.europa.eu/project/id/675680) (grant no. 675680);
- [PerformFISH](https://cordis.europa.eu/project/id/727610) (grant no. 727610);
- [AGINFRA PLUS](https://cordis.europa.eu/project/id/731001) (grant no. 731001);
- [DESIRA](https://cordis.europa.eu/project/id/818194) (grant no. 818194);
- [ARIADNEplus](https://cordis.europa.eu/project/id/823914) (grant no. 823914);
- [RISIS 2](https://cordis.europa.eu/project/id/824091) (grant no. 824091);
- [EOSC-Pillar](https://cordis.europa.eu/project/id/857650) (grant no. 857650);
- [Blue Cloud](https://cordis.europa.eu/project/id/862409) (grant no. 862409);
- [SoBigData-PlusPlus](https://cordis.europa.eu/project/id/871042) (grant no. 871042);

View File

@ -1,17 +0,0 @@
<ReleaseNotes>
<Changeset
component="org.gcube.portal.threadlocal-vars-cleaner.2-1-1"
date="2020-03-26">
<Change>Small fix which checks if the current Liferay Site is a valid context and avoid to call auth if it is not</Change>
</Changeset>
<Changeset
component="org.gcube.portal.threadlocal-vars-cleaner.2-1-0" date="18">
<Change>Added automatic injection of context and token of any AJAX
calls</Change>
</Changeset>
<Changeset
component="org.gcube.portal.threadlocal-vars-cleaner.2-0-0"
date="2016-06-23">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

View File

@ -1,42 +0,0 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>changelog.xml</include>
<include>profile.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
<fileSet>
<directory>target/apidocs</directory>
<outputDirectory>/${artifactId}/doc/api</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<fileMode>755</fileMode>
</fileSet>
</fileSets>
<files>
<file>
<source>${distroDirectory}/profile.xml</source>
<outputDirectory>./</outputDirectory>
<filtered>true</filtered>
</file>
<file>
<source>target/${build.finalName}.jar</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID></ID>
<Type>Library</Type>
<Profile>
<Description>${description}</Description>
<Class>Portal</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Files>
<File>${build.finalName}.war</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

30
pom.xml
View File

@ -11,13 +11,12 @@
<groupId>org.gcube.portal</groupId>
<artifactId>threadlocal-vars-cleaner</artifactId>
<version>2.1.1</version>
<version>2.3.1</version>
<packaging>jar</packaging>
<name>threadlocal-vars-cleaner</name>
<description>This component clean the Smartgears ThreadLocal variables each time a new Thread is assigned to a request from tomcat thread pool</description>
<properties>
<java-version>1.8</java-version>
<distroDirectory>${project.basedir}/distro</distroDirectory>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<distroDirectory>distro</distroDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -33,7 +32,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.6.0</version>
<version>3.6.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -61,11 +60,21 @@
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>oidc-library-portal</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@ -81,21 +90,6 @@
<build>
<finalName>threadlocal-vars-cleaner-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>

View File

@ -8,124 +8,146 @@ import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.valves.ValveBase;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.provider.UserInfo;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
/**
*
* @author Massimiliano Assante, CNR ISTI
* @author Lucio Lelii, CNR ISTI
* @author Mauro Mugnaini, Nubisware S.r.l.
*
*/
public class SmartGearsPortalValve extends ValveBase {
private static final Logger _log = LoggerFactory.getLogger(SmartGearsPortalValve.class);
private final static String DEFAULT_ROLE = "OrganizationMember";
private final static String LIFERAY_POLLER_CONTEXT = "poller/receive";
public class SmartGearsPortalValve extends ValveBase {
private static final Logger _log = LoggerFactory.getLogger(SmartGearsPortalValve.class);
private final static String DEFAULT_ROLE = "OrganizationMember";
private final static String LIFERAY_POLLER_CONTEXT = "poller/receive";
@Override
public void invoke(Request req, Response resp) throws IOException, ServletException {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
AuthorizationProvider.instance.reset();
//_log.trace("SmartGearsPortalValve SecurityTokenProvider and AuthorizationProvider reset OK");
if (req instanceof HttpServletRequest) {
HttpServletRequest request = (HttpServletRequest) req;
if (!req.getRequestURL().toString().endsWith(LIFERAY_POLLER_CONTEXT)) { //avoid calling gCube auth service for liferay internal poller
PortalContext context = PortalContext.getConfiguration();
String scope = context.getCurrentScope(request);
String username = getCurrentUsername(request);
if (scope != null && username != null && validateContext(scope)) {
String userToken = null;
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("Something went wrong in generating token for " + username + " in scope " + scope);
e.printStackTrace();
}
//_log.trace("Security token set OK for " + username + " in scope " + scope);
}
}
}
getNext().invoke(req, resp);
}
/**
*
* @param context
* @return true if is the context is syntactically valid
*/
private static boolean validateContext(String context) {
String separator = "/";
if (!context.matches("\\S+"))
return false;
String[] components=context.split(separator);
if (components.length<2 || components.length>4)
return false;
return true;
}
@Override
public void invoke(Request req, Response resp) throws IOException, ServletException {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
AuthorizationProvider.instance.reset();
AccessTokenProvider.instance.reset();
//_log.trace("SmartGearsPortalValve SecurityTokenProvider and AuthorizationProvider reset OK");
if (req instanceof HttpServletRequest) {
HttpServletRequest request = (HttpServletRequest) req;
if (!req.getRequestURL().toString().endsWith(LIFERAY_POLLER_CONTEXT)) { //avoid calling gCube auth service for liferay internal poller
PortalContext context = PortalContext.getConfiguration();
String scope = context.getCurrentScope(request);
String username = getCurrentUsername(request);
if (scope != null && username != null && validateContext(scope)) {
String userToken = null;
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("Something went wrong in generating token for " + username + " in scope " + scope);
e.printStackTrace();
}
/**
*
* @param username
* @param scope
* @throws Exception
*/
private static String generateAuthorizationToken(String username, String scope) {
List<String> userRoles = new ArrayList<>();
userRoles.add(DEFAULT_ROLE);
String token;
try {
token = authorizationService().generateUserToken(new UserInfo(username, userRoles), scope);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return token;
}
_log.debug("Getting current user");
User user = getCurrentUser(request);
// user cannot be null otherwise also the getCurrentUsername(request) returned null username in previous lines
_log.debug("Getting current session");
HttpSession session = request.getSession(false);
if (session != null) {
OIDCUmaUtil.checkUMATicketAndProvideInThreadLocal(request, (HttpServletResponse) resp, user,
session, scope);
} else {
_log.debug("Session is null, cannot continue with OIDC/UMA checks");
}
/**
*
* @param httpServletRequest the httpServletRequest object
* @return the instance of the user
* @see GCubeUser
*/
public static String getCurrentUsername(HttpServletRequest httpServletRequest) {
String userIdNo = httpServletRequest.getHeader(PortalContext.USER_ID_ATTR_NAME);
if (userIdNo != null && userIdNo.compareTo("undefined") != 0) {
long userId = -1;
try {
userId = Long.parseLong(userIdNo);
return UserLocalServiceUtil.getUser(userId).getScreenName();
} catch (NumberFormatException e) {
_log.error("The userId is not a number -> " + userIdNo);
return null;
} catch (Exception e) {
_log.error("The userId does not belong to any user -> " + userIdNo);
return null;
}
}
return null;
}
//_log.trace("Security token set OK for " + username + " in scope " + scope);
}
}
}
getNext().invoke(req, resp);
}
/**
*
* @param context
* @return true if is the context is syntactically valid
*/
private static boolean validateContext(String context) {
String separator = "/";
if (!context.matches("\\S+"))
return false;
String[] components = context.split(separator);
if (components.length < 2 || components.length > 4)
return false;
return true;
}
/**
*
* @param username
* @param scope
* @throws Exception
*/
private static String generateAuthorizationToken(String username, String scope) {
List<String> userRoles = new ArrayList<>();
userRoles.add(DEFAULT_ROLE);
String token;
try {
token = authorizationService().generateUserToken(new UserInfo(username, userRoles), scope);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return token;
}
/**
*
* @param httpServletRequest the httpServletRequest object
* @return the instance of the user
* @see GCubeUser
*/
public static String getCurrentUsername(HttpServletRequest httpServletRequest) {
User user = getCurrentUser(httpServletRequest);
return user != null ? user.getScreenName() : null;
}
public static User getCurrentUser(HttpServletRequest httpServletRequest) {
String userIdNo = httpServletRequest.getHeader(PortalContext.USER_ID_ATTR_NAME);
if (userIdNo != null && userIdNo.compareTo("undefined") != 0) {
long userId = -1;
try {
userId = Long.parseLong(userIdNo);
return UserLocalServiceUtil.getUser(userId);
} catch (NumberFormatException e) {
_log.error("The userId is not a number -> " + userIdNo);
return null;
} catch (Exception e) {
_log.error("The userId does not belong to any user -> " + userIdNo);
return null;
}
}
return null;
}
}