File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Security with swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Security with swing" Watch "Security with swing" New topic

Security with swing

Engin Okucu
Ranch Hand

Joined: Feb 09, 2002
Posts: 174
I want to develop an application that must authenticate users in swing.
When i start the application , i have the login and password frame .
After that i'm authenticated , i want to restrict acces to the user so that it cannot for example remove an item from the Jlist.
Then the button remove will not be displayed to this user perhaps it is not an administrator.
When the administrator connects , he will able to see the remove button.
He will have all access to manage the items displayed.
How can i do it ?
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

This doesn't really have anything to do with Swing per se...

You just need to create a 'User' object when the user has sucessfully logged in. Then store it somewhere where every listener can get to it through a static method.

How you use this 'User' object is up to you... you can make subclasses of 'User' like 'Guest', 'Operator', 'Admin', etc. and test based on that inside the action. This is a really simple model... for more complex security requirements (like 'a user can do this action if they are a manager, but only if they are a manager at the location they are trying to affect') you might want to either extend this model or go with a more 'function-based' security model rather than a 'class-based' security model. If security is a big part of your app you might want to make a class that implements ActionListener and that has a lot of built in calls to do security based things.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Engin Okucu
Ranch Hand

Joined: Feb 09, 2002
Posts: 174
Thank you very much. I'm going to try it.
I agree. Here's the link:
subject: Security with swing
It's not a secret anymore!