Skip to content

Commit d9d98de

Browse files
committed
Use OptionalUtil.orElseOptional instead of weird Optional-wrapping workaround
1 parent 6fc3c1f commit d9d98de

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

webauthn-server-attestation/src/main/java/com/yubico/fido/metadata/FidoMetadataService.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.yubico.fido.metadata.FidoMetadataService.Filters.AuthenticatorToBeFiltered;
2828
import com.yubico.internal.util.CertificateParser;
29+
import com.yubico.internal.util.OptionalUtil;
2930
import com.yubico.webauthn.RegistrationResult;
3031
import com.yubico.webauthn.RelyingParty;
3132
import com.yubico.webauthn.RelyingParty.RelyingPartyBuilder;
@@ -505,22 +506,19 @@ public Set<MetadataBLOBPayloadEntry> findEntries(
505506
.collect(Collectors.toSet());
506507

507508
final Optional<AAGUID> nonzeroAaguid =
508-
Optional.ofNullable(
509-
aaguid
510-
.filter(a -> !a.isZero())
511-
.orElseGet(
512-
() -> {
513-
log.debug("findEntries: attempting to look up AAGUID from certificate");
514-
if (!attestationCertificateChain.isEmpty()) {
515-
return CertificateParser.parseFidoAaguidExtension(
516-
attestationCertificateChain.get(0))
517-
.map(ByteArray::new)
518-
.map(AAGUID::new)
519-
.orElse(null);
520-
} else {
521-
return null;
522-
}
523-
}));
509+
OptionalUtil.orElseOptional(
510+
aaguid.filter(a -> !a.isZero()),
511+
() -> {
512+
log.debug("findEntries: attempting to look up AAGUID from certificate");
513+
if (attestationCertificateChain.isEmpty()) {
514+
return Optional.empty();
515+
} else {
516+
return CertificateParser.parseFidoAaguidExtension(
517+
attestationCertificateChain.get(0))
518+
.map(ByteArray::new)
519+
.map(AAGUID::new);
520+
}
521+
});
524522

525523
log.debug(
526524
"findEntries(certSubjectKeyIdentifiers = {}, aaguid = {}, nonzeroAaguid= {})",

webauthn-server-core/src/main/java/com/yubico/webauthn/FinishAssertionSteps.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static com.yubico.internal.util.ExceptionUtil.assertTrue;
2828

2929
import COSE.CoseException;
30+
import com.yubico.internal.util.OptionalUtil;
3031
import com.yubico.webauthn.data.AuthenticatorAssertionResponse;
3132
import com.yubico.webauthn.data.ByteArray;
3233
import com.yubico.webauthn.data.COSEAlgorithmIdentifier;
@@ -124,20 +125,20 @@ public void validate() {
124125
class Step6 implements Step<Step7> {
125126

126127
private final Optional<ByteArray> userHandle =
127-
request
128-
.getUserHandle()
129-
.map(Optional::of)
130-
.orElseGet(() -> response.getResponse().getUserHandle())
131-
.map(Optional::of)
132-
.orElseGet(
133-
() ->
134-
request.getUsername().flatMap(credentialRepository::getUserHandleForUsername));
128+
OptionalUtil.orElseOptional(
129+
request.getUserHandle(),
130+
() ->
131+
OptionalUtil.orElseOptional(
132+
response.getResponse().getUserHandle(),
133+
() ->
134+
request
135+
.getUsername()
136+
.flatMap(credentialRepository::getUserHandleForUsername)));
135137

136138
private final Optional<String> username =
137-
request
138-
.getUsername()
139-
.map(Optional::of)
140-
.orElseGet(() -> userHandle.flatMap(credentialRepository::getUsernameForUserHandle));
139+
OptionalUtil.orElseOptional(
140+
request.getUsername(),
141+
() -> userHandle.flatMap(credentialRepository::getUsernameForUserHandle));
141142

142143
private final Optional<RegisteredCredential> registration =
143144
userHandle.flatMap(uh -> credentialRepository.lookup(response.getId(), uh));

0 commit comments

Comments
 (0)