Ckan information are now stored into http session and are associated to the scope
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129835 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
86f252b3a3
commit
37087d2d4f
|
@ -269,6 +269,9 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
String username = session.getUsername();
|
String username = session.getUsername();
|
||||||
String groupName = session.getGroupName(); // e.g. devVRE
|
String groupName = session.getGroupName(); // e.g. devVRE
|
||||||
|
|
||||||
|
// get key per scope
|
||||||
|
String keyPerScope = concatenateSessionKeyScope(CKAN_HIGHEST_ROLE, session.getScope());
|
||||||
|
|
||||||
// check if session expired
|
// check if session expired
|
||||||
if(username.equals(TEST_USER)){
|
if(username.equals(TEST_USER)){
|
||||||
|
|
||||||
|
@ -276,9 +279,9 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
// check into session
|
// check into session
|
||||||
if(session.getAttribute(CKAN_HIGHEST_ROLE) != null){
|
if(httpSession.getAttribute(keyPerScope) != null){
|
||||||
|
|
||||||
toReturn = (CkanRole)session.getAttribute(CKAN_HIGHEST_ROLE);
|
toReturn = (CkanRole)httpSession.getAttribute(keyPerScope);
|
||||||
logger.info("Found user role into session " + toReturn + " and it is going to be returned");
|
logger.info("Found user role into session " + toReturn + " and it is going to be returned");
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
@ -291,13 +294,13 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
if(isSysAdmin){
|
if(isSysAdmin){
|
||||||
|
|
||||||
logger.info("The user is a sysadmin of the catalog -> he can edit/add");
|
logger.info("The user is a sysadmin of the catalog -> he can edit/add");
|
||||||
session.setAttribute(CKAN_HIGHEST_ROLE, CkanRole.SYSADMIN);
|
httpSession.setAttribute(keyPerScope, CkanRole.SYSADMIN);
|
||||||
toReturn = CkanRole.SYSADMIN;
|
toReturn = CkanRole.SYSADMIN;
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
toReturn = UserUtil.getHighestRole(currentScope, username, groupName, ckanUtils);
|
toReturn = UserUtil.getHighestRole(currentScope, username, groupName, ckanUtils);
|
||||||
session.setAttribute(CKAN_HIGHEST_ROLE, toReturn);
|
httpSession.setAttribute(keyPerScope, toReturn);
|
||||||
logger.info("Set role " + toReturn + " into session for user " + username);
|
logger.info("Set role " + toReturn + " into session for user " + username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,11 +310,9 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
// 3) metadata profiles
|
// 3) metadata profiles
|
||||||
// In this way the publish widget can simply retrieve those information from the ASL session
|
// In this way the publish widget can simply retrieve those information from the ASL session
|
||||||
if(!toReturn.equals(CkanRole.MEMBER)){
|
if(!toReturn.equals(CkanRole.MEMBER)){
|
||||||
|
UserUtil.getLicenses(httpSession, username, concatenateSessionKeyScope(CKAN_LICENSES_KEY, currentScope), ckanUtils);
|
||||||
UserUtil.getLicenses(session, CKAN_LICENSES_KEY, ckanUtils);
|
UserUtil.getUserOrganizationsList(httpSession, username, concatenateSessionKeyScope(CKAN_ORGANIZATIONS_PUBLISH_KEY, currentScope), ckanUtils, getUserCKanTokenFromSession());
|
||||||
UserUtil.getUserOrganizationsList(session, CKAN_ORGANIZATIONS_PUBLISH_KEY, ckanUtils, getUserCKanTokenFromSession());
|
UserUtil.getMetadataProfilesList(httpSession, username, concatenateSessionKeyScope(CKAN_PROFILES_KEY, currentScope), ckanUtils);
|
||||||
UserUtil.getMetadataProfilesList(session, CKAN_PROFILES_KEY, ckanUtils);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,8 +336,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current user's token.
|
* Get current user's token
|
||||||
*
|
|
||||||
* @return String the ckan user's token
|
* @return String the ckan user's token
|
||||||
*/
|
*/
|
||||||
private String getUserCKanTokenFromSession(){
|
private String getUserCKanTokenFromSession(){
|
||||||
|
@ -348,9 +348,14 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
token = TEST_SEC_TOKEN;
|
token = TEST_SEC_TOKEN;
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
// store info in the http session
|
||||||
ASLSession session = getASLSession(httpSession);
|
HttpSession httpSession = getThreadLocalRequest().getSession();
|
||||||
String username = session.getUsername();
|
|
||||||
|
ASLSession aslSession = getASLSession(httpSession);
|
||||||
|
String username = aslSession.getUsername();
|
||||||
|
|
||||||
|
// get the key per scope
|
||||||
|
String keyPerScope = concatenateSessionKeyScope(CKAN_TOKEN_KEY, aslSession.getScope());
|
||||||
|
|
||||||
// check if session expired
|
// check if session expired
|
||||||
if(username.equals(TEST_USER)){
|
if(username.equals(TEST_USER)){
|
||||||
|
@ -361,11 +366,11 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
}else{
|
}else{
|
||||||
try{
|
try{
|
||||||
logger.debug("User in session is " + username);
|
logger.debug("User in session is " + username);
|
||||||
if(session.getAttribute(CKAN_TOKEN_KEY) != null)
|
if(httpSession.getAttribute(keyPerScope) != null)
|
||||||
token = (String)session.getAttribute(CKAN_TOKEN_KEY);
|
token = (String)httpSession.getAttribute(keyPerScope);
|
||||||
else{
|
else{
|
||||||
token = getCkanUtilsObj().getApiKeyFromUsername(username);
|
token = getCkanUtilsObj().getApiKeyFromUsername(username);
|
||||||
session.setAttribute(CKAN_TOKEN_KEY, token);
|
httpSession.setAttribute(keyPerScope, token);
|
||||||
logger.debug("Ckan token has been set for user " + username);
|
logger.debug("Ckan token has been set for user " + username);
|
||||||
}
|
}
|
||||||
logger.debug("Found ckan token " + token.substring(0, 3) + "************************" + " for user " + username);
|
logger.debug("Found ckan token " + token.substring(0, 3) + "************************" + " for user " + username);
|
||||||
|
@ -475,11 +480,13 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
ASLSession session = getASLSession(httpSession);
|
ASLSession session = getASLSession(httpSession);
|
||||||
String username = session.getUsername();
|
String username = session.getUsername();
|
||||||
|
|
||||||
|
String keyPerScope = concatenateSessionKeyScope(CKAN_ORGS_USER_KEY, session.getScope());
|
||||||
|
|
||||||
if(!username.equals(TEST_USER)){
|
if(!username.equals(TEST_USER)){
|
||||||
|
|
||||||
// check if the aslsession already has such information
|
// check if the aslsession already has such information
|
||||||
if(session.getAttribute(CKAN_ORGS_USER_KEY) != null){
|
if(httpSession.getAttribute(keyPerScope) != null){
|
||||||
toReturn = (Map<String, String>) session.getAttribute(CKAN_ORGS_USER_KEY);
|
toReturn = (Map<String, String>) httpSession.getAttribute(keyPerScope);
|
||||||
logger.debug("List of organizations was into the session " + toReturn);
|
logger.debug("List of organizations was into the session " + toReturn);
|
||||||
}else{
|
}else{
|
||||||
logger.debug("Organizations list wasn't into session, retrieving them");
|
logger.debug("Organizations list wasn't into session, retrieving them");
|
||||||
|
@ -488,7 +495,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
toReturn.put(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName());
|
toReturn.put(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName());
|
||||||
}
|
}
|
||||||
logger.debug("List of organizations to return for user " + username + " is " + toReturn);
|
logger.debug("List of organizations to return for user " + username + " is " + toReturn);
|
||||||
session.setAttribute(CKAN_ORGS_USER_KEY, toReturn);
|
httpSession.setAttribute(keyPerScope, toReturn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -516,4 +523,14 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a string made of key + scope
|
||||||
|
* @param key
|
||||||
|
* @param scope
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String concatenateSessionKeyScope(String key, String scope){
|
||||||
|
return key.concat(scope);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.CKanUtils;
|
import org.gcube.datacatalogue.ckanutillibrary.CKanUtils;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization;
|
import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization;
|
||||||
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
|
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
|
||||||
|
@ -288,12 +288,10 @@ public class UserUtil {
|
||||||
* @param ckanLicensesKey
|
* @param ckanLicensesKey
|
||||||
* @param ckanUtils
|
* @param ckanUtils
|
||||||
*/
|
*/
|
||||||
public static void getLicenses(ASLSession session, String ckanLicensesKey, CKanUtils ckanUtils) {
|
public static void getLicenses(HttpSession session, String username, String ckanLicensesKey, CKanUtils ckanUtils) {
|
||||||
|
|
||||||
try{
|
try{
|
||||||
String username = session.getUsername();
|
|
||||||
logger.debug("User in session is " + username);
|
logger.debug("User in session is " + username);
|
||||||
|
|
||||||
List<String> titlesLicenses = ckanUtils.getLicenseTitles();
|
List<String> titlesLicenses = ckanUtils.getLicenseTitles();
|
||||||
LicensesBean licensesBean = new LicensesBean(titlesLicenses);
|
LicensesBean licensesBean = new LicensesBean(titlesLicenses);
|
||||||
session.setAttribute(ckanLicensesKey, licensesBean);
|
session.setAttribute(ckanLicensesKey, licensesBean);
|
||||||
|
@ -311,12 +309,10 @@ public class UserUtil {
|
||||||
* @param ckanOrganizationsPublishKey
|
* @param ckanOrganizationsPublishKey
|
||||||
* @param ckanUtils
|
* @param ckanUtils
|
||||||
*/
|
*/
|
||||||
public static void getUserOrganizationsList(ASLSession session,
|
public static void getUserOrganizationsList(HttpSession session, String username,
|
||||||
String ckanOrganizationsPublishKey, CKanUtils ckanUtils, String token) {
|
String ckanOrganizationsPublishKey, CKanUtils ckanUtils, String token) {
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
String username = session.getUsername();
|
|
||||||
logger.debug("Request for user " + username + " organizations list");
|
logger.debug("Request for user " + username + " organizations list");
|
||||||
List<String> orgsName = new ArrayList<String>();
|
List<String> orgsName = new ArrayList<String>();
|
||||||
|
|
||||||
|
@ -358,12 +354,11 @@ public class UserUtil {
|
||||||
* @param ckanOrganizationsPublishKey
|
* @param ckanOrganizationsPublishKey
|
||||||
* @param ckanUtils
|
* @param ckanUtils
|
||||||
*/
|
*/
|
||||||
public static void getMetadataProfilesList(ASLSession session,
|
public static void getMetadataProfilesList(HttpSession session, String username,
|
||||||
String ckanProfilesKey, CKanUtils ckanUtils) {
|
String ckanProfilesKey, CKanUtils ckanUtils) {
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
String username = session.getUsername();
|
|
||||||
logger.debug("User in session is " + username);
|
logger.debug("User in session is " + username);
|
||||||
|
|
||||||
List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>();
|
List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>();
|
||||||
|
|
Loading…
Reference in New Issue