Esempio n. 1
0
        public static bool CanFindAccount(this Cmdlet command, AccountIdentity account, AccountType accountType)
        {
            if (account == null)
            {
                return(false);
            }
            var name  = account.Name;
            var error = $"Cannot find an account with identity '{name}'.";

            if (accountType == AccountType.Role)
            {
                if (!Role.Exists(name) && !RolesInRolesManager.IsCreatorOwnerRole(name) && !RolesInRolesManager.IsSystemRole(name))
                {
                    command.WriteError(new ErrorRecord(new ObjectNotFoundException(error),
                                                       ErrorIds.AccountNotFound.ToString(),
                                                       ErrorCategory.ObjectNotFound, account));
                    return(false);
                }
            }

            if (accountType == AccountType.User && !User.Exists(name))
            {
                command.WriteError(new ErrorRecord(new ObjectNotFoundException(error), ErrorIds.AccountNotFound.ToString(),
                                                   ErrorCategory.ObjectNotFound, account));
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        public AccountIdentity(string name)
        {
            Assert.ArgumentNotNullOrEmpty(name, "name");

            var domain  = "sitecore";
            var account = name;

            if (name.Contains(@"\"))
            {
                domain  = StringUtil.GetPrefix(name, '\\');
                account = StringUtil.GetPostfix(name, '\\');
            }

            if (!Regex.IsMatch(account, @"^\w[\w\s.\\_-]*$", RegexOptions.Compiled))
            {
                throw new ArgumentException(
                          $"The name '{name}' is improperly formatted.\n\nThe name can only contain the following characters: a-z, 0-9, periods, dashes, underscores, backslashes, and spaces.", "name");
            }

            Domain  = domain;
            Account = account;
            if (RolesInRolesManager.IsCreatorOwnerRole(account))
            {
                Name = name;
            }
            else
            {
                Name = string.IsNullOrEmpty(domain) ? account : domain + @"\" + account;
            }
        }
Esempio n. 3
0
        public static Account GetAccountFromIdentity(this Cmdlet command, AccountIdentity identity)
        {
            Account account = identity;

            if (account == null)
            {
                if (RolesInRolesManager.IsCreatorOwnerRole(identity.Name) || RolesInRolesManager.IsSystemRole(identity.Name))
                {
                    return(Role.FromName(identity.Name));
                }
                var error = $"Cannot find an account with identity '{identity.Name}'.";
                command.WriteError(new ErrorRecord(new ObjectNotFoundException(error), ErrorIds.AccountNotFound.ToString(),
                                                   ErrorCategory.ObjectNotFound, identity));
            }
            return(account);
        }