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>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>Removed ASL session dependency</Change>
|
||||
</Changeset>
|
||||
<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>
|
||||
|
|
12
pom.xml
12
pom.xml
|
@ -55,13 +55,6 @@
|
|||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>xerces</groupId>
|
||||
<artifactId>xercesImpl</artifactId>
|
||||
<version>2.9.1</version>
|
||||
<scope>provided</scope>
|
||||
<!-- put at provided for deploying -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
<artifactId>gwt-servlet</artifactId>
|
||||
|
@ -116,11 +109,6 @@
|
|||
<artifactId>portal-service</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.applicationsupportlayer</groupId>
|
||||
<artifactId>aslcore</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>social-networking-library</artifactId>
|
||||
|
|
|
@ -10,14 +10,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
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.DataCatalogueFactory;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean;
|
||||
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.widgets.ckandatapublisherwidget.client.CKanPublisherService;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads.AssociationToGroupAndNotifyThread;
|
||||
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.ResourceElementBean;
|
||||
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.model.GCubeUser;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -44,15 +43,13 @@ import eu.trentorise.opendata.jackan.model.CkanLicense;
|
|||
* Server side of the data publisher.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
@SuppressWarnings({"serial","deprecation"})
|
||||
public class CKANPublisherServicesImpl extends RemoteServiceServlet implements CKanPublisherService{
|
||||
|
||||
private static final long serialVersionUID = 7252248774050361697L;
|
||||
|
||||
// Logger
|
||||
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>
|
||||
private ConcurrentHashMap<String, String> mapOrganizationScope = new ConcurrentHashMap<String, String>();
|
||||
|
||||
|
@ -66,7 +63,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
DataCatalogue instance = null;
|
||||
String scopeInWhichDiscover = null;
|
||||
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);
|
||||
instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
|
||||
}catch(Exception e){
|
||||
|
@ -75,38 +72,14 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
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)
|
||||
* @param username
|
||||
* @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");
|
||||
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);
|
||||
}
|
||||
else{
|
||||
orgsName = Utils.getUserOrganizationsListAdminEditor(scope, username, getASLSession().getGroupName(), this);
|
||||
orgsName = Utils.getUserOrganizationsListAdminEditor(scope, username, Utils.getGroupFromScope(scope).getGroupName(), this);
|
||||
httpSession.setAttribute(keyPerScope, 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) {
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
@ -157,66 +131,47 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
@Override
|
||||
public LicensesBean getLicenses() {
|
||||
|
||||
ASLSession session = getASLSession();
|
||||
String username = session.getUsername();
|
||||
// get http session
|
||||
HttpSession httpSession = getThreadLocalRequest().getSession();
|
||||
String scope = Utils.getScopeFromClientUrl(getThreadLocalRequest());
|
||||
logger.info("Request for CKAN licenses for scope " + scope);
|
||||
String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope);
|
||||
|
||||
if(username.equals(TEST_USER)){
|
||||
|
||||
logger.warn("Session expired, returning null token");
|
||||
return null;
|
||||
|
||||
}else{
|
||||
|
||||
// get http session
|
||||
HttpSession httpSession = getThreadLocalRequest().getSession();
|
||||
String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
||||
logger.info("Request for CKAN licenses for scope " + scope);
|
||||
String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope);
|
||||
|
||||
LicensesBean licensesBean = null;
|
||||
if(httpSession.getAttribute(keyPerScope) != null){
|
||||
licensesBean = (LicensesBean)httpSession.getAttribute(keyPerScope);
|
||||
logger.info("List of licenses was into session");
|
||||
}
|
||||
else{
|
||||
List<CkanLicense> titlesLicenses = getCatalogue(scope).getLicenses();
|
||||
List<String> titles = new ArrayList<String>();
|
||||
List<String> urls = new ArrayList<String>();
|
||||
for (CkanLicense license : titlesLicenses) {
|
||||
titles.add(license.getTitle());
|
||||
String url = (license.getUrl() != null && !license.getUrl().isEmpty()) ? license.getUrl() : "";
|
||||
urls.add(url);
|
||||
}
|
||||
licensesBean = new LicensesBean(titles, urls);
|
||||
httpSession.setAttribute(keyPerScope, licensesBean);
|
||||
logger.info("List of licenses has been saved into session");
|
||||
}
|
||||
|
||||
return licensesBean;
|
||||
LicensesBean licensesBean = null;
|
||||
if(httpSession.getAttribute(keyPerScope) != null){
|
||||
licensesBean = (LicensesBean)httpSession.getAttribute(keyPerScope);
|
||||
logger.info("List of licenses was into session");
|
||||
}
|
||||
else{
|
||||
List<CkanLicense> titlesLicenses = getCatalogue(scope).getLicenses();
|
||||
List<String> titles = new ArrayList<String>();
|
||||
List<String> urls = new ArrayList<String>();
|
||||
for (CkanLicense license : titlesLicenses) {
|
||||
titles.add(license.getTitle());
|
||||
String url = (license.getUrl() != null && !license.getUrl().isEmpty()) ? license.getUrl() : "";
|
||||
urls.add(url);
|
||||
}
|
||||
licensesBean = new LicensesBean(titles, urls);
|
||||
httpSession.setAttribute(keyPerScope, licensesBean);
|
||||
logger.info("List of licenses has been saved into session");
|
||||
}
|
||||
|
||||
return licensesBean;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatasetMetadataBean getDatasetBean(String folderId){
|
||||
|
||||
DatasetMetadataBean bean = null;
|
||||
|
||||
ASLSession aslSession = getASLSession();
|
||||
String userName = aslSession.getUsername();
|
||||
String userName = Utils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
|
||||
logger.info("DatasetBean request for " + folderId + " and " + userName);
|
||||
|
||||
if(isWithinPortal()){
|
||||
try{
|
||||
|
||||
// check if session expired
|
||||
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);
|
||||
String scope = Utils.getScopeFromClientUrl(getThreadLocalRequest());
|
||||
|
||||
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.setMaintainer("Costantino Perciante");
|
||||
bean.setMaintainerEmail("costantino.perciante@isti.cnr.it");
|
||||
bean.setOrganizationList(getUserOrganizationsListAdmin(userName, TEST_SCOPE));
|
||||
bean.setOrganizationList(getUserOrganizationsListAdmin(userName, Utils.getCurrentContext(getThreadLocalRequest(), true)));
|
||||
bean.setOwnerIdentifier(userName);
|
||||
|
||||
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);
|
||||
|
||||
ASLSession aslSession = getASLSession();
|
||||
String userName = aslSession.getUsername();
|
||||
String userName = Utils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
|
||||
try{
|
||||
|
||||
// check if session expired
|
||||
if(userName.equals(TEST_USER)){
|
||||
logger.warn("SESSION EXPIRED");
|
||||
return null;
|
||||
}
|
||||
|
||||
String title = toCreate.getTitle();
|
||||
String organizationNameOrId = toCreate.getSelectedOrganization();
|
||||
String author = toCreate.getAuthorFullName();
|
||||
|
@ -343,7 +291,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
datasetUrl,
|
||||
datasetId,
|
||||
toCreate.getTitle(),
|
||||
aslSession.getUserFullName(),
|
||||
Utils.getCurrentUser(getThreadLocalRequest()).getFullname(),
|
||||
userName,
|
||||
utils,
|
||||
organizationNameOrId,
|
||||
|
@ -362,7 +310,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
datasetUrl,
|
||||
false, // send notification to other people
|
||||
toCreate.getTags(),
|
||||
aslSession.getUserFullName()
|
||||
Utils.getCurrentUser(getThreadLocalRequest()).getFullname()
|
||||
);
|
||||
threadWritePost.start();
|
||||
|
||||
|
@ -378,9 +326,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
|
||||
@Override
|
||||
public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) {
|
||||
|
||||
ASLSession session = getASLSession();
|
||||
String username = session.getUsername();
|
||||
String username = Utils.getCurrentUser(getThreadLocalRequest()).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("Owner is " + username + " and resource is " + resource);
|
||||
|
@ -392,35 +338,31 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
|
||||
}else{
|
||||
|
||||
if(username.equals(TEST_USER)){
|
||||
logger.warn("SESSION EXPIRED!");
|
||||
return null;
|
||||
}else{
|
||||
try{
|
||||
ResourceBean resourceBean = new ResourceBean(
|
||||
resource.getUrl(),
|
||||
resource.getName(),
|
||||
resource.getDescription(),
|
||||
null,
|
||||
username,
|
||||
datasetId,
|
||||
null);
|
||||
try{
|
||||
ResourceBean resourceBean = new ResourceBean(
|
||||
resource.getUrl(),
|
||||
resource.getName(),
|
||||
resource.getDescription(),
|
||||
null,
|
||||
username,
|
||||
datasetId,
|
||||
null);
|
||||
|
||||
// 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());
|
||||
DataCatalogue catalogue = getCatalogue(scope);
|
||||
String resourceId = catalogue.addResourceToDataset(resourceBean, catalogue.getApiKeyFromUsername(username));
|
||||
// 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());
|
||||
DataCatalogue catalogue = getCatalogue(scope);
|
||||
String resourceId = catalogue.addResourceToDataset(resourceBean, catalogue.getApiKeyFromUsername(username));
|
||||
|
||||
if(resourceId != null){
|
||||
logger.debug("Resource " + resource.getName() + " is now available");
|
||||
// set its id and turn it to the client
|
||||
resource.setOriginalIdInWorkspace(resourceId);
|
||||
return resource;
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to create new resource", e);
|
||||
if(resourceId != null){
|
||||
logger.debug("Resource " + resource.getName() + " is now available");
|
||||
// set its id and turn it to the client
|
||||
resource.setOriginalIdInWorkspace(resourceId);
|
||||
return resource;
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to create new resource", e);
|
||||
}
|
||||
|
||||
logger.debug("No resource created");
|
||||
return null;
|
||||
}
|
||||
|
@ -437,28 +379,22 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
return deleted;
|
||||
}else{
|
||||
|
||||
ASLSession session = getASLSession();
|
||||
String username = session.getUsername();
|
||||
|
||||
if(username.equals(TEST_USER)){
|
||||
logger.warn("SESSION EXPIRED!");
|
||||
return deleted;
|
||||
}else{
|
||||
try{
|
||||
// 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());
|
||||
DataCatalogue catalogue = getCatalogue(scope);
|
||||
deleted = catalogue.
|
||||
deleteResourceFromDataset(resource.getOriginalIdInWorkspace(), catalogue.getApiKeyFromUsername(username));
|
||||
if(deleted){
|
||||
logger.info("Resource described by " + resource + " deleted");
|
||||
}else
|
||||
logger.error("Resource described by " + resource + " NOT deleted");
|
||||
}catch(Exception e){
|
||||
logger.error("Error while trying to delete resource described by " + resource, e);
|
||||
}
|
||||
return deleted;
|
||||
String username = Utils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
try{
|
||||
// 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());
|
||||
DataCatalogue catalogue = getCatalogue(scope);
|
||||
deleted = catalogue.
|
||||
deleteResourceFromDataset(resource.getOriginalIdInWorkspace(), catalogue.getApiKeyFromUsername(username));
|
||||
if(deleted){
|
||||
logger.info("Resource described by " + resource + " deleted");
|
||||
}else
|
||||
logger.error("Resource described by " + resource + " NOT deleted");
|
||||
}catch(Exception e){
|
||||
logger.error("Error while trying to delete resource described by " + resource, e);
|
||||
}
|
||||
return deleted;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -470,7 +406,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
try{
|
||||
String evaluatedScope = getScopeFromOrgName(orgName);
|
||||
logger.debug("Evaluated scope is " + evaluatedScope);
|
||||
toReturn = Utils.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest().getSession(), getASLSession());
|
||||
toReturn = Utils.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest());
|
||||
}catch(Exception 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())
|
||||
return true; // it's an error somehow
|
||||
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);
|
||||
return getCatalogue(scope).existProductWithNameOrId(idFromTitle);
|
||||
}catch(Exception e){
|
||||
|
@ -564,22 +500,16 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
@Override
|
||||
public List<GroupBean> getUserGroups() {
|
||||
|
||||
ASLSession session = getASLSession();
|
||||
List<GroupBean> toReturn = new ArrayList<GroupBean>();
|
||||
|
||||
if(isWithinPortal()){
|
||||
String username = session.getUsername();
|
||||
|
||||
if(username.equals(TEST_USER)){
|
||||
logger.warn("Session expired");
|
||||
return null;
|
||||
}
|
||||
String username = Utils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
|
||||
logger.debug("Request for user " + username + " groups");
|
||||
|
||||
// get http session
|
||||
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
|
||||
String keyPerScopeGroups = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scope);
|
||||
|
|
|
@ -10,16 +10,18 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
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.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
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.datacatalogue.ckanutillibrary.ApplicationProfileScopePerUrlReader;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.models.RolesCkanGroupOrOrg;
|
||||
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.model.GCubeGroup;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
|
||||
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_WRITE_APPLICATION_POST = "2/posts/write-post-app/";
|
||||
private static final String MEDIATYPE_JSON = "application/json";
|
||||
public static final String GCUBE_REQUEST_URL = "gcube-request-url";
|
||||
|
||||
/** Gets the gcube item properties.
|
||||
*
|
||||
|
@ -282,20 +286,22 @@ public class Utils {
|
|||
* Retrieve the list of metadata beans
|
||||
* @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>();
|
||||
String username = aslSession.getUsername();
|
||||
String username = getCurrentUser(request).getUsername();
|
||||
logger.debug("User in session is " + username);
|
||||
|
||||
// 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);
|
||||
|
||||
// scope in which we need to discover
|
||||
String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_PROFILES_KEY, scopeInWhichDiscover);
|
||||
|
||||
HttpSession httpSession = request.getSession();
|
||||
|
||||
if(httpSession.getAttribute(keyPerScope) != null){
|
||||
beans = (List<MetaDataProfileBean>)httpSession.getAttribute(keyPerScope);
|
||||
logger.info("List of profiles was into session");
|
||||
|
@ -507,4 +513,100 @@ public class Utils {
|
|||
}
|
||||
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