Ejemplo n.º 1
0
        /// <summary>
        /// Executes implementation for this rule
        /// </summary>
        /// <param name="parent">The composed rule containing this rule</param>
        /// <param name="entry">The search result we are checking</param>
        /// <param name="attributeValue">The current attribute value as pass through the chain</param>
        /// <returns>Either a success or error result</returns>
        public override RuleResult Execute(ComposedRule parent, SearchResultEntry entry, string attributeValue)
        {
            string objectType = this.GetObjectType(entry);

            this.MaxLength = objectType.Equals("user", StringComparison.CurrentCultureIgnoreCase) ? 20 : 256;

            return(base.Execute(parent, entry, attributeValue));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes implementation for this rule
        /// </summary>
        /// <param name="parent">The composed rule containing this rule</param>
        /// <param name="entry">The search result we are checking</param>
        /// <param name="attributeValue">The current attribute value as pass through the chain</param>
        /// <returns>Either a success or error result</returns>
        public override RuleResult Execute(ComposedRule parent, SearchResultEntry entry, string attributeValue)
        {
            if (Constants.PeriodsRegex.IsMatch(attributeValue))
            {
                this.GetErrorResult(ErrorType.Format, this.Fixer(entry, attributeValue));
            }

            return(this.GetSuccessResult());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Executes implementation for this rule
        /// </summary>
        /// <param name="parent">The composed rule containing this rule</param>
        /// <param name="entry">The search result we are checking</param>
        /// <param name="attributeValue">The current attribute value as pass through the chain</param>
        /// <returns>Either a success or error result</returns>
        public override RuleResult Execute(ComposedRule parent, SearchResultEntry entry, string attributeValue)
        {
            if (entry.Attributes.Contains(StringLiterals.UserPrincipalName))
            {
                return(this.GetSuccessResult());
            }

            return(base.Execute(parent, entry, attributeValue));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Executes implementation for this rule
        /// </summary>
        /// <param name="parent">The composed rule containing this rule</param>
        /// <param name="entry">The search result we are checking</param>
        /// <param name="attributeValue">The current attribute value as pass through the chain</param>
        /// <returns>Either a success or error result</returns>
        public override RuleResult Execute(ComposedRule parent, SearchResultEntry entry, string attributeValue)
        {
            if (string.IsNullOrEmpty(attributeValue))
            {
                var updatedValue = this.Fixer(entry, attributeValue);
                return(this.GetErrorResult(ErrorType.Blank, updatedValue));
            }

            return(this.GetSuccessResult());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Executes implementation for this rule
        /// </summary>
        /// <param name="parent">The composed rule containing this rule</param>
        /// <param name="entry">The search result we are checking</param>
        /// <param name="attributeValue">The current attribute value as pass through the chain</param>
        /// <returns>Either a success or error result</returns>
        public override RuleResult Execute(ComposedRule parent, SearchResultEntry entry, string attributeValue)
        {
            string objectType = this.GetObjectType(entry);

            if (objectType.Equals("group", StringComparison.CurrentCultureIgnoreCase))
            {
                return(base.Execute(parent, entry, attributeValue));
            }

            return(this.GetSuccessResult());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Executes implementation for this rule
        /// </summary>
        /// <param name="parent">The composed rule containing this rule</param>
        /// <param name="entry">The search result we are checking</param>
        /// <param name="attributeValue">The current attribute value as pass through the chain</param>
        /// <returns>Either a success or error result</returns>
        public override RuleResult Execute(ComposedRule parent, SearchResultEntry entry, string attributeValue)
        {
            if (attributeValue.Length > this.MaxLength)
            {
                var updatedValue = this.Fixer != null?this.Fixer(entry, attributeValue) : attributeValue.Substring(0, this.MaxLength);

                return(this.GetErrorResult(ErrorType.Length, updatedValue));
            }

            return(this.GetSuccessResult());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Executes implementation for this rule
        /// </summary>
        /// <param name="parent">The composed rule containing this rule</param>
        /// <param name="entry">The search result we are checking</param>
        /// <param name="attributeValue">The current attribute value as pass through the chain</param>
        /// <returns>Either a success or error result</returns>
        public override RuleResult Execute(ComposedRule parent, SearchResultEntry entry, string attributeValue)
        {
            string objectType = this.GetObjectType(entry);

            if (objectType.Equals("contact", StringComparison.CurrentCultureIgnoreCase) && parent.AttributeName == StringLiterals.MailNickName)
            {
                return(base.Execute(parent, entry, attributeValue));
            }

            return(this.GetSuccessResult());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a new instance of <see cref="TargetAddressBlankRule"/>
        /// </summary>
        public TargetAddressBlankRule() : base((entry, value) =>
        {
            var objectType = ComposedRule.GetObjectType(entry);
            // the orginal code doesn't provide a fix if the type isn't "contact"
            if (objectType.Equals("contact", StringComparison.CurrentCultureIgnoreCase))
            {
                value = "SMTP:" + entry.Attributes[StringLiterals.Mail][0].ToString();
                return(value.Length > 256 ? value.Substring(0, 256) : value);
            }

            return(value);
        })
        { }
Ejemplo n.º 9
0
        /// <summary>
        /// Executes implementation for this rule
        /// </summary>
        /// <param name="parent">The composed rule containing this rule</param>
        /// <param name="entry">The search result we are checking</param>
        /// <param name="attributeValue">The current attribute value as pass through the chain</param>
        /// <returns>Either a success or error result</returns>
        public override RuleResult Execute(ComposedRule parent, SearchResultEntry entry, string attributeValue)
        {
            int colonPosn = attributeValue.IndexOf(":");

            if (colonPosn > 0)
            {
                //In case the suffix has a colon, we need to show a character error.
                //And replace it.
                string suffix = attributeValue.Substring(colonPosn + 1);
                if (suffix.Contains(":"))
                {
                    return(this.GetErrorResult(ErrorType.Character, attributeValue.Substring(0, colonPosn) + ":" + suffix.Replace(":", "")));
                }
            }

            return(this.GetSuccessResult());
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Executes implementation for this rule
        /// </summary>
        /// <param name="parent">The composed rule containing this rule</param>
        /// <param name="entry">The search result we are checking</param>
        /// <param name="attributeValue">The current attribute value as pass through the chain</param>
        /// <returns>Either a success or error result</returns>
        public override RuleResult Execute(ComposedRule parent, SearchResultEntry entry, string attributeValue)
        {
            string objectType = this.GetObjectType(entry);
            var    homeMdb    = entry.Attributes[StringLiterals.HomeMdb];

            // When the entry is a contact or user
            if (objectType.Equals("contact", StringComparison.CurrentCultureIgnoreCase) || objectType.Equals("user", StringComparison.CurrentCultureIgnoreCase))
            {
                // and homeMdb is not defined
                if (homeMdb == null || homeMdb.Count == 0 || homeMdb[0] == null || string.IsNullOrWhiteSpace(homeMdb[0].ToString()))
                {
                    // targetAddress cannot be blank
                    return(base.Execute(parent, entry, attributeValue));
                }
            }

            return(this.GetSuccessResult());
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Executes implementation for this rule
        /// </summary>
        /// <param name="parent">The composed rule containing this rule</param>
        /// <param name="entry">The search result we are checking</param>
        /// <param name="attributeValue">The current attribute value as pass through the chain</param>
        /// <returns>Either a success or error result</returns>
        public override RuleResult Execute(ComposedRule parent, SearchResultEntry entry, string attributeValue)
        {
            if (this.CheckExpression.IsMatch(attributeValue))
            {
                string updated;
                if (this.Fixer == null)
                {
                    var tempVal = this.CheckExpression.Replace(attributeValue, string.Empty);
                    updated = string.IsNullOrEmpty(tempVal) ? entry.Attributes[StringLiterals.Cn][0].ToString() : tempVal;
                }
                else
                {
                    updated = this.Fixer(entry, attributeValue);
                }

                return(this.GetErrorResult(ErrorType.Character, updated));
            }

            return(this.GetSuccessResult());
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Executes implementation for this rule
        /// </summary>
        /// <param name="parent">The composed rule containing this rule</param>
        /// <param name="entry">The search result we are checking</param>
        /// <param name="attributeValue">The current attribute value as pass through the chain</param>
        /// <returns>Either a success or error result</returns>
        public override RuleResult Execute(ComposedRule parent, SearchResultEntry entry, string attributeValue)
        {
            // record in memory the entry details with a list of the attributes that end up needing to be checked
            if (DuplicateStore.IsDuplicate(parent.AttributeName, attributeValue, entry))
            {
                // we now need to execute some complicated logic from the original application depending
                // settings, etc. this isn't pretty but it follows the original for now

                var actionType    = ActionType.Edit;
                var originalValue = entry.Attributes[parent.AttributeName][0].ToString();

                // if nothing else has changed the value prior to this (which is why no duplicate rule needs to be run last)
                if (originalValue == attributeValue)
                {
                    switch (parent.AttributeName.ToLowerInvariant())
                    {
                    case "proxyaddresses":
                        if (Constants.SMTPRegex.IsMatch(attributeValue))
                        {
                            if (entry.Attributes.Contains(StringLiterals.MailNickName))
                            {
                                if (attributeValue.ToLowerInvariant().Substring(0, 5) == "smtp:")
                                {
                                    actionType = ActionType.Complete;
                                }
                            }
                            else
                            {
                                actionType = ActionType.Remove;
                            }
                        }
                        break;

                    case "userprincipalname":
                        if (entry.Attributes.Contains(StringLiterals.MailNickName))
                        {
                            actionType = ActionType.Complete;
                        }
                        break;

                    case "mail":
                        if (entry.Attributes.Contains(StringLiterals.MailNickName))
                        {
                            actionType = ActionType.Complete;
                        }
                        break;

                    case "mailnickname":
                        if (entry.Attributes.Contains(StringLiterals.HomeMdb))
                        {
                            actionType = ActionType.Complete;
                        }
                        break;

                    case "samaccountname":
                        if (entry.Attributes.Contains(StringLiterals.MailNickName))
                        {
                            actionType = ActionType.Complete;
                        }
                        break;
                    }
                }

                return(this.GetErrorResult(ErrorType.Duplicate, attributeValue, actionType));
            }

            return(this.GetSuccessResult());
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Executes implementation for this rule
        /// </summary>
        /// <param name="parent">The composed rule containing this rule</param>
        /// <param name="entry">The search result we are checking</param>
        /// <param name="attributeValue">The current attribute value as pass through the chain</param>
        /// <returns>Either a success or error result</returns>
        public override RuleResult Execute(ComposedRule parent, SearchResultEntry entry, string attributeValue)
        {
            var       tldList           = new ValidTLDList();
            bool      success           = true;
            ErrorType errors            = ErrorType.None;
            string    validateAttribute = Constants.SMTPRegex.IsMatch(attributeValue) ? attributeValue.Substring(attributeValue.IndexOf(":") + 1) : attributeValue;

            if (validateAttribute.LastIndexOf(".") != -1)
            {
                string tldDomain = validateAttribute.ToLowerInvariant().Substring(validateAttribute.LastIndexOf("."));
                if (tldDomain.Length > 1)
                {
                    if (!tldList.IsValid(tldDomain))
                    {
                        success = false;
                        errors |= ErrorType.TopLevelDomain;
                    }
                }
            }

            if (!Constants.DomainPartRegex.IsMatch(validateAttribute))
            {
                success = false;
                errors |= ErrorType.DomainPart;
                if (validateAttribute.LastIndexOf("@") != -1)
                {
                    validateAttribute = validateAttribute.Substring(0, validateAttribute.LastIndexOf("@") + 1)
                                        + (new Regex(@"[^a-z0-9.-]", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)).Replace(validateAttribute.Substring(validateAttribute.LastIndexOf("@") + 1), "");
                }
            }

            if (!Constants.LocalPartRegex.IsMatch(validateAttribute) || (validateAttribute.Split('@').Length - 1 > 1))
            {
                success = false;
                errors |= ErrorType.LocalPart;
                if (validateAttribute.LastIndexOf("@") != -1)
                {
                    string validateLocal = (new Regex(@"[^a-z0-9.!#$%&'*+/=?^_`{|}~-]", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)).Replace(validateAttribute.Substring(0, validateAttribute.LastIndexOf("@")), "");
                    validateAttribute = (validateLocal + validateAttribute.Substring(validateAttribute.LastIndexOf("@"))).Replace(".@", "@");
                }
            }

            if (!Constants.Rfc2822Regex.IsMatch(validateAttribute))
            {
                success = false;
                errors |= ErrorType.Format;
            }

            if (success)
            {
                return(this.GetSuccessResult());
            }
            else
            {
                attributeValue = Constants.SMTPRegex.IsMatch(attributeValue)
                    ? attributeValue.Substring(0, attributeValue.IndexOf(":") + 1).Trim() + validateAttribute
                    : validateAttribute;

                return(this.GetErrorResult(errors, attributeValue));
            }
        }