Skip to content

Commit 6ad41f5

Browse files
committed
Rename Authenticator#userName to Authenticator#username
Motivation: The Authenticator#userName field name is used by the construction of the User instance based on the data object to JSON converter. The User#subject() method maps the username value of the principal built from the JSON representation, leading to return null instead of the user name. Change: Rename Authenticator#userName as well as the property accessors to username and update the tests accordingly.
1 parent 7aab215 commit 6ad41f5

File tree

9 files changed

+28
-26
lines changed

9 files changed

+28
-26
lines changed

vertx-auth-webauthn4j/src/main/generated/io/vertx/ext/auth/webauthn4j/AttestationCertificatesConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import io.vertx.core.json.JsonObject;
44
import io.vertx.core.json.JsonArray;
5+
import java.time.Instant;
6+
import java.time.format.DateTimeFormatter;
57

68
/**
79
* Converter and mapper for {@link io.vertx.ext.auth.webauthn4j.AttestationCertificates}.
@@ -14,7 +16,7 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, Attesta
1416
switch (member.getKey()) {
1517
case "alg":
1618
if (member.getValue() instanceof String) {
17-
obj.setAlg(COSEAlgorithm.valueOf((String)member.getValue()));
19+
obj.setAlg(io.vertx.ext.auth.webauthn4j.COSEAlgorithm.valueOf((String)member.getValue()));
1820
}
1921
break;
2022
case "x5c":

vertx-auth-webauthn4j/src/main/generated/io/vertx/ext/auth/webauthn4j/AuthenticatorConverter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public class AuthenticatorConverter {
1414
static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, Authenticator obj) {
1515
for (java.util.Map.Entry<String, Object> member : json) {
1616
switch (member.getKey()) {
17-
case "userName":
17+
case "username":
1818
if (member.getValue() instanceof String) {
19-
obj.setUserName((String)member.getValue());
19+
obj.setUsername((String)member.getValue());
2020
}
2121
break;
2222
case "type":
@@ -68,8 +68,8 @@ static void toJson(Authenticator obj, JsonObject json) {
6868
}
6969

7070
static void toJson(Authenticator obj, java.util.Map<String, Object> json) {
71-
if (obj.getUserName() != null) {
72-
json.put("userName", obj.getUserName());
71+
if (obj.getUsername() != null) {
72+
json.put("username", obj.getUsername());
7373
}
7474
if (obj.getType() != null) {
7575
json.put("type", obj.getType());

vertx-auth-webauthn4j/src/main/generated/io/vertx/ext/auth/webauthn4j/WebAuthn4JOptionsConverter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import io.vertx.core.json.JsonObject;
44
import io.vertx.core.json.JsonArray;
5+
import java.time.Instant;
6+
import java.time.format.DateTimeFormatter;
57

68
/**
79
* Converter and mapper for {@link io.vertx.ext.auth.webauthn4j.WebAuthn4JOptions}.
@@ -39,10 +41,10 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, WebAuth
3941
break;
4042
case "pubKeyCredParams":
4143
if (member.getValue() instanceof JsonArray) {
42-
java.util.ArrayList<COSEAlgorithm> list = new java.util.ArrayList<>();
44+
java.util.ArrayList<io.vertx.ext.auth.webauthn4j.COSEAlgorithm> list = new java.util.ArrayList<>();
4345
((Iterable<Object>)member.getValue()).forEach( item -> {
4446
if (item instanceof String)
45-
list.add(COSEAlgorithm.valueOf((String)item));
47+
list.add(io.vertx.ext.auth.webauthn4j.COSEAlgorithm.valueOf((String)item));
4648
});
4749
obj.setPubKeyCredParams(list);
4850
}

vertx-auth-webauthn4j/src/main/java/io/vertx/ext/auth/webauthn4j/Authenticator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class Authenticator {
3737
/**
3838
* The username linked to this authenticator
3939
*/
40-
private String userName;
40+
private String username;
4141

