public override Task HandleCollectCompletedEvent(BankIdCollectCompletedEvent e) { var properties = new Dictionary <string, string> { { PropertyName_BankIdOrderRef, e.OrderRef } }; if (_options.LogUserNames) { properties.Add(PropertyName_UserName, e.CompletionData.User.Name); properties.Add(PropertyName_UserGivenName, e.CompletionData.User.GivenName); properties.Add(PropertyName_UserSurname, e.CompletionData.User.Surname); } if (_options.LogDeviceIpAddress) { properties.Add(PropertyName_BankIdUserDeviceIpAddress, e.CompletionData.Device.IpAddress); } if (_options.LogCertificateDates) { properties.Add(PropertyName_BankIdUserCertNotBefore, e.CompletionData.Cert.NotBefore); properties.Add(PropertyName_BankIdUserCertNotAfter, e.CompletionData.Cert.NotAfter); } var personalIdentityNumber = PersonalIdentityNumber.Parse(e.CompletionData.User.PersonalIdentityNumber); return(Track( e, properties, personalIdentityNumber: personalIdentityNumber, detectedDevice: e.DetectedUserDevice, loginOptions: e.BankIdOptions )); }
public void Day_Equals_Day(int year, int month, int day, int birthNumber, int checksum) { var personalIdentityNumber = new PersonalIdentityNumber(year, month, day, birthNumber, checksum); var dateOfBirth = personalIdentityNumber.GetDateOfBirthHint(); Assert.Equal(day, dateOfBirth.Day); }
public void TryParse_Returns_True_And_Outs_PIN_When_Valid_PIN() { var isValid = PersonalIdentityNumber.TryParse("000101-2384", out PersonalIdentityNumber personalIdentityNumber); Assert.True(isValid); Assert.Equal(new PersonalIdentityNumber(2000, 01, 01, 238, 4), personalIdentityNumber); }
internal BankIdAspNetAuthenticateSuccessEvent(AuthenticationTicket authenticationTicket, PersonalIdentityNumber personalIdentityNumber, BankIdSupportedDevice detectedUserDevice) : base(BankIdEventTypes.AspNetAuthenticateSuccessEventId, BankIdEventTypes.AspNetAuthenticateSuccessEventName, BankIdEventSeverity.Success) { AuthenticationTicket = authenticationTicket; PersonalIdentityNumber = personalIdentityNumber; DetectedUserDevice = detectedUserDevice; }
private static void Sample_ParseSwedishPersonalIdentityNumbers_Strict(IEnumerable <PersonalIdentityNumber> pins) { foreach (var input in pins) { WriteHeader($"Input: {input.To10DigitString()}, strict mode TenDigits"); if (PersonalIdentityNumber.TryParse(input.To10DigitString(), StrictMode.TenDigits, out var identityNumber10)) { WriteSwedishPersonalIdentityNumberInfo(identityNumber10); } else { Console.Error.WriteLine("Unable to parse the input as a SwedishPersonalIdentityNumber."); WriteSpace(); } WriteHeader($"Input: {input.To12DigitString()}, strict mode TenDigits"); if (PersonalIdentityNumber.TryParse(input.To12DigitString(), StrictMode.TenDigits, out var identityNumber12)) { WriteSwedishPersonalIdentityNumberInfo(identityNumber12); } else { Console.Error.WriteLine("Unable to parse the input as a SwedishPersonalIdentityNumber."); WriteSpace(); } } }
public void TryParseInSpecificYear_Returns_True_And_Outs_PIN_When_Valid_PIN() { var isValid = PersonalIdentityNumber.TryParseInSpecificYear("990913+9801", 2018, out PersonalIdentityNumber personalIdentityNumber); Assert.True(isValid); Assert.Equal(new PersonalIdentityNumber(1899, 09, 13, 980, 1), personalIdentityNumber); }
public void TryParse_Returns_False_And_Outputs_Null_When_Invalid_Day() { var isValid = PersonalIdentityNumber.TryParse("170199-2388", out PersonalIdentityNumber personalIdentityNumber); Assert.False(isValid); Assert.Null(personalIdentityNumber); }
public void When_Not_Yet_Born_Throws_Exception(int year, int month, int day, int birthNumber, int checksum) { var personalIdentityNumber = new PersonalIdentityNumber(year, month, day, birthNumber, checksum); var ex = Assert.Throws <ArgumentException>(() => personalIdentityNumber.GetAgeHint(_date_2000_04_14)); Assert.Contains("The person is not yet born.", ex.Message); }
public void A_PIN_Is_Not_Equal_Object_Null_Using_Method() { var personalIdentityNumber1 = PersonalIdentityNumber.Parse("199908072391"); var equals = personalIdentityNumber1.Equals((object)null); Assert.False(equals); }
public void Two_Different_PIN_Are_Not_Equal_Using_Method() { var personalIdentityNumber1 = PersonalIdentityNumber.Parse("199908072391"); var personalIdentityNumber2 = PersonalIdentityNumber.Parse("191202119986"); var equals = personalIdentityNumber1.Equals(personalIdentityNumber2); Assert.False(equals); }
public void Two_Identical_PIN_Returns_Same_Hashcode() { var personalIdentityNumberString = "199908072391"; var personalIdentityNumber1 = PersonalIdentityNumber.Parse(personalIdentityNumberString); var personalIdentityNumber2 = PersonalIdentityNumber.Parse(personalIdentityNumberString); Assert.Equal(personalIdentityNumber1.GetHashCode(), personalIdentityNumber2.GetHashCode()); }
public void Two_Different_PIN_Are_Not_Equal_Using_Operator() { var personalIdentityNumber1 = PersonalIdentityNumber.Parse("199908072391"); var personalIdentityNumber2 = PersonalIdentityNumber.Parse("191202119986"); var equals = personalIdentityNumber1 != personalIdentityNumber2; Assert.True(equals); }
public void Two_Identical_PIN_Are_Not_Unequal_Using_Operator() { var personalIdentityNumberString = "199908072391"; var personalIdentityNumber1 = PersonalIdentityNumber.Parse(personalIdentityNumberString); var personalIdentityNumber2 = PersonalIdentityNumber.Parse(personalIdentityNumberString); var notEquals = personalIdentityNumber1 != personalIdentityNumber2; Assert.False(notEquals); }
public void Two_Identical_PIN_When_One_Is_Object_Are_Equal_Using_Method() { var personalIdentityNumberString = "199908072391"; var personalIdentityNumber1 = PersonalIdentityNumber.Parse(personalIdentityNumberString); var personalIdentityNumber2 = (object)PersonalIdentityNumber.Parse(personalIdentityNumberString); var equals = personalIdentityNumber1.Equals(personalIdentityNumber2); Assert.True(equals); }
public void Two_Identical_PIN_Are_Equal_Using_Operator() { var personalIdentityNumberString = "199908072391"; var personalIdentityNumber1 = PersonalIdentityNumber.Parse(personalIdentityNumberString); var personalIdentityNumber2 = PersonalIdentityNumber.Parse(personalIdentityNumberString); var equals = personalIdentityNumber1 == personalIdentityNumber2; Assert.True(equals); }
/// <summary> /// Method checks whether SaveButton should be disabled or not /// </summary> /// <param name="obj">Leave it empty</param> /// <returns>True if button can be enabled and false otherwise</returns> private bool SaveCanExcecute(object obj) { if (string.IsNullOrWhiteSpace(PersonalIdentityNumber) || PersonalIdentityNumber.Any(c => !char.IsDigit(c))) { return(false); } if (string.IsNullOrWhiteSpace(Name)) { return(false); } if (string.IsNullOrWhiteSpace(Surname)) { return(false); } if (string.IsNullOrWhiteSpace(Street)) { return(false); } if (string.IsNullOrWhiteSpace(HouseNumber)) { return(false); } if (string.IsNullOrWhiteSpace(City)) { return(false); } if (string.IsNullOrWhiteSpace(ApartmentNumber)) { return(false); } if (string.IsNullOrWhiteSpace(PostalCode)) { return(false); } if (string.IsNullOrWhiteSpace(PhoneNumber)) { return(false); } if (string.IsNullOrWhiteSpace(Email)) { return(false); } if (string.IsNullOrWhiteSpace(IdentityCardNumber)) { return(false); } if (Position == null) { return(false); } if (string.IsNullOrWhiteSpace(Password)) { return(false); } return(SportType != null); }
public void Accepts_Valid_Personal_Identity_Number(int year, int month, int day, int birthNumber, int checksum) { var personalIdentityNumber = new PersonalIdentityNumber(year, month, day, birthNumber, checksum); Assert.Equal(year, personalIdentityNumber.Year); Assert.Equal(month, personalIdentityNumber.Month); Assert.Equal(day, personalIdentityNumber.Day); Assert.Equal(birthNumber, personalIdentityNumber.BirthNumber); Assert.Equal(checksum, personalIdentityNumber.Checksum); }
/// <summary>Validates the specified Swedish Personal Identity Number with respect to the current validation attribute.</summary> /// <param name="value">The Swedish Personal Identity Number to validate.</param> /// <param name="validationContext">The context information about the validation operation.</param> /// <returns>An instance of the <see cref="System.ComponentModel.DataAnnotations.ValidationResult"></see> class.</returns> protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var valueString = (string)value; if (!PersonalIdentityNumber.TryParse(valueString, out _)) { var errorMessage = FormatErrorMessage(validationContext.DisplayName); return(new ValidationResult(errorMessage)); } return(ValidationResult.Success); }
public void GetAgeHint_Handles_LeapYears_Correctly(string personalIdentityNumber, string actualDate, int expectedAge) { // Arrange var swedishPersonalIdentityNumber = PersonalIdentityNumber.Parse(personalIdentityNumber); var date = DateTime.ParseExact(actualDate, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal); // Act var age = swedishPersonalIdentityNumber.GetAgeHint(date); // Assert Assert.Equal(expectedAge, age); }
/// <summary> /// Error Validation /// </summary> /// <param name="columnName">Property Name</param> /// <returns>Error Message</returns> public string this[string columnName] { get { switch (columnName) { case "Name": return(string.IsNullOrWhiteSpace(Name) ? "Pole obowiązkowe" : null); case "Surname": return(string.IsNullOrWhiteSpace(Surname) ? "Pole obowiązkowe" : null); case "Street": return(string.IsNullOrWhiteSpace(Street) ? "Pole obowiązkowe" : null); case "HouseNumber": return(string.IsNullOrWhiteSpace(HouseNumber) ? "Pole obowiązkowe" : null); case "City": return(string.IsNullOrWhiteSpace(City) ? "Pole obowiązkowe" : null); case "ApartmentNumber": return(string.IsNullOrWhiteSpace(ApartmentNumber) ? "Pole obowiązkowe" : null); case "PostalCode": return(string.IsNullOrWhiteSpace(PostalCode) ? "Pole obowiązkowe" : null); case "PhoneNumber": return(string.IsNullOrWhiteSpace(PhoneNumber) ? "Pole obowiązkowe" : null); case "Email": return(string.IsNullOrWhiteSpace(Email) ? "Pole obowiązkowe" : null); case "IdentityCardNumber": return(string.IsNullOrWhiteSpace(IdentityCardNumber) ? "Pole obowiązkowe" : null); case "PersonalIdentityNumber": return(string.IsNullOrWhiteSpace(PersonalIdentityNumber) || PersonalIdentityNumber.Any(c => !char.IsDigit(c)) ? "Pole obowiązkowe, musi być liczbą" : null); case "Position": return(Position == null ? "Pole obowiązkowe" : null); case "SportType": return(SportType == null ? "Pole obowiązkowe" : null); } return(null); } }
public void NumberString_Will_Use_Different_Delimiter_When_Executed_On_Or_After_Person_Turns_100() { var pin = new PersonalIdentityNumber(1912, 02, 11, 998, 6); var stringBeforeTurning100 = pin.To10DigitStringInSpecificYear(2011); var stringOnYearTurning100 = pin.To10DigitStringInSpecificYear(2012); var stringAfterTurning100 = pin.To10DigitStringInSpecificYear(2013); var withHyphen = "120211-9986"; var withPlus = "120211+9986"; Assert.Equal(withHyphen, stringBeforeTurning100); Assert.Equal(withPlus, stringOnYearTurning100); Assert.Equal(withPlus, stringAfterTurning100); }
private static PersonalIdentityNumber?GetPersonalIdentityNumber(AuthenticationProperties properties) { bool TryGetPinString(out string?s) { return(properties.Items.TryGetValue(BankIdConstants.AuthenticationPropertyItemSwedishPersonalIdentityNumber, out s)); } if (TryGetPinString(out var personalIdentityNumber) && !string.IsNullOrWhiteSpace(personalIdentityNumber)) { return(PersonalIdentityNumber.Parse(personalIdentityNumber, StrictMode.Off)); } return(null); }
private Task AddProfileClaims(BankIdClaimsTransformationContext context) { var personalIdentityNumber = PersonalIdentityNumber.Parse(context.PersonalIdentityNumber); context.AddClaim(BankIdClaimTypes.Subject, personalIdentityNumber.To12DigitString()); context.AddClaim(BankIdClaimTypes.Name, context.Name); context.AddClaim(BankIdClaimTypes.FamilyName, context.Surname); context.AddClaim(BankIdClaimTypes.GivenName, context.GivenName); context.AddClaim(BankIdClaimTypes.SwedishPersonalIdentityNumber, personalIdentityNumber.To10DigitString()); return(Task.CompletedTask); }
public void Same_Number_Will_Use_Different_Delimiter_When_Parsed_On_Or_After_Person_Turns_100() { var withHyphen = "120211-9986"; var withPlus = "120211+9986"; var pinBeforeTurning100 = ParseInSpecificYear(withHyphen, 2011); var pinOnYearTurning100 = ParseInSpecificYear(withPlus, 2012); var pinAfterTurning100 = ParseInSpecificYear(withPlus, 2013); var expected = new PersonalIdentityNumber(1912, 02, 11, 998, 6); Assert.Equal(expected, pinBeforeTurning100); Assert.Equal(expected, pinOnYearTurning100); Assert.Equal(expected, pinAfterTurning100); }
private static void Sample_ParseSwedishPersonalIdentityNumbers() { foreach (var input in RawInputs) { WriteHeader($"Input: {input}"); if (PersonalIdentityNumber.TryParse(input, out var identityNumber)) { WriteSwedishPersonalIdentityNumberInfo(identityNumber); } else { Console.Error.WriteLine("Unable to parse the input as a SwedishPersonalIdentityNumber."); WriteSpace(); } } }
protected override async Task <HandleRequestResult> HandleRemoteAuthenticateAsync() { var detectedDevice = GetDetectedDevice(); var state = GetStateFromCookie(); if (state == null) { return(await HandleRemoteAuthenticateFail("Invalid state cookie", detectedDevice)); } DeleteStateCookie(); var loginResultProtected = Request.Query["loginResult"]; if (string.IsNullOrEmpty(loginResultProtected)) { return(await HandleRemoteAuthenticateFail("Missing login result", detectedDevice)); } var loginResult = _loginResultProtector.Unprotect(loginResultProtected); if (loginResult == null || !loginResult.IsSuccessful) { return(await HandleRemoteAuthenticateFail("Invalid login result", detectedDevice)); } var properties = state.AuthenticationProperties; var ticket = await GetAuthenticationTicket(loginResult, properties); await _bankIdEventTrigger.TriggerAsync(new BankIdAspNetAuthenticateSuccessEvent( ticket, PersonalIdentityNumber.Parse(loginResult.PersonalIdentityNumber), detectedDevice )); return(HandleRequestResult.Success(ticket)); }
protected override IEnumerable <Claim> GetClaims(BankIdGetSessionResponse loginResult) { if (loginResult.UserAttributes == null) { throw new ArgumentNullException(nameof(loginResult.UserAttributes)); } var personalIdentityNumber = PersonalIdentityNumber.Parse(loginResult.UserAttributes.PersonalIdentityNumber); var claims = new List <Claim> { new Claim(GrandIdClaimTypes.Subject, personalIdentityNumber.To12DigitString()), new Claim(GrandIdClaimTypes.Name, loginResult.UserAttributes.Name), new Claim(GrandIdClaimTypes.FamilyName, loginResult.UserAttributes.Surname), new Claim(GrandIdClaimTypes.GivenName, loginResult.UserAttributes.GivenName), new Claim(GrandIdClaimTypes.SwedishPersonalIdentityNumber, personalIdentityNumber.To10DigitString()) }; if (Options.IssueGenderClaim) { var jwtGender = JwtSerializer.GetGender(personalIdentityNumber.GetGenderHint()); if (!string.IsNullOrEmpty(jwtGender)) { claims.Add(new Claim(GrandIdClaimTypes.Gender, jwtGender)); } } if (Options.IssueBirthdateClaim) { var jwtBirthdate = JwtSerializer.GetBirthdate(personalIdentityNumber.GetDateOfBirthHint()); claims.Add(new Claim(GrandIdClaimTypes.Birthdate, jwtBirthdate)); } return(claims); }
public void ToString_Returns_12DigitString() { var personalIdentityNumber = new PersonalIdentityNumber(1999, 08, 07, 239, 1); Assert.Equal("199908072391", personalIdentityNumber.ToString()); }
public void TryParseInSpecificYear_Return_False_When_Null() { var isValid = PersonalIdentityNumber.TryParseInSpecificYear(null, 2018, out _); Assert.False(isValid); }
public void TryParseInSpecificYear_Return_False_When_Whitespace_String() { var isValid = PersonalIdentityNumber.TryParseInSpecificYear(" ", 2018, out _); Assert.False(isValid); }