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"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <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> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -25,5 +25,5 @@
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <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> </classpath>

18
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>github-connector</artifactId> <artifactId>github-connector</artifactId>
<version>1.1.0-SNAPSHOT</version> <version>1.2.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<description>github-connector</description> <description>github-connector</description>
@ -152,13 +152,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.common.portal</groupId>
<artifactId>custom-portal-handler</artifactId> <artifactId>portal-manager</artifactId>
</dependency> <scope>provided</scope>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
</dependency> </dependency>
<dependency> <dependency>
@ -188,12 +184,6 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </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 --> <!-- Storage -->
<dependency> <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.client.util.GWTMessages;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ExpiredSessionServiceException; import org.gcube.portlets.widgets.githubconnector.shared.exception.ExpiredSessionServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.session.UserInfo; 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.core.shared.GWT;
import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Timer;
@ -37,11 +37,11 @@ public class GitHubConnectorController {
private void checkSession() { private void checkSession() {
// if you do not need to something when the session expire // if you do not need to something when the session expire
CheckSession.getInstance().startPolling(); //CheckSession.getInstance().startPolling();
} }
private void sessionExpiredShow() { private void sessionExpiredShow() {
CheckSession.showLogoutDialog(); //CheckSession.showLogoutDialog();
} }
private void sessionExpiredShowDelayed() { 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.client.wizard.WizardWindow;
import org.gcube.portlets.widgets.githubconnector.shared.git.GitHubCloneSession; 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.core.client.GWT;
import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Timer;
@ -38,11 +37,11 @@ public class GitHubConnectorWizard extends WizardWindow {
private void checkSession() { private void checkSession() {
// if you do not need to something when the session expire // if you do not need to something when the session expire
CheckSession.getInstance().startPolling(); //CheckSession.getInstance().startPolling();
} }
private void sessionExpiredShow() { private void sessionExpiredShow() {
CheckSession.showLogoutDialog(); //CheckSession.showLogoutDialog();
} }
public void sessionExpiredShowDelayed() { public void sessionExpiredShowDelayed() {

View File

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

View File

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

View File

@ -3,14 +3,12 @@
*/ */
package org.gcube.portlets.widgets.githubconnector.server; package org.gcube.portlets.widgets.githubconnector.server;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.common.portal.PortalContext;
import org.gcube.application.framework.core.session.SessionManager; import org.gcube.portlets.widgets.githubconnector.server.util.ServiceCredentials;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.widgets.githubconnector.shared.Constants; 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; 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); private static final Logger logger = Logger.getLogger(SessionUtil.class);
public static ASLSession getASLSession(HttpSession httpSession) public static ServiceCredentials getServiceCredentials(
throws ServiceException { HttpServletRequest httpServletRequest) throws ServiceException {
String username = (String) httpSession ServiceCredentials sCredentials = null;
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); String userName = null;
ASLSession aslSession; String scope = null;
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 {
String token = null; String token = null;
if (Constants.DEBUG_MODE) {
token = Constants.DEFAULT_TOKEN;
} else {
token = aslSession.getSecurityToken();
}
logger.info("received token: " + token);
return token;
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 {
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 * @author giancarlo email: <a
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a> * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* *
*/ */
public class UserInfo implements Serializable { public class UserInfo implements Serializable {
@ -13,10 +13,9 @@ public class UserInfo implements Serializable {
private static final long serialVersionUID = -2826549639677017234L; private static final long serialVersionUID = -2826549639677017234L;
private String username; private String username;
private long groupId; private String groupId;
private String groupName; private String groupName;
private String scope; private String scope;
private String scopeName;
private String userEmailAddress; private String userEmailAddress;
private String userFullName; private String userFullName;
@ -34,15 +33,13 @@ public class UserInfo implements Serializable {
* @param userEmailAddress * @param userEmailAddress
* @param userFullName * @param userFullName
*/ */
public UserInfo(String username, long groupId, String groupName, public UserInfo(String username, String groupId, String groupName,
String scope, String scopeName, String userEmailAddress, String scope, String userEmailAddress, String userFullName) {
String userFullName) {
super(); super();
this.username = username; this.username = username;
this.groupId = groupId; this.groupId = groupId;
this.groupName = groupName; this.groupName = groupName;
this.scope = scope; this.scope = scope;
this.scopeName = scopeName;
this.userEmailAddress = userEmailAddress; this.userEmailAddress = userEmailAddress;
this.userFullName = userFullName; this.userFullName = userFullName;
} }
@ -55,11 +52,11 @@ public class UserInfo implements Serializable {
this.username = username; this.username = username;
} }
public long getGroupId() { public String getGroupId() {
return groupId; return groupId;
} }
public void setGroupId(long groupId) { public void setGroupId(String groupId) {
this.groupId = groupId; this.groupId = groupId;
} }
@ -79,14 +76,6 @@ public class UserInfo implements Serializable {
this.scope = scope; this.scope = scope;
} }
public String getScopeName() {
return scopeName;
}
public void setScopeName(String scopeName) {
this.scopeName = scopeName;
}
public String getUserEmailAddress() { public String getUserEmailAddress() {
return userEmailAddress; return userEmailAddress;
} }
@ -107,8 +96,8 @@ public class UserInfo implements Serializable {
public String toString() { public String toString() {
return "UserInfo [username=" + username + ", groupId=" + groupId return "UserInfo [username=" + username + ", groupId=" + groupId
+ ", groupName=" + groupName + ", scope=" + scope + ", groupName=" + groupName + ", scope=" + scope
+ ", scopeName=" + scopeName + ", userEmailAddress=" + ", userEmailAddress=" + userEmailAddress + ", userFullName="
+ userEmailAddress + ", userFullName=" + userFullName + "]"; + userFullName + "]";
} }
} }

View File

@ -11,15 +11,6 @@
<servlet-name>jUnitHostImpl</servlet-name> <servlet-name>jUnitHostImpl</servlet-name>
<servlet-class>com.google.gwt.junit.server.JUnitHostImpl</servlet-class> <servlet-class>com.google.gwt.junit.server.JUnitHostImpl</servlet-class>
</servlet> </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-mapping>
<servlet-name>GitHubConnectorServlet</servlet-name> <servlet-name>GitHubConnectorServlet</servlet-name>
<url-pattern>/githubman/githubconnectorservice</url-pattern> <url-pattern>/githubman/githubconnectorservice</url-pattern>
@ -28,15 +19,6 @@
<servlet-name>jUnitHostImpl</servlet-name> <servlet-name>jUnitHostImpl</servlet-name>
<url-pattern>/githubman/junithost/*</url-pattern> <url-pattern>/githubman/junithost/*</url-pattern>
</servlet-mapping> </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-list>
<welcome-file>GitHubConnector.html</welcome-file> <welcome-file>GitHubConnector.html</welcome-file>
</welcome-file-list> </welcome-file-list>