• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Security with swing

 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much. I'm going to try it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic