// [PolicyPermission(System.Security.Permissions.SecurityAction.Demand, PolicyId = PermissionPolicyIdentifiers.CreateApplication)] internal static void AddApplication(AddApplicationParms parms) { var policies = new List <SecurityPolicyInfo>(); if (parms.GrantPolicies?.Count > 0) { policies = parms.GrantPolicies.OfType <String>().Select(o => m_client.GetPolicies(r => r.Oid == o).CollectionItem.FirstOrDefault()).OfType <SecurityPolicy>().Select(o => new SecurityPolicyInfo(o)).ToList(); } if (parms.DenyPolicies?.Count > 0) { policies = policies.Union(parms.DenyPolicies.OfType <String>().Select(o => m_client.GetPolicies(r => r.Oid == o).CollectionItem.FirstOrDefault()).OfType <SecurityPolicy>().Select(o => new SecurityPolicyInfo(o))).ToList(); } policies.ForEach(o => o.Grant = parms.GrantPolicies?.Contains(o.Oid) == true ? PolicyGrantType.Grant : PolicyGrantType.Deny); if (policies.Count != (parms.DenyPolicies?.Count ?? 0) + (parms.GrantPolicies?.Count ?? 0)) { throw new InvalidOperationException("Could not find one or more policies"); } if (String.IsNullOrEmpty(parms.Secret)) { parms.Secret = BitConverter.ToString(Guid.NewGuid().ToByteArray()).Replace("-", "").Substring(0, 12); Console.WriteLine("Application secret: {0}", parms.Secret); } m_client.CreateApplication(new SecurityApplicationInfo() { Policies = policies, Entity = new SecurityApplication() { Name = parms.ApplictionId.OfType <String>().First(), ApplicationSecret = parms.Secret } }); Console.WriteLine("CREATE {0}", parms.ApplictionId[0]); }