diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index 1afbdfc..5fe3680 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -4,12 +4,6 @@
-
- uses
-
-
- uses
-
diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java
index 8689be4..b2fffab 100644
--- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java
@@ -46,7 +46,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
private static final String HTTPS = "https";
private static final String HTTP = "http";
public static String CKANCONNECTORCONTEXT = "CkanConnectorContext";
-// public static String CKANHIDEHEADER = "CkanHideHeader";
+ // public static String CKANHIDEHEADER = "CkanHideHeader";
public static String CKANCONNECTORLOGOUT = "CkanConnectorLogout";
public static final String USERNAME_ATTRIBUTE = ScopeHelper.USERNAME_ATTRIBUTE;
private static Logger logger = LoggerFactory.getLogger(GcubeCkanDataCatalogServiceImpl.class);
@@ -63,21 +63,25 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
// ckan utils methods
private CKanUtilsImpl instance;
- /* (non-Javadoc)
- * @see javax.servlet.GenericServlet#init()
+ /**
+ * Since it needs the scope, we need to check if it is null or not
+ * @return
*/
- @Override
- public void init(){
+ private CKanUtilsImpl getCkanUtilsObj(){
- // retrieve ckan information
- try{
- String currentScope = ScopeProvider.instance.get();
- instance = new CKanUtilsImpl(currentScope);
- }catch(Exception e){
- logger.error("Unable to retrieve ckan information");
+ if(instance == null){
+ // retrieve ckan information
+ try{
+ String currentScope = ScopeProvider.instance.get();
+ logger.debug("Scope is " + currentScope);
+ instance = new CKanUtilsImpl(currentScope);
+ }catch(Exception e){
+ logger.error("Unable to retrieve ckan information", e);
+ }
}
- }
+ return instance;
+ }
/* (non-Javadoc)
* @see org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService#getCKanConnector(java.lang.String, java.lang.String)
@@ -250,7 +254,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
return CkanRole.ADMIN;
}
// first of all, check if the user is a sysadmin in the catalog (in this case he can do everything)
- boolean isSysAdmin = instance.isSysAdmin(username, getUserCKanTokenFromSession());
+ boolean isSysAdmin = getCkanUtilsObj().isSysAdmin(username, getUserCKanTokenFromSession());
if(isSysAdmin){
@@ -287,7 +291,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
}
// with this invocation, we check if the role is present in ckan and if it is not it will be added
- boolean res = instance.checkRole(username, groupName, correspondentRoleToCheck);
+ boolean res = getCkanUtilsObj().checkRole(username, groupName, correspondentRoleToCheck);
if(res)
return reMapRole(mainRole);
@@ -342,18 +346,25 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
String username = session.getUsername();
logger.debug("User in session is " + username);
- String token = null;
- if(this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY) != null)
- token = (String)this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY);
- else{
+ try{
- token = instance.getApiKeyFromUsername(username);
- this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token);
- logger.debug("Ckan token has been set for user " + username);
+ String token = null;
+ if(this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY) != null)
+ token = (String)this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY);
+ else{
+
+ token = getCkanUtilsObj().getApiKeyFromUsername(username);
+ this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token);
+ logger.debug("Ckan token has been set for user " + username);
+ }
+
+ logger.debug("Found ckan token " + token + " for user " + username);
+ return token;
+
+ }catch(Exception e){
+ logger.error("Error while retrieving the key" , e);
}
-
- logger.debug("Found ckan token " + token + " for user " + username);
- return token;
+ return null;
}
@@ -367,7 +378,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
ASLSession session = getASLSession(httpSession);
String username = session.getUsername();
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession());
-// String token = getGcubeSecurityToken();
+ // String token = getGcubeSecurityToken();
logger.info("Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue());
String ckanConnectorLogut = getServletContext().getInitParameter(CKANCONNECTORLOGOUT);