Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Security group
PostPosted: Wed Oct 19, 2011 5:39 am 

Joined: Mon Sep 12, 2011 4:52 am
Posts: 29

Offline
Hi. I need to save into a string at which security group the actual logged user belongs to. For example, if the logged user is an amministrator, the string will contain "Group_01" value. Could you help me?
Thank you!
Best regards.


 Profile  
 
 Post subject: Re: Security group
PostPosted: Wed Oct 19, 2011 10:08 am 
User avatar

Joined: Fri Jul 15, 2011 3:21 pm
Posts: 214

Offline
First create a "System Tag" for the "Current User".

Attachment:
add_system_tag.JPG
add_system_tag.JPG [ 38.06 KiB | Viewed 6895 times ]


Attachment:
add_system_tag_curr_user.JPG
add_system_tag_curr_user.JPG [ 83.75 KiB | Viewed 6895 times ]


Then add some script to copy the current user string to another tag when it's value changes.

Attachment:
system_curr_user_change.JPG
system_curr_user_change.JPG [ 74.43 KiB | Viewed 6895 times ]

_________________
Best Regards,

Beijer Electronics, Inc.
Ron Lloyd | Applications Engineer


 Profile  
 
 Post subject: Re: Security group
PostPosted: Wed Oct 19, 2011 10:18 am 
User avatar

Joined: Fri Jul 15, 2011 3:21 pm
Posts: 214

Offline
I just realized, this only helps you determine the current user, but not the current users group. I don't know of a way to do that except with an if else statement.

Code:
void SystemTagCurrentUser_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
      {
         if (Globals.Tags.SystemTagCurrentUser.Value == "user1")
         {
            Globals.Tags.Tag1.Value = "group1";         
         }
      }


I will do some more research and see if there is a more elegant solution.

_________________
Best Regards,

Beijer Electronics, Inc.
Ron Lloyd | Applications Engineer


 Profile  
 
 Post subject: Re: Security group
PostPosted: Thu Oct 20, 2011 9:18 am 
User avatar

Joined: Fri Jul 15, 2011 3:21 pm
Posts: 214

Offline
There is a more elegant solution, but it requires some helper functions. You can place this in a script module.

Code:
namespace Neo.ApplicationFramework.Generated
{
   using System.Windows.Forms;
   using System;
   using System.Drawing;
   using Neo.ApplicationFramework.Tools;
   using Neo.ApplicationFramework.Common.Graphics.Logic;
   using Neo.ApplicationFramework.Controls;
   using Neo.ApplicationFramework.Interfaces;
   
   using System.Collections.Generic;
   
   public partial class SecurityFunctions
   {
      
      public string GetUserGroups(string userName)
      {
         IList<ISecurityUser> HMIUsers = Globals.Security.Users;
         int userIndex = GetUserIndex(HMIUsers, userName);
         
         IList<ISecurityGroup> userGroups = HMIUsers[userIndex].SecurityGroups;
         string groupNames = string.Empty;
         foreach(ISecurityGroup securityGroup in userGroups)
         {
            groupNames += string.Format("{0}, ", securityGroup.GroupName);
         }
         groupNames = groupNames.Remove(groupNames.Length-2, 2);
         return groupNames;
      }
      
      private int GetUserIndex(IList<ISecurityUser> users, string userName)
      {
         bool foundUser=false;
         int index = 0;
         while(index < users.Count-1 && !foundUser)
         {
            if(users[index].Username == userName)
            {
               foundUser = true;
            }
            else
            {
               index++;
            }
         }
         return index;
      }
   }
}


With these helper functions, you can then use code similar to this.

Code:
void SystemTagCurrentUser_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
      {
         if(Globals.Tags.SystemTagCurrentUser.Value != string.Empty)
         {
            Globals.Tags.Tag1.Value =
               Globals.SecurityFunctions.GetUserGroups(Globals.Tags.SystemTagCurrentUser.Value);
         }            
      }


