The portlet now works also outside the portal with no user logged in. Of course, just the home and statistics buttons are shown. In order to make it properly working, the ckan token must be removed from the session when the user logouts from liferay

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129662 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-29 16:35:01 +00:00
parent b00f2993c4
commit 043fd0430c
7 changed files with 123 additions and 57 deletions

View File

@ -37,4 +37,10 @@ public interface GcubeCkanDataCatalogService extends RemoteService {
* @return
*/
String logoutURIFromCkan();
/**
* Check if the there is a user logged in
* @return
*/
boolean outsidePortal();
}

View File

@ -42,4 +42,7 @@ public interface GcubeCkanDataCatalogServiceAsync {
void getCkanOrganizationsNamesAndUrlsForUser(
AsyncCallback<Map<String, String>> callback);
void outsidePortal(AsyncCallback<Boolean> callback);
}

View File

@ -184,4 +184,17 @@ public class CkanMetadataManagementPanel extends FlowPanel{
insertMeta.setVisible(show);
}
/**
* Show only home/statistics buttons
*/
public void doNotUserRelatedInfo(){
insertMeta.setVisible(false);
editMeta.setVisible(false);
myDatasets.setVisible(false);
myOrganizations.setVisible(false);
myGroups.setVisible(false);
}
}

View File

@ -39,7 +39,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
private RootPanel rootPanel;
private HandlerManager eventBus;
private CkanConnectorAccessPoint ckanAccessPoint;
/**
* Instantiates a new g cube ckan data catalog panel.
*
@ -53,6 +53,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
managementPanel = new CkanMetadataManagementPanel(eventBus);
ckanOrganizationsPanel = new CkanOrganizationsPanel(this);
initPanel();
setTopPanelVisible(true);
String pathParameter = Window.Location.getParameter(GCubeCkanDataCatalog.GET_PATH_PARAMETER);
String queryParameter = Window.Location.getParameter(GCubeCkanDataCatalog.GET_QUERY_PARAMETER);
@ -71,51 +72,75 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
Window.alert("Sorry, An error occurred during contacting Gcube Ckan Data Catalogue!");
}
});
// RETRIEVE USER'S ORGANIZATIONS
GCubeCkanDataCatalog.service.getCkanOrganizationsNamesAndUrlsForUser(new AsyncCallback<Map<String,String>>() {
@Override
public void onSuccess(Map<String, String> result) {
if(result != null)
ckanOrganizationsPanel.setOrganizations(result);
}
@Override
public void onFailure(Throwable caught) {
}
});
//MANAGE CKAN MANAGEMENT PANEL ACCORDING TO MY ROLE
GCubeCkanDataCatalog.service.getMyRole(new AsyncCallback<CkanRole>() {
GCubeCkanDataCatalog.service.outsidePortal(new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
}
public void onSuccess(Boolean result) {
@Override
public void onSuccess(CkanRole result) {
if(result){
// the portlet is outside the portal and no user is logged in
// show only home and statistics
managementPanel.doNotUserRelatedInfo();
setTopPanelVisible(true);
}else{
// RETRIEVE USER'S ORGANIZATIONS
GCubeCkanDataCatalog.service.getCkanOrganizationsNamesAndUrlsForUser(new AsyncCallback<Map<String,String>>() {
@Override
public void onSuccess(Map<String, String> result) {
if(result != null)
ckanOrganizationsPanel.setOrganizations(result);
}
@Override
public void onFailure(Throwable caught) {
}
});
//MANAGE CKAN MANAGEMENT PANEL ACCORDING TO MY ROLE
GCubeCkanDataCatalog.service.getMyRole(new AsyncCallback<CkanRole>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(CkanRole result) {
switch (result) {
case ADMIN:
showEditInsertButtons(true);
break;
case EDITOR:
showEditInsertButtons(true);
break;
case MEMBER:
showEditInsertButtons(false);
break;
case SYSADMIN:
showEditInsertButtons(true);
break;
default:
break;
}
}
});
switch (result) {
case ADMIN:
showEditInsertButtons(true);
break;
case EDITOR:
showEditInsertButtons(true);
break;
case MEMBER:
showEditInsertButtons(false);
break;
case SYSADMIN:
showEditInsertButtons(true);
break;
default:
break;
}
}
@Override
public void onFailure(Throwable caught) {
// the portlet is outside the portal and no user is logged in
// show only home and statistics
managementPanel.doNotUserRelatedInfo();
}
});
@ -156,7 +181,6 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
public void setTopPanelVisible(boolean bool){
managementPanel.setVisible(bool);
updateSize();
}
/**
@ -212,12 +236,12 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
GWT.log("New iFrame size w: "+rootWidth + " h: "+rootHeight);
this.setSize(rootWidth+"px",rootHeight+"px");
int height = rootHeight - getTopPanelHeight();
// if(height<2000)
// height = 2000;
// if(height<2000)
// height = 2000;
if(ckanFramePanel.getFrame()!=null){
ckanFramePanel.getFrame().setSize(rootWidth+"px", height+"px");
int newH = managementPanel!=null && managementPanel.getCurrentHeight()>0?managementPanel.getOffsetHeight()+height:height;
// managementPanel.setHeight(height+50+"px");
// managementPanel.setHeight(height+50+"px");
this.setHeight(newH+"px");
}
}
@ -255,9 +279,9 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
* Show the organizations panel
*/
public void showOrganizations() {
ckanOrganizationsPanel.setVisible(true);
ckanFramePanel.setVisible(false);
}
}

