Fixed invalid scope bug when creating the ckanutils library

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129452 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-27 09:10:47 +00:00
parent 5405ca56c1
commit 0ae2fe5236
2 changed files with 36 additions and 31 deletions

View File

@ -4,12 +4,6 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="workspace-sharing-widget-1.7.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/workspace-sharing-widget-TRUNK/workspace-sharing-widget-TRUNK">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="workspace-uploader-1.4.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/workspace-uploader-TRUNK/workspace-uploader-TRUNK">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="gcube-ckan-datacatalog"/>
<property name="java-output-path" value="/gcube-ckan-datacatalog/target/gcube-ckan-datacatalog-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</wb-module>

View File

@ -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);