This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Handle Multiple Sessions  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1759
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this is the correct forum or not.

My application has a user object where name, role assignments, etc is stored. This user object is set to a session attribute.
All properties are set to empty strings as default until user logs on.

My trouble is after the user logs on they then open another instance of the same application. This sets all the user object properties back to empty strings on the first application instance.

How can this be avoided?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obvious answer: have whatever sets the scoped variables to empty strings check to see if there value are already there to not.

But, why have anything set them to empty strings in the first place? What is the utility of that?
 
Steve Dyke
Ranch Hand
Posts: 1759
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Obvious answer: have whatever sets the scoped variables to empty strings check to see if there value are already there to not.

But, why have anything set them to empty strings in the first place? What is the utility of that?


Thanks Bear. Right or wrong I have these initial values set to empty for Guest access to the application(mostly view only). You have to logon to do any manipulation.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But why do you set them as empty in the first place? Why bother? What's the justification except making things more complicated than they need to be?
 
Steve Dyke
Ranch Hand
Posts: 1759
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:But why do you set them as empty in the first place? Why bother? What's the justification except making things more complicated than they need to be?


Let me clarify what I am doing by saying 'setting'. The user object class properties are equal to empty strings by default.

Example:
private String fname = "";
private String lname = "";

Then I use the returns from log on prompt to do a data lookup and set the property values to user data field values.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You still haven't explained why you are setting the empty stings. It's needless and obviously causing problems.

And why are those settings significant in any case? It should be really simple: either you have a "user object" in the session, which means they are logged in, or you don't have a "user object" in the session, in which case they aren't logged in. Anything other than that is over-complicated and needless.
 
Steve Dyke
Ranch Hand
Posts: 1759
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You still haven't explained why you are setting the empty stings. It's needless and obviously causing problems.

And why are those settings significant in any case? It should be really simple: either you have a "user object" in the session, which means they are logged in, or you don't have a "user object" in the session, in which case they aren't logged in. Anything other than that is over-complicated and needless.


I see. And thanks for working with me on understanding this. But what if I use the user object to control inter application access and the user object does not exist?

Example:

one of the user properties is managerAccess(either true or false). An add new record function is wrapped by a if(user.mangaerAccess) condition. If the user object does not exist I get errors. So I created the user object to avoid this.
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if there is no user object in session then user.managerAccess should not get executed.
I mean all the methods on user object should get executed only if user object exists in session.
 
Steve Dyke
Ranch Hand
Posts: 1759
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tapas Chand wrote:if there is no user object in session then user.managerAccess should not get executed.
I mean all the methods on user object should get executed only if user object exists in session.


The user.ismanagerAccess() is a property not a method.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Dyke wrote: So I created the user object to avoid this.

You are solving the problem at the wrong level. If the user object doesn't exist, you shouldn't try to use it. Simple as that.

Where are you doing all this? If you are writing your own security (not recommended) then this should likely be done in a filter that aborts the request or forwards to the long mechanism if no user object exists.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Dyke wrote:
The user.ismanagerAccess() is a property not a method.

It's still a getter method, even if it's a bean property.

Regardless, see above, test if a user object exists or not. Simple.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!