Pass session variables via security context

I'm working in MVC application. I need to put/pass couple of values in the controller level and retrieve the same in the service or business layer or persistence layer.

Few said we need to defined security context which is accessible in presentation or in any layer.

Please let me know how to define and access it. Is there is a better way then security context?

Thanks.
Software ProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

girionisCommented:
What type of variables do you need to pass? There are several different ways to do what you need.
0
Software ProgrammerAuthor Commented:
for example user id, tenant id and other variables. We don't like to use MDC which is specific for logging. We need to pass the session variables and to access in the business layer. How to pass the variable via security context?
0
girionisCommented:
I wouldn't put them in the security context. Security context is only for security-related stuff. If you want to store, lets say, the balance of an account you wouldn't do it in the security context.

If you want your business layer to be completely agnostic of your presentation layer then you will have to store these variables in another object  which is accessible from everywhere. I don't know if this is a good idea though since this might introduce issues such as thread-safety. If I were you I would simply pass the information I need from call to call (from method to method).
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Software ProgrammerAuthor Commented:
Do you mean i need to have a thread local variable which should be accessed in any layer ????

Like how MDC is implemented in the log4j ??

if yes, do we have any utility which takes care of the thread safety which can be used across layer...
0
girionisCommented:
Do you mean i need to have a thread local variable which should be accessed in any layer ????

If you go with the first approach yes.

if yes, do we have any utility which takes care of the thread safety which can be used across layer...

I don't know of any. Chances are that you will have to write your own code (it's not hard).
0
Software ProgrammerAuthor Commented:
0
girionisCommented:
Yes it should work.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Software ProgrammerAuthor Commented:
Thanks for the confirmation
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.