moved to version 1.2.0 due to several changes. Removed asl session too
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@134752 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
28f55bad95
commit
70a07ac0c7
|
@ -1,12 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/gcube-ckan-datacatalog-1.1.1-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||
<classpathentry kind="src" output="target/gcube-ckan-datacatalog-1.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/gcube-ckan-datacatalog-1.1.1-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
|
||||
<classpathentry excluding="**" kind="src" output="target/gcube-ckan-datacatalog-1.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
|
@ -33,5 +33,5 @@
|
|||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/gcube-ckan-datacatalog-1.1.1-SNAPSHOT/WEB-INF/classes"/>
|
||||
<classpathentry kind="output" path="target/gcube-ckan-datacatalog-1.2.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.portlets.gcubeckan.gcube-ckan-datacatalog.1-1-1"
|
||||
<Changeset component="org.gcube.portlets.gcubeckan.gcube-ckan-datacatalog.1-2-0"
|
||||
date="2016-12-01">
|
||||
<Change>Groups tab changed</Change>
|
||||
<Change>[Task #5615] Logout is performed before browser tab is closed</Change>
|
||||
<Change>Portlet's borders are removed by default</Change>
|
||||
<Change>Removed asl session</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.portlets.gcubeckan.gcube-ckan-datacatalog.1-1-0"
|
||||
date="2016-10-10">
|
||||
|
|
26
pom.xml
26
pom.xml
|
@ -13,7 +13,7 @@
|
|||
<groupId>org.gcube.portlets.gcubeckan</groupId>
|
||||
<artifactId>gcube-ckan-datacatalog</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>1.1.1-SNAPSHOT</version>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<name>gCube CKAN Data Catalog</name>
|
||||
<description>The gCube CKAN Data Catalog portlet</description>
|
||||
|
||||
|
@ -59,11 +59,11 @@
|
|||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>xerces</groupId> -->
|
||||
<!-- <artifactId>xercesImpl</artifactId> -->
|
||||
<!-- <version>2.9.1</version> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>xerces</groupId> -->
|
||||
<!-- <artifactId>xercesImpl</artifactId> -->
|
||||
<!-- <version>2.9.1</version> -->
|
||||
<!-- </dependency> -->
|
||||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
<artifactId>gwt-user</artifactId>
|
||||
|
@ -90,7 +90,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope-maps</artifactId>
|
||||
<scope>compile</scope>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- END FWS -->
|
||||
|
||||
|
@ -121,11 +121,6 @@
|
|||
<artifactId>portal-manager</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.applicationsupportlayer</groupId>
|
||||
<artifactId>aslcore</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.portlet</groupId>
|
||||
<artifactId>portlet-api</artifactId>
|
||||
|
@ -172,13 +167,6 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Session expired checker -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.portlets.widgets</groupId>
|
||||
<artifactId>session-checker</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
<inherits
|
||||
name='org.gcube.portlets.widgets.ckandatapublisherwidget.CKanMetadataPublisher' />
|
||||
|
||||
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' />
|
||||
|
||||
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />
|
||||
|
||||
<!-- Specify the paths for translatable code -->
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.resource.CkanPor
|
|||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
|
||||
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.logical.shared.ResizeEvent;
|
||||
|
@ -107,9 +106,6 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
|
|||
}
|
||||
else {
|
||||
|
||||
// polling for session expired check
|
||||
CheckSession.getInstance().startPolling();
|
||||
|
||||
// MANAGE CKAN MANAGEMENT PANEL ACCORDING TO MY ROLE
|
||||
GCubeCkanDataCatalog.service.getMyRole(new AsyncCallback<CkanRole>() {
|
||||
|
||||
|
|
|
@ -8,16 +8,12 @@ import java.util.List;
|
|||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.application.framework.core.session.SessionManager;
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.ApplicationProfileScopePerUrlReader;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods;
|
||||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
|
||||
|
@ -50,14 +46,8 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
private static final String HTTP = "http";
|
||||
public static String CKANCONNECTORCONTEXT = "CkanConnectorContext";
|
||||
public static String CKANCONNECTORLOGOUT = "CkanConnectorLogout";
|
||||
public static final String USERNAME_ATTRIBUTE = ScopeHelper.USERNAME_ATTRIBUTE;
|
||||
private static Logger logger = LoggerFactory.getLogger(GcubeCkanDataCatalogServiceImpl.class);
|
||||
|
||||
public final static String TEST_USER = "andrea.rossi";
|
||||
public final static String TEST_SCOPE = "/gcube/devNext/NextNext";
|
||||
public final static String TEST_MAIL = "test.user@test-com";
|
||||
public final static String TEST_SEC_TOKEN = "4d071434-021e-41ac-9aae-a3489fcf06d8-98187548";
|
||||
|
||||
/**
|
||||
* Instanciate the ckan util library.
|
||||
* Since it needs the scope, we need to check if it is null or not
|
||||
|
@ -65,11 +55,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
* @return
|
||||
*/
|
||||
public DataCatalogue getCatalogue(String discoverScope){
|
||||
|
||||
HttpSession httpSession = getThreadLocalRequest().getSession();
|
||||
ASLSession aslSession = getASLSession(httpSession);
|
||||
String currentScope = aslSession.getScope();
|
||||
|
||||
String currentScope = SessionUtil.getCurrentContext(getThreadLocalRequest(), false);
|
||||
DataCatalogue instance = null;
|
||||
try{
|
||||
String scopeInWhichDiscover = discoverScope != null && !discoverScope.isEmpty() ? discoverScope : currentScope;
|
||||
|
@ -89,14 +75,11 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
logger.info("getCKanConnector [pathInfo: "+pathInfoParameter + ", query: "+queryStringParameters+"], current url is " + currentPortletUrl);
|
||||
try{
|
||||
|
||||
// call asl session otherwise ScopeProvider.instance.get(); returns null
|
||||
ASLSession aslSession = getASLSession(this.getThreadLocalRequest().getSession());
|
||||
// just get the current scope and set it into ScopeProvider...
|
||||
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
||||
|
||||
// retrieve scope per current portlet url
|
||||
String scopePerCurrentUrl = ApplicationProfileScopePerUrlReader.getScopePerUrl(currentPortletUrl);
|
||||
|
||||
// save it
|
||||
this.getThreadLocalRequest().getSession().setAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL, scopePerCurrentUrl);
|
||||
String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest());
|
||||
|
||||
if(queryStringParameters!=null && Base64.isBase64(queryStringParameters.getBytes())){
|
||||
byte[] valueDecoded=Base64.decodeBase64(queryStringParameters.getBytes());
|
||||
|
@ -133,7 +116,6 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
}
|
||||
|
||||
//CKAN BASE URL
|
||||
ASLSession session = getASLSession(this.getThreadLocalRequest().getSession());
|
||||
GcoreEndpointReader ckanEndPoint = null;
|
||||
try{
|
||||
ckanEndPoint = SessionUtil.getCkanEndPoint(this.getThreadLocalRequest().getSession(), scopePerCurrentUrl);
|
||||
|
@ -162,12 +144,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
|
||||
//GET TOKEN
|
||||
String gcubeTokenValue = null;
|
||||
if(SessionUtil.isIntoPortal()){
|
||||
gcubeTokenValue = getGcubeSecurityToken(scopePerCurrentUrl);
|
||||
}else{
|
||||
logger.warn("******** Using TEST_USER security token!!!");
|
||||
gcubeTokenValue = TEST_SEC_TOKEN;
|
||||
}
|
||||
gcubeTokenValue = getGcubeSecurityToken(scopePerCurrentUrl);
|
||||
|
||||
// set the token into the CkanConnectorAccessPoint
|
||||
ckan.addGubeToken(gcubeTokenValue);
|
||||
|
@ -178,7 +155,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
}
|
||||
|
||||
// retrieve the list of VREs to whom the user belongs
|
||||
List<String> listVres = UserUtil.getListVreForUser(session.getUserEmailAddress());
|
||||
List<String> listVres = UserUtil.getListVreForUser(SessionUtil.getCurrentUser(getThreadLocalRequest()).getEmail());
|
||||
ckan.addListOfVREs(listVres);
|
||||
|
||||
return ckan;
|
||||
|
@ -193,8 +170,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
protected String getGcubeSecurityToken(String context) throws Exception {
|
||||
|
||||
// ask it directly to the auth service
|
||||
ASLSession session = getASLSession(this.getThreadLocalRequest().getSession());
|
||||
String username = session.getUsername();
|
||||
String username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
String token = null;
|
||||
try{
|
||||
logger.debug("Checking if token for user " + username + " in context " + context + " already exists...");
|
||||
|
@ -209,32 +185,6 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ASL session.
|
||||
*
|
||||
* @param httpSession the http session
|
||||
* @return the ASL session
|
||||
*/
|
||||
protected ASLSession getASLSession(HttpSession httpSession)
|
||||
{
|
||||
String sessionID = httpSession.getId();
|
||||
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
|
||||
|
||||
if (user == null) {
|
||||
logger.warn("****** STARTING IN TEST MODE - NO USER FOUND *******");
|
||||
//for test only
|
||||
user = TEST_USER;
|
||||
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
|
||||
ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user);
|
||||
session.setScope(TEST_SCOPE);
|
||||
return session;
|
||||
}
|
||||
else
|
||||
logger.trace("user found in session "+user);
|
||||
return SessionManager.getInstance().getASLSession(sessionID, user);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService#getMyRole()
|
||||
*/
|
||||
|
@ -250,56 +200,50 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
}else{
|
||||
|
||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||
ASLSession session = getASLSession(httpSession);
|
||||
String username = session.getUsername();
|
||||
String username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
|
||||
// get the scope
|
||||
String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest());
|
||||
|
||||
// get key per scope
|
||||
String keyPerScopeRole = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_HIGHEST_ROLE, scopePerCurrentUrl);
|
||||
String keyPerScopeOrganizations = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scopePerCurrentUrl);
|
||||
String keyPerScopeGroups = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scopePerCurrentUrl);
|
||||
|
||||
// check into session
|
||||
if(httpSession.getAttribute(keyPerScopeRole) != null){
|
||||
|
||||
toReturn = (CkanRole)httpSession.getAttribute(keyPerScopeRole);
|
||||
logger.info("Found user role into session " + toReturn + " and it is going to be returned for user " + username);
|
||||
|
||||
// check if session expired
|
||||
if(username.equals(TEST_USER)){
|
||||
logger.warn("Session expired, returning " + toReturn);
|
||||
}else{
|
||||
|
||||
// get the scope
|
||||
String scopePerCurrentUrl = (String)this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
||||
try{
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
String groupName = gm.getGroup(gm.getGroupIdFromInfrastructureScope(scopePerCurrentUrl)).getGroupName();
|
||||
|
||||
// get key per scope
|
||||
String keyPerScopeRole = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_HIGHEST_ROLE, scopePerCurrentUrl);
|
||||
String keyPerScopeOrganizations = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scopePerCurrentUrl);
|
||||
String keyPerScopeGroups = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scopePerCurrentUrl);
|
||||
// we build up also a list that keeps track of the scopes (orgs) in which the user has at least role EDITOR
|
||||
List<OrganizationBean> orgsInWhichAtLeastEditorRole = new ArrayList<OrganizationBean>();
|
||||
toReturn = UserUtil.getHighestRole(scopePerCurrentUrl, username, groupName, this, orgsInWhichAtLeastEditorRole);
|
||||
|
||||
// check into session
|
||||
if(httpSession.getAttribute(keyPerScopeRole) != null){
|
||||
// put role in session
|
||||
httpSession.setAttribute(keyPerScopeRole, toReturn);
|
||||
logger.info("Set role " + toReturn + " into session for user " + username);
|
||||
|
||||
toReturn = (CkanRole)httpSession.getAttribute(keyPerScopeRole);
|
||||
logger.info("Found user role into session " + toReturn + " and it is going to be returned for user " + username);
|
||||
|
||||
}else{
|
||||
|
||||
try{
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
String groupName = gm.getGroup(gm.getGroupIdFromInfrastructureScope(scopePerCurrentUrl)).getGroupName();
|
||||
|
||||
// we build up also a list that keeps track of the scopes (orgs) in which the user has at least role EDITOR
|
||||
List<OrganizationBean> orgsInWhichAtLeastEditorRole = new ArrayList<OrganizationBean>();
|
||||
toReturn = UserUtil.getHighestRole(scopePerCurrentUrl, username, groupName, this, orgsInWhichAtLeastEditorRole);
|
||||
|
||||
// put role in session
|
||||
httpSession.setAttribute(keyPerScopeRole, toReturn);
|
||||
logger.info("Set role " + toReturn + " into session for user " + username);
|
||||
|
||||
// if he is an admin/editor preload:
|
||||
// 1) organizations in which he can publish (the widget will find these info in session)
|
||||
// 2) the list of groups
|
||||
if(toReturn.equals(CkanRole.ADMIN) || toReturn.equals(CkanRole.EDITOR)){
|
||||
httpSession.setAttribute(keyPerScopeOrganizations, orgsInWhichAtLeastEditorRole);
|
||||
httpSession.setAttribute(keyPerScopeGroups, fetchUserGroups(scopePerCurrentUrl, username));
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("Error while retreving roles... returning " + toReturn, e);
|
||||
// if he is an admin/editor preload:
|
||||
// 1) organizations in which he can publish (the widget will find these info in session)
|
||||
// 2) the list of groups
|
||||
if(toReturn.equals(CkanRole.ADMIN) || toReturn.equals(CkanRole.EDITOR)){
|
||||
httpSession.setAttribute(keyPerScopeOrganizations, orgsInWhichAtLeastEditorRole);
|
||||
httpSession.setAttribute(keyPerScopeGroups, fetchUserGroups(scopePerCurrentUrl, username));
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("Error while retreving roles... returning " + toReturn, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// return the role
|
||||
return toReturn;
|
||||
}
|
||||
|
@ -340,12 +284,10 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
|
||||
@Override
|
||||
public String logoutURIFromCkan() {
|
||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||
ASLSession session = getASLSession(httpSession);
|
||||
String username = session.getUsername();
|
||||
String username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
|
||||
// get the scope from session
|
||||
String scopePerCurrentUrl = (String)this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
||||
String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest());
|
||||
|
||||
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession(), scopePerCurrentUrl);
|
||||
logger.info("Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue());
|
||||
|
@ -366,11 +308,16 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
public String logoutFromCkanURL() {
|
||||
|
||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||
ASLSession session = getASLSession(httpSession);
|
||||
String username = session.getUsername();
|
||||
String username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
|
||||
if(username == null){
|
||||
logger.warn("User is null");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
logger.info("Getting CKAN Logout URL...");
|
||||
String scopePerCurrentUrl = (String) this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
||||
String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest());
|
||||
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(httpSession, scopePerCurrentUrl);
|
||||
// String token = getGcubeSecurityToken();
|
||||
logger.info("Logout from CKAN for: "+username );
|
||||
|
@ -461,38 +408,35 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
}else{
|
||||
|
||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||
ASLSession session = getASLSession(httpSession);
|
||||
String username = session.getUsername();
|
||||
String username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
|
||||
// retrieve scope per current portlet url
|
||||
String scopePerCurrentUrl = (String)this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
||||
String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest());
|
||||
String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGS_USER_KEY, scopePerCurrentUrl);
|
||||
|
||||
if(!username.equals(TEST_USER)){
|
||||
|
||||
// check if the aslsession already has such information
|
||||
if(httpSession.getAttribute(keyPerScope) != null){
|
||||
toReturn = (List<BeanUserInOrgGroupRole>) httpSession.getAttribute(keyPerScope);
|
||||
logger.debug("List of organizations was into the session " + toReturn);
|
||||
}else{
|
||||
logger.debug("Organizations list wasn't into session, retrieving them");
|
||||
DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl);
|
||||
List<CkanOrganization> organizations = catalogue.getOrganizationsByUser(username);
|
||||
String apiKey = catalogue.getApiKeyFromUsername(username);
|
||||
for (CkanOrganization ckanOrganization : organizations) {
|
||||
String role = catalogue.getRoleOfUserInOrganization(username, ckanOrganization.getName(), apiKey);
|
||||
BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName(), CkanRole.valueOf(role.toUpperCase()));
|
||||
toReturn.add(org);
|
||||
}
|
||||
logger.debug("List of organizations to return for user " + username + " is " + toReturn);
|
||||
httpSession.setAttribute(keyPerScope, toReturn);
|
||||
// check if the aslsession already has such information
|
||||
if(httpSession.getAttribute(keyPerScope) != null){
|
||||
toReturn = (List<BeanUserInOrgGroupRole>) httpSession.getAttribute(keyPerScope);
|
||||
logger.debug("List of organizations was into the session " + toReturn);
|
||||
}else{
|
||||
logger.debug("Organizations list wasn't into session, retrieving them");
|
||||
DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl);
|
||||
List<CkanOrganization> organizations = catalogue.getOrganizationsByUser(username);
|
||||
String apiKey = catalogue.getApiKeyFromUsername(username);
|
||||
for (CkanOrganization ckanOrganization : organizations) {
|
||||
String role = catalogue.getRoleOfUserInOrganization(username, ckanOrganization.getName(), apiKey);
|
||||
BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName(), CkanRole.valueOf(role.toUpperCase()));
|
||||
toReturn.add(org);
|
||||
}
|
||||
logger.debug("List of organizations to return for user " + username + " is " + toReturn);
|
||||
httpSession.setAttribute(keyPerScope, toReturn);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<BeanUserInOrgGroupRole> getCkanGroupsNamesAndUrlsForUser() {
|
||||
|
@ -506,34 +450,31 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
|
||||
}else{
|
||||
|
||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||
ASLSession session = getASLSession(httpSession);
|
||||
String username = session.getUsername();
|
||||
HttpSession httpSession = getThreadLocalRequest().getSession();
|
||||
String username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
|
||||
// retrieve scope per current portlet url
|
||||
String scopePerCurrentUrl = (String)this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
||||
String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest());
|
||||
String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_USER_KEY, scopePerCurrentUrl);
|
||||
|
||||
if(!username.equals(TEST_USER)){
|
||||
|
||||
// check if the aslsession already has such information
|
||||
if(httpSession.getAttribute(keyPerScope) != null){
|
||||
toReturn = (List<BeanUserInOrgGroupRole>) httpSession.getAttribute(keyPerScope);
|
||||
logger.debug("List of groups was into the session " + toReturn);
|
||||
}else{
|
||||
logger.debug("Groups list wasn't into session, retrieving them");
|
||||
DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl);
|
||||
List<CkanGroup> groups = catalogue.getGroupsByUser(username);
|
||||
String apiKey = catalogue.getApiKeyFromUsername(username);
|
||||
for (CkanGroup ckanGroup : groups) {
|
||||
String role = catalogue.getRoleOfUserInGroup(username, ckanGroup.getName(), apiKey);
|
||||
BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanGroup.getTitle(), "/group/" + ckanGroup.getName(), CkanRole.valueOf(role.toUpperCase()));
|
||||
toReturn.add(org);
|
||||
}
|
||||
logger.debug("List of organizations to return for user " + username + " is " + toReturn);
|
||||
httpSession.setAttribute(keyPerScope, toReturn);
|
||||
// check if the aslsession already has such information
|
||||
if(httpSession.getAttribute(keyPerScope) != null){
|
||||
toReturn = (List<BeanUserInOrgGroupRole>) httpSession.getAttribute(keyPerScope);
|
||||
logger.debug("List of groups was into the session " + toReturn);
|
||||
}else{
|
||||
logger.debug("Groups list wasn't into session, retrieving them");
|
||||
DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl);
|
||||
List<CkanGroup> groups = catalogue.getGroupsByUser(username);
|
||||
String apiKey = catalogue.getApiKeyFromUsername(username);
|
||||
for (CkanGroup ckanGroup : groups) {
|
||||
String role = catalogue.getRoleOfUserInGroup(username, ckanGroup.getName(), apiKey);
|
||||
BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanGroup.getTitle(), "/group/" + ckanGroup.getName(), CkanRole.valueOf(role.toUpperCase()));
|
||||
toReturn.add(org);
|
||||
}
|
||||
logger.debug("List of organizations to return for user " + username + " is " + toReturn);
|
||||
httpSession.setAttribute(keyPerScope, toReturn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
|
@ -550,11 +491,13 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
|
||||
}else{
|
||||
|
||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||
ASLSession session = getASLSession(httpSession);
|
||||
String username = session.getUsername();
|
||||
return username.equals(TEST_USER);
|
||||
|
||||
String username = null;
|
||||
try{
|
||||
username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
}catch(Exception e){
|
||||
logger.warn("Maybe there is no user ");
|
||||
}
|
||||
return username == null || username.isEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,19 @@
|
|||
*/
|
||||
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.ApplicationProfileScopePerUrlReader;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
|
||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -22,7 +32,7 @@ public class SessionUtil {
|
|||
|
||||
public static final String CKAN_END_POINT = "CKAN_END_POINT";
|
||||
public static final String CKAN_ACCESS_POINT = "CKAN_ACCESS_POINT";
|
||||
|
||||
public static final String GCUBE_REQUEST_URL = "gcube-request-url";
|
||||
private static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
|
||||
|
||||
/**
|
||||
|
@ -97,4 +107,103 @@ public class SessionUtil {
|
|||
String key = getKeyForSession(CKAN_ACCESS_POINT, scope);
|
||||
return (CkanConnectorAccessPoint) session.getAttribute(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the scope in which ckan information needs to be discovered from the url
|
||||
* @param httpServletRequest
|
||||
* @return
|
||||
*/
|
||||
public static String getScopeFromClientUrl(HttpServletRequest httpServletRequest){
|
||||
|
||||
if(httpServletRequest == null)
|
||||
throw new IllegalArgumentException("HttpServletRequest is null!");
|
||||
|
||||
String scopeToReturn = null;
|
||||
try{
|
||||
String clientUrl = getCurrentClientUrl(httpServletRequest).split("\\?")[0];
|
||||
logger.debug("Client url is " + clientUrl);
|
||||
|
||||
// check if this information is in session, otherwise set it and return
|
||||
HttpSession session = httpServletRequest.getSession();
|
||||
|
||||
if((scopeToReturn = (String) session.getAttribute(clientUrl)) != null){
|
||||
logger.debug("Scope to return is " + scopeToReturn);
|
||||
}else{
|
||||
// ask to the ckan library and set it
|
||||
scopeToReturn = ApplicationProfileScopePerUrlReader.getScopePerUrl(clientUrl);
|
||||
logger.debug("Scope to return is " + scopeToReturn);
|
||||
session.setAttribute(clientUrl, scopeToReturn);
|
||||
}
|
||||
}catch(Exception e){
|
||||
scopeToReturn = getCurrentContext(httpServletRequest, false);
|
||||
logger.warn("Failed to determine the scope from the client url, returning the current one: " + scopeToReturn);
|
||||
}
|
||||
return scopeToReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Needed to get the url of the client
|
||||
* @param httpServletRequest the httpServletRequest object
|
||||
* @return the instance of the user
|
||||
* @see the url at client side
|
||||
*/
|
||||
public static String getCurrentClientUrl(HttpServletRequest httpServletRequest) {
|
||||
if(httpServletRequest == null)
|
||||
throw new IllegalArgumentException("HttpServletRequest is null!");
|
||||
|
||||
return httpServletRequest.getHeader(GCUBE_REQUEST_URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current user by using the portal manager
|
||||
* @return a GcubeUser object
|
||||
*/
|
||||
public static GCubeUser getCurrentUser(HttpServletRequest request){
|
||||
|
||||
if(request == null)
|
||||
throw new IllegalArgumentException("HttpServletRequest is null!");
|
||||
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
GCubeUser user = pContext.getCurrentUser(request);
|
||||
logger.debug("Returning user " + user);
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current scope by using the portal manager
|
||||
* @param b
|
||||
* @return a GcubeUser object
|
||||
*/
|
||||
public static String getCurrentContext(HttpServletRequest request, boolean setInThread){
|
||||
|
||||
if(request == null)
|
||||
throw new IllegalArgumentException("HttpServletRequest is null!");
|
||||
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
String context = pContext.getCurrentScope(request);
|
||||
logger.debug("Returning context " + context);
|
||||
|
||||
if(context != null && setInThread)
|
||||
ScopeProvider.instance.set(context);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the group given the scope
|
||||
* @param scope
|
||||
* @return
|
||||
* @throws UserManagementSystemException
|
||||
* @throws GroupRetrievalFault
|
||||
*/
|
||||
public static GCubeGroup getGroupFromScope(String scope) throws UserManagementSystemException, GroupRetrievalFault{
|
||||
|
||||
if(scope == null || scope.isEmpty())
|
||||
throw new IllegalArgumentException("Scope is missing here!!");
|
||||
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
long groupId = gm.getGroupIdFromInfrastructureScope(scope);
|
||||
return gm.getGroup(groupId);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module rename-to='gCubeCkanDataCatalog'>
|
||||
<!-- Inherit the core Web Toolkit stuff. -->
|
||||
<inherits name='com.google.gwt.user.User' />
|
||||
|
||||
<!-- Inherit the default GWT style sheet. You can change -->
|
||||
<!-- the theme of your GWT application by uncommenting -->
|
||||
<!-- any one of the following lines. -->
|
||||
<inherits name="com.github.gwtbootstrap.Bootstrap" />
|
||||
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard' /> -->
|
||||
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
|
||||
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
|
||||
|
||||
<!-- Other module inherits -->
|
||||
|
||||
<!-- Specify the app entry point class. -->
|
||||
<entry-point
|
||||
class='org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GCubeCkanDataCatalog' />
|
||||
|
||||
<!-- Inherits widget -->
|
||||
<inherits
|
||||
name='org.gcube.portlets.widgets.ckandatapublisherwidget.CKanMetadataPublisher' />
|
||||
|
||||
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' />
|
||||
|
||||
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />
|
||||
|
||||
<inherits name="com.google.gwt.http.HTTP" />
|
||||
|
||||
<!-- Specify the paths for translatable code -->
|
||||
<source path='client' />
|
||||
<source path='shared' />
|
||||
|
||||
</module>
|
Loading…
Reference in New Issue