示例#1
0
        internal static void ListPolicies(ListPolicyParms parms)
        {
            IEnumerable <SecurityPolicy> policies = null;

            if (!String.IsNullOrEmpty(parms.Name))
            {
                policies = m_client.GetPolicies(o => o.Name.Contains(parms.Name)).CollectionItem.OfType <SecurityPolicy>();
            }
            else if (!String.IsNullOrEmpty(parms.Oid))
            {
                policies = m_client.GetPolicies(o => o.Oid.Contains(parms.Oid)).CollectionItem.OfType <SecurityPolicy>();
            }
            else
            {
                policies = m_client.GetPolicies(o => true).CollectionItem.OfType <SecurityPolicy>();
            }

            // Now output
            DisplayUtil.TablePrint(policies,
                                   new String[] { "SID", "Name", "Oid" },
                                   new int[] { 38, 38, 44 },
                                   p => p.Key,
                                   p => p.Name,
                                   p => p.Oid
                                   );
        }
        // [PolicyPermission(System.Security.Permissions.SecurityAction.Demand, PolicyId = PermissionPolicyIdentifiers.ReadMetadata)]
        internal static void ListRoles(ApplicationListParams parms)
        {
            AmiCollection list = null;
            int           tr   = 0;

            if (parms.Active)
            {
                list = m_client.Query <SecurityApplication>(o => o.ObsoletionTime.HasValue, 0, 100, out tr);
            }
            else if (parms.Locked)
            {
                list = m_client.Query <SecurityApplication>(o => o.Lockout.HasValue, 0, 100, out tr);
            }
            else
            {
                list = m_client.Query <SecurityApplication>(o => o.ObsoletionTime == null, 0, 100, out tr);
            }

            DisplayUtil.TablePrint(list.CollectionItem.OfType <SecurityApplicationInfo>(),
                                   new String[] { "SID", "Name", "Last Auth.", "Lockout", "ILA", "A" },
                                   new int[] { 38, 24, 22, 22, 4, 2 },
                                   o => o.Entity.Key,
                                   o => o.Entity.Name,
                                   o => o.Entity.LastAuthenticationXml,
                                   o => o.Entity.LockoutXml,
                                   o => o.Entity.InvalidAuthAttempts ?? 0,
                                   o => !o.Entity.ObsoletionTime.HasValue ? "*" : null);
        }
        public static void ListAssigningAuthority(ListAssigningAuthorityParams parms)
        {
            IEnumerable <AssigningAuthority> auths = null;

            if (!String.IsNullOrEmpty(parms.Name))
            {
                auths = m_amiClient.GetAssigningAuthorities(o => o.Name.Contains(parms.Name)).CollectionItem.OfType <AssigningAuthority>();
            }
            else if (!String.IsNullOrEmpty(parms.Oid))
            {
                auths = m_amiClient.GetAssigningAuthorities(o => o.Oid == parms.Oid).CollectionItem.OfType <AssigningAuthority>();
            }
            else if (!String.IsNullOrEmpty(parms.Url))
            {
                auths = m_amiClient.GetAssigningAuthorities(o => o.Url == parms.Url).CollectionItem.OfType <AssigningAuthority>();
            }
            else
            {
                auths = m_amiClient.GetAssigningAuthorities(o => o.CreationTime != null).CollectionItem.OfType <AssigningAuthority>();
            }

            DisplayUtil.TablePrint(auths,
                                   o => o.DomainName,
                                   o => o.Name,
                                   o => o.Url,
                                   o => o.IsUnique);
        }
        public static void ServiceInformation()
        {
            var diagReport = m_client.GetServerDiagnoticReport().ApplicationInfo;

            DisplayUtil.TablePrint(diagReport.ServiceInfo,
                                   new String[] { "Service", "Classification", "Running" },
                                   new int[] { 60, 20, 10 },
                                   o => o.Description,
                                   o => o.Class,
                                   o => o.IsRunning
                                   );
        }
        public static void ServiceThreadInformation()
        {
            var diagReport = m_client.GetServerDiagnoticReport();

            DisplayUtil.TablePrint(diagReport.Threads,
                                   new String[] { "Name", "CPU Time", "State", "Task" },
                                   new int[] { 32, 10, 10, 32 },
                                   o => o.Name,
                                   o => o.CpuTime,
                                   o => o.State,
                                   o => o.TaskInfo
                                   );
        }
示例#6
0
        public static void ListApplets()
        {
            var applets = m_client.GetApplets();

            DisplayUtil.TablePrint(applets.CollectionItem.OfType <AppletManifestInfo>(),
                                   new String[] { "ID", "Name", "Version", "Publisher", "S" },
                                   new int[] { 25, 25, 10, 58, 2 },
                                   o => o.AppletInfo.Id,
                                   o => o.AppletInfo.Names.FirstOrDefault().Value,
                                   o => o.AppletInfo.Version,
                                   o => o.AppletInfo.Author,
                                   o => o.PublisherData != null ? "*" : null
                                   );
        }
示例#7
0
        internal static void Userlist(UserListParms parms)
        {
            var           un    = parms.UserName?.OfType <String>()?.FirstOrDefault();
            AmiCollection users = null;

            if (parms.Locked && !String.IsNullOrEmpty(un))
            {
                users = m_client.GetUsers(o => o.UserName.Contains(un) && o.Lockout.HasValue);
            }
            else if (!String.IsNullOrEmpty(un))
            {
                users = m_client.GetUsers(o => o.UserName.Contains(un));
            }
            else
            {
                users = m_client.GetUsers(o => o.ObsoletionTime == null);
            }

            if (parms.Active)
            {
                users.CollectionItem = users.CollectionItem.OfType <SecurityUserInfo>().Where(o => o.Entity.ObsoletionTime.HasValue).OfType <object>().ToList();
            }
            if (parms.Human)
            {
                users.CollectionItem = users.CollectionItem.OfType <SecurityUserInfo>().Where(o => o.Entity.UserClass == ActorTypeKeys.HumanUser).OfType <object>().ToList();
            }
            else if (parms.System)
            {
                users.CollectionItem = users.CollectionItem.OfType <SecurityUserInfo>().Where(o => o.Entity.UserClass != ActorTypeKeys.HumanUser).OfType <object>().ToList();
            }
            DisplayUtil.TablePrint(users.CollectionItem.OfType <SecurityUserInfo>(),
                                   new String[] { "SID", "Name", "Last Auth", "Lockout", "ILA", "A" },
                                   new int[] { 38, 24, 22, 22, 4, 2 },
                                   o => o.Entity.Key,
                                   o => o.Entity.UserName,
                                   o => o.Entity.LastLoginTimeXml,
                                   o => o.Entity.LockoutXml,
                                   o => o.Entity.InvalidLoginAttempts,
                                   o => o.Entity.ObsoletionTime.HasValue ? null : "*"
                                   );
        }
示例#8
0
        // [PolicyPermission(System.Security.Permissions.SecurityAction.Demand, PolicyId = PermissionPolicyIdentifiers.ReadMetadata)]
        internal static void ListRoles(RoleListParams parms)
        {
            AmiCollection list = null;
            int           tr   = 0;

            if (parms.Active)
            {
                list = m_client.Query <SecurityRole>(o => o.ObsoletionTime != null, 0, 100, out tr);
            }
            else
            {
                list = m_client.Query <SecurityRole>(o => o.ObsoletionTime == null, 0, 100, out tr);
            }

            DisplayUtil.TablePrint(list.CollectionItem.OfType <SecurityRoleInfo>(),
                                   new String[] { "SID", "Name", "Description", "A" },
                                   new int[] { 38, 20, 48, 2 },
                                   o => o.Entity.Key,
                                   o => o.Entity.Name,
                                   o => o.Entity.Description,
                                   o => !o.Entity.ObsoletionTime.HasValue ? "*" : null);
        }
示例#9
0
        // [PolicyPermission(System.Security.Permissions.SecurityAction.Demand, PolicyId = PermissionPolicyIdentifiers.CreateDevice)]
        internal static void QueryData(HdsiQueryParameters parms)
        {
            if (String.IsNullOrEmpty(parms.ResourceType))
            {
                throw new ArgumentNullException("Require --resourceType or -r");
            }

            // Get the type
            var type = new ModelSerializationBinder().BindToType(null, parms.ResourceType);

            if (type == null)
            {
                throw new InvalidOperationException($"Cannot find reosurce type {parms.ResourceType}");
            }

            if (!parms.AsDataSet)
            {
                Console.WriteLine("Type: {0}", type);
            }

            // Build the parameter list
            NameValueCollection nvc = new NameValueCollection();

            if (parms.Filter != null)
            {
                foreach (var kv in parms.Filter)
                {
                    var f = kv.Split('=');
                    nvc.Add(f[0], f[1]);
                }
            }

            Int32.TryParse(parms.Offset ?? "0", out int offset);
            Int32.TryParse(parms.Count ?? "25", out int count);

            if (parms.Display == null)
            {
                parms.Display = new System.Collections.Specialized.StringCollection()
                {
                    "id", "ToString"
                }
            }
            ;

            // Get the specified lambda expression
            var builderMethod  = typeof(QueryExpressionParser).GetGenericMethod(nameof(QueryExpressionParser.BuildLinqExpression), new Type[] { type }, new Type[] { typeof(NameValueCollection) });
            var linqExpression = builderMethod.Invoke(null, new object[] { nvc });

            if (!parms.AsDataSet)
            {
                Console.WriteLine("Filter: {0}", linqExpression);
            }

            // Fetch results

            var queryMethod = m_client.GetType().GetGenericMethod(nameof(HdsiServiceClient.Query), new Type[] { type }, new Type[] { linqExpression.GetType(), typeof(int), typeof(int?), typeof(String[]), typeof(Guid?), typeof(ModelSort <>).MakeGenericType(type).MakeArrayType() });
            var result      = queryMethod.Invoke(m_client, new object[] { linqExpression, offset, count, parms.Expand?.OfType <String>().ToArray(), null, null }) as Bundle;


            if (!parms.AsDataSet)
            {
                Console.WriteLine("Result: {0} .. {1} of {2}", result.Offset, result.Item.Count, result.TotalResults);
                var displayCols = parms.Display.OfType <String>().Select(o =>
                {
                    return((Expression <Func <IdentifiedData, Object> >)(col => o == "ToString" ? col.ToString() : QueryExpressionParser.BuildPropertySelector(type, o, true).Compile().DynamicInvoke(col)));
                }).ToArray();

                DisplayUtil.TablePrint <IdentifiedData>(result.Item, parms.Display.OfType <String>().ToArray(), parms.Display.OfType <String>().Select(o => 40).ToArray(), displayCols);
            }
            else
            {
                Dataset ds = new Dataset($"sdbac Dataset for {type} filter {nvc}");

                Delegate displaySelector = null;
                if (parms.Display.Count > 0)
                {
                    displaySelector = QueryExpressionParser.BuildPropertySelector(type, parms.Display.OfType <String>().FirstOrDefault(), true).Compile();
                }

                foreach (var itm in result.Item)
                {
                    ds.Action.Add(new DataUpdate()
                    {
                        InsertIfNotExists = true,
                        IgnoreErrors      = true,
                        Element           = (IdentifiedData)(displaySelector != null ? displaySelector.DynamicInvoke(itm) : itm)
                    });
                }

                m_xsz.Serialize(Console.Out, ds);
            }
        }
    }