Exemplo n.º 1
0
    static void Main()
    {
        PolicyDecision policy = new PolicyDecision();
        policy.ApplicationName = "Application 1";

        String roleName = "Another: " + DateTime.Now;
        policy.CreateRole(roleName);

        Console.WriteLine("AllRoles: " + String.Join(", ", policy.GetAllRoles()));

        Console.WriteLine("Users from Role 1: " + String.Join(", ", policy.GetUsersInRole("Role 1")));

        Console.WriteLine("Is User 1 in Role 1? " + policy.IsUserInRole("User 1", "Role 1"));
        Console.WriteLine("Is User 3 in Role 1? " + policy.IsUserInRole("User 3", "Role 1"));

        policy.DeleteRole(roleName, true);
        policy.CreateRole("Test: " + DateTime.Now);
    }
Exemplo n.º 2
0
    public void AddRemoveUsers_UserAlreadyExists()
    {
        PolicyDecision policy = new PolicyDecision(config);
        policy.ApplicationName = "Application 2";

        if (false == policy.RoleExists("Role 1"))
          policy.CreateRole("Role 1");

        if (policy.IsUserInRole("User 1", "Role 1"))
          policy.RemoveUsersFromRoles(new String[] { "User 1" },
                  new String[] { "Role 1" });

        Assert.DoesNotThrow(() => policy.AddUsersToRoles(new String[] { "User 1" },
                             new String[] { "Role 1" }));

        Assert.Throws(typeof(ProviderException),
          () => policy.AddUsersToRoles(new String[] { "User 1" },
                           new String[] { "Role 1" }));

        policy.RemoveUsersFromRoles(new String[] { "User 1" },
                new String[] { "Role 1" });
        policy.DeleteRole("Role 1", false);
    }
Exemplo n.º 3
0
    public void UserRole_InvalidNames()
    {
        PolicyDecision policy = new PolicyDecision(config);

        Type[] expectations = new Type[] {
          typeof(ProviderException),
          typeof(ProviderException),
          typeof(ArgumentException)
        };
        String[] values = new String[] {
          String.Empty,
          null,
          "something , another ,"
        };
        Action<String>[] tests = new Action<String>[] {
          (value) => policy.CreateRole(value),
        (value) => policy.DeleteRole(value, false),
        (value) => policy.RoleExists(value),
        (value) => policy.GetUsersInRole(value),
        (value) => policy.IsUserInRole("Valid", value),
        (value) => policy.IsUserInRole(value, "Valid"),
        (value) => policy.GetRolesForUser(value),
        (value) => policy.FindUsersInRole(value, "Valid"),
        (value) => policy.FindUsersInRole("Valid", value)
        };

        for (Int32 i = 0; i != tests.Length; ++i)
          for (Int32 j = 0; j != values.Length; ++j)
        Assert.Throws(expectations[j], () => tests[i](values[j]));
    }