View File

@ -39,7 +39,12 @@ public class GCubeCkanDataCatalogPortlet extends GenericPortlet{
*/
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
System.out.println("LOADING ********* FROM "+VIEW_JSP);
ScopeHelper.setContext(request, ScopeHelper.USERNAME_ATTRIBUTE);
try {
ScopeHelper.setContext(request, ScopeHelper.USERNAME_ATTRIBUTE); // <-- Static method which sets the username in the session and the scope depending on the context automatically
}
catch (Exception e) {
System.out.println("Could not initialize portlet context");
}
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP);
rd.include(request,response);
}

View File

@ -65,11 +65,10 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
private static Logger logger = LoggerFactory.getLogger(GcubeCkanDataCatalogServiceImpl.class);
private final static String DEFAULT_ROLE = "OrganizationMember";
public final static String TEST_USER = "francesco.mangiacrapa";
public final static String TEST_USER = "test.user";
public final static String TEST_SCOPE = "/gcube/devsec/devVRE";
public final static String TEST_MAIL = "francesco.mangiacrapa@isti.cnr.it";
public final static String TEST_MAIL = "test.user@test-com";
public final static String TEST_SEC_TOKEN = "4620e6d0-2313-4f48-9d54-eb3efd01a810";
// private final static String TEST_SEC_TOKEN = "f539884c-8697-4ac0-9bbf-2f4d595281f5";
public static final String CKAN_TOKEN_KEY = "ckanToken";
@ -137,10 +136,17 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
* @return the ckan connector access point
*/
private CkanConnectorAccessPoint getCkanConnectorAccessPoint(String pathInfoParameter, String queryStringParameters) {
if(outsidePortal()){
CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(getCkanUtilsObj().getCatalogueUrl());
return ckan;
}
//CKAN BASE URL
ASLSession session = getASLSession(this.getThreadLocalRequest().getSession());
GcoreEndpointReader ckanEndPoint = SessionUtil.getCkanEndPoint(session);
GcoreEndpointReader ckanEndPoint = SessionUtil.getCkanEndPoint(this.getThreadLocalRequest().getSession(), session.getScope());
String ckanConnectorBaseUrl = ckanEndPoint.getCkanResourceEntyName();
ckanConnectorBaseUrl = ckanConnectorBaseUrl.startsWith(HTTP) && !ckanConnectorBaseUrl.startsWith(HTTPS)?ckanConnectorBaseUrl.replaceFirst(HTTP, HTTPS):ckanConnectorBaseUrl;
ckanConnectorBaseUrl = ckanConnectorBaseUrl.contains(PORT_HTTP)?ckanConnectorBaseUrl.replace(PORT_HTTP, PORT_HTTPS):ckanConnectorBaseUrl;
@ -239,9 +245,8 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
user = TEST_USER;
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user);
session.setScope(TEST_SCOPE);
session.setUserEmailAddress(TEST_MAIL);
//session.setScope("/gcube/devsec/devVRE");
//session.setScope(TEST_SCOPE);
//session.setUserEmailAddress(TEST_MAIL);
return session;
} else logger.trace("user found in session "+user);
@ -397,8 +402,6 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(ckanAP.getBaseUrl());
ckan.addPathInfo(ckanConnectorLogut);
ckan.addGubeToken(ckanAP.getGcubeTokenValue());
URL url;
return ckan.buildURI();
}
@ -503,6 +506,18 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
return toReturn;
}
@Override
public boolean outsidePortal() {
HttpSession httpSession = this.getThreadLocalRequest().getSession();
ASLSession session = getASLSession(httpSession);
String username = session.getUsername();
if(username.equals(TEST_USER))
return true;
return false;
}
/*
public static void main(String[] args) {

View File

@ -32,13 +32,13 @@ public class SessionUtil {
* @param session the session
* @return the ckan end point
*/
public static GcoreEndpointReader getCkanEndPoint(ASLSession session){
public static GcoreEndpointReader getCkanEndPoint(HttpSession session, String scope){
GcoreEndpointReader ckanEndPoint = (GcoreEndpointReader) session.getAttribute(CKAN_END_POINT);
if(ckanEndPoint==null){
logger.debug("GcoreEndpointReader is null, instancing new..");
ckanEndPoint = new GcoreEndpointReader(session.getScope());
ckanEndPoint = new GcoreEndpointReader(scope);
session.setAttribute(CKAN_END_POINT, ckanEndPoint);
}
logger.debug("returning: "+ckanEndPoint);