Added fix to save Ckan EndPoint and AccessPoint in session

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@130528 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-07-19 10:31:53 +00:00
parent 15afca7aab
commit d593a9c963
3 changed files with 37 additions and 18 deletions

View File

@ -38,13 +38,14 @@ public class CkanLogout extends HttpServlet {
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
logger.info("CkanLogout performing...");
HttpSession httpSession = req.getSession();
ASLSession session = getASLSession(httpSession);
String scope = session.getScope();
String username = session.getUsername();
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(req.getSession());
logger.info("CkanLogout performing...");
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(req.getSession(), scope);
// String token = getGcubeSecurityToken();
logger.info("Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue());
logger.info("Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue() +", the scope is: "+scope);
String ckanConnectorLogut = getServletContext().getInitParameter(GcubeCkanDataCatalogServiceImpl.CKANCONNECTORLOGOUT);
logger.debug(GcubeCkanDataCatalogServiceImpl.CKANCONNECTORLOGOUT + " is: "+ckanConnectorLogut);

View File

@ -109,7 +109,8 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
}
CkanConnectorAccessPoint ckAP = getCkanConnectorAccessPoint(pathInfoParameter, queryStringParameters);
SessionUtil.saveCkanAccessPoint(this.getThreadLocalRequest().getSession(), ckAP);
ASLSession aslSession = getASLSession(this.getThreadLocalRequest().getSession());
SessionUtil.saveCkanAccessPoint(this.getThreadLocalRequest().getSession(), aslSession.getScope(), ckAP);
logger.info("Builded URI to CKAN Connector: "+ckAP.buildURI());
logger.debug("returning ckanConnectorUri: "+ckAP);
return ckAP;
@ -133,10 +134,8 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
private CkanConnectorAccessPoint getCkanConnectorAccessPoint(String pathInfoParameter, String queryStringParameters) throws Exception {
if(outsidePortal()){
CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(getCkanUtilsObj().getCatalogueUrl(),"");
return ckan;
}
//CKAN BASE URL
@ -394,7 +393,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
HttpSession httpSession = this.getThreadLocalRequest().getSession();
ASLSession session = getASLSession(httpSession);
String username = session.getUsername();
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession());
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession(), session.getScope());
// String token = getGcubeSecurityToken();
logger.info("Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue());
@ -415,7 +414,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
HttpSession httpSession = this.getThreadLocalRequest().getSession();
ASLSession session = getASLSession(httpSession);
String username = session.getUsername();
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession());
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession(), session.getScope());
// String token = getGcubeSecurityToken();
logger.info("Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue());

View File

@ -29,16 +29,20 @@ public class SessionUtil {
* Gets the ckan end point.
*
* @param session the session
* @param scope the scope
* @return the ckan end point
* @throws Exception the exception
*/
public static GcoreEndpointReader getCkanEndPoint(HttpSession session, String scope) throws Exception{
GcoreEndpointReader ckanEndPoint = (GcoreEndpointReader) session.getAttribute(CKAN_END_POINT);
String key = getKeyForSession(CKAN_END_POINT, scope);
logger.debug("Getting GcoreEndpointReader for key: "+key +", from HttpSession");
GcoreEndpointReader ckanEndPoint = (GcoreEndpointReader) session.getAttribute(key);
logger.debug("GcoreEndpointReader for key: "+key +", found in session? "+(ckanEndPoint!=null));
if(ckanEndPoint==null){
logger.debug("GcoreEndpointReader is null, instancing new..");
ckanEndPoint = new GcoreEndpointReader(scope);
session.setAttribute(CKAN_END_POINT, ckanEndPoint);
session.setAttribute(key, ckanEndPoint);
}
logger.debug("returning: "+ckanEndPoint);
return ckanEndPoint;
@ -60,23 +64,38 @@ public class SessionUtil {
}
/**
* @param ckAP
* Save ckan access point.
*
* @param session the session
* @param scope the scope
* @param ckAP the ck ap
*/
public static void saveCkanAccessPoint(HttpSession session, CkanConnectorAccessPoint ckAP) {
session.setAttribute(CKAN_ACCESS_POINT, ckAP);
public static void saveCkanAccessPoint(HttpSession session, String scope, CkanConnectorAccessPoint ckAP) {
String key = getKeyForSession(CKAN_ACCESS_POINT, scope);
session.setAttribute(key, ckAP);
}
/**
* Gets the key for session.
*
* @param key the key
* @param scope the scope
* @return the key for session
*/
private static String getKeyForSession(String key, String scope){
return key+scope;
}
/**
* Gets the ckan access point.
*
* @param session the session
* @param scope the scope
* @return the ckan access point
*/
public static CkanConnectorAccessPoint getCkanAccessPoint(HttpSession session) {
return (CkanConnectorAccessPoint) session.getAttribute(CKAN_ACCESS_POINT);
public static CkanConnectorAccessPoint getCkanAccessPoint(HttpSession session, String scope) {
String key = getKeyForSession(CKAN_ACCESS_POINT, scope);
return (CkanConnectorAccessPoint) session.getAttribute(key);
}