예제 #1
0
def process_object(args):
    pobject = load_entity(PermObj(), args)
    print(args.entity + ' ' + args.operation)
    if not args.obj_name:
        print("error --obj_name required for entity object")
        return False
    elif args.operation == ADD:
        admin.add_object(pobject)
    elif args.operation == UPDATE:
        admin.update_object(pobject)
    elif args.operation == DELETE:
        admin.delete_object(pobject)
    elif args.operation == READ:
        print_entity(review.read_object(pobject), pobject.obj_name)
        pass
    elif args.operation == SEARCH:
        pobject.obj_name += '*'
        objs = review.find_objects(pobject)
        if len(objs) > 0:
            for idx, obj in enumerate(objs):
                print_entity(obj, pobject.obj_name + ':' + str(idx))
        else:
            print_ln('No matching records found matching filter: ' +
                     pobject.obj_name)
    else:
        print('process_object failed, invalid operation=' + args.operation)
        return False
    return True
예제 #2
0
 def test_search_roles(self):
     """
     Test role search by name in file
     """
     print_ln('test search role by name')
     try:
         rs = roledao.search(Role(name="test*"))
         for r in rs:
             print_entity(r, "Role")
     except Exception as e:
         self.fail('role search failed, exception=' + e.msg)
예제 #3
0
 def test_search_perms(self):
     """
     Test perm search by obj_name in file
     """
     print_ln('test read perms by obj_name')
     try:
         perm = Perm(obj_name="test*")
         p = permdao.read(perm)
         print_entity(p, "Perm")
     except Exception as e:
         self.fail('perm search failed, exception=' + e.msg)
예제 #4
0
 def test_search_users(self):
     """
     Test the user search by uid in file
     """
     print_ln('test search users by uid')
     try:
         for user in userdao.search(User(uid="foo*")):
             print_entity(user, "search user")
             print_entity(userdao.read(user), "read user")
     except Exception as e:
         self.fail('user search failed, exception=' + e.msg)
예제 #5
0
 def test_search_perms(self):
     """
     Test the perm search by obj_name and op_name in ldap
     """
     print_ln('test search perms by objNm')        
     try:
         prm = Perm(obj_name = "TOB*", op_name = "TOP*")
         pList = permdao.search(prm)
         for idx, entity in enumerate(pList) :            
             print_entity (entity, "Perm[" + str(idx+1) + "]:", 1)
     except Exception as e:
         self.fail('perm search failed, exception=' + e.msg)
예제 #6
0
def process_perm(args):
    perm = load_entity(Perm(), args)
    print(args.entity + ' ' + args.operation)
    if args.operation == ADD:
        admin.add_perm(perm)
    elif args.operation == UPDATE:
        admin.update_perm(perm)
    elif args.operation == DELETE:
        admin.delete_perm(perm)
    elif args.operation == GRANT:
        role_nm = args.role
        print('role=' + role_nm)
        admin.grant(perm, Role(name=role_nm))
    elif args.operation == REVOKE:
        role_nm = args.role
        print('role=' + role_nm)
        admin.revoke(perm, Role(name=role_nm))
    elif args.operation == READ:
        print_entity(review.read_perm(perm),
                     perm.obj_name + '.' + perm.op_name)
        pass
    elif args.operation == SEARCH:
        role_nm = args.role
        userid = args.uid
        prms = []
        label = ''
        if userid:
            label = userid
            prms = review.user_perms(User(uid=userid))
        elif role_nm:
            label = role_nm
            prms = review.role_perms(Role(name=role_nm))
        else:
            if perm.obj_name:
                perm.obj_name += '*'
            else:
                perm.obj_name = '*'
            if perm.op_name:
                perm.op_name += '*'
            else:
                perm.op_name = '*'
            label = perm.obj_name + '.' + perm.op_name
            prms = review.find_perms(perm)
        if len(prms) > 0:
            for idx, prm in enumerate(prms):
                print_entity(prm, label + ':' + str(idx))
        else:
            print_ln('No matching records found matching filter: ' + label)
    else:
        print('process_perm failed, invalid operation=' + args.operation)
        return False
    return True
예제 #7
0
    def test02_assigned_roles(self):
        """
        Test the assigned roles method
        """
        print_ln('test_assigned_roles')

        try:
            uList = review.find_users(User(uid='py-user*'))
            for usr in uList:
                print_ln("Assigned roles user="******"Assigned role", 1)
        except Exception as e:
            self.fail('test_assigned_roles failed, exception=' + e.msg)
예제 #8
0
 def test_validators(self):
     """
     Test the temporal constraints
     """
     print('test time-based constraints')
     validators = []
     validators.append(Date())
     validators.append(Day())
     validators.append(LockDate())
     validators.append(Time())
     validators.append(TimeOut())
     for constraint in cons1:
         for validator in validators:
             result = validator.validate(constraint, CurrentDateTime())
             print_entity(constraint, "Validate" + str(validator))
             print_ln('result=' + str(result), 1)