cancel
Showing results for 
Search instead for 
Did you mean: 

user management -logic thinking

Former Member
0 Kudos

currently , i have many users to be managed in user management...

i set up my webydnpro to authenticated the user,

i will based on the user role and then restricted the access to the application,

can view only their department stuff...

let's say a 5 department , i categorized into


hr_admin hr_normal_user,hr_super_user
sales_admin, sales_normal_user, sales_super_user,
................
enterprise_super_user (can view all department info)

what i do is basically many if and else statement...and many hardcode

can anyone proposed a better solution for this.....


String user_role=new String();
	while(rit.hasNext()){
		String roleName=(String) rit.next();
		IRole role=rfact.getRole(roleName);
		user_role=role.getDisplayName();
		
	//check role
	if(user_role.equalsIgnoreCase("hr_ADMIN")){
		role_hr_ADMIN=true;
	}else if(user_role.equalsIgnoreCase("hr_NORMAL_USER")){
		role_hr_NORMAL_USER=true;
	}else if(user_role.equalsIgnoreCase("hr_SUPER_USER")){
		role_hr_SUPER_USER=true;
	}

this is troublesome...any suggestion....

if i going to make this if ...else..to switch ..how can i do that...


switch(user_role){        //error >> >>>in side switch cannot be String
case hr_ADMIN: 
       role_hr_ADMIN=true;
       break;
case hr_NORMAL_USER;
       role_hr_NORMAL_USER=true;
       break;
}

Accepted Solutions (1)

Accepted Solutions (1)

oliver
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

first I wouldn't hardcode the roles in the code. You could put them into the DB or some kind of XML file, specifying which roles are necessary for each part of the app. This way you can easily change them afterwards.

Second it may be a good idea to use iUser methods like <i>isMemberOfRole </i>or <i>isMemberOfGroup </i>because these can also check roles and groups deeper in the hirarchy.

Regarding drawbacks with the switch statement, well it's Java. We probably have to deal with it;) But the mentioned functions return boolean values so you can use them in your if statements.

Best regards,

ok

Former Member
0 Kudos

how could i able to use the switch statement since if..else is troublesome

switch(user_role){ //error >> >>>in side switch cannot be String

case hr_ADMIN:

role_hr_ADMIN=true;

break;

case hr_NORMAL_USER;

role_hr_NORMAL_USER=true;

break;

}

Message was edited by:

yzme yzme

Answers (0)