Up | Example 01 - StructuredPropertyBag | Example 02 - WinForms Controls | Example 3 - Custom User Interface | Example 04 - TCP Socket Communication | Example 05 - Simple Text Print | Example 06 - Modeless .Net Dialog | Example 07 - StopWatch | Example 08 - Product Selection Page | Example 09 - PyScripter - Eclipse Test Program | Example 10 - Access Control with custom .Net Plugin

 

  

 
Example 10 - Access Control with custom .Net Plugin
# Scorpion Plugin : UserManager module example
#
# The UserManager must implement two methods and register in to Scorpion
#
# Example Central Start
#    import UserManager
#    RegisterUserManager(UserManager.UserManager())
#
# logon(self,user)
#   signature:
#     string user - default/current user
#   returns:
#     bool,string,string - ok,user,password
#
# queryAccess(self,attr,user)
#   signature:
#     string attr - security attribute
#     string user - current user
#   returns:
#     bool - ok
#
import sys

#security attributes in Scorpion 7.0.0.396
_attr = ('Start','Stop','Close','Settings','Service')

#The UserManager class
class UserManager:
  def __init__(self):
    self.users=('guest','operator','technician','admin')
    self.passwords=('guest','oper','service','admin')
    self.rights=(
      (),                           #guest
      (_attr[0],_attr[1],_attr[2]), #operator
      (_attr[3]),                   #technician
      _attr                         #admin
    )

  def logon(self,user):
    #print self,'logon',user
    while True:
      ok,user,pw=LogonDialog(self.users,user)
      if ok:
        for i in range(len(self.users)):
          if user==self.users[i]:
            if pw==self.passwords[i]:
              return True,user

  def queryAccess(self,attr,user):
    #print self,'queryAccess',user,attr
    for i in range(len(self.users)):
      if user==self.users[i]:
        return attr in self.rights[i]
    return False

#-------------------------------------------------------------------------------
# init / test
#-------------------------------------------------------------------------------
if "Scorpion" in sys.modules:
  from Scorpion import LogonDialog
else:  # tested in PyScripter / Eclipse test environment
  def LogonDialog(users,user):
    return 1,'operator','oper'  #in test - return valid user/pw else run forever!!!

  usrmgr=UserManager()
  ok,usr=usrmgr.logon('operator')
  print 'logon',ok,usr
  if ok:
    for i in _attr:
      print usr,i,usrmgr.queryAccess(i,usr)

	
 
 

Scorpion Vision Version XII : Build 646 - Date: 20170225
Scorpion Vision Software® is a registered trademark of Tordivel AS.
Copyright © 2000 - 2017 Tordivel AS.