removed asl session
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@134751 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
91fd3e68d6
commit
430c5f36ff
|
@ -3,6 +3,7 @@
|
||||||
<Change>A post is automatically created by the Product Catalogue user every time someone publishes</Change>
|
<Change>A post is automatically created by the Product Catalogue user every time someone publishes</Change>
|
||||||
<Change>The user now can select all files in the hierarchy and publish them</Change>
|
<Change>The user now can select all files in the hierarchy and publish them</Change>
|
||||||
<Change>The user can now associate the product to the available groups</Change>
|
<Change>The user can now associate the product to the available groups</Change>
|
||||||
|
<Change>Removed ASL session dependency</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset component="org.gcube.portlets-widgets.ckan-metadata-publisher-widget.1-1-0" date="2016-10-11">
|
<Changeset component="org.gcube.portlets-widgets.ckan-metadata-publisher-widget.1-1-0" date="2016-10-11">
|
||||||
<Change>Creation of a group is now supported</Change>
|
<Change>Creation of a group is now supported</Change>
|
||||||
|
|
12
pom.xml
12
pom.xml
|
@ -55,13 +55,6 @@
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>xerces</groupId>
|
|
||||||
<artifactId>xercesImpl</artifactId>
|
|
||||||
<version>2.9.1</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
<!-- put at provided for deploying -->
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.gwt</groupId>
|
<groupId>com.google.gwt</groupId>
|
||||||
<artifactId>gwt-servlet</artifactId>
|
<artifactId>gwt-servlet</artifactId>
|
||||||
|
@ -116,11 +109,6 @@
|
||||||
<artifactId>portal-service</artifactId>
|
<artifactId>portal-service</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.applicationsupportlayer</groupId>
|
|
||||||
<artifactId>aslcore</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.portal</groupId>
|
<groupId>org.gcube.portal</groupId>
|
||||||
<artifactId>social-networking-library</artifactId>
|
<artifactId>social-networking-library</artifactId>
|
||||||
|
|
|
@ -10,14 +10,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
|
||||||
import org.gcube.application.framework.core.session.SessionManager;
|
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
|
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory;
|
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean;
|
import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes;
|
import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods;
|
import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods;
|
||||||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads.AssociationToGroupAndNotifyThread;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads.AssociationToGroupAndNotifyThread;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads.WritePostCatalogueManagerThread;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads.WritePostCatalogueManagerThread;
|
||||||
|
@ -30,6 +27,8 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfile
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -44,15 +43,13 @@ import eu.trentorise.opendata.jackan.model.CkanLicense;
|
||||||
* Server side of the data publisher.
|
* Server side of the data publisher.
|
||||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"serial","deprecation"})
|
|
||||||
public class CKANPublisherServicesImpl extends RemoteServiceServlet implements CKanPublisherService{
|
public class CKANPublisherServicesImpl extends RemoteServiceServlet implements CKanPublisherService{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7252248774050361697L;
|
||||||
|
|
||||||
// Logger
|
// Logger
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class);
|
||||||
|
|
||||||
public static final String TEST_SCOPE = "/gcube";
|
|
||||||
public static final String TEST_USER = "test.user";
|
|
||||||
|
|
||||||
// map <orgName, scope>
|
// map <orgName, scope>
|
||||||
private ConcurrentHashMap<String, String> mapOrganizationScope = new ConcurrentHashMap<String, String>();
|
private ConcurrentHashMap<String, String> mapOrganizationScope = new ConcurrentHashMap<String, String>();
|
||||||
|
|
||||||
|
@ -66,7 +63,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
DataCatalogue instance = null;
|
DataCatalogue instance = null;
|
||||||
String scopeInWhichDiscover = null;
|
String scopeInWhichDiscover = null;
|
||||||
try{
|
try{
|
||||||
scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : getASLSession().getScope();
|
scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : Utils.getCurrentContext(getThreadLocalRequest(), false);
|
||||||
logger.debug("Discovering ckan instance into scope " + scopeInWhichDiscover);
|
logger.debug("Discovering ckan instance into scope " + scopeInWhichDiscover);
|
||||||
instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
|
instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
@ -75,38 +72,14 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* the current ASLSession
|
|
||||||
* @return the session
|
|
||||||
*/
|
|
||||||
private ASLSession getASLSession() {
|
|
||||||
String sessionID = this.getThreadLocalRequest().getSession().getId();
|
|
||||||
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
|
|
||||||
|
|
||||||
if (user == null) {
|
|
||||||
logger.warn("USER IS NULL setting testing user and Running OUTSIDE PORTAL");
|
|
||||||
user = getDevelopmentUser();
|
|
||||||
SessionManager.getInstance().getASLSession(sessionID, user).setScope(TEST_SCOPE);
|
|
||||||
}
|
|
||||||
return SessionManager.getInstance().getASLSession(sessionID, user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* when packaging test will fail if the user is not set to test.user
|
|
||||||
* @return .
|
|
||||||
*/
|
|
||||||
public String getDevelopmentUser() {
|
|
||||||
String user = TEST_USER;
|
|
||||||
// user = "costantino.perciante";
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the list of organizations in which the user can publish (roles ADMIN)
|
* Retrieve the list of organizations in which the user can publish (roles ADMIN)
|
||||||
* @param username
|
* @param username
|
||||||
* @return the list of organizations
|
* @return the list of organizations
|
||||||
|
* @throws GroupRetrievalFault
|
||||||
|
* @throws UserManagementSystemException
|
||||||
*/
|
*/
|
||||||
private List<OrganizationBean> getUserOrganizationsListAdmin(String username, String scope) {
|
private List<OrganizationBean> getUserOrganizationsListAdmin(String username, String scope) throws UserManagementSystemException, GroupRetrievalFault {
|
||||||
|
|
||||||
logger.debug("Request for user " + username + " organizations list");
|
logger.debug("Request for user " + username + " organizations list");
|
||||||
List<OrganizationBean> orgsName = new ArrayList<OrganizationBean>();
|
List<OrganizationBean> orgsName = new ArrayList<OrganizationBean>();
|
||||||
|
@ -119,7 +92,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
logger.info("List of organizations was into session " + orgsName);
|
logger.info("List of organizations was into session " + orgsName);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
orgsName = Utils.getUserOrganizationsListAdminEditor(scope, username, getASLSession().getGroupName(), this);
|
orgsName = Utils.getUserOrganizationsListAdminEditor(scope, username, Utils.getGroupFromScope(scope).getGroupName(), this);
|
||||||
httpSession.setAttribute(keyPerScope, orgsName);
|
httpSession.setAttribute(keyPerScope, orgsName);
|
||||||
logger.info("Organizations name for user " + username + " has been saved into session " + orgsName);
|
logger.info("Organizations name for user " + username + " has been saved into session " + orgsName);
|
||||||
}
|
}
|
||||||
|
@ -149,7 +122,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
*/
|
*/
|
||||||
private String findLicenseIdByLicense(String chosenLicense) {
|
private String findLicenseIdByLicense(String chosenLicense) {
|
||||||
|
|
||||||
String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
// get scope from client url
|
||||||
|
String scope = Utils.getScopeFromClientUrl(getThreadLocalRequest());
|
||||||
return getCatalogue(scope).findLicenseIdByLicenseTitle(chosenLicense);
|
return getCatalogue(scope).findLicenseIdByLicenseTitle(chosenLicense);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -157,19 +131,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
@Override
|
@Override
|
||||||
public LicensesBean getLicenses() {
|
public LicensesBean getLicenses() {
|
||||||
|
|
||||||
ASLSession session = getASLSession();
|
|
||||||
String username = session.getUsername();
|
|
||||||
|
|
||||||
if(username.equals(TEST_USER)){
|
|
||||||
|
|
||||||
logger.warn("Session expired, returning null token");
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}else{
|
|
||||||
|
|
||||||
// get http session
|
// get http session
|
||||||
HttpSession httpSession = getThreadLocalRequest().getSession();
|
HttpSession httpSession = getThreadLocalRequest().getSession();
|
||||||
String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
String scope = Utils.getScopeFromClientUrl(getThreadLocalRequest());
|
||||||
logger.info("Request for CKAN licenses for scope " + scope);
|
logger.info("Request for CKAN licenses for scope " + scope);
|
||||||
String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope);
|
String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope);
|
||||||
|
|
||||||
|
@ -193,30 +157,21 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
}
|
}
|
||||||
|
|
||||||
return licensesBean;
|
return licensesBean;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatasetMetadataBean getDatasetBean(String folderId){
|
public DatasetMetadataBean getDatasetBean(String folderId){
|
||||||
|
|
||||||
DatasetMetadataBean bean = null;
|
DatasetMetadataBean bean = null;
|
||||||
|
String userName = Utils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||||
ASLSession aslSession = getASLSession();
|
|
||||||
String userName = aslSession.getUsername();
|
|
||||||
|
|
||||||
logger.info("DatasetBean request for " + folderId + " and " + userName);
|
logger.info("DatasetBean request for " + folderId + " and " + userName);
|
||||||
|
|
||||||
if(isWithinPortal()){
|
if(isWithinPortal()){
|
||||||
try{
|
try{
|
||||||
|
|
||||||
// check if session expired
|
String scope = Utils.getScopeFromClientUrl(getThreadLocalRequest());
|
||||||
if(userName.equals(TEST_USER)){
|
|
||||||
logger.debug("SESSION EXPIRED");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
|
||||||
String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
|
||||||
|
|
||||||
logger.debug("Scope recovered from session is " + scope);
|
logger.debug("Scope recovered from session is " + scope);
|
||||||
|
|
||||||
|
@ -262,7 +217,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
bean.setAuthorEmail("costantino.perciante@isti.cnr.it");
|
bean.setAuthorEmail("costantino.perciante@isti.cnr.it");
|
||||||
bean.setMaintainer("Costantino Perciante");
|
bean.setMaintainer("Costantino Perciante");
|
||||||
bean.setMaintainerEmail("costantino.perciante@isti.cnr.it");
|
bean.setMaintainerEmail("costantino.perciante@isti.cnr.it");
|
||||||
bean.setOrganizationList(getUserOrganizationsListAdmin(userName, TEST_SCOPE));
|
bean.setOrganizationList(getUserOrganizationsListAdmin(userName, Utils.getCurrentContext(getThreadLocalRequest(), true)));
|
||||||
bean.setOwnerIdentifier(userName);
|
bean.setOwnerIdentifier(userName);
|
||||||
|
|
||||||
if(folderId != null && !folderId.isEmpty()){
|
if(folderId != null && !folderId.isEmpty()){
|
||||||
|
@ -281,17 +236,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
|
|
||||||
logger.debug("Request for creating a dataset with these information " + toCreate);
|
logger.debug("Request for creating a dataset with these information " + toCreate);
|
||||||
|
|
||||||
ASLSession aslSession = getASLSession();
|
String userName = Utils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||||
String userName = aslSession.getUsername();
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
// check if session expired
|
|
||||||
if(userName.equals(TEST_USER)){
|
|
||||||
logger.warn("SESSION EXPIRED");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String title = toCreate.getTitle();
|
String title = toCreate.getTitle();
|
||||||
String organizationNameOrId = toCreate.getSelectedOrganization();
|
String organizationNameOrId = toCreate.getSelectedOrganization();
|
||||||
String author = toCreate.getAuthorFullName();
|
String author = toCreate.getAuthorFullName();
|
||||||
|
@ -343,7 +291,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
datasetUrl,
|
datasetUrl,
|
||||||
datasetId,
|
datasetId,
|
||||||
toCreate.getTitle(),
|
toCreate.getTitle(),
|
||||||
aslSession.getUserFullName(),
|
Utils.getCurrentUser(getThreadLocalRequest()).getFullname(),
|
||||||
userName,
|
userName,
|
||||||
utils,
|
utils,
|
||||||
organizationNameOrId,
|
organizationNameOrId,
|
||||||
|
@ -362,7 +310,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
datasetUrl,
|
datasetUrl,
|
||||||
false, // send notification to other people
|
false, // send notification to other people
|
||||||
toCreate.getTags(),
|
toCreate.getTags(),
|
||||||
aslSession.getUserFullName()
|
Utils.getCurrentUser(getThreadLocalRequest()).getFullname()
|
||||||
);
|
);
|
||||||
threadWritePost.start();
|
threadWritePost.start();
|
||||||
|
|
||||||
|
@ -378,9 +326,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) {
|
public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) {
|
||||||
|
String username = Utils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||||
ASLSession session = getASLSession();
|
|
||||||
String username = session.getUsername();
|
|
||||||
|
|
||||||
logger.debug("Incoming request for creating new resource for dataset with id " + datasetId + " and organization name of the dataset is " + resource.getOrganizationNameDatasetParent());
|
logger.debug("Incoming request for creating new resource for dataset with id " + datasetId + " and organization name of the dataset is " + resource.getOrganizationNameDatasetParent());
|
||||||
logger.debug("Owner is " + username + " and resource is " + resource);
|
logger.debug("Owner is " + username + " and resource is " + resource);
|
||||||
|
@ -392,10 +338,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
if(username.equals(TEST_USER)){
|
|
||||||
logger.warn("SESSION EXPIRED!");
|
|
||||||
return null;
|
|
||||||
}else{
|
|
||||||
try{
|
try{
|
||||||
ResourceBean resourceBean = new ResourceBean(
|
ResourceBean resourceBean = new ResourceBean(
|
||||||
resource.getUrl(),
|
resource.getUrl(),
|
||||||
|
@ -420,7 +362,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Unable to create new resource", e);
|
logger.error("Unable to create new resource", e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
logger.debug("No resource created");
|
logger.debug("No resource created");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -437,13 +379,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
return deleted;
|
return deleted;
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
ASLSession session = getASLSession();
|
String username = Utils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||||
String username = session.getUsername();
|
|
||||||
|
|
||||||
if(username.equals(TEST_USER)){
|
|
||||||
logger.warn("SESSION EXPIRED!");
|
|
||||||
return deleted;
|
|
||||||
}else{
|
|
||||||
try{
|
try{
|
||||||
// get the scope in which we should discover the ckan instance given the organization name in which the dataset was created
|
// get the scope in which we should discover the ckan instance given the organization name in which the dataset was created
|
||||||
String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent());
|
String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent());
|
||||||
|
@ -458,7 +394,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
logger.error("Error while trying to delete resource described by " + resource, e);
|
logger.error("Error while trying to delete resource described by " + resource, e);
|
||||||
}
|
}
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +406,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
try{
|
try{
|
||||||
String evaluatedScope = getScopeFromOrgName(orgName);
|
String evaluatedScope = getScopeFromOrgName(orgName);
|
||||||
logger.debug("Evaluated scope is " + evaluatedScope);
|
logger.debug("Evaluated scope is " + evaluatedScope);
|
||||||
toReturn = Utils.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest().getSession(), getASLSession());
|
toReturn = Utils.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest());
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Failed to retrieve profiles for scope coming from organization name " + orgName, e);
|
logger.error("Failed to retrieve profiles for scope coming from organization name " + orgName, e);
|
||||||
}
|
}
|
||||||
|
@ -484,7 +420,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
if(title == null || title.isEmpty())
|
if(title == null || title.isEmpty())
|
||||||
return true; // it's an error somehow
|
return true; // it's an error somehow
|
||||||
try{
|
try{
|
||||||
String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
String scope = Utils.getScopeFromClientUrl(getThreadLocalRequest());
|
||||||
String idFromTitle = org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.fromProductTitleToName(title);
|
String idFromTitle = org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.fromProductTitleToName(title);
|
||||||
return getCatalogue(scope).existProductWithNameOrId(idFromTitle);
|
return getCatalogue(scope).existProductWithNameOrId(idFromTitle);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
@ -564,22 +500,16 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
@Override
|
@Override
|
||||||
public List<GroupBean> getUserGroups() {
|
public List<GroupBean> getUserGroups() {
|
||||||
|
|
||||||
ASLSession session = getASLSession();
|
|
||||||
List<GroupBean> toReturn = new ArrayList<GroupBean>();
|
List<GroupBean> toReturn = new ArrayList<GroupBean>();
|
||||||
|
|
||||||
if(isWithinPortal()){
|
if(isWithinPortal()){
|
||||||
String username = session.getUsername();
|
String username = Utils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||||
|
|
||||||
if(username.equals(TEST_USER)){
|
|
||||||
logger.warn("Session expired");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug("Request for user " + username + " groups");
|
logger.debug("Request for user " + username + " groups");
|
||||||
|
|
||||||
// get http session
|
// get http session
|
||||||
HttpSession httpSession = getThreadLocalRequest().getSession();
|
HttpSession httpSession = getThreadLocalRequest().getSession();
|
||||||
String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
String scope = Utils.getScopeFromClientUrl(getThreadLocalRequest());
|
||||||
|
|
||||||
// check if they are in session
|
// check if they are in session
|
||||||
String keyPerScopeGroups = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scope);
|
String keyPerScopeGroups = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scope);
|
||||||
|
|
|
@ -10,16 +10,18 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
|
||||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||||
import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem;
|
import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem;
|
||||||
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.datacatalogue.ckanutillibrary.ApplicationProfileScopePerUrlReader;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
|
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.models.RolesCkanGroupOrOrg;
|
import org.gcube.datacatalogue.ckanutillibrary.models.RolesCkanGroupOrOrg;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes;
|
import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes;
|
||||||
|
@ -46,6 +48,7 @@ import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
|
import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -72,6 +75,7 @@ public class Utils {
|
||||||
private static final String SOCIAL_SERVICE_APPLICATION_TOKEN = "2/tokens/generate-application-token/";
|
private static final String SOCIAL_SERVICE_APPLICATION_TOKEN = "2/tokens/generate-application-token/";
|
||||||
private static final String SOCIAL_SERVICE_WRITE_APPLICATION_POST = "2/posts/write-post-app/";
|
private static final String SOCIAL_SERVICE_WRITE_APPLICATION_POST = "2/posts/write-post-app/";
|
||||||
private static final String MEDIATYPE_JSON = "application/json";
|
private static final String MEDIATYPE_JSON = "application/json";
|
||||||
|
public static final String GCUBE_REQUEST_URL = "gcube-request-url";
|
||||||
|
|
||||||
/** Gets the gcube item properties.
|
/** Gets the gcube item properties.
|
||||||
*
|
*
|
||||||
|
@ -282,20 +286,22 @@ public class Utils {
|
||||||
* Retrieve the list of metadata beans
|
* Retrieve the list of metadata beans
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static List<MetaDataProfileBean> getMetadataProfilesList(String scope, HttpSession httpSession, ASLSession aslSession) {
|
public static List<MetaDataProfileBean> getMetadataProfilesList(String scope, HttpServletRequest request) {
|
||||||
|
|
||||||
List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>();
|
List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>();
|
||||||
String username = aslSession.getUsername();
|
String username = getCurrentUser(request).getUsername();
|
||||||
logger.debug("User in session is " + username);
|
logger.debug("User in session is " + username);
|
||||||
|
|
||||||
// check the scope we need to discover
|
// check the scope we need to discover
|
||||||
String scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : aslSession.getScope();
|
String scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : getCurrentContext(request, false);
|
||||||
|
|
||||||
logger.debug("Discovering into scope " + scopeInWhichDiscover);
|
logger.debug("Discovering into scope " + scopeInWhichDiscover);
|
||||||
|
|
||||||
// scope in which we need to discover
|
// scope in which we need to discover
|
||||||
String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_PROFILES_KEY, scopeInWhichDiscover);
|
String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_PROFILES_KEY, scopeInWhichDiscover);
|
||||||
|
|
||||||
|
HttpSession httpSession = request.getSession();
|
||||||
|
|
||||||
if(httpSession.getAttribute(keyPerScope) != null){
|
if(httpSession.getAttribute(keyPerScope) != null){
|
||||||
beans = (List<MetaDataProfileBean>)httpSession.getAttribute(keyPerScope);
|
beans = (List<MetaDataProfileBean>)httpSession.getAttribute(keyPerScope);
|
||||||
logger.info("List of profiles was into session");
|
logger.info("List of profiles was into session");
|
||||||
|
@ -507,4 +513,100 @@ public class Utils {
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
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,17 +0,0 @@
|
||||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
|
|
||||||
|
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Junit tests class
|
|
||||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
|
||||||
*/
|
|
||||||
public class TestClass {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUser() {
|
|
||||||
assert(new CKANPublisherServicesImpl().getDevelopmentUser().equals(CKANPublisherServicesImpl.TEST_USER));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue