コード例 #1
0
ファイル: UserCmdlet.cs プロジェクト: vindamle/openiz
        internal static void UserInfo(GenericUserParms parms)
        {
            if (parms.UserName == null)
            {
                throw new InvalidOperationException("Must specify a user");
            }

            foreach (var un in parms.UserName)
            {
                var user = m_client.GetUsers(o => o.UserName == un).CollectionItem.FirstOrDefault();
                if (user == null)
                {
                    throw new KeyNotFoundException($"User {un} not found");
                }

                Console.WriteLine("User: {0}", user.UserName);
                Console.WriteLine("\tSID: {0}", user.UserId);
                Console.WriteLine("\tEmail: {0}", user.Email);
                Console.WriteLine("\tPhone: {0}", user.User.PhoneNumber);
                Console.WriteLine("\tInvalid Logins: {0}", user.User.InvalidLoginAttempts);
                Console.WriteLine("\tLockout: {0}", user.User.Lockout);
                Console.WriteLine("\tLast Login: {0}", user.User.LastLoginTime);
                Console.WriteLine("\tCreated: {0} ({1})", user.User.CreationTime, m_client.GetUser(user.User.CreatedByKey.ToString()).UserName);
                if (user.User.UpdatedTime.HasValue)
                {
                    Console.WriteLine("\tLast Updated: {0} ({1})", user.User.UpdatedTime, m_client.GetUser(user.User.UpdatedByKey.ToString()).UserName);
                }
                if (user.User.ObsoletionTime.HasValue)
                {
                    Console.WriteLine("\tDeActivated: {0} ({1})", user.User.ObsoletionTime, m_client.GetUser(user.User.ObsoletedByKey.ToString()).UserName);
                }
                Console.WriteLine("\tGroups: {0}", String.Join(";", user.Roles.Select(o => o.Name)));

                List <SecurityPolicyInfo> policies = m_client.GetPolicies(o => o.ObsoletionTime == null).CollectionItem.OrderBy(o => o.Oid).ToList();
                policies.ForEach(o => o.Grant = (PolicyGrantType)10);
                foreach (var rol in user.Roles)
                {
                    foreach (var pol in m_client.GetRole(rol.Id.ToString()).Policies)
                    {
                        var existing = policies.FirstOrDefault(o => o.Oid == pol.Oid);
                        if (pol.Grant < existing.Grant)
                        {
                            existing.Grant = pol.Grant;
                        }
                    }
                }

                Console.WriteLine("\tEffective Policies:");
                foreach (var itm in policies)
                {
                    Console.Write("\t\t{0} : ", itm.Name);
                    if (itm.Grant == (PolicyGrantType)10) // Lookup parent
                    {
                        var parent = policies.LastOrDefault(o => itm.Oid.StartsWith(o.Oid + ".") && itm.Oid != o.Oid);
                        if (parent != null && parent.Grant <= PolicyGrantType.Grant)
                        {
                            Console.WriteLine("{0} (inherited from {1})", parent.Grant, parent.Name);
                        }
                        else
                        {
                            Console.WriteLine("Deny (automatic)");
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0} (explicit)", itm.Grant);
                    }
                }
            }
        }