4242
/**
4343
* The type of key (must be "public-key")
@@ -87,12 +87,12 @@ public Authenticator(JsonObject json) {
8787
AuthenticatorConverter.fromJson(json, this);
8888
}
8989

90-
public String getUserName() {
91-
return userName;
90+
public String getUsername() {
91+
return username;
9292
}
9393

94-
public Authenticator setUserName(String userName) {
95-
this.userName = userName;
94+
public Authenticator setUsername(String username) {
95+
this.username = username;
9696
return this;
9797
}
9898

vertx-auth-webauthn4j/src/main/java/io/vertx/ext/auth/webauthn4j/impl/WebAuthn4JImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.webauthn4j.async.verifier.attestation.statement.androidkey.AndroidKeyAttestationStatementAsyncVerifier;
4848
import com.webauthn4j.async.verifier.attestation.statement.androidsafetynet.AndroidSafetyNetAttestationStatementAsyncVerifier;
4949
import com.webauthn4j.async.verifier.attestation.statement.apple.AppleAnonymousAttestationStatementAsyncVerifier;
50-
import com.webauthn4j.async.verifier.attestation.statement.none.NoneAttestationStatementAsyncVerifier;
5150
import com.webauthn4j.async.verifier.attestation.statement.packed.PackedAttestationStatementAsyncVerifier;
5251
import com.webauthn4j.async.verifier.attestation.statement.tpm.TPMAttestationStatementAsyncVerifier;
5352
import com.webauthn4j.async.verifier.attestation.statement.u2f.FIDOU2FAttestationStatementAsyncVerifier;
@@ -438,7 +437,7 @@ public Future<User> authenticate(Credentials credentials) {
438437
.compose(authrInfo -> {
439438
// by default the store can upsert if a credential is missing, the user has been verified so it is valid
440439
// the store however might disallow this operation
441-
authrInfo.setUserName(username);
440+
authrInfo.setUsername(username);
442441

443442
// the create challenge is complete we can finally save this
444443
// new authenticator to the storage

vertx-auth-webauthn4j/src/test/java/io/vertx/tests/DummyStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Future<List<Authenticator>> find(String userName, String credentialId) {
2727
database.stream()
2828
.filter(entry -> {
2929
if (userName != null) {
30-
return userName.equals(entry.getUserName());
30+
return userName.equals(entry.getUsername());
3131
}
3232
if (credentialId != null) {
3333
return credentialId.equals(entry.getCredID());
@@ -47,10 +47,10 @@ public Future<Void> storeCredential(Authenticator authenticator) {
4747
if (found != 0) {
4848
return Future.failedFuture("Authenticator already exists");
4949
} else {
50-
// this is a new authenticator, make sure the user does not already exist, otherwise we risk adding
50+
// this is a new authenticator, make sure the user does not already exist, otherwise we risk adding
5151
// third-person credentials to an existing user
5252
long existingUser = database.stream()
53-
.filter(entry -> authenticator.getUserName().equals(entry.getUserName()))
53+
.filter(entry -> authenticator.getUsername().equals(entry.getUsername()))
5454
.count();
5555
if(existingUser == 0) {
5656
database.add(authenticator);

vertx-auth-webauthn4j/src/test/java/io/vertx/tests/EmulatorTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.webauthn4j.converter.AuthenticatorDataConverter;
3030
import com.webauthn4j.converter.exception.DataConversionException;
3131
import com.webauthn4j.converter.util.ObjectConverter;
32-
import com.webauthn4j.data.attestation.authenticator.AAGUID;
3332
import com.webauthn4j.data.attestation.authenticator.AttestedCredentialData;
3433
import com.webauthn4j.data.attestation.statement.COSEAlgorithmIdentifier;
3534
import com.webauthn4j.data.client.Origin;
@@ -271,7 +270,7 @@ private Future<?> testRegistration(WebAuthn4J webAuthN, ClientPlatform clientPla
271270
.flatMap(user -> {
272271
assertNotNull(user);
273272
// make sure we have the right user name
274-
assertEquals(username, user.principal().getString("userName"));
273+
assertEquals(username, user.subject());
275274
// also make sure we saved the user in the DB under that username
276275
return database.find(username, null);
277276
})
@@ -280,7 +279,7 @@ private Future<?> testRegistration(WebAuthn4J webAuthN, ClientPlatform clientPla
280279
assertEquals(1, authenticators.size());
281280
Authenticator authenticator = authenticators.get(0);
282281
// Check username, credid, counter, publicKey
283-
assertEquals(username, authenticator.getUserName());
282+
assertEquals(username, authenticator.getUsername());
284283
assertEquals(should.get("credId"), authenticator.getCredID());
285284
should.put("counter", authenticator.getCounter());
286285
assertEquals(should.get("publicKey"), authenticator.getPublicKey());
@@ -357,7 +356,7 @@ private Future<?> testAuthentication(WebAuthn4J webAuthN, ClientPlatform clientP
357356
.flatMap(user -> {
358357
assertNotNull(user);
359358
// make sure we have the right user name
360-
assertEquals(username, user.principal().getString("userName"));
359+
assertEquals(username, user.subject());
361360
// also make sure we saved the user in the DB under that username
362361
return database.find(username, null);
363362
})
@@ -366,7 +365,7 @@ private Future<?> testAuthentication(WebAuthn4J webAuthN, ClientPlatform clientP
366365
assertEquals(1, authenticators.size());
367366
Authenticator authenticator = authenticators.get(0);
368367
// Check username, credid, counter, publicKey
369-
assertEquals(username, authenticator.getUserName());
368+
assertEquals(username, authenticator.getUsername());
370369
assertEquals(should.get("credId"), authenticator.getCredID());
371370
assertEquals(should.<Long>get("counter") + 1, authenticator.getCounter());
372371
assertEquals(should.get("publicKey"), authenticator.getPublicKey());

vertx-auth-webauthn4j/src/test/java/io/vertx/tests/NavigatorCredentialsCreateTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void testRegister(TestContext should) {
9999
});
100100
}
101101

102-
102+
103103
@Test
104104
public void testRegisterExistingUser(TestContext should) {
105105
final Async test = should.async();
@@ -111,7 +111,7 @@ public void testRegisterExistingUser(TestContext should) {
111111

112112
database.add(
113113
new Authenticator()
114-
.setUserName("paulo")
114+
.setUsername("paulo")
115115
.setCredID("O3ZJlAdXvra6PwvL4I9AP99dS1_v3DDRuB_SwTAHFbUfMtvWTOFycCeb6CkXZXiPWi9Nr0ptUnlnHP3U40ptEA")
116116
.setPublicKey("pQECAyYgASFYIBl0C67nFN_OwbODu_iE0hI5nM0ppUkqjhU9NhQvBaiLIlggffUTx8E6OM85huU3DcadeuaBBh8kGI8vdm3zesf3YRc")
117117
.setCounter(2)

vertx-auth-webauthn4j/src/test/java/io/vertx/tests/NavigatorCredentialsGetTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void testRequestLogin(TestContext should) {
3737

3838
database.add(
3939
new Authenticator()
40-
.setUserName("paulo")
40+
.setUsername("paulo")
4141
.setCredID("O3ZJlAdXvra6PwvL4I9AP99dS1_v3DDRuB_SwTAHFbUfMtvWTOFycCeb6CkXZXiPWi9Nr0ptUnlnHP3U40ptEA")
4242
.setPublicKey("pQECAyYgASFYIBl0C67nFN_OwbODu_iE0hI5nM0ppUkqjhU9NhQvBaiLIlggffUTx8E6OM85huU3DcadeuaBBh8kGI8vdm3zesf3YRc")
4343
.setCounter(2)
@@ -67,7 +67,7 @@ public void testLoginRequestChallenge(TestContext should) {
6767

6868
database.add(
6969
new Authenticator()
70-
.setUserName("paulo")
70+
.setUsername("paulo")
7171
.setCredID("rYLaf9xagyA2YnO-W3CZDW8udSg8VeMMm25nenU7nCSxUqy1pEzOdb9oFrDxZZDmrp3odfuTPuONQCiSMH-Tyg")
7272
.setPublicKey("pQECAyYgASFYILBNcdWmiMsmjA1QkNpG91GpEbhMIOqWLieDP6mLnGETIlggGMiqXz8BuSiPa0ovGVxxxbdUbJVm6THKNhUCifFhJCE")
7373
.setCounter(4)

0 commit comments

Comments
 (0)