Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Assign Security Group
PostPosted: Thu Jul 06, 2017 5:15 am 

Joined: Fri Jan 15, 2016 4:00 am
Posts: 5

Offline
Hello,

On my screen 1 I am having multiple controls like button,textbox etc
What I am trying to do is I want to assign security group to controls present on my screen using script module.


 Profile  
 
 Post subject: Re: Assign Security Group
PostPosted: Thu Jul 06, 2017 8:30 am 

Joined: Mon Jun 11, 2012 2:10 pm
Posts: 89

Offline
Hi ParthDesai,

What is it exactly you are trying to do? On the screen you can configure controls to be hidden, disabled, etc. based on user access level. Are you trying to control what the user can do from the script side? For instance, if they are low-level user pressing button does A, but if they are high-level user it does B?

If you are looking at the latter case, you can determine if the user is in a specific group using a function like this:
Code:
public bool hasAccess(string reqGroup)
{
   string curUser = Globals.Security.CurrentUser;
   foreach (ISecurityUser user in Globals.Security.Users)
      if (user.Username == curUser)
      {
         foreach (ISecurityGroup sgroup in user.SecurityGroups)
            if (sgroup.GroupName == reqGroup) return true;
         return false;
      }
   return false;
}

Then in your controls script you would have:
Code:
if (hasAccess("Operators"))
{
   ...
}

You can also popup a login window:
Code:
Globals.Security.Login();

To log them out you can use:
Code:
Globals.Security.Logout();

_________________
Adam M.
Controls Engineer
FlexEnergy


 Profile  
 
 Post subject: Re: Assign Security Group
PostPosted: Thu Jul 06, 2017 9:00 am 

Joined: Fri Jan 15, 2016 4:00 am
Posts: 5

Offline
Hello,

I have two system.windows.Form.Button control on my third party user control and wanted to give administrator access to one of the button using C#.
So wanted to know how I can give access to one of the button through script or through code in my usercontrol.


 Profile  
 
 Post subject: Re: Assign Security Group
PostPosted: Thu Jul 06, 2017 3:25 pm 

Joined: Mon Jun 11, 2012 2:10 pm
Posts: 89

Offline
OK.

When you say "give administrator access" do you mean log them in as an administrator? To do this you could specify a username and password to the login function like so:
Code:
Globals.Security.Login("userName", "password");

If you want, you can pre-check if the user is already logged in as administrator via the code I supplied in my prior post (also below). Note this requires that the user does not change the password for the account - I don't know if there is a way to determine the new password. (You can just supply the username and require the user to give the password.)

If you just want to make sure the user has Administrator privileges before the button does anything, you could use the following, using the function from my prior post in the button_click routine:
Code:
if (hasAccess("Administrator"))
{
   [restricted code here]
}

_________________
Adam M.
Controls Engineer
FlexEnergy


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron