nikolas.laskaris 2016-09-21 15:31:25 +00:00
parent 1c9c4041c7
commit 15d687462e
5 changed files with 961 additions and 870 deletions

View File

@ -74,8 +74,8 @@
<dependency> <dependency>
<groupId>org.gcube.resources</groupId> <groupId>org.gcube.resources</groupId>
<artifactId>registry-publisher</artifactId> <artifactId>registry-publisher</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version> <!-- <version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version> -->
<!-- <version>[1.2.4-SNAPSHOT, 2.0.0-SNAPSHOT)</version> --> <version>[1.2.4-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<!-- changed from version 1.1.0-SNAPSHOT. If this change introduces problems, please revert --> <!-- changed from version 1.1.0-SNAPSHOT. If this change introduces problems, please revert -->
</dependency> </dependency>

View File

@ -66,6 +66,24 @@ public class ASLSession{
// ACCESS LOGGER // ACCESS LOGGER
AccessLogger accessLogger = AccessLogger.getAccessLogger(); AccessLogger accessLogger = AccessLogger.getAccessLogger();
/**
* A constructor based on the user and a HttpSession
* @param session the HttpSession
* @param user the username
*/
ASLSession(String externalSessionId, String user)
{
//OLD, for backwards compatibility
innerSession = new HashMap<String, Object>();
notifiers = new HashMap<String, Notifier>();
lastUsedTime = System.currentTimeMillis();
username = user;
this.externalSessionID = externalSessionId;
groupModel = new ASLGroupModel();
}
/** /**
* A constructor based on the user and a HttpSession * A constructor based on the user and a HttpSession
* @param session the HttpSession * @param session the HttpSession
@ -73,23 +91,18 @@ public class ASLSession{
*/ */
ASLSession(HttpSession session, String user) ASLSession(HttpSession session, String user)
{ {
this(session.getId(), user);
//NEW //NEW
this.session = session;
session.setAttribute("notifiers", new HashMap<String, Notifier>()); session.setAttribute("notifiers", new HashMap<String, Notifier>());
session.setAttribute("lastUsedTime", System.currentTimeMillis()); session.setAttribute("lastUsedTime", System.currentTimeMillis());
session.setAttribute("username", user); session.setAttribute("username", user);
session.setAttribute("groupModel", new ASLGroupModel()); session.setAttribute("groupModel", new ASLGroupModel());
this.session = session;
//OLD, for backwards compatibility
innerSession = new HashMap<String, Object>();
notifiers = new HashMap<String, Notifier>();
lastUsedTime = System.currentTimeMillis();
username = user;
externalSessionID = session.getId();
groupModel = new ASLGroupModel();
} }
private void initializeAttributes() { private void initializeAttributes() {
if(session != null) {
//NEW WAY
Enumeration <String> sessAttrNames = session.getAttributeNames(); Enumeration <String> sessAttrNames = session.getAttributeNames();
while(sessAttrNames.hasMoreElements()){ while(sessAttrNames.hasMoreElements()){
String key = sessAttrNames.nextElement(); String key = sessAttrNames.nextElement();
@ -98,6 +111,8 @@ public class ASLSession{
break; break;
} }
} }
}
else {
//for backwards compatibility //for backwards compatibility
for (String key:innerSession.keySet()) { for (String key:innerSession.keySet()) {
if (key.equals("collectionsPresentableFields") || key.equals(SessionConstants.collectionsHierarchy)) { if (key.equals("collectionsPresentableFields") || key.equals(SessionConstants.collectionsHierarchy)) {
@ -106,6 +121,7 @@ public class ASLSession{
} }
} }
} }
}
/** /**
* It looks into tomcat's web.xml file for session-timeout value. * It looks into tomcat's web.xml file for session-timeout value.
@ -118,11 +134,10 @@ public class ASLSession{
public long getSessionTimeoutMillis() throws IOException, ParserConfigurationException { public long getSessionTimeoutMillis() throws IOException, ParserConfigurationException {
//NEW WAY, BASED ON HTTPSESSION //NEW WAY, BASED ON HTTPSESSION
if(session != null)
return session.getMaxInactiveInterval() * 1000; return session.getMaxInactiveInterval() * 1000;
else{
//OLD WAY TO CHECK THE SESSION TIMEOUT (WILL BECOME DEPRECATED). //OLD WAY TO CHECK THE SESSION TIMEOUT (WILL BECOME DEPRECATED).
/*
if(sessionTimeout > 0) //means that is already set to a value ! if(sessionTimeout > 0) //means that is already set to a value !
return sessionTimeout; return sessionTimeout;
int timeoutMins; int timeoutMins;
@ -173,7 +188,7 @@ public class ASLSession{
sessionTimeout = timeoutMins * 60000; //in milliseconds sessionTimeout = timeoutMins * 60000; //in milliseconds
logger.info("Session Timeout is: " + sessionTimeout); logger.info("Session Timeout is: " + sessionTimeout);
return sessionTimeout; return sessionTimeout;
*/ }
} }
/** /**
@ -183,16 +198,20 @@ public class ASLSession{
* @return the new timeout in milliseconds * @return the new timeout in milliseconds
*/ */
public long increaseSessionTimeout(long milliseconds, boolean resetCounting){ public long increaseSessionTimeout(long milliseconds, boolean resetCounting){
if(session != null){
//NEW WAY //NEW WAY
int secs = (int)milliseconds/1000; int secs = (int)milliseconds/1000;
session.setMaxInactiveInterval(session.getMaxInactiveInterval() + secs); session.setMaxInactiveInterval(session.getMaxInactiveInterval() + secs);
return session.getMaxInactiveInterval()*1000; return session.getMaxInactiveInterval()*1000;
}
else{
//OLD WAY, for backwards compatibility //OLD WAY, for backwards compatibility
// if(resetCounting) if(resetCounting)
// lastUsedTime = System.currentTimeMillis(); lastUsedTime = System.currentTimeMillis();
// sessionTimeout += milliseconds; sessionTimeout += milliseconds;
// return sessionTimeout; return sessionTimeout;
}
} }
@ -201,7 +220,7 @@ public class ASLSession{
*/ */
public boolean isValid() public boolean isValid()
{ {
if(session != null){
//NEW WAY //NEW WAY
try { try {
session.getCreationTime(); session.getCreationTime();
@ -209,9 +228,9 @@ public class ASLSession{
return false; return false;
} }
return true; return true;
}
else{
//OLD WAY //OLD WAY
/*
long maxTime = -1; //it will never be -1 long maxTime = -1; //it will never be -1
try { try {
maxTime = getSessionTimeoutMillis(); maxTime = getSessionTimeoutMillis();
@ -220,7 +239,7 @@ public class ASLSession{
if((System.currentTimeMillis() - lastUsedTime) > maxTime) if((System.currentTimeMillis() - lastUsedTime) > maxTime)
return false; return false;
return true; return true;
*/ }
} }
/** /**
@ -231,11 +250,15 @@ public class ASLSession{
@Deprecated @Deprecated
public boolean isEmpty() public boolean isEmpty()
{ {
if(session != null){
//NEW WAY //NEW WAY
return getAttributeNames().isEmpty(); return getAttributeNames().isEmpty();
//OLD WAY, for backwards compatibility }
// lastUsedTime = System.currentTimeMillis(); else{
// return innerSession.isEmpty(); //OLD WAY
lastUsedTime = System.currentTimeMillis();
return innerSession.isEmpty();
}
} }
/** /**
@ -244,6 +267,7 @@ public class ASLSession{
*/ */
public boolean hasAttribute(String name) public boolean hasAttribute(String name)
{ {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
lastUsedTime = System.currentTimeMillis(); lastUsedTime = System.currentTimeMillis();
if(innerSession.containsKey(name)) if(innerSession.containsKey(name))
@ -254,13 +278,13 @@ public class ASLSession{
innerSession.put(name, session.getAttribute(name)); innerSession.put(name, session.getAttribute(name));
return true; return true;
} }
return false;
//NEW WAY }
// return (session.getAttribute(name)==null) ? false : true; else {
//OLD WAY, for backwards compatibility //OLD WAY, for backwards compatibility
// lastUsedTime = System.currentTimeMillis(); lastUsedTime = System.currentTimeMillis();
// return innerSession.containsKey(name); return innerSession.containsKey(name);
}
} }
/** /**
@ -268,6 +292,7 @@ public class ASLSession{
*/ */
public Set<String> getAttributeNames() public Set<String> getAttributeNames()
{ {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
Enumeration<String> names = session.getAttributeNames(); Enumeration<String> names = session.getAttributeNames();
Set<String> output = new HashSet<String>(); Set<String> output = new HashSet<String>();
@ -275,7 +300,12 @@ public class ASLSession{
output.add(names.nextElement()); output.add(names.nextElement());
output.addAll(innerSession.keySet()); output.addAll(innerSession.keySet());
return output; return output;
}
else{
//OLD WAY, for backwards compatibility
lastUsedTime = System.currentTimeMillis();
return innerSession.keySet();
}
//NEW WAY //NEW WAY
// Enumeration<String> names = session.getAttributeNames(); // Enumeration<String> names = session.getAttributeNames();
@ -284,9 +314,6 @@ public class ASLSession{
// output.add(names.nextElement()); // output.add(names.nextElement());
// return output; // return output;
//OLD WAY, for backwards compatibility
// lastUsedTime = System.currentTimeMillis();
// return innerSession.keySet();
} }
/** /**
@ -298,6 +325,7 @@ public class ASLSession{
@Deprecated @Deprecated
public Object getAttribute(String name) public Object getAttribute(String name)
{ {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
lastUsedTime = System.currentTimeMillis(); lastUsedTime = System.currentTimeMillis();
Object innerObj = innerSession.get(name); Object innerObj = innerSession.get(name);
@ -309,13 +337,14 @@ public class ASLSession{
return httpObj; return httpObj;
} }
return null; return null;
}
else {
//OLD WAY, for backwards compatibility
lastUsedTime = System.currentTimeMillis();
return innerSession.get(name);
}
//NEW WAY //NEW WAY
// return session.getAttribute(name); // return session.getAttribute(name);
//OLD WAY, for backwards compatibility
// lastUsedTime = System.currentTimeMillis();
// return innerSession.get(name);
} }
/** /**
@ -327,15 +356,20 @@ public class ASLSession{
@Deprecated @Deprecated
public void setAttribute(String name, Object value) public void setAttribute(String name, Object value)
{ {
if(session != null) {
//NEW WAY //NEW WAY
session.setAttribute(name, value); session.setAttribute(name, value);
}
// else{
//OLD WAY, for backwards compatibility //OLD WAY, for backwards compatibility
lastUsedTime = System.currentTimeMillis(); lastUsedTime = System.currentTimeMillis();
innerSession.put(name, value); innerSession.put(name, value);
// }
} }
public String getOriginalScopeName() { public String getOriginalScopeName() {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
String httpSessionScope = (String) session.getAttribute("scopeName"); String httpSessionScope = (String) session.getAttribute("scopeName");
if(scopeName != null) if(scopeName != null)
@ -345,11 +379,13 @@ public class ASLSession{
return httpSessionScope; return httpSessionScope;
} }
return null; return null;
}
else {
//OLD WAY, for backwards compatibility
return scopeName;
}
//NEW WAY //NEW WAY
//return (String) session.getAttribute("scopeName"); //return (String) session.getAttribute("scopeName");
//OLD WAY, for backwards compatibility
// return scopeName;
} }
/** /**
@ -363,20 +399,23 @@ public class ASLSession{
@Deprecated @Deprecated
public Object removeAttribute(String name) public Object removeAttribute(String name)
{ {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
lastUsedTime = System.currentTimeMillis(); lastUsedTime = System.currentTimeMillis();
Object httpAttrib = session.getAttribute(name); Object httpAttrib = session.getAttribute(name);
session.removeAttribute(name); session.removeAttribute(name);
Object innerAttrib = innerSession.remove(name); Object innerAttrib = innerSession.remove(name);
return (httpAttrib == null) ? innerAttrib : httpAttrib; return (httpAttrib == null) ? innerAttrib : httpAttrib;
}
else {
//OLD WAY, for backwards compatibility
lastUsedTime = System.currentTimeMillis();
return innerSession.remove(name);
}
//NEW WAY //NEW WAY
// Object attr = session.getAttribute(name); // Object attr = session.getAttribute(name);
// session.removeAttribute(name); // session.removeAttribute(name);
// return attr; // return attr;
//OLD WAY, for backwards compatibility
// lastUsedTime = System.currentTimeMillis();
// return innerSession.remove(name);
} }
/** /**
@ -387,12 +426,17 @@ public class ASLSession{
@Deprecated @Deprecated
public void removeAll() public void removeAll()
{ {
if(session != null) {
//NEW WAY //NEW WAY
for(String name : getAttributeNames()) for(String name : getAttributeNames())
session.removeAttribute(name); session.removeAttribute(name);
}
// else{
//OLD WAY, for backwards compatibility //OLD WAY, for backwards compatibility
lastUsedTime = System.currentTimeMillis(); lastUsedTime = System.currentTimeMillis();
innerSession.clear(); innerSession.clear();
// }
} }
public String getParentScope(){ public String getParentScope(){
@ -405,8 +449,11 @@ public class ASLSession{
*/ */
public void invalidate() public void invalidate()
{ {
if(session != null) {
//NEW WAY //NEW WAY
session.setMaxInactiveInterval(0); session.setMaxInactiveInterval(0);
}
// else {
//OLD WAY, for backwards compatibility //OLD WAY, for backwards compatibility
long maxTime = -1; //it will never be -1 long maxTime = -1; //it will never be -1
try { try {
@ -414,6 +461,7 @@ public class ASLSession{
} catch (Exception e) { e.printStackTrace();} } catch (Exception e) { e.printStackTrace();}
lastUsedTime = System.currentTimeMillis() - maxTime - 120000; // 2 minutes excessive lastUsedTime = System.currentTimeMillis() - maxTime - 120000; // 2 minutes excessive
// }
} }
@ -421,10 +469,14 @@ public class ASLSession{
* @return the session id * @return the session id
*/ */
public String getExternalSessionID() { public String getExternalSessionID() {
if(session != null) {
//NEW WAY //NEW WAY
return session.getId(); return session.getId();
}
else{
//OLD WAY //OLD WAY
// return externalSessionID; return externalSessionID;
}
} }
/** /**
@ -432,6 +484,7 @@ public class ASLSession{
*/ */
public String getUsername() { public String getUsername() {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
String httpUN = (String)session.getAttribute("username"); String httpUN = (String)session.getAttribute("username");
if(username != null) if(username != null)
@ -441,17 +494,20 @@ public class ASLSession{
return httpUN; return httpUN;
} }
return null; return null;
}
else{
//OLD WAY, for backwards compatibility
return username;
}
//NEW WAY //NEW WAY
// return (String)session.getAttribute("username"); // return (String)session.getAttribute("username");
//OLD WAY, for backwards compatibility
// return username;
} }
/** /**
* @return the scope * @return the scope
*/ */
public String getScope() { public String getScope() {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
String httpScope = (String)session.getAttribute("scope"); String httpScope = (String)session.getAttribute("scope");
if(scope!=null) if(scope!=null)
@ -461,17 +517,18 @@ public class ASLSession{
return httpScope; return httpScope;
} }
return null; return null;
}
else {
//OLD WAY, for backwards compatibility
if(scope==null)
logger.debug("Scope is null, returning null");
return scope;
}
//NEW WAY //NEW WAY
// String scp = (String)session.getAttribute("scope"); // String scp = (String)session.getAttribute("scope");
// if(scp==null) // if(scp==null)
// logger.debug("Scope is null, returning null"); // logger.debug("Scope is null, returning null");
// return scp; // return scp;
//OLD WAY, for backwards compatibility
// if(scope==null)
// logger.debug("Scope is null, returning null");
// return scope;
} }
/** /**
@ -479,6 +536,7 @@ public class ASLSession{
*/ */
public String getScopeName(){ public String getScopeName(){
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
String httpScope = (String)session.getAttribute("scope"); String httpScope = (String)session.getAttribute("scope");
if(scope!=null) if(scope!=null)
@ -488,16 +546,18 @@ public class ASLSession{
return httpScope; return httpScope;
} }
return null; return null;
}
else {
//OLD WAY, for backwards compatibility
if(scope==null)
logger.debug("Scope is null, returning null");
return scope;
}
//NEW WAY //NEW WAY
// String scp = (String)session.getAttribute("scope"); // String scp = (String)session.getAttribute("scope");
// if(scp==null) // if(scp==null)
// logger.debug("Scope is null, returning null"); // logger.debug("Scope is null, returning null");
// return scp; // return scp;
//OLD WAY, for backwards compatibility
// if(scope==null)
// logger.debug("Scope is null, returning null");
// return scope;
} }
/** /**
@ -505,14 +565,15 @@ public class ASLSession{
*/ */
public void setScope(String scope) { public void setScope(String scope) {
String previousScopeName = null; String previousScopeName = null;
if(session != null) {
//NEW WAY //NEW WAY
logger.info("The scope about to set is: " + scope); logger.info("The scope about to set is: " + scope);
previousScopeName = (String)session.getAttribute("scope"); previousScopeName = (String)session.getAttribute("scope");
session.setAttribute("scope", scope); session.setAttribute("scope", scope);
session.setAttribute("scopeName", scope); session.setAttribute("scopeName", scope);
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
}
// else {
//OLD WAY, for backwards compatibility //OLD WAY, for backwards compatibility
logger.info("The scope about to set is: " + scope); logger.info("The scope about to set is: " + scope);
lastUsedTime = System.currentTimeMillis(); lastUsedTime = System.currentTimeMillis();
@ -522,6 +583,7 @@ public class ASLSession{
this.scope = scope; this.scope = scope;
this.scopeName = scope; this.scopeName = scope;
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
// }
//THE BELOW PART REMAINS THE SAME FOR BOTH NEW AND OLD //THE BELOW PART REMAINS THE SAME FOR BOTH NEW AND OLD
// get the attribute that indicates of log in has been done from the login portlet - or if the user logs in from a bookmark // get the attribute that indicates of log in has been done from the login portlet - or if the user logs in from a bookmark
@ -533,13 +595,13 @@ public class ASLSession{
logger.debug("Passing the logging because the variable was set"); logger.debug("Passing the logging because the variable was set");
return; return;
} }
if ((previousScopeName != null && !previousScopeName.equals((String)session.getAttribute("scope"))) || previousScopeName == null) { if ((previousScopeName != null && !previousScopeName.equals(getScope())) || previousScopeName == null) {
logger.info("Logging the entrance"); logger.info("Logging the entrance");
//TODO: Should do something with the below line //TODO: Should do something with the below line
// innerSession.clear(); // innerSession.clear();
// ACCESS LOGGER // ACCESS LOGGER
LoginToVreAccessLogEntry loginEntry = new LoginToVreAccessLogEntry(); LoginToVreAccessLogEntry loginEntry = new LoginToVreAccessLogEntry();
accessLogger.logEntry((String)session.getAttribute("username"), scope, loginEntry); accessLogger.logEntry(getUsername(), scope, loginEntry);
} else } else
logger.debug("Passing the logging because the scope was the same"); logger.debug("Passing the logging because the scope was the same");
initializeAttributes(); initializeAttributes();
@ -549,21 +611,33 @@ public class ASLSession{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void addNotifier(String key, Notifier value){ private void addNotifier(String key, Notifier value){
if(session != null)
((HashMap<String, Notifier>)session.getAttribute("notifiers")).put(key, value); ((HashMap<String, Notifier>)session.getAttribute("notifiers")).put(key, value);
else
logger.error("Could not set notifier for "+key);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Notifier getNotifier(String key){ private Notifier getNotifier(String key){
if(session != null)
return ((HashMap<String, Notifier>)session.getAttribute("notifiers")).get(key); return ((HashMap<String, Notifier>)session.getAttribute("notifiers")).get(key);
else{
logger.error("Could not get notifier for " + key +" because HTTPSession was null. WILL RETURN NULL NOTIFIER");
return null;
}
} }
public void setSecurityToken(String token){ public void setSecurityToken(String token){
if(session != null) {
//NEW WAY //NEW WAY
SecurityTokenProvider.instance.set(token); SecurityTokenProvider.instance.set(token);
session.setAttribute("securityToken", token); session.setAttribute("securityToken", token);
}
// else{
//OLD WAY, for backwards compatibility //OLD WAY, for backwards compatibility
this.securityToken = token; this.securityToken = token;
// }
} }
public void logUserLogin(String scope) { public void logUserLogin(String scope) {
@ -571,7 +645,7 @@ public class ASLSession{
loggedIn = true; loggedIn = true;
// ACCESS LOGGER // ACCESS LOGGER
LoginToVreAccessLogEntry loginEntry = new LoginToVreAccessLogEntry(); LoginToVreAccessLogEntry loginEntry = new LoginToVreAccessLogEntry();
accessLogger.logEntry((String)session.getAttribute("username"), scope, loginEntry); accessLogger.logEntry(getUsername(), scope, loginEntry);
} }
/** /**
@ -609,18 +683,23 @@ public class ASLSession{
} }
public void setGroupModelInfos(String groupName, long groupId) { public void setGroupModelInfos(String groupName, long groupId) {
if(session != null) {
//NEW WAY //NEW WAY
ASLGroupModel aslGM = ((ASLGroupModel)session.getAttribute("groupModel")); ASLGroupModel aslGM = ((ASLGroupModel)session.getAttribute("groupModel"));
aslGM.setGroupName(groupName); aslGM.setGroupName(groupName);
aslGM.setGroupId(groupId); aslGM.setGroupId(groupId);
session.setAttribute("groupModel", aslGM); session.setAttribute("groupModel", aslGM);
}
else{
//OLD WAY, for backwards compatibility //OLD WAY, for backwards compatibility
groupModel.setGroupName(groupName); groupModel.setGroupName(groupName);
groupModel.setGroupId(groupId); groupModel.setGroupId(groupId);
} }
}
public long getGroupId() { public long getGroupId() {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
ASLGroupModel agmHttp = (ASLGroupModel) session.getAttribute("groupModel"); ASLGroupModel agmHttp = (ASLGroupModel) session.getAttribute("groupModel");
if(groupModel != null) if(groupModel != null)
@ -630,15 +709,17 @@ public class ASLSession{
return agmHttp.getGroupId(); return agmHttp.getGroupId();
} }
return Long.MIN_VALUE; //should throw an exception instead... but long's primitive and we need not to change the api return Long.MIN_VALUE; //should throw an exception instead... but long's primitive and we need not to change the api
}
else {
//OLD WAY, for backwards compatibility
return groupModel.getGroupId();
}
//NEW WAY //NEW WAY
// return ((ASLGroupModel)session.getAttribute("groupModel")).getGroupId(); // return ((ASLGroupModel)session.getAttribute("groupModel")).getGroupId();
//OLD WAY, for backwards compatibility
// return groupModel.getGroupId();
} }
public String getGroupName() { public String getGroupName() {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
ASLGroupModel agmHttp = (ASLGroupModel) session.getAttribute("groupModel"); ASLGroupModel agmHttp = (ASLGroupModel) session.getAttribute("groupModel");
if(groupModel != null) if(groupModel != null)
@ -648,15 +729,20 @@ public class ASLSession{
return agmHttp.getGroupName(); return agmHttp.getGroupName();
} }
return null; return null;
}
else {
//OLD WAY, for backwards compatibility
return groupModel.getGroupName();
}
//NEW WAY //NEW WAY
// return ((ASLGroupModel)session.getAttribute("groupModel")).getGroupName(); // return ((ASLGroupModel)session.getAttribute("groupModel")).getGroupName();
//OLD WAY, for backwards compatibility
// return groupModel.getGroupName();
} }
public void setUserEmailAddress(String email) { public void setUserEmailAddress(String email) {
//LET"S SET IT ON BOTH...
//NEW WAY //NEW WAY
if(session != null)
session.setAttribute("userEmailAddress", email); session.setAttribute("userEmailAddress", email);
//OLD WAY, for backwards compatibility //OLD WAY, for backwards compatibility
this.userEmailAddress = email; this.userEmailAddress = email;
@ -664,6 +750,7 @@ public class ASLSession{
public String getUserEmailAddress() { public String getUserEmailAddress() {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
String httpUEA = (String)session.getAttribute("userEmailAddress"); String httpUEA = (String)session.getAttribute("userEmailAddress");
if(userEmailAddress!=null) if(userEmailAddress!=null)
@ -673,16 +760,20 @@ public class ASLSession{
return httpUEA; return httpUEA;
} }
return null; return null;
}
else {
//OLD WAY, for backwards compatibility
return this.userEmailAddress;
}
//NEW WAY //NEW WAY
// return (String)session.getAttribute("userEmailAddress"); // return (String)session.getAttribute("userEmailAddress");
//OLD WAY, for backwards compatibility
// return this.userEmailAddress;
} }
public void setUserFullName(String fullName) { public void setUserFullName(String fullName) {
//Let's set it on both
//NEW WAY //NEW WAY
if(session != null)
session.setAttribute("fullName", fullName); session.setAttribute("fullName", fullName);
//OLD WAY, for backwards compatibility //OLD WAY, for backwards compatibility
this.fullName = fullName; this.fullName = fullName;
@ -690,6 +781,7 @@ public class ASLSession{
public String getUserFullName() { public String getUserFullName() {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
String httpFN = (String)session.getAttribute("fullName"); String httpFN = (String)session.getAttribute("fullName");
if(fullName != null) if(fullName != null)
@ -699,23 +791,26 @@ public class ASLSession{
return httpFN; return httpFN;
} }
return null; return null;
}
else
//OLD WAY, for backwards compatibility
return this.fullName;
//NEW WAY //NEW WAY
// return (String)session.getAttribute("fullName"); // return (String)session.getAttribute("fullName");
//OLD WAY, for backwards compatibility
// return this.fullName;
} }
public void setUserAvatarId(String avatarId) { public void setUserAvatarId(String avatarId) {
//Let's set it on both
//NEW WAY //NEW WAY
if(session != null)
session.setAttribute("avatarId", avatarId); session.setAttribute("avatarId", avatarId);
//OLD WAY, for backwards compatibility //OLD WAY, for backwards compatibility
this.avatarId = avatarId; this.avatarId = avatarId;
} }
public String getUserAvatarId() { public String getUserAvatarId() {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
String httpUAid = (String)session.getAttribute("avatarId"); String httpUAid = (String)session.getAttribute("avatarId");
if(this.avatarId != null) if(this.avatarId != null)
@ -725,15 +820,18 @@ public class ASLSession{
return httpUAid; return httpUAid;
} }
return null; return null;
}
else
//OLD WAY, for backwards compatibility
return this.avatarId;
//NEW WAY //NEW WAY
// return (String)session.getAttribute("avatarId"); // return (String)session.getAttribute("avatarId");
//OLD WAY, for backwards compatibility
// return this.avatarId;
} }
public void setUserGender(GenderType gender) { public void setUserGender(GenderType gender) {
//Let's set it on both
//NEW WAY //NEW WAY
if(session != null)
session.setAttribute("gender", gender); session.setAttribute("gender", gender);
//OLD WAY, for backwards compatibility //OLD WAY, for backwards compatibility
this.gender = gender; this.gender = gender;
@ -741,7 +839,7 @@ public class ASLSession{
public GenderType getUserGender() { public GenderType getUserGender() {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
Object httpGObj = session.getAttribute("gender"); Object httpGObj = session.getAttribute("gender");
if(this.gender != null) if(this.gender != null)
@ -751,15 +849,16 @@ public class ASLSession{
return (GenderType) httpGObj; return (GenderType) httpGObj;
} }
return null; return null;
}
else
//OLD WAY, for backwards compatibility
return this.gender;
//NEW WAY //NEW WAY
// return (GenderType)session.getAttribute("gender"); // return (GenderType)session.getAttribute("gender");
//OLD WAY, for backwards compatibility
// return this.gender;
} }
public String getSecurityToken() { public String getSecurityToken() {
if(session != null) {
//HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033 //HYBRID, TEMPORARY SOLUTION FOR FEATURE #5033
String httpSecurityToken = (String)session.getAttribute("securityToken"); String httpSecurityToken = (String)session.getAttribute("securityToken");
if(this.securityToken != null){ if(this.securityToken != null){
@ -772,13 +871,15 @@ public class ASLSession{
return httpSecurityToken; return httpSecurityToken;
} }
return null; //if reached this point, means that all security tokens are null return null; //if reached this point, means that all security tokens are null
}
else {
//OLD WAY, for backwards compatibility
logger.debug("Getting security token: " + securityToken+" in thread "+Thread.currentThread().getId());
return securityToken;
}
//NEW WAY //NEW WAY
// String securityToken = (String)session.getAttribute("securityToken"); // String securityToken = (String)session.getAttribute("securityToken");
// logger.debug("Getting security token: " + securityToken+" in thread "+Thread.currentThread().getId()); // logger.debug("Getting security token: " + securityToken+" in thread "+Thread.currentThread().getId());
// return securityToken;
//OLD WAY, for backwards compatibility
// logger.debug("Getting security token: " + securityToken+" in thread "+Thread.currentThread().getId());
// return securityToken; // return securityToken;
} }

View File

@ -5,8 +5,6 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import javax.servlet.http.HttpSession;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -17,81 +15,75 @@ public class SessionManager {
/** The logger. */ /** The logger. */
private static final Logger logger = LoggerFactory.getLogger(SessionManager.class); private static final Logger logger = LoggerFactory.getLogger(SessionManager.class);
// protected static Thread thread = new CleanSessionThread(); protected static Thread thread = new CleanSessionThread();
protected static SessionManager sessionManager = new SessionManager(); protected static SessionManager sessionManager = new SessionManager();
protected HashMap<String, ASLSession> sessions; protected HashMap<String, ASLSession> sessions;
protected SessionManager() { protected SessionManager() {
sessions = new HashMap<String, ASLSession>(); sessions = new HashMap<String, ASLSession>();
// thread.setDaemon(true); thread.setDaemon(true);
// thread.start(); thread.start();
} }
public static SessionManager getInstance() { public static SessionManager getInstance() {
return sessionManager; return sessionManager;
} }
public void setASLSession(HttpSession userSession, String username){
ASLSession aslSession = new ASLSession(userSession, username);
sessions.put(userSession.getId() + "_" + username, aslSession);
}
public ASLSession getASLSession(String externalSessionID, String username) public ASLSession getASLSession(String externalSessionID, String username)
{ {
ASLSession session = sessions.get(externalSessionID + "_" + username); ASLSession session = sessions.get(externalSessionID + "_" + username);
// if(session == null || !session.isValid() || !session.getUsername().equals(username)) if(session == null || !session.isValid() || !session.getUsername().equals(username))
// { {
// session = new ASLSession(externalSessionID, username); session = new ASLSession(externalSessionID, username);
// sessions.put(externalSessionID + "_" + username, session); sessions.put(externalSessionID + "_" + username, session);
// } }
// if (session.getScope()!=null) //covers first helper's invocation if (session.getScope()!=null) //covers first helper's invocation
// ScopeProvider.instance.set(session.getScopeName()); ScopeProvider.instance.set(session.getScopeName());
//
// if (session.getSecurityToken()!=null){ if (session.getSecurityToken()!=null){
// logger.debug("Setting SecurityTokenProvider to: "+session.getSecurityToken()+" in thread "+Thread.currentThread().getId()); logger.debug("Setting SecurityTokenProvider to: "+session.getSecurityToken()+" in thread "+Thread.currentThread().getId());
// SecurityTokenProvider.instance.set(session.getSecurityToken()); SecurityTokenProvider.instance.set(session.getSecurityToken());
// } }
return session; return session;
} }
// @Override @Override
// protected void finalize() throws Throwable { protected void finalize() throws Throwable {
// thread.interrupt(); thread.interrupt();
// logger.debug(new Date(System.currentTimeMillis()) + " clean thread was interrupted"); logger.debug(new Date(System.currentTimeMillis()) + " clean thread was interrupted");
// thread.join(); thread.join();
// logger.debug(new Date(System.currentTimeMillis()) + " clean thread was joint"); logger.debug(new Date(System.currentTimeMillis()) + " clean thread was joint");
// super.finalize(); super.finalize();
// } }
// protected static class CleanSessionThread extends Thread protected static class CleanSessionThread extends Thread
// { {
// public void run() public void run()
// { {
// while(true) while(true)
// { {
// try { try {
// Thread.sleep(300000); Thread.sleep(300000);
// } catch (InterruptedException e) { } catch (InterruptedException e) {
// logger.error("Exception:", e); logger.error("Exception:", e);
// logger.debug(new Date(System.currentTimeMillis()) + " clean thread was interrupted (in clean thread)"); logger.debug(new Date(System.currentTimeMillis()) + " clean thread was interrupted (in clean thread)");
// break; break;
// } }
// //TODO: cleanup invalid sessions: add locks... //TODO: cleanup invalid sessions: add locks...
// Set<String> keys = sessionManager.sessions.keySet(); Set<String> keys = sessionManager.sessions.keySet();
// Iterator<String> iter = keys.iterator(); Iterator<String> iter = keys.iterator();
// while(iter.hasNext()) while(iter.hasNext())
// { {
// String extSessionID = iter.next(); String extSessionID = iter.next();
// if(!sessionManager.sessions.get(extSessionID).isValid()) if(!sessionManager.sessions.get(extSessionID).isValid())
// { {
// sessionManager.sessions.remove(extSessionID); sessionManager.sessions.remove(extSessionID);
// } }
// } }
// } }
// logger.debug(new Date(System.currentTimeMillis()) + " clean thread was terminated"); logger.debug(new Date(System.currentTimeMillis()) + " clean thread was terminated");
// } }
//
// } }
} }

View File

@ -26,12 +26,12 @@ import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.application.framework.core.util.CacheEntryConstants; import org.gcube.application.framework.core.util.CacheEntryConstants;
import org.gcube.application.framework.core.util.QueryString; import org.gcube.application.framework.core.util.QueryString;
import org.gcube.application.framework.core.util.SessionConstants; import org.gcube.application.framework.core.util.SessionConstants;
//import org.gcube.common.resources.gcore.Resources; import org.gcube.common.resources.gcore.Resources;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.publisher.RegistryPublisher; import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory; import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
//import org.gcube.informationsystem.publisher.ScopedPublisher; import org.gcube.informationsystem.publisher.ScopedPublisher;
//import org.gcube.informationsystem.publisher.stubs.registry.faults.PublisherException; import org.gcube.informationsystem.publisher.stubs.registry.faults.PublisherException;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -62,7 +62,7 @@ public class GenericResource implements GenericResourceInfoI {
// protected static ISPublisher publisher = null; // protected static ISPublisher publisher = null;
// protected static ISClient client = null; // protected static ISClient client = null;
// protected static ScopedPublisher scopedPublisher = null; protected static ScopedPublisher scopedPublisher = null;
protected static RegistryPublisher publisher = null; protected static RegistryPublisher publisher = null;
protected static DiscoveryClient<org.gcube.common.resources.gcore.GenericResource> client = null; protected static DiscoveryClient<org.gcube.common.resources.gcore.GenericResource> client = null;
@ -82,7 +82,7 @@ public class GenericResource implements GenericResourceInfoI {
session = SessionManager.getInstance().getASLSession(extrenalSessionID, username); session = SessionManager.getInstance().getASLSession(extrenalSessionID, username);
try { try {
ScopeProvider.instance.set(session.getScope()); ScopeProvider.instance.set(session.getScope());
// scopedPublisher = RegistryPublisherFactory.scopedPublisher(); scopedPublisher = RegistryPublisherFactory.scopedPublisher();
publisher = RegistryPublisherFactory.create(); publisher = RegistryPublisherFactory.create();
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception:", e); logger.error("Exception:", e);
@ -109,7 +109,7 @@ public class GenericResource implements GenericResourceInfoI {
this.session = session; this.session = session;
try { try {
ScopeProvider.instance.set(session.getScope()); ScopeProvider.instance.set(session.getScope());
// scopedPublisher = RegistryPublisherFactory.scopedPublisher(); scopedPublisher = RegistryPublisherFactory.scopedPublisher();
publisher = RegistryPublisherFactory.create(); publisher = RegistryPublisherFactory.create();
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception:", e); logger.error("Exception:", e);
@ -316,8 +316,7 @@ public class GenericResource implements GenericResourceInfoI {
//maybe should change the visibility (into public) of addScope() within the Resource class of common-gcore-resources package in order to use it here. //maybe should change the visibility (into public) of addScope() within the Resource class of common-gcore-resources package in order to use it here.
List<String> scopes=new ArrayList<String>(); List<String> scopes=new ArrayList<String>();
scopes.add(session.getScope()); scopes.add(session.getScope());
org.gcube.common.resources.gcore.GenericResource res = scopedPublisher.create(gCubeRes, scopes);
org.gcube.common.resources.gcore.GenericResource res = publisher.create(gCubeRes, scopes);
logger.info("Created Generic Resource with id: "+res.id()+" on scope: "+scopes.toString()); logger.info("Created Generic Resource with id: "+res.id()+" on scope: "+scopes.toString());
// 1-oct-2013 -- adding generic resource to cache // 1-oct-2013 -- adding generic resource to cache
@ -576,7 +575,7 @@ public class GenericResource implements GenericResourceInfoI {
// //TODO // //TODO
// CachesManager.getInstance().getGenericResourceCache().get(queryString).setTimeToLive(0); // CachesManager.getInstance().getGenericResourceCache().get(queryString).setTimeToLive(0);
// } // }
} catch (Exception e) { } catch (PublisherException e) {
logger.error("Exception:", e); logger.error("Exception:", e);
throw new RemoteException(); throw new RemoteException();
} }

View File

@ -20,7 +20,7 @@ import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.publisher.RegistryPublisher; import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory; import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
//import org.gcube.informationsystem.publisher.ScopedPublisher; import org.gcube.informationsystem.publisher.ScopedPublisher;
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException; import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -32,8 +32,8 @@ public class RuntimeResource {
private static final Logger logger = LoggerFactory.getLogger(RuntimeResource.class); private static final Logger logger = LoggerFactory.getLogger(RuntimeResource.class);
// protected static ScopedPublisher scopedPublisher = null; protected static ScopedPublisher scopedPublisher = null;
protected static RegistryPublisher registryPublisher = null; // protected static RegistryPublisher registryPublisher = null;
protected static DiscoveryClient<ServiceEndpoint> client = null; protected static DiscoveryClient<ServiceEndpoint> client = null;
/** /**
@ -47,9 +47,8 @@ public class RuntimeResource {
session = SessionManager.getInstance().getASLSession(extrenalSessionID, username); session = SessionManager.getInstance().getASLSession(extrenalSessionID, username);
try { try {
ScopeProvider.instance.set(session.getScope()); ScopeProvider.instance.set(session.getScope());
scopedPublisher = RegistryPublisherFactory.scopedPublisher();
// scopedPublisher = RegistryPublisherFactory.scopedPublisher(); // registryPublisher = RegistryPublisherFactory.create();
registryPublisher = RegistryPublisherFactory.create();
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception:", e); logger.error("Exception:", e);
} }
@ -71,8 +70,8 @@ public class RuntimeResource {
this.session = session; this.session = session;
try { try {
ScopeProvider.instance.set(session.getScope()); ScopeProvider.instance.set(session.getScope());
// scopedPublisher = RegistryPublisherFactory.scopedPublisher(); scopedPublisher = RegistryPublisherFactory.scopedPublisher();
registryPublisher = RegistryPublisherFactory.create(); // registryPublisher = RegistryPublisherFactory.create();
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception:", e); logger.error("Exception:", e);
} }
@ -96,8 +95,8 @@ public class RuntimeResource {
public String createRuntimeResource(ServiceEndpoint runtimeResource) throws RegistryNotFoundException { public String createRuntimeResource(ServiceEndpoint runtimeResource) throws RegistryNotFoundException {
List<String> scopes = new ArrayList<String>(); List<String> scopes = new ArrayList<String>();
scopes.add(session.getScope()); scopes.add(session.getScope());
// ServiceEndpoint se = scopedPublisher.create(runtimeResource, scopes); ServiceEndpoint se = scopedPublisher.create(runtimeResource, scopes);
ServiceEndpoint se = registryPublisher.create(runtimeResource); // ServiceEndpoint se = registryPublisher.create(runtimeResource);
logger.debug("Created Runtime Resource with id: "+se.id()+" on scope: "+scopes.toString()); logger.debug("Created Runtime Resource with id: "+se.id()+" on scope: "+scopes.toString());
return se.id(); return se.id();
} }
@ -110,8 +109,8 @@ public class RuntimeResource {
*/ */
public String updateRuntimeResource(ServiceEndpoint runtimeResource) throws RemoteException { public String updateRuntimeResource(ServiceEndpoint runtimeResource) throws RemoteException {
try { try {
// ServiceEndpoint se = scopedPublisher.update(runtimeResource); ServiceEndpoint se = scopedPublisher.update(runtimeResource);
ServiceEndpoint se = registryPublisher.update(runtimeResource); // ServiceEndpoint se = registryPublisher.update(runtimeResource);
logger.debug("Updated Runtime Resource with id: "+runtimeResource.id()+"\tNew id : "+se.id()); logger.debug("Updated Runtime Resource with id: "+runtimeResource.id()+"\tNew id : "+se.id());
return se.id(); return se.id();
} catch (Exception e) { } catch (Exception e) {
@ -130,8 +129,8 @@ public class RuntimeResource {
try { try {
List<String> scopes=new ArrayList<String>(); List<String> scopes=new ArrayList<String>();
scopes.add(session.getScope()); scopes.add(session.getScope());
// ServiceEndpoint se = scopedPublisher.remove(runtimeResource,scopes); ServiceEndpoint se = scopedPublisher.remove(runtimeResource,scopes);
ServiceEndpoint se = registryPublisher.remove(runtimeResource); // ServiceEndpoint se = registryPublisher.remove(runtimeResource);
logger.debug("Deleted Runtime Resource with id: "+runtimeResource.id()); logger.debug("Deleted Runtime Resource with id: "+runtimeResource.id());
return se.id(); return se.id();
} catch (Exception e) { } catch (Exception e) {