login & roles with gui

V

VisionSet

How is this usually done?

My thoughts at the moment are to have a abstract singleton factory for my 3
user roles

these can handle things like login, password change etc and also be a lookup
for the current role.

Have subclasses of swing components that differ only in the things they
allow the user roles to do.

If a user is never going to be allowed to do xyz, is there any point adding
xyz to a component, let alone just setting setEnabled(false) ?

What is the usual OO approach to this task?
 
G

Guest

How is this usually done?

My thoughts at the moment are to have a abstract singleton factory for my
3 user roles

these can handle things like login, password change etc and also be a
lookup for the current role.

Have subclasses of swing components that differ only in the things they
allow the user roles to do.

If a user is never going to be allowed to do xyz, is there any point
adding xyz to a component, let alone just setting setEnabled(false) ?

What is the usual OO approach to this task?

Create a User class. Among the other methods have the functions
hasPermission and hasPermissions. It is up to you on how you assign
permissions to a User. Could be an XML file or database.


HTH,
La'ie Techie
 
V

VisionSet

La?ie Techie said:
Create a User class. Among the other methods have the functions
hasPermission and hasPermissions. It is up to you on how you assign
permissions to a User. Could be an XML file or database.


HTH,

do you mean like:

widgitX.setEnabled(user.hasPermission(User.CAN_EDIT_WIDGIT_X));

&

class User {

public static final int CAN_EDIT_WIDGIT_X = 0;
public static final int CAN_EDIT_WIDGIT_Y = 1;
public static final int CAN_EDIT_WIDGIT_Z = 2;

static boolean[] secretaryPerms = {true,false,false};
static boolean[] adminPerms = {true,true,false};

boolean[] perm;

User(int role) {
switch(role) {
case SECRETARY: perm = secretaryPerms; break;
case ADMIN: perm = adminPerms; break;
}
}

hasPermission(int item) {
return perm[item];
}
}

if so, I prefer the subclass approach.

not sure how you mean with the plural hasPermissions(array[] ???)
 
G

Guest

do you mean like:

widgitX.setEnabled(user.hasPermission(User.CAN_EDIT_WIDGIT_X));

Note that I was describing a framework which can be adapted to many
different projects. Currently you only have three roles. What happens
when you add more?

My permissions are String objects. I generally have a view and edit
version for each permission. Each widget maintains a list of permissions
needed to view and/or edit it (or subwidgets).

Your User class should be a front end to some data source so that
different permissions could be assigned to different users.

The plural user.hasPermissions( someArray ) returns true only if the user
has every permission listed in the array.

In any event, this is just a suggestion.

Aloha,
La'ie Techie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top