Exemple #1
0
        /// <summary>
        /// <para>
        /// Show <c>GetEntityRights</c> function usage.
        /// </para>
        /// </summary>
        /// <param name="client">
        /// <see cref="HermesAuthorizationServiceClient"/> instance.
        /// </param>
        private static void GetEntityRights(
            HermesAuthorizationServiceClient client)
        {
            Rights rights = client.GetEntityRights("1", "101", "SomeEntity1");

            Assert.AreEqual(
                rights, Rights.Read | Rights.Insert, "entiry3 should have Execute rights.");
        }
Exemple #2
0
 /// <summary>
 /// <para>
 /// Show <c>CheckRole</c> function usage.
 /// </para>
 /// </summary>
 /// <param name="client">
 /// <see cref="HermesAuthorizationServiceClient"/> instance.
 /// </param>
 private static void CheckRole(HermesAuthorizationServiceClient client)
 {
     Assert.IsTrue(
         client.CheckRole("1", "101", "Admin"),
         "Admin Role should been granted");
     Assert.IsFalse(
         client.CheckRole("1", "101", "Employee"),
         "None Role should not been granted");
 }
Exemple #3
0
        public void testDemo()
        {
            HermesAuthorizationServiceClient client =
                HermesAuthorizationServiceClient.GetClient();

            CheckEntity(client);
            CheckRole(client);
            CheckFunction(client);
            GetEntityRights(client);
        }
Exemple #4
0
 /// <summary>
 /// <para>
 /// Show <c>CheckEntity</c> function usage.
 /// </para>
 /// </summary>
 /// <param name="client">
 /// <see cref="HermesAuthorizationServiceClient"/> instance.
 /// </param>
 private static void CheckEntity(
     HermesAuthorizationServiceClient client)
 {
     Assert.IsTrue(
         client.CheckEntity("1", "101", "SomeEntity1", Rights.Read),
         "entity1 should have read rights.");
     Assert.IsFalse(client.CheckEntity(
                        "1", "101", "SomeEntity2", Rights.Read),
                    "entity2 should not have read rights.");
     Assert.IsTrue(
         client.CheckEntity("1", "101", "SomeEntity2", Rights.Update),
         "entity2 should have update rights.");
 }
Exemple #5
0
 /// <summary>
 /// <para>
 /// Show <c>CheckFunction</c> function usage.
 /// </para>
 /// </summary>
 /// <param name="client">
 /// <see cref="HermesAuthorizationServiceClient"/> instance.
 /// </param>
 private static void CheckFunction(
     HermesAuthorizationServiceClient client)
 {
     //Check Function
     Assert.IsTrue(
         client.CheckFunction("1", "101", "Enter Competition"),
         "User can do test action.");
     Assert.IsTrue(
         client.CheckFunction("1", "101", "Enter Competition"),
         "User can do do action.");
     Assert.IsFalse(
         client.CheckFunction("1", "101", "Post Components"),
         "User can not do none action.");
 }
Exemple #6
0
 /// <summary>
 /// <para>
 /// Check functions.
 /// </para>
 /// </summary>
 /// <param name="applicationId">
 /// application id.
 /// </param>
 /// <param name="sessionID">id of the current session</param>
 /// <param name="sessionToken">token for the current session</param>
 /// <param name="attributes">the attributes to be checked.</param>
 /// <returns>
 /// true if all attributes pass check, otherwise false.
 /// </returns>
 private static bool CheckFunctionalAttributes(string applicationId,
                                               string sessionID, string sessionToken, FunctionalAbilitiesAttribute[] attributes)
 {
     using (HermesAuthorizationServiceClient client =
                HermesAuthorizationServiceClient.GetClient())
     {
         IAuthorizationMappingProvider provider = CreateMapper();
         foreach (FunctionalAbilitiesAttribute attribute in attributes)
         {
             foreach (string functionalAbility in attribute.FunctionalAbilities)
             {
                 if (client.CheckFunction(sessionID, sessionToken,
                                          provider.GetFunctionName(functionalAbility)))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Exemple #7
0
 /// <summary>
 /// <para>
 /// Get the function name using the <paramref name="referenceFunctionName"/>.
 /// </para>
 /// </summary>
 /// <param name="applicationId">
 /// application id.
 /// </param>
 /// <param name="sessionId">id of the current session</param>
 /// <param name="sessionToken">token for the current session</param>
 /// <param name="referenceFunctionName">
 /// Reference function name.
 /// </param>
 /// <returns></returns>
 public static IList <KeyValuePair <string, string> > GetFunctionAttributes
     (string applicationId, string sessionId,
     string sessionToken, string referenceFunctionName)
 {
     using (HermesAuthorizationServiceClient client =
                HermesAuthorizationServiceClient.GetClient())
     {
         IAuthorizationMappingProvider         provider   = CreateMapper();
         List <KeyValuePair <string, string> > attributes =
             client.GetFunctionAttributes(sessionId, sessionToken,
                                          provider.GetFunctionName(referenceFunctionName));
         List <KeyValuePair <string, string> > ret =
             new List <KeyValuePair <string, string> >();
         foreach (KeyValuePair <string, string> value in attributes)
         {
             ret.Add(new KeyValuePair <string, string>(
                         provider.GetFunctionAttributeName(
                             referenceFunctionName, value.Key), value.Value));
         }
         return(ret);
     }
 }
Exemple #8
0
        public void Test2()
        {
            TestHelper.LoadConfig();

            serviceHost = new TCWcfServiceHost(
                typeof(HermesAuthorizationService), DemoEndPointAddress);
            BasicHttpBinding        binding  = new BasicHttpBinding();
            ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();

            behavior.HttpGetEnabled = true;
            serviceHost.Description.Behaviors.Add(behavior);
            serviceHost.AddServiceEndpoint(
                typeof(IAuthorization), binding, "");
            serviceHost.Open();



            client = HermesAuthorizationServiceClient.GetClient();

            Assert.IsTrue(client.CheckEntity("1", "101", "SomeEntity1",
                                             Rights.Read), "entity1 should have read rights.");
            Assert.IsFalse(client.CheckEntity("1", "101", "SomeEntity2",
                                              Rights.Read), "entity2 should not have read rights.");
        }