minor fix for ckan roles handling
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@129675 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
77ad08ddc6
commit
30050a874b
|
@ -114,7 +114,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
|
||||
// for the data catalogue
|
||||
public static final String CKAN_TOKEN_KEY = "ckanToken";
|
||||
public static final String CKAN_ROLE = "ckanRole"; // editor, admin, member
|
||||
public static final String CKAN_ROLE = "ckanRole"; // a true value means the user has editor/admin role, false means member
|
||||
|
||||
// ckan utils methods
|
||||
private CKanUtilsImpl instance;
|
||||
|
@ -3436,10 +3436,15 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
|
||||
if(!isWithinPortal()){
|
||||
workspaceLogger.warn("OUT FROM PORTAL DETECTED RETURNING TRUE");
|
||||
asl.setAttribute(CKAN_ROLE, "editor");
|
||||
asl.setAttribute(CKAN_ROLE, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(username.equals(WsUtil.TEST_USER)){
|
||||
workspaceLogger.warn("Session expired");
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if this information was already into the ASL Session (true means the user has at least in one org
|
||||
// the role editor/admin), false that he is just a member so he cannot publish
|
||||
Boolean role = (Boolean)asl.getAttribute(CKAN_ROLE);
|
||||
|
@ -3449,9 +3454,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
return role;
|
||||
else{
|
||||
|
||||
CKanUtilsImpl ckanUtils = getCkanUtils();
|
||||
|
||||
try{
|
||||
// first of all, check if the user is a sysadmin in the catalog (in this case he can do everything)
|
||||
boolean isSysAdmin = getCkanUtils().isSysAdmin(username, getUserCKanTokenFromSession());
|
||||
boolean isSysAdmin = ckanUtils.isSysAdmin(username, getUserCKanTokenFromSession());
|
||||
|
||||
if(isSysAdmin){
|
||||
|
||||
|
@ -3506,7 +3513,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
continue;
|
||||
|
||||
// with this invocation, we check if the role is present in ckan and if it is not it will be added
|
||||
toReturn &= getCkanUtils().checkRole(username, groupName, correspondentRoleToCheck);
|
||||
toReturn &= ckanUtils.checkRole(username, groupName, correspondentRoleToCheck);
|
||||
|
||||
}
|
||||
|
||||
|
@ -3536,25 +3543,22 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
* @return String the ckan user's token
|
||||
*/
|
||||
private String getUserCKanTokenFromSession(){
|
||||
|
||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||
ASLSession session = WsUtil.getAslSession(httpSession);
|
||||
String username = session.getUsername();
|
||||
workspaceLogger.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);
|
||||
if(session.getAttribute(CKAN_TOKEN_KEY) != null)
|
||||
token = (String)session.getAttribute(CKAN_TOKEN_KEY);
|
||||
else{
|
||||
|
||||
token = getCkanUtils().getApiKeyFromUsername(username);
|
||||
this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token);
|
||||
session.setAttribute(CKAN_TOKEN_KEY, token);
|
||||
workspaceLogger.debug("Ckan token has been set for user " + username);
|
||||
}
|
||||
|
||||
workspaceLogger.debug("Found ckan token " + token + " for user " + username);
|
||||
workspaceLogger.debug("Found ckan token " + token.substring(0, 3) + "********************" + " for user " + username);
|
||||
return token;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue