Exemplo n.º 1
0
        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() as SecurityUserInfo;
                if (user == null)
                {
                    throw new KeyNotFoundException($"User {un} not found");
                }

                DisplayUtil.PrintPolicies(user,
                                          new string[] { "Name", "SID", "Email", "Phone", "Invalid Logins", "Lockout", "Last Login", "Created", "Updated", "De-Activated", "Roles" },
                                          u => u.UserName,
                                          u => u.Key,
                                          u => u.Email,
                                          u => u.PhoneNumber,
                                          u => u.InvalidLoginAttempts,
                                          u => u.LockoutXml,
                                          u => u.LastLoginTimeXml,
                                          u => String.Format("{0} ({1})", u.CreationTimeXml, m_client.GetUser(m_client.GetProvenance(u.CreatedByKey.Value).UserKey.Value).Entity.UserName),
                                          u => String.Format("{0} ({1})", u.UpdatedTimeXml, m_client.GetUser(m_client.GetProvenance(u.UpdatedByKey.Value).UserKey.Value).Entity.UserName),
                                          u => String.Format("{0} ({1})", u.ObsoletionTimeXml, m_client.GetUser(m_client.GetProvenance(u.ObsoletedByKey.Value).UserKey.Value).Entity.UserName),
                                          u => String.Join(" , ", user.Roles)
                                          );
            }
        }
Exemplo n.º 2
0
        // // [PolicyPermission(System.Security.Permissions.SecurityAction.Demand, PolicyId = PermissionPolicyIdentifiers.AlterIdentity)]
        internal static void Userudel(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() as SecurityUserInfo;
                if (user == null)
                {
                    throw new KeyNotFoundException($"User {un} not found");
                }

                var patch = new Patch()
                {
                    AppliesTo = new PatchTarget(user.Entity),
                    Operation = new List <PatchOperation>()
                    {
                        new PatchOperation(PatchOperationType.Remove, "obsoletedBy", null),
                        new PatchOperation(PatchOperationType.Remove, "obsoletionTime", null)
                    }
                };
                m_client.Client.Patch($"SecurityUser/{user.Key}", user.Tag, patch);
            }
        }
Exemplo n.º 3
0
        // // [PolicyPermission(System.Security.Permissions.SecurityAction.Demand, PolicyId = PermissionPolicyIdentifiers.AlterIdentity)]
        internal static void Userdel(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() as SecurityUserInfo;
                if (user == null)
                {
                    throw new KeyNotFoundException($"User {un} not found");
                }

                m_client.DeleteUser(user.Entity.Key.Value);
            }
        }
Exemplo n.º 4
0
        // // [PolicyPermission(System.Security.Permissions.SecurityAction.Demand, PolicyId = PermissionPolicyIdentifiers.AlterIdentity)]
        internal static void Userudel(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() as SecurityUserInfo;
                if (user == null)
                {
                    throw new KeyNotFoundException($"User {un} not found");
                }

                user.Entity.Lockout        = DateTime.MinValue;
                user.Entity.ObsoletionTime = null;
                user.Entity.ObsoletedBy    = null;

                m_client.UpdateUser(user.Entity.Key.Value, user);
            }
        }
Exemplo n.º 5
0
        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);
                    }
                }
            }
        }