Attachments:
UserNameAndGroup.zip [25.69 KiB]
Downloaded 337 times

_________________
Best Regards,

Beijer Electronics, Inc.
Ron Lloyd | Applications Engineer
 Profile  
 
 Post subject: Re: Security group
PostPosted: Fri Oct 21, 2011 1:23 am 

Joined: Mon Sep 12, 2011 4:52 am
Posts: 29

Offline
Thank you very much!!!


 Profile  
 
 Post subject: Re: Security group
PostPosted: Mon Mar 05, 2012 9:06 pm 

Joined: Wed Feb 22, 2012 12:01 am
Posts: 44

Offline
Dear Ron,

I guess I found another way to get Security Group:
Code:
using Neo.ApplicationFramework.Tools.Security;

and then call class SecurityGroup
Code:
public SecurityGroup _securityGroup;


Code:
namespace Neo.ApplicationFramework.Generated
{
    using System.Windows.Forms;
    using System;
    using System.Drawing;
    using Neo.ApplicationFramework.Tools;
    using Neo.ApplicationFramework.Common.Graphics.Logic;
    using Neo.ApplicationFramework.Controls;
    using Neo.ApplicationFramework.Interfaces;
   
   using Neo.ApplicationFramework.Tools.Security;
   
    public partial class Screen1
    {
      public SecurityGroup _securityGroup;
      public string temp;
      
      void Button2_Click(System.Object sender, System.EventArgs e)
      {
         temp = _securityGroup.GroupName.ToString();
         Text1.Text = temp;
      }
    }
}


but it turned out that thing did NOT work that way... It got error whenever I click the button to get GroupName. It really confuses me: what's wrong with this code?

Attached in this post is my project.

Best regards,

Phong Duong


Attachments:
SecurityGroup.zip [26.4 KiB]
Downloaded 280 times
 Profile  
 
 Post subject: Re: Security group
PostPosted: Tue Mar 06, 2012 11:00 am 

Joined: Wed Feb 22, 2012 12:01 am
Posts: 44

Offline
Dear Ron,

Moreover, this is what made me confused:
Ron L. wrote:
IList<ISecurityUser> HMIUsers = Globals.Security.Users;
int userIndex = GetUserIndex(HMIUsers, userName);

IList<ISecurityGroup> userGroups = HMIUsers[userIndex].SecurityGroups;


Actually, this security group pop up in my head in the first time, so I did some search in Script help and user manual. How could you find out that Globals.Security.Users object is an array?

Thanks and best regards,

Phong Duong


 Profile  
 
 Post subject: Re: Security group
PostPosted: Wed Mar 07, 2012 7:47 pm 

Joined: Wed Feb 22, 2012 12:01 am
Posts: 44

Offline
ajack wrote:
Dear Ron,

Moreover, this is what made me confused:
Ron L. wrote:
IList<ISecurityUser> HMIUsers = Globals.Security.Users;
int userIndex = GetUserIndex(HMIUsers, userName);

IList<ISecurityGroup> userGroups = HMIUsers[userIndex].SecurityGroups;


Actually, this security group pop up in my head in the first time, so I did some search in Script help and user manual. How could you find out that Globals.Security.Users object is an array?


So silly me, I did found out about Globals.Security.User. Actually, that class implement IList interface, so it must be a collection of data.

Thanks!

Phong Duong


 Profile  
 
 Post subject: Re: Security group
PostPosted: Thu Mar 08, 2012 3:28 am 

Joined: Wed Feb 22, 2012 12:01 am
Posts: 44

Offline
ajack wrote:
I guess I found another way to get Security Group:
Code:
using Neo.ApplicationFramework.Tools.Security;

and then call class SecurityGroup
Code:
public SecurityGroup _securityGroup;



Dear Ron,

I was so silly, SecurityGroup and SecurityUser is just a class, I need to call an instance, which has the Group and User properties of current user. But I just don't know which instance has those properties...

Thanks,

Phong Duong


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 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: