ref 6279:Statistical Algorithms Importer - getUserId doesn't work when session expires and Reload is performed
https://support.d4science.org/issues/6279 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/github-connector@142313 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1552367f65
commit
3f1d57de66
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/github-connector-1.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||
<classpathentry kind="src" output="target/github-connector-1.3.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
@ -22,8 +22,9 @@
|
|||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="output" path="target/github-connector-1.2.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
<classpathentry kind="output" path="target/github-connector-1.3.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.portlets.widgets.githubconnector.1-3-0"
|
||||
date="2017-02-15">
|
||||
<Change>Updated PortalContext support[ticket #6279]</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.portlets.widgets.githubconnector.1-2-0"
|
||||
date="2016-12-15">
|
||||
<Change>Added Portal Context</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.portlets.widgets.githubconnector.1-1-0"
|
||||
date="2016-10-01">
|
||||
<Change>Removed accesslogger dependency</Change>
|
||||
|
|
47
pom.xml
47
pom.xml
|
@ -12,7 +12,7 @@
|
|||
|
||||
<groupId>org.gcube.portlets.widgets</groupId>
|
||||
<artifactId>github-connector</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<description>github-connector</description>
|
||||
|
@ -163,6 +163,12 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>client-context-library</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,)</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Authorization -->
|
||||
<dependency>
|
||||
|
@ -177,12 +183,12 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- GCube Widgets -->
|
||||
<!-- GCube Widgets
|
||||
<dependency>
|
||||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>gcube-widgets</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependency> -->
|
||||
|
||||
|
||||
<!-- Storage -->
|
||||
|
@ -373,6 +379,41 @@
|
|||
</plugin>
|
||||
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
|
||||
<plugin>
|
||||
<groupId>org.eclipse.m2e</groupId>
|
||||
<artifactId>lifecycle-mapping</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<configuration>
|
||||
<lifecycleMappingMetadata>
|
||||
<pluginExecutions>
|
||||
<pluginExecution>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>
|
||||
org.codehaus.mojo
|
||||
</groupId>
|
||||
<artifactId>
|
||||
gwt-maven-plugin
|
||||
</artifactId>
|
||||
<versionRange>
|
||||
[2.7.0,)
|
||||
</versionRange>
|
||||
<goals>
|
||||
<goal>resources</goal>
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<ignore></ignore>
|
||||
</action>
|
||||
</pluginExecution>
|
||||
</pluginExecutions>
|
||||
</lifecycleMappingMetadata>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
|
|
|
@ -11,6 +11,7 @@ import javax.portlet.PortletRequestDispatcher;
|
|||
import javax.portlet.RenderRequest;
|
||||
import javax.portlet.RenderResponse;
|
||||
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -44,9 +45,9 @@ public class GitHubConnectorPortlet extends GenericPortlet {
|
|||
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
|
||||
|
||||
logger.trace("Loading from JSP: "+VIEW_JSP);
|
||||
logger.trace("Setting user in session using PortalContext");
|
||||
PortalContext.setUserInSession(request);
|
||||
|
||||
//logger.trace("setting context using ScopeHelper");
|
||||
//ScopeHelper.setContext(request);
|
||||
|
||||
logger.trace("passing to the render");
|
||||
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP);
|
||||
|
|
|
@ -19,8 +19,8 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi
|
||||
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
* @author Giancarlo Panichi email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
|
@ -46,10 +46,12 @@ public class GitHubConnectorServiceImpl extends RemoteServiceServlet implements
|
|||
public UserInfo hello() throws ServiceException {
|
||||
try {
|
||||
|
||||
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
|
||||
ServiceCredentials serviceCredentials = SessionUtil
|
||||
.getServiceCredentials(this.getThreadLocalRequest());
|
||||
logger.debug("hello()");
|
||||
UserInfo userInfo = new UserInfo(serviceCredentials.getUserName(),
|
||||
serviceCredentials.getGroupId(), serviceCredentials.getGroupName(),
|
||||
serviceCredentials.getGroupId(),
|
||||
serviceCredentials.getGroupName(),
|
||||
serviceCredentials.getScope(),
|
||||
serviceCredentials.getEmail(),
|
||||
serviceCredentials.getFullName());
|
||||
|
@ -70,7 +72,8 @@ public class GitHubConnectorServiceImpl extends RemoteServiceServlet implements
|
|||
public ArrayList<GitHubRepository> getRepositories(String repositoryOwner,
|
||||
GitHubCredential gitHubCredential) throws ServiceException {
|
||||
try {
|
||||
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
|
||||
ServiceCredentials serviceCredentials = SessionUtil
|
||||
.getServiceCredentials(this.getThreadLocalRequest());
|
||||
logger.debug("getRepository(): " + gitHubCredential);
|
||||
GitConnectorService gitConnectorService = new GitConnectorService(
|
||||
serviceCredentials.getUserName(), gitHubCredential);
|
||||
|
@ -89,13 +92,16 @@ public class GitHubConnectorServiceImpl extends RemoteServiceServlet implements
|
|||
public void cloneRepository(GitHubCloneSession gitHubCloneSession)
|
||||
throws ServiceException {
|
||||
try {
|
||||
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
|
||||
ServiceCredentials serviceCredentials = SessionUtil
|
||||
.getServiceCredentials(this.getThreadLocalRequest());
|
||||
logger.debug("cloneRepository(): " + gitHubCloneSession);
|
||||
GitConnectorService gitConnectorService = new GitConnectorService(
|
||||
serviceCredentials.getUserName(),
|
||||
gitHubCloneSession.getGitHubCredential());
|
||||
gitConnectorService.cloneRepository(gitHubCloneSession.getDestinationFolderId(),
|
||||
gitHubCloneSession.getRepositoryOwner(), gitHubCloneSession.getRepositoryName());
|
||||
gitConnectorService.cloneRepository(
|
||||
gitHubCloneSession.getDestinationFolderId(),
|
||||
gitHubCloneSession.getRepositoryOwner(),
|
||||
gitHubCloneSession.getRepositoryName());
|
||||
return;
|
||||
} catch (ServiceException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -6,10 +6,15 @@ package org.gcube.portlets.widgets.githubconnector.server;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.widgets.githubconnector.server.util.ServiceCredentials;
|
||||
import org.gcube.portlets.widgets.githubconnector.shared.Constants;
|
||||
import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -22,46 +27,160 @@ public class SessionUtil {
|
|||
|
||||
private static final Logger logger = Logger.getLogger(SessionUtil.class);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param httpServletRequest
|
||||
* @return
|
||||
* @throws TDGWTServiceException
|
||||
*/
|
||||
public static ServiceCredentials getServiceCredentials(
|
||||
HttpServletRequest httpServletRequest) throws ServiceException {
|
||||
HttpServletRequest httpServletRequest)
|
||||
throws ServiceException {
|
||||
return getServiceCredentials(httpServletRequest, null);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param httpServletRequest
|
||||
* @param scopeGroupId
|
||||
* @return
|
||||
* @throws TDGWTServiceException
|
||||
*/
|
||||
public static ServiceCredentials getServiceCredentials(
|
||||
HttpServletRequest httpServletRequest, String scopeGroupId)
|
||||
throws ServiceException {
|
||||
|
||||
ServiceCredentials sCredentials = null;
|
||||
String userName = null;
|
||||
String scope = null;
|
||||
String token = null;
|
||||
String groupId = null;
|
||||
String groupName = null;
|
||||
|
||||
if (Constants.DEBUG_MODE) {
|
||||
logger.info("No credential found in session, use test user!");
|
||||
/*
|
||||
* InfoLocale infoLocale = getInfoLocale(httpServletRequest, null);
|
||||
* Locale locale = new Locale(infoLocale.getLanguage());
|
||||
*
|
||||
* ResourceBundle messages = ResourceBundle.getBundle(
|
||||
* StatAlgoImporterServiceMessagesConstants.TDGWTServiceMessages,
|
||||
* locale);
|
||||
*/
|
||||
userName = Constants.DEFAULT_USER;
|
||||
scope = Constants.DEFAULT_SCOPE;
|
||||
token = Constants.DEFAULT_TOKEN;
|
||||
|
||||
logger.info("Set SecurityToken: " + token);
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
logger.info("Set ScopeProvider: " + scope);
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
sCredentials = new ServiceCredentials(userName, scope, token);
|
||||
|
||||
} else {
|
||||
logger.info("Retrieving credential in session!");
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
userName = pContext.getCurrentUser(httpServletRequest)
|
||||
.getUsername();
|
||||
boolean hasScopeGroupId = false;
|
||||
|
||||
if (scopeGroupId != null && !scopeGroupId.isEmpty()) {
|
||||
hasScopeGroupId = true;
|
||||
|
||||
} else {
|
||||
hasScopeGroupId = false;
|
||||
}
|
||||
|
||||
if (hasScopeGroupId) {
|
||||
scope = pContext.getCurrentScope(scopeGroupId);
|
||||
} else {
|
||||
scope = pContext.getCurrentScope(httpServletRequest);
|
||||
token = pContext.getCurrentUserToken(httpServletRequest);
|
||||
String name = pContext.getCurrentUser(httpServletRequest)
|
||||
.getFirstName();
|
||||
String lastName = pContext.getCurrentUser(httpServletRequest)
|
||||
.getLastName();
|
||||
String fullName = pContext.getCurrentUser(httpServletRequest).getFullname();
|
||||
}
|
||||
|
||||
String email = pContext.getCurrentUser(httpServletRequest)
|
||||
.getEmail();
|
||||
String groupId = String.valueOf(pContext
|
||||
if (scope == null || scope.isEmpty()) {
|
||||
String error = "Error retrieving scope: " + scope;
|
||||
logger.error(error);
|
||||
throw new ServiceException(error);
|
||||
}
|
||||
|
||||
GCubeUser gCubeUser = pContext.getCurrentUser(httpServletRequest);
|
||||
|
||||
if (gCubeUser == null) {
|
||||
String error = "Error retrieving gCubeUser in scope " + scope
|
||||
+ ": " + gCubeUser;
|
||||
logger.error(error);
|
||||
throw new ServiceException(error);
|
||||
}
|
||||
|
||||
userName = gCubeUser.getUsername();
|
||||
|
||||
if (userName == null || userName.isEmpty()) {
|
||||
String error = "Error retrieving username in scope " + scope
|
||||
+ ": " + userName;
|
||||
logger.error(error);
|
||||
throw new ServiceException(error);
|
||||
}
|
||||
|
||||
token = pContext.getCurrentUserToken(scope, userName);
|
||||
|
||||
if (token == null || token.isEmpty()) {
|
||||
String error = "Error retrieving token for " + userName
|
||||
+ " in " + scope + ": " + token;
|
||||
logger.error(error);
|
||||
throw new ServiceException(error);
|
||||
}
|
||||
|
||||
String name = gCubeUser.getFirstName();
|
||||
String lastName = gCubeUser.getLastName();
|
||||
String fullName = gCubeUser.getFullname();
|
||||
|
||||
String userAvatarURL = gCubeUser.getUserAvatarURL();
|
||||
|
||||
String email = gCubeUser.getEmail();
|
||||
|
||||
if (hasScopeGroupId) {
|
||||
logger.info("Set SecurityToken: " + token);
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
logger.info("Set ScopeProvider: " + scope);
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
groupId = scopeGroupId;
|
||||
|
||||
long gId;
|
||||
|
||||
try {
|
||||
gId = Long.parseLong(scopeGroupId);
|
||||
} catch (Throwable e) {
|
||||
String error = "Error retrieving groupId: " + scopeGroupId;
|
||||
logger.error(error, e);
|
||||
throw new ServiceException(error);
|
||||
}
|
||||
|
||||
GCubeGroup group;
|
||||
try {
|
||||
group = new LiferayGroupManager().getGroup(gId);
|
||||
} catch (Throwable e) {
|
||||
String error = "Error retrieving group: " + groupName;
|
||||
logger.error(error);
|
||||
throw new ServiceException(error);
|
||||
}
|
||||
|
||||
groupName = group.getGroupName();
|
||||
|
||||
} else {
|
||||
|
||||
groupId = String.valueOf(pContext
|
||||
.getCurrentGroupId(httpServletRequest));
|
||||
String groupName = pContext.getCurrentGroupName(httpServletRequest);
|
||||
|
||||
sCredentials = new ServiceCredentials(userName, fullName, name, lastName,
|
||||
email, scope, groupId, groupName, token);
|
||||
groupName = pContext.getCurrentGroupName(httpServletRequest);
|
||||
|
||||
}
|
||||
|
||||
logger.info("ServiceCredential: " + sCredentials);
|
||||
sCredentials = new ServiceCredentials(userName, fullName, name,
|
||||
lastName, email, scope, groupId, groupName, userAvatarURL,
|
||||
token);
|
||||
}
|
||||
|
||||
logger.info("ServiceCredentials: " + sCredentials);
|
||||
|
||||
return sCredentials;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ public class ServiceCredentials implements Serializable {
|
|||
private String scope;
|
||||
private String groupId;
|
||||
private String groupName;
|
||||
private String userAvatarURL;
|
||||
private String token;
|
||||
|
||||
public ServiceCredentials() {
|
||||
|
@ -34,7 +35,7 @@ public class ServiceCredentials implements Serializable {
|
|||
|
||||
public ServiceCredentials(String userName, String fullName, String name,
|
||||
String lastName, String email, String scope, String groupId,
|
||||
String groupName, String token) {
|
||||
String groupName, String userAvatarURL, String token) {
|
||||
super();
|
||||
this.userName = userName;
|
||||
this.fullName = fullName;
|
||||
|
@ -44,6 +45,7 @@ public class ServiceCredentials implements Serializable {
|
|||
this.scope = scope;
|
||||
this.groupId = groupId;
|
||||
this.groupName = groupName;
|
||||
this.userAvatarURL = userAvatarURL;
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
|
@ -111,6 +113,14 @@ public class ServiceCredentials implements Serializable {
|
|||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
public String getUserAvatarURL() {
|
||||
return userAvatarURL;
|
||||
}
|
||||
|
||||
public void setUserAvatarURL(String userAvatarURL) {
|
||||
this.userAvatarURL = userAvatarURL;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
@ -124,10 +134,8 @@ public class ServiceCredentials implements Serializable {
|
|||
return "ServiceCredentials [userName=" + userName + ", fullName="
|
||||
+ fullName + ", name=" + name + ", lastName=" + lastName
|
||||
+ ", email=" + email + ", scope=" + scope + ", groupId="
|
||||
+ groupId + ", groupName=" + groupName + ", token=" + token
|
||||
+ "]";
|
||||
+ groupId + ", groupName=" + groupName + ", userAvatarURL="
|
||||
+ userAvatarURL + ", token=" + token + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue