File tree Expand file tree Collapse file tree
test/java/ee/sk/smartid/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22All notable changes to this project will be documented in this file.
33The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) .
44
5+ ## [ 2.1.4] - Upcoming
6+
7+ ### Fixed
8+ - bug where non-Baltic certificates without date-of-birth resulted with an exception
9+
510## [ 2.1.3] - 2021-12-22
611
712### Fixed
Original file line number Diff line number Diff line change @@ -299,7 +299,7 @@ else if (rdn.getType().equalsIgnoreCase("C")) {
299299 }
300300 }
301301
302- private static LocalDate getDateOfBirth (AuthenticationIdentity identity ) {
302+ public static LocalDate getDateOfBirth (AuthenticationIdentity identity ) {
303303 return Optional .ofNullable (
304304 CertificateAttributeUtil .getDateOfBirth (identity .getAuthCertificate ()))
305305 .orElse (NationalIdentityNumberUtil .getDateOfBirth (identity ));
Original file line number Diff line number Diff line change @@ -17,14 +17,17 @@ public class NationalIdentityNumberUtil {
1717 .withResolverStyle (ResolverStyle .STRICT );
1818
1919 /**
20- * Detect date-of-birth from national identification number if possible or return null.
20+ * Detect date-of-birth from a Baltic national identification number if possible or return null.
2121 *
2222 * This method always returns the value for all Estonian and Lithuanian national identification numbers.
2323 *
2424 * It also works for older Latvian personal codes but Latvian personal codes issued after July 1st 2017
2525 * (starting with "32") do not carry date-of-birth.
2626 *
27- * Some (but not all) Smart-ID certificates have date-of-birth on a separate attribute.
27+ * For non-Baltic countries (countries other than Estonia, Latvia or Lithuania) it always returns null
28+ * (even if it would be possible to deduce date of birth from national identity number).
29+ *
30+ * Newer (but not all) Smart-ID certificates have date-of-birth on a separate attribute.
2831 * It is recommended to use that value if present.
2932 * @see CertificateAttributeUtil#getDateOfBirth(java.security.cert.X509Certificate)
3033 *
@@ -41,7 +44,7 @@ public static LocalDate getDateOfBirth(AuthenticationIdentity authenticationIden
4144 case "LV" :
4245 return parseLvDateOfBirth (identityNumber );
4346 default :
44- throw new UnprocessableSmartIdResponseException ( "Unknown country: " + authenticationIdentity . getCountry ()) ;
47+ return null ;
4548 }
4649 }
4750
Original file line number Diff line number Diff line change @@ -96,4 +96,22 @@ public void parseLvDateOfBirth_invalidIdCode_throwsException() {
9696 assertThat (exception .getMessage (), is ("Unable get birthdate from Latvian personal code 331265-0234" ));
9797 }
9898
99+ @ Test
100+ public void getDateOfBirthFromIdCode_sweden_returnsNull () {
101+ AuthenticationIdentity identity = new AuthenticationIdentity ();
102+ identity .setCountry ("SE" );
103+ identity .setIdentityNumber ("1995012-79039" );
104+
105+ assertThat (NationalIdentityNumberUtil .getDateOfBirth (identity ), is (nullValue ()));
106+ }
107+
108+ @ Test
109+ public void getDateOfBirthFromIdCode_poland_returnsNull () {
110+ AuthenticationIdentity identity = new AuthenticationIdentity ();
111+ identity .setCountry ("PL" );
112+ identity .setIdentityNumber ("64120301283" );
113+
114+ assertThat (NationalIdentityNumberUtil .getDateOfBirth (identity ), is (nullValue ()));
115+ }
116+
99117}
You can’t perform that action at this time.
0 commit comments