tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Imran Balkhi" <im...@sibisoft.com>
Subject RE: How to clean objects in user's session
Date Sun, 20 Jul 2003 01:42:38 GMT
Thanks Tim, your suggestion works. Here is the changed code

 	Enumeration sessionAttributes = session.getAttributeNames();
      ArrayList list = new ArrayList();
 	while(sessionAttributes.hasMoreElements()) {
 		String name = (String) sessionAttributes.nextElement();
 		if ((name.compareTo("userSession") != 0) &&
 		    (name.compareTo("style") != 0) &&
 		    (name.compareTo("moduleID") != 0) &&
 		    (name.compareTo("listNavigatorMap") != 0))
			list.add(name);
 		}
	}
	Iterator iList = list.iterator();
	while(iList.hasNext()) {
		session.removeAttribute((String) iList.next());
	}

Imran
-----Original Message-----
From: Tim Funk [mailto:funkman@joedog.org]
Sent: Saturday, July 19, 2003 5:48 AM
To: Tomcat Users List
Subject: Re: How to clean objects in user's session


Older versions of tomcat have their Enumeration from
session.getAttributeNames() backed by an Iterator. So if a change is made
you
get the ConcurrentModificationException. I know tomcat 5 does not have this
problem but I don't know about tomcat4. Since your using 4.1.24 - I am
guessing the change was not backported.

The easiest solution is to call invalidate - but this also usually logs the
user out too so it may not be acceptable. Once a session is invalidated - it
can't be used anymore for getting and setting stuff.

The alternative is clone/copy the Enumeration (probably the hard way by an
extra iteration) - then iterate through the copied version. The copied
version has no relation to the list so you can clear its atributes without
the exception.

-Tim



Imran Balkhi wrote:
> Hello,
>
> Our application is divided into multiple vertical views (ie, multiple
> company). User can work in only one vertical slice at a time (ie, abc
> company). Currently users have to logout and login again to change the
> vertical. There is a business requirement to provide ability to switch
> verticals without the need to logout and relogin. Here are my options.
>
>
> 1) invalidate the session object and create a new session. I am not sure
> if this is possible with logout and relogin routine. We are using our own
> authentication.
>
> 2) remove vertical specific objects from user's session. This option
> seems to be less intrusive on users. However, I am not able to remove
> objects Here is the test code
>
> if((userPreference.getCurrentCompanyId() > 0) &&
>     userPreference.getCurrentCompanyId() != companyId){
> 	Enumeration sessionAttributes = session.getAttributeNames();
> 	while(sessionAttributes.hasMoreElements()) {
> 		String name = (String) sessionAttributes.nextElement();
> 		if ((name.compareTo("userSession") != 0) &&  //exclude vertical
> independent objects
> 		    (name.compareTo("style") != 0) &&
> 		    (name.compareTo("moduleID") != 0) &&
> 		    (name.compareTo("listNavigatorMap") != 0))
> 			logger.debug ("Name :  " + name);
> 			session.removeAttribute(name);
> 		}
> 	}
> }
>
> I am getting ConcurrentModificationException, detials are in attached
file.
>
> Can any one point out what am I doing wrong or let me know if there are
> better ways to get to goal.
>
> Thanks,
> Imran
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message