protected override void ConfigureCreateRuleSet() { When(user => !string.IsNullOrWhiteSpace(user.UserName), () => { RuleFor(user => user.UserName) .MustAsync(async(userName, token) => await _UserRepository.IsUserNameAvailable(userName)) .WithState(u => new ScimError( HttpStatusCode.Conflict, ScimErrorType.Uniqueness, ScimErrorDetail.AttributeUnique("userName"))); }); When(user => user.Password != null, () => { RuleFor(user => user.Password) .MustAsync(async(password, token) => await _PasswordManager.MeetsRequirements(password)) .WithState(u => new ScimError( HttpStatusCode.BadRequest, ScimErrorType.InvalidValue, "The attribute 'password' does not meet the security requirements set by the provider.")); }); }
protected override void ConfigureUpdateRuleSet() { RuleFor(user => user.Id) .Immutable(() => ExistingRecord.Id, StringComparer.OrdinalIgnoreCase) .WithState(u => new ScimError( HttpStatusCode.BadRequest, ScimErrorType.Mutability, ScimErrorDetail.AttributeImmutable("id"))); // Updating a username validation When(user => user.UserName != null && !user.UserName.Equals(ExistingRecord.UserName, StringComparison.OrdinalIgnoreCase), () => { RuleFor(user => user.UserName) .MustAsync(async(user, userName, token) => await _UserRepository.IsUserNameAvailable(userName)) .WithState(user => new ScimError( HttpStatusCode.Conflict, ScimErrorType.Uniqueness, ScimErrorDetail.AttributeUnique("userName"))); }); // Updating a user password When(user => user.Password != null && _PasswordManager.PasswordIsDifferent(user.Password, ExistingRecord.Password), () => { RuleFor(user => user.Password) .MustAsync(async(password, token) => await _PasswordManager.MeetsRequirements(password)) .WithState(u => new ScimError( HttpStatusCode.BadRequest, ScimErrorType.InvalidValue, "The attribute 'password' does not meet the security requirements set by the provider.")); }); }