예제 #1
0
        /// <summary>
        /// Register with rights from database and one additional right
        /// </summary>
        /// <param name="legitimationUuid">associated legitimated id</param>
        /// <param name="additionalRight"></param>
        /// <param name="token">optional pregiven token</param>
        /// <returns>the registered token</returns>
        public async Task <string> Register(string legitimationUuid, PureRight additionalRight, string token = null)
        {
            List <PureRight> pureRights = await GetPureRights(legitimationUuid);

            pureRights.Add(additionalRight);
            return(ApplyRights(legitimationUuid, pureRights, token));
        }
예제 #2
0
 private async Task <List <PureRight> > GetPureRights(string legitimationUuid)
 {
     return(await AmazonDynamoDBFactory.ExecuteInTransactionContext(async (client, context) =>
     {
         List <PureRight> pureRights = new List <PureRight>();
         var request = new QueryRequest
         {
             TableName = BesteRightsAuthorization.TableName,
             //ScanIndexForward = false,
             KeyConditions = new Dictionary <string, Condition>
             {
                 { "TableId", new Condition()
                   {
                       ComparisonOperator = ComparisonOperator.EQ,
                       AttributeValueList = new List <AttributeValue>
                       {
                           new AttributeValue {
                               N = TABLE_ID.ToString()
                           }
                       }
                   } }
             },
             ExpressionAttributeNames = new Dictionary <string, string>
             {
                 { "#namespace", "Namespace" },
                 { "#legitimationuuid", "LegitimationUuid" }
             },
             ExpressionAttributeValues = new Dictionary <string, AttributeValue>
             {
                 { ":namespace", new AttributeValue {
                       S = BesteRightsNamespace
                   } },
                 { ":legitimationuuid", new AttributeValue {
                       S = legitimationUuid
                   } }
             },
             FilterExpression = "#namespace = :namespace and #legitimationuuid = :legitimationuuid"
         };
         var response = await AmazonDynamoDBFactory.Client.QueryAsync(request);
         foreach (var item in response.Items)
         {
             PureRight pureRight = new PureRight
             {
                 RecourceModule = item["RecourceModule"].S,
                 Authorized = item["Authorized"].N == "1" ? true : false,
                 Operation = item["Operation"].S
             };
             if (item.ContainsKey("RecourceId"))
             {
                 pureRight.RecourceId = Convert.ToInt32(item["RecourceId"].N);
             }
             pureRights.Add(pureRight);
         }
         return pureRights;
     }));
 }