Updated to PortalContext

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/github-connector@134687 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-11-24 14:52:28 +00:00
parent 6e0f3e072c
commit 53c17494de
10 changed files with 211 additions and 130 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/github-connector-1.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/github-connector-1.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
@ -25,5 +25,5 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="target/github-connector-1.1.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/github-connector-1.2.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

18
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>github-connector</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<description>github-connector</description>
@ -152,13 +152,9 @@
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
@ -188,12 +184,6 @@
<scope>compile</scope>
</dependency>
<!-- Session Checker -->
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- Storage -->
<dependency>

View File

@ -4,7 +4,7 @@ import org.gcube.portlets.widgets.githubconnector.client.rpc.GitHubConnectorServ
import org.gcube.portlets.widgets.githubconnector.client.util.GWTMessages;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ExpiredSessionServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.session.UserInfo;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.Timer;
@ -37,11 +37,11 @@ public class GitHubConnectorController {
private void checkSession() {
// if you do not need to something when the session expire
CheckSession.getInstance().startPolling();
//CheckSession.getInstance().startPolling();
}
private void sessionExpiredShow() {
CheckSession.showLogoutDialog();
//CheckSession.showLogoutDialog();
}
private void sessionExpiredShowDelayed() {

View File

@ -2,7 +2,6 @@ package org.gcube.portlets.widgets.githubconnector.client;
import org.gcube.portlets.widgets.githubconnector.client.wizard.WizardWindow;
import org.gcube.portlets.widgets.githubconnector.shared.git.GitHubCloneSession;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Timer;
@ -38,11 +37,11 @@ public class GitHubConnectorWizard extends WizardWindow {
private void checkSession() {
// if you do not need to something when the session expire
CheckSession.getInstance().startPolling();
//CheckSession.getInstance().startPolling();
}
private void sessionExpiredShow() {
CheckSession.showLogoutDialog();
//CheckSession.showLogoutDialog();
}
public void sessionExpiredShowDelayed() {

View File

@ -11,7 +11,6 @@ import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -46,8 +45,8 @@ public class GitHubConnectorPortlet extends GenericPortlet {
logger.trace("Loading from JSP: "+VIEW_JSP);
logger.trace("setting context using ScopeHelper");
ScopeHelper.setContext(request);
//logger.trace("setting context using ScopeHelper");
//ScopeHelper.setContext(request);
logger.trace("passing to the render");
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP);

View File

@ -3,11 +3,10 @@ package org.gcube.portlets.widgets.githubconnector.server;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portlets.widgets.githubconnector.client.rpc.GitHubConnectorService;
import org.gcube.portlets.widgets.githubconnector.server.git.GitConnectorService;
import org.gcube.portlets.widgets.githubconnector.server.util.ServiceCredentials;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.git.GitHubCloneSession;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.GitHubRepository;
@ -46,15 +45,14 @@ public class GitHubConnectorServiceImpl extends RemoteServiceServlet implements
@Override
public UserInfo hello() throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
SessionUtil.getToken(aslSession);
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("hello()");
UserInfo userInfo = new UserInfo(aslSession.getUsername(),
aslSession.getGroupId(), aslSession.getGroupName(),
aslSession.getScope(), aslSession.getScopeName(),
aslSession.getUserEmailAddress(),
aslSession.getUserFullName());
UserInfo userInfo = new UserInfo(serviceCredentials.getUserName(),
serviceCredentials.getGoupId(), serviceCredentials.getGroupName(),
serviceCredentials.getScope(),
serviceCredentials.getEmail(),
serviceCredentials.getFullName());
logger.debug("UserInfo: " + userInfo);
return userInfo;
} catch (ServiceException e) {
@ -72,12 +70,10 @@ public class GitHubConnectorServiceImpl extends RemoteServiceServlet implements
public ArrayList<GitHubRepository> getRepositories(String repositoryOwner,
GitHubCredential gitHubCredential) throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
SessionUtil.getToken(aslSession);
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("getRepository(): " + gitHubCredential);
GitConnectorService gitConnectorService = new GitConnectorService(
aslSession.getUsername(), gitHubCredential);
serviceCredentials.getUserName(), gitHubCredential);
return gitConnectorService.getRepositories(repositoryOwner);
} catch (ServiceException e) {
e.printStackTrace();
@ -93,12 +89,10 @@ public class GitHubConnectorServiceImpl extends RemoteServiceServlet implements
public void cloneRepository(GitHubCloneSession gitHubCloneSession)
throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
SessionUtil.getToken(aslSession);
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("cloneRepository(): " + gitHubCloneSession);
GitConnectorService gitConnectorService = new GitConnectorService(
aslSession.getUsername(),
serviceCredentials.getUserName(),
gitHubCloneSession.getGitHubCredential());
gitConnectorService.cloneRepository(gitHubCloneSession.getDestinationFolderId(),
gitHubCloneSession.getRepositoryOwner(), gitHubCloneSession.getRepositoryName());

View File

@ -3,14 +3,12 @@
*/
package org.gcube.portlets.widgets.githubconnector.server;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.common.portal.PortalContext;
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.ExpiredSessionServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException;
/**
@ -24,50 +22,49 @@ public class SessionUtil {
private static final Logger logger = Logger.getLogger(SessionUtil.class);
public static ASLSession getASLSession(HttpSession httpSession)
throws ServiceException {
String username = (String) httpSession
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
ASLSession aslSession;
if (username == null) {
if (Constants.DEBUG_MODE) {
logger.info("no user found in session, use test user");
username = Constants.DEFAULT_USER;
String scope = Constants.DEFAULT_SCOPE;
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE,
username);
aslSession = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
aslSession.setScope(scope);
} else {
logger.info("no user found in session!");
throw new ExpiredSessionServiceException("Session Expired!");
}
} else {
aslSession = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
}
logger.info("SessionUtil: aslSession " + aslSession.getUsername() + " "
+ aslSession.getScope());
return aslSession;
}
public static String getToken(ASLSession aslSession)
throws ServiceException {
public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest) throws ServiceException {
ServiceCredentials sCredentials = null;
String userName = null;
String scope = null;
String token = null;
if (Constants.DEBUG_MODE) {
logger.info("No credential found in session, use test user!");
userName = Constants.DEFAULT_USER;
scope = Constants.DEFAULT_SCOPE;
token = Constants.DEFAULT_TOKEN;
sCredentials = new ServiceCredentials(userName, scope, token);
} else {
token = aslSession.getSecurityToken();
}
logger.info("received token: " + token);
return token;
logger.info("Retrieving credential in session!");
PortalContext pContext = PortalContext.getConfiguration();
userName = pContext.getCurrentUser(httpServletRequest)
.getUsername();
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
.getCurrentGroupId(httpServletRequest));
String groupName = pContext.getCurrentGroupName(httpServletRequest);
sCredentials = new ServiceCredentials(userName, fullName, name, lastName,
email, scope, groupId, groupName, token);
}
logger.info("ServiceCredential: " + sCredentials);
return sCredentials;
}
}

View File

@ -0,0 +1,131 @@
package org.gcube.portlets.widgets.githubconnector.server.util;
import java.io.Serializable;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ServiceCredentials implements Serializable {
private static final long serialVersionUID = 3560918948310315680L;
private String userName;
private String fullName;
private String name;
private String lastName;
private String email;
private String scope;
private String goupId;
private String groupName;
private String token;
public ServiceCredentials() {
super();
}
public ServiceCredentials(String userName, String scope, String token) {
super();
this.userName = userName;
this.scope = scope;
this.token = token;
}
public ServiceCredentials(String userName, String fullName, String name,
String lastName, String email, String scope, String goupId,
String groupName, String token) {
super();
this.userName = userName;
this.fullName = fullName;
this.name = name;
this.lastName = lastName;
this.email = email;
this.scope = scope;
this.goupId = goupId;
this.groupName = groupName;
this.token = token;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getGoupId() {
return goupId;
}
public void setGoupId(String goupId) {
this.goupId = goupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
@Override
public String toString() {
return "ServiceCredentials [userName=" + userName + ", fullName="
+ fullName + ", name=" + name + ", lastName=" + lastName
+ ", email=" + email + ", scope=" + scope + ", goupId="
+ goupId + ", groupName=" + groupName + ", token=" + token
+ "]";
}
}

View File

@ -4,8 +4,8 @@ import java.io.Serializable;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class UserInfo implements Serializable {
@ -13,10 +13,9 @@ public class UserInfo implements Serializable {
private static final long serialVersionUID = -2826549639677017234L;
private String username;
private long groupId;
private String groupId;
private String groupName;
private String scope;
private String scopeName;
private String userEmailAddress;
private String userFullName;
@ -34,15 +33,13 @@ public class UserInfo implements Serializable {
* @param userEmailAddress
* @param userFullName
*/
public UserInfo(String username, long groupId, String groupName,
String scope, String scopeName, String userEmailAddress,
String userFullName) {
public UserInfo(String username, String groupId, String groupName,
String scope, String userEmailAddress, String userFullName) {
super();
this.username = username;
this.groupId = groupId;
this.groupName = groupName;
this.scope = scope;
this.scopeName = scopeName;
this.userEmailAddress = userEmailAddress;
this.userFullName = userFullName;
}
@ -55,11 +52,11 @@ public class UserInfo implements Serializable {
this.username = username;
}
public long getGroupId() {
public String getGroupId() {
return groupId;
}
public void setGroupId(long groupId) {
public void setGroupId(String groupId) {
this.groupId = groupId;
}
@ -79,14 +76,6 @@ public class UserInfo implements Serializable {
this.scope = scope;
}
public String getScopeName() {
return scopeName;
}
public void setScopeName(String scopeName) {
this.scopeName = scopeName;
}
public String getUserEmailAddress() {
return userEmailAddress;
}
@ -107,8 +96,8 @@ public class UserInfo implements Serializable {
public String toString() {
return "UserInfo [username=" + username + ", groupId=" + groupId
+ ", groupName=" + groupName + ", scope=" + scope
+ ", scopeName=" + scopeName + ", userEmailAddress="
+ userEmailAddress + ", userFullName=" + userFullName + "]";
+ ", userEmailAddress=" + userEmailAddress + ", userFullName="
+ userFullName + "]";
}
}

View File

@ -11,15 +11,6 @@
<servlet-name>jUnitHostImpl</servlet-name>
<servlet-class>com.google.gwt.junit.server.JUnitHostImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>checkServlet</servlet-name>
<servlet-class>org.gcube.portlets.widgets.sessionchecker.server.SessionCheckerServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>scopeService</servlet-name>
<servlet-class>org.gcube.portlets.user.gcubewidgets.server.ScopeServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GitHubConnectorServlet</servlet-name>
<url-pattern>/githubman/githubconnectorservice</url-pattern>
@ -28,15 +19,6 @@
<servlet-name>jUnitHostImpl</servlet-name>
<url-pattern>/githubman/junithost/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>checkServlet</servlet-name>
<url-pattern>/githubman/checksession</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>scopeService</servlet-name>
<url-pattern>/githubman/scopeService</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>GitHubConnector.html</welcome-file>
</welcome-file-list>