diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RegistrationTestData.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RegistrationTestData.scala index 30137555f..f343fcd0b 100644 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RegistrationTestData.scala +++ b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RegistrationTestData.scala @@ -29,7 +29,6 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory import com.fasterxml.jackson.databind.node.ObjectNode import com.yubico.internal.util.CertificateParser import com.yubico.internal.util.JacksonCodecs -import com.yubico.internal.util.scala.JavaConverters._ import com.yubico.webauthn.TestAuthenticator.AttestationCert import com.yubico.webauthn.TestAuthenticator.AttestationMaker import com.yubico.webauthn.TestAuthenticator.AttestationSigner @@ -58,6 +57,7 @@ import java.security.PrivateKey import java.security.cert.X509Certificate import java.security.spec.PKCS8EncodedKeySpec import scala.jdk.CollectionConverters._ +import scala.jdk.OptionConverters.RichOption import scala.util.Failure import scala.util.Success import scala.util.Try @@ -752,7 +752,7 @@ case class RegistrationTestData( ).asJava ) .extensions(requestedExtensions) - .authenticatorSelection(authenticatorSelection.asJava) + .authenticatorSelection(authenticatorSelection.toJava) .build() def response: PublicKeyCredential[ diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyAssertionSpec.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyAssertionSpec.scala index b9a7aef9e..a1093b7c5 100644 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyAssertionSpec.scala +++ b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyAssertionSpec.scala @@ -29,7 +29,6 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory import com.fasterxml.jackson.databind.node.ObjectNode import com.upokecenter.cbor.CBORObject import com.yubico.internal.util.JacksonCodecs -import com.yubico.internal.util.scala.JavaConverters._ import com.yubico.webauthn.data.AssertionExtensionInputs import com.yubico.webauthn.data.AuthenticatorAssertionResponse import com.yubico.webauthn.data.AuthenticatorTransport @@ -71,6 +70,8 @@ import java.security.MessageDigest import java.security.interfaces.ECPublicKey import java.util.Optional import scala.jdk.CollectionConverters._ +import scala.jdk.OptionConverters.RichOption +import scala.jdk.OptionConverters.RichOptional import scala.util.Failure import scala.util.Success import scala.util.Try @@ -137,7 +138,7 @@ class RelyingPartyAssertionSpec userHandle: ByteArray, ): Optional[ByteArray] = if (username == Defaults.username) - Some(userHandle).asJava + Some(userHandle).toJava else ??? @@ -146,7 +147,7 @@ class RelyingPartyAssertionSpec username: String, ): Optional[String] = if (userHandle == Defaults.userHandle) - Some(username).asJava + Some(username).toJava else ??? @@ -201,12 +202,12 @@ class RelyingPartyAssertionSpec .builder() .challenge(challenge) .rpId(rpId.getId) - .allowCredentials(allowCredentials.asJava) + .allowCredentials(allowCredentials.toJava) .userVerification(userVerificationRequirement) .extensions(requestedExtensions) .build() ) - .username(usernameForRequest.asJava) + .username(usernameForRequest.toJava) .build() val response = PublicKeyCredential @@ -246,9 +247,9 @@ class RelyingPartyAssertionSpec .build() ) else None - ).asJava + ).toJava override def lookupAll(credId: ByteArray) = - lookup(credId, null).asScala.toSet.asJava + lookup(credId, null).toScala.toSet.asJava override def getCredentialIdsForUsername(username: String) = ??? override def getUserHandleForUsername(username: String) : Optional[ByteArray] = @@ -274,7 +275,7 @@ class RelyingPartyAssertionSpec builder .build() - ._finishAssertion(request, response, callerTokenBindingId.asJava) + ._finishAssertion(request, response, callerTokenBindingId.toJava) } testWithEachProvider { it => @@ -298,10 +299,10 @@ class RelyingPartyAssertionSpec .build() ) - request1.getPublicKeyCredentialRequestOptions.getUserVerification.asScala should be( + request1.getPublicKeyCredentialRequestOptions.getUserVerification.toScala should be( None ) - request2.getPublicKeyCredentialRequestOptions.getUserVerification.asScala should be( + request2.getPublicKeyCredentialRequestOptions.getUserVerification.toScala should be( None ) } @@ -317,11 +318,11 @@ class RelyingPartyAssertionSpec val request = rp.startAssertion( StartAssertionOptions .builder() - .userVerification(uv.asJava) + .userVerification(uv.toJava) .build() ) - request.getPublicKeyCredentialRequestOptions.getUserVerification.asScala should equal( + request.getPublicKeyCredentialRequestOptions.getUserVerification.toScala should equal( uv ) } @@ -368,15 +369,15 @@ class RelyingPartyAssertionSpec username: String ): Optional[ByteArray] = if (username == user.getName) - Some(user.getId).asJava - else None.asJava + Some(user.getId).toJava + else None.toJava override def getUsernameForUserHandle( userHandle: ByteArray ): Optional[String] = if (userHandle == user.getId) - Some(user.getName).asJava - else None.asJava + Some(user.getName).toJava + else None.toJava override def lookup( credentialId: ByteArray, @@ -386,8 +387,8 @@ class RelyingPartyAssertionSpec if ( credentialId == credential.getCredentialId && userHandle == user.getId ) - Some(credential).asJava - else None.asJava + Some(credential).toJava + else None.toJava } override def lookupAll( @@ -492,13 +493,13 @@ class RelyingPartyAssertionSpec val requestCreds = result.getPublicKeyCredentialRequestOptions.getAllowCredentials.get.asScala - requestCreds.head.getTransports.asScala should equal( + requestCreds.head.getTransports.toScala should equal( Some(cred1Transports.asJava) ) - requestCreds(1).getTransports.asScala should equal( + requestCreds(1).getTransports.toScala should equal( Some(Set.empty.asJava) ) - requestCreds(2).getTransports.asScala should equal(None) + requestCreds(2).getTransports.toScala should equal(None) } } } @@ -614,7 +615,7 @@ class RelyingPartyAssertionSpec .publicKeyCose(getPublicKeyBytes(Defaults.credentialKey)) .signatureCount(0) .build() - ).asJava + ).toJava override def lookupAll(id: ByteArray) = ??? override def getCredentialIdsForUsername(username: String) = ??? override def getUserHandleForUsername( @@ -623,14 +624,14 @@ class RelyingPartyAssertionSpec Some( if (username == owner.username) owner.userHandle else nonOwner.userHandle - ).asJava + ).toJava override def getUsernameForUserHandle( userHandle: ByteArray ): Optional[String] = Some( if (userHandle == owner.userHandle) owner.username else nonOwner.username - ).asJava + ).toJava }) describe("If the user was identified before the authentication ceremony was initiated, e.g., via a username or cookie, verify that the identified user is the owner of credentialSource. If response.userHandle is present, let userHandle be its value. Verify that userHandle also maps to the same user.") { @@ -749,7 +750,7 @@ class RelyingPartyAssertionSpec val step: steps.Step7 = new steps.Step7( Defaults.username, Defaults.userHandle, - None.asJava, + None.toJava, ) step.validations shouldBe a[Failure[_]] @@ -1302,7 +1303,7 @@ class RelyingPartyAssertionSpec val appid = new AppId("https://test.example.org/foo") val extensions = AssertionExtensionInputs .builder() - .appid(Some(appid).asJava) + .appid(Some(appid).toJava) .build() it("fails if RP ID is different.") { @@ -2238,10 +2239,10 @@ class RelyingPartyAssertionSpec .build() ) - result.getClientExtensionOutputs.get.getLargeBlob.get.getWritten.asScala should be( + result.getClientExtensionOutputs.get.getLargeBlob.get.getWritten.toScala should be( Some(true) ) - result.getClientExtensionOutputs.get.getLargeBlob.get.getBlob.asScala should be( + result.getClientExtensionOutputs.get.getLargeBlob.get.getBlob.toScala should be( None ) } @@ -2282,10 +2283,10 @@ class RelyingPartyAssertionSpec .build() ) - result.getClientExtensionOutputs.get.getLargeBlob.get.getBlob.asScala should be( + result.getClientExtensionOutputs.get.getLargeBlob.get.getBlob.toScala should be( Some(ByteArray.fromHex("00010203")) ) - result.getClientExtensionOutputs.get.getLargeBlob.get.getWritten.asScala should be( + result.getClientExtensionOutputs.get.getLargeBlob.get.getWritten.toScala should be( None ) } @@ -2337,7 +2338,7 @@ class RelyingPartyAssertionSpec .build() ) - result.getAuthenticatorExtensionOutputs.get.getUvm.asScala should equal( + result.getAuthenticatorExtensionOutputs.get.getUvm.toScala should equal( Some( List( new UvmEntry( diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyRegistrationSpec.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyRegistrationSpec.scala index 7686eb8d9..ddae4cfa4 100644 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyRegistrationSpec.scala +++ b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyRegistrationSpec.scala @@ -31,7 +31,6 @@ import com.upokecenter.cbor.CBORObject import com.yubico.internal.util.BinaryUtil import com.yubico.internal.util.CertificateParser import com.yubico.internal.util.JacksonCodecs -import com.yubico.internal.util.scala.JavaConverters._ import com.yubico.webauthn.TestAuthenticator.AttestationCert import com.yubico.webauthn.TestAuthenticator.AttestationMaker import com.yubico.webauthn.attestation.AttestationTrustSource @@ -96,6 +95,8 @@ import java.util.Collections import java.util.Optional import javax.security.auth.x500.X500Principal import scala.jdk.CollectionConverters._ +import scala.jdk.OptionConverters.RichOption +import scala.jdk.OptionConverters.RichOptional import scala.util.Failure import scala.util.Success import scala.util.Try @@ -161,7 +162,7 @@ class RelyingPartyRegistrationSpec ._finishRegistration( testData.request, testData.response, - callerTokenBindingId.asJava, + callerTokenBindingId.toJava, ) } @@ -1091,7 +1092,7 @@ class RelyingPartyRegistrationSpec step.validations shouldBe a[Success[_]] step.tryNext shouldBe a[Success[_]] step.format should equal(format) - step.attestationStatementVerifier.asScala shouldBe empty + step.attestationStatementVerifier.toScala shouldBe empty } } @@ -1104,7 +1105,7 @@ class RelyingPartyRegistrationSpec step.validations shouldBe a[Success[_]] step.tryNext shouldBe a[Success[_]] step.format should equal(format) - step.attestationStatementVerifier.asScala should not be empty + step.attestationStatementVerifier.toScala should not be empty } } @@ -1194,7 +1195,7 @@ class RelyingPartyRegistrationSpec ) ), new AttestationObject(testData.attestationObject), - Some(new FidoU2fAttestationStatementVerifier).asJava, + Optional.of(new FidoU2fAttestationStatementVerifier), ) step.validations shouldBe a[Failure[_]] @@ -1212,7 +1213,7 @@ class RelyingPartyRegistrationSpec val step: FinishRegistrationSteps#Step19 = new steps.Step19( Crypto.sha256(testData.clientDataJsonBytes), new AttestationObject(testData.attestationObject), - Some(new FidoU2fAttestationStatementVerifier).asJava, + Optional.of(new FidoU2fAttestationStatementVerifier), ) step.validations shouldBe a[Failure[_]] @@ -1257,7 +1258,7 @@ class RelyingPartyRegistrationSpec val step: FinishRegistrationSteps#Step19 = new steps.Step19( Crypto.sha256(testData.clientDataJsonBytes), new AttestationObject(testData.attestationObject), - Some(new FidoU2fAttestationStatementVerifier).asJava, + Optional.of(new FidoU2fAttestationStatementVerifier), ) step.validations shouldBe a[Failure[_]] @@ -1408,7 +1409,7 @@ class RelyingPartyRegistrationSpec val step: FinishRegistrationSteps#Step19 = new steps.Step19( Crypto.sha256(testData.clientDataJsonBytes), new AttestationObject(testData.attestationObject), - Some(new NoneAttestationStatementVerifier).asJava, + Optional.of(new NoneAttestationStatementVerifier), ) step.validations shouldBe a[Success[_]] @@ -1649,7 +1650,7 @@ class RelyingPartyRegistrationSpec step.validations shouldBe a[Success[_]] step.tryNext shouldBe a[Success[_]] step.attestationType should be(AttestationType.BASIC) - step.attestationTrustPath.asScala should not be empty + step.attestationTrustPath.toScala should not be empty step.attestationTrustPath.get.asScala should be( List(testData.packedAttestationCert) ) @@ -1859,7 +1860,7 @@ class RelyingPartyRegistrationSpec step.attestationType should be( AttestationType.SELF_ATTESTATION ) - step.attestationTrustPath.asScala shouldBe empty + step.attestationTrustPath.toScala shouldBe empty } } } @@ -2293,7 +2294,7 @@ class RelyingPartyRegistrationSpec step.validations shouldBe a[Success[_]] step.tryNext shouldBe a[Success[_]] step.attestationType should be(AttestationType.UNKNOWN) - step.attestationTrustPath.asScala shouldBe empty + step.attestationTrustPath.toScala shouldBe empty } it("(Deleted) If verification of the attestation statement failed, the Relying Party MUST fail the registration ceremony.") { @@ -2357,7 +2358,7 @@ class RelyingPartyRegistrationSpec steps.begin.next.next.next.next.next.next.next.next.next.next.next.next.next step.validations shouldBe a[Success[_]] - step.getTrustRoots.asScala.map( + step.getTrustRoots.toScala.map( _.getTrustRoots.asScala ) should equal( Some(Set(attestationRootCert)) @@ -2377,7 +2378,7 @@ class RelyingPartyRegistrationSpec steps.begin.next.next.next.next.next.next.next.next.next.next.next.next.next step.validations shouldBe a[Success[_]] - step.getTrustRoots.asScala shouldBe empty + step.getTrustRoots.toScala shouldBe empty step.tryNext shouldBe a[Success[_]] } } @@ -2833,7 +2834,7 @@ class RelyingPartyRegistrationSpec describe("It is RECOMMENDED to also:") { it("Associate the credentialId with the transport hints returned by calling credential.response.getTransports(). This value SHOULD NOT be modified before or after storing it. It is RECOMMENDED to use this value to populate the transports of the allowCredentials option in future get() calls to help the client know how to find a suitable authenticator.") { - result.getKeyId.getTransports.asScala should equal( + result.getKeyId.getTransports.toScala should equal( Some( testData.response.getResponse.getTransports ) @@ -3234,7 +3235,7 @@ class RelyingPartyRegistrationSpec .build() ) - result.isDiscoverable.asScala should equal(Some(true)) + result.isDiscoverable.toScala should equal(Some(true)) } it("when set to false.") { @@ -3257,7 +3258,7 @@ class RelyingPartyRegistrationSpec .build() ) - result.isDiscoverable.asScala should equal(Some(false)) + result.isDiscoverable.toScala should equal(Some(false)) } it("when not available.") { @@ -3269,7 +3270,7 @@ class RelyingPartyRegistrationSpec .build() ) - result.isDiscoverable.asScala should equal(None) + result.isDiscoverable.toScala should equal(None) } } @@ -3372,7 +3373,7 @@ class RelyingPartyRegistrationSpec .build() ) - result.getAuthenticatorExtensionOutputs.get.getUvm.asScala should equal( + result.getAuthenticatorExtensionOutputs.get.getUvm.toScala should equal( Some( List( new UvmEntry( @@ -3467,7 +3468,7 @@ class RelyingPartyRegistrationSpec .build() ) - result.getKeyId.getTransports.asScala.map(_.asScala) should equal( + result.getKeyId.getTransports.toScala.map(_.asScala) should equal( Some(Set(AuthenticatorTransport.USB, AuthenticatorTransport.NFC)) ) } @@ -3491,7 +3492,7 @@ class RelyingPartyRegistrationSpec .build() ) - result.getKeyId.getTransports.asScala.map(_.asScala) should equal( + result.getKeyId.getTransports.toScala.map(_.asScala) should equal( Some(Set.empty) ) } @@ -3514,7 +3515,7 @@ class RelyingPartyRegistrationSpec .build() ) - result.getKeyId.getTransports.asScala.map(_.asScala) should equal( + result.getKeyId.getTransports.toScala.map(_.asScala) should equal( Some(Set.empty) ) } @@ -3551,7 +3552,7 @@ class RelyingPartyRegistrationSpec ) val result = steps.run() result.isAttestationTrusted should be(true) - result.getAttestationTrustPath.asScala.map(_.asScala) should equal( + result.getAttestationTrustPath.toScala.map(_.asScala) should equal( Some(testData.attestationCertChain.init.map(_._1)) ) } diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyStartOperationSpec.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyStartOperationSpec.scala index 28fa74ed2..055348a73 100644 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyStartOperationSpec.scala +++ b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyStartOperationSpec.scala @@ -24,7 +24,6 @@ package com.yubico.webauthn -import com.yubico.internal.util.scala.JavaConverters._ import com.yubico.webauthn.Generators._ import com.yubico.webauthn.data.AssertionExtensionInputs import com.yubico.webauthn.data.AttestationConveyancePreference @@ -52,6 +51,8 @@ import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks import java.util.Optional import scala.jdk.CollectionConverters._ +import scala.jdk.OptionConverters.RichOption +import scala.jdk.OptionConverters.RichOptional @RunWith(classOf[JUnitRunner]) class RelyingPartyStartOperationSpec @@ -73,8 +74,8 @@ class RelyingPartyStartOperationSpec override def getUsernameForUserHandle( userHandle: ByteArray ): Optional[String] = - if (userHandle == userId.getId) Some(userId.getName).asJava - else None.asJava + if (userHandle == userId.getId) Some(userId.getName).toJava + else None.toJava override def lookup( credentialId: ByteArray, userHandle: ByteArray, @@ -129,7 +130,7 @@ class RelyingPartyStartOperationSpec .build() ) - result.getExcludeCredentials.asScala.map(_.asScala) should equal( + result.getExcludeCredentials.toScala.map(_.asScala) should equal( Some(credentials) ) } @@ -164,7 +165,7 @@ class RelyingPartyStartOperationSpec .authenticatorSelection(authnrSel) .build() ) - pkcco.getAuthenticatorSelection.asScala should equal(Some(authnrSel)) + pkcco.getAuthenticatorSelection.toScala should equal(Some(authnrSel)) } it("allows setting authenticatorSelection with an Optional value.") { @@ -190,8 +191,8 @@ class RelyingPartyStartOperationSpec ) .build() ) - pkccoWith.getAuthenticatorSelection.asScala should equal(Some(authnrSel)) - pkccoWithout.getAuthenticatorSelection.asScala should equal(None) + pkccoWith.getAuthenticatorSelection.toScala should equal(Some(authnrSel)) + pkccoWithout.getAuthenticatorSelection.toScala should equal(None) } it("uses the RelyingParty setting for attestationConveyancePreference.") { @@ -218,7 +219,7 @@ class RelyingPartyStartOperationSpec .timeout(Optional.empty[java.lang.Long]) .build() ) - pkcco.getTimeout.asScala shouldBe empty + pkcco.getTimeout.toScala shouldBe empty } it("allows setting the timeout to a positive value.") { @@ -233,7 +234,7 @@ class RelyingPartyStartOperationSpec .build() ) - pkcco.getTimeout.asScala should equal(Some(timeout)) + pkcco.getTimeout.toScala should equal(Some(timeout)) } } @@ -281,7 +282,7 @@ class RelyingPartyStartOperationSpec .build() ) - result.getExtensions.getAppidExclude.asScala should equal(Some(appId)) + result.getExtensions.getAppidExclude.toScala should equal(Some(appId)) } } @@ -294,7 +295,7 @@ class RelyingPartyStartOperationSpec .build() ) - result.getExtensions.getAppidExclude.asScala should equal(None) + result.getExtensions.getAppidExclude.toScala should equal(None) } it("does not override the appidExclude extension with an empty value if already non-null in StartRegistrationOptions.") { @@ -313,7 +314,7 @@ class RelyingPartyStartOperationSpec .build() ) - result.getExtensions.getAppidExclude.asScala should equal( + result.getExtensions.getAppidExclude.toScala should equal( Some(requestAppId) ) } @@ -336,7 +337,7 @@ class RelyingPartyStartOperationSpec .build() ) - result.getExtensions.getAppidExclude.asScala should equal( + result.getExtensions.getAppidExclude.toScala should equal( Some(requestAppId) ) } @@ -453,16 +454,16 @@ class RelyingPartyStartOperationSpec .build() ) - pkccoDiscouraged.getAuthenticatorSelection.get.getResidentKey.asScala should be( + pkccoDiscouraged.getAuthenticatorSelection.get.getResidentKey.toScala should be( Some(ResidentKeyRequirement.DISCOURAGED) ) - pkccoPreferred.getAuthenticatorSelection.get.getResidentKey.asScala should be( + pkccoPreferred.getAuthenticatorSelection.get.getResidentKey.toScala should be( Some(ResidentKeyRequirement.PREFERRED) ) - pkccoRequired.getAuthenticatorSelection.get.getResidentKey.asScala should be( + pkccoRequired.getAuthenticatorSelection.get.getResidentKey.toScala should be( Some(ResidentKeyRequirement.REQUIRED) ) - pkccoUnspecified.getAuthenticatorSelection.get.getResidentKey.asScala should be( + pkccoUnspecified.getAuthenticatorSelection.get.getResidentKey.toScala should be( None ) } @@ -509,13 +510,13 @@ class RelyingPartyStartOperationSpec .build() ) - pkcco.getAuthenticatorSelection.get.getAuthenticatorAttachment.asScala should be( + pkcco.getAuthenticatorSelection.get.getAuthenticatorAttachment.toScala should be( Some(AuthenticatorAttachment.CROSS_PLATFORM) ) - pkccoWith.getAuthenticatorSelection.get.getAuthenticatorAttachment.asScala should be( + pkccoWith.getAuthenticatorSelection.get.getAuthenticatorAttachment.toScala should be( Some(AuthenticatorAttachment.PLATFORM) ) - pkccoWithout.getAuthenticatorSelection.get.getAuthenticatorAttachment.asScala should be( + pkccoWithout.getAuthenticatorSelection.get.getAuthenticatorAttachment.toScala should be( None ) } @@ -528,7 +529,7 @@ class RelyingPartyStartOperationSpec val rp = relyingParty(credentials = credentials, userId = userId) val result = rp.startAssertion(StartAssertionOptions.builder().build()) - result.getPublicKeyCredentialRequestOptions.getAllowCredentials.asScala shouldBe empty + result.getPublicKeyCredentialRequestOptions.getAllowCredentials.toScala shouldBe empty } } @@ -542,7 +543,7 @@ class RelyingPartyStartOperationSpec .build() ) - result.getPublicKeyCredentialRequestOptions.getAllowCredentials.asScala + result.getPublicKeyCredentialRequestOptions.getAllowCredentials.toScala .map(_.asScala.toSet) should equal(Some(credentials)) } } @@ -557,7 +558,7 @@ class RelyingPartyStartOperationSpec .build() ) - result.getPublicKeyCredentialRequestOptions.getAllowCredentials.asScala + result.getPublicKeyCredentialRequestOptions.getAllowCredentials.toScala .map(_.asScala.toSet) should equal(Some(credentials)) } } @@ -602,13 +603,13 @@ class RelyingPartyStartOperationSpec val requestCreds = result.getPublicKeyCredentialRequestOptions.getAllowCredentials.get.asScala - requestCreds.head.getTransports.asScala should equal( + requestCreds.head.getTransports.toScala should equal( Some(cred1Transports.asJava) ) - requestCreds(1).getTransports.asScala should equal( + requestCreds(1).getTransports.toScala should equal( Some(Set.empty.asJava) ) - requestCreds(2).getTransports.asScala should equal(None) + requestCreds(2).getTransports.toScala should equal(None) } } @@ -633,7 +634,7 @@ class RelyingPartyStartOperationSpec .build() ) - result.getPublicKeyCredentialRequestOptions.getExtensions.getAppid.asScala should equal( + result.getPublicKeyCredentialRequestOptions.getExtensions.getAppid.toScala should equal( Some(appId) ) } @@ -648,7 +649,7 @@ class RelyingPartyStartOperationSpec .build() ) - result.getPublicKeyCredentialRequestOptions.getExtensions.getAppid.asScala should equal( + result.getPublicKeyCredentialRequestOptions.getExtensions.getAppid.toScala should equal( None ) } @@ -669,7 +670,7 @@ class RelyingPartyStartOperationSpec .build() ) - result.getPublicKeyCredentialRequestOptions.getExtensions.getAppid.asScala should equal( + result.getPublicKeyCredentialRequestOptions.getExtensions.getAppid.toScala should equal( Some(requestAppId) ) } @@ -692,7 +693,7 @@ class RelyingPartyStartOperationSpec .build() ) - result.getPublicKeyCredentialRequestOptions.getExtensions.getAppid.asScala should equal( + result.getPublicKeyCredentialRequestOptions.getExtensions.getAppid.toScala should equal( Some(requestAppId) ) } @@ -706,7 +707,7 @@ class RelyingPartyStartOperationSpec .timeout(Optional.empty[java.lang.Long]) .build() ) - req.getPublicKeyCredentialRequestOptions.getTimeout.asScala shouldBe empty + req.getPublicKeyCredentialRequestOptions.getTimeout.toScala shouldBe empty } it("allows setting the timeout to a positive value.") { @@ -720,7 +721,7 @@ class RelyingPartyStartOperationSpec .build() ) - req.getPublicKeyCredentialRequestOptions.getTimeout.asScala should equal( + req.getPublicKeyCredentialRequestOptions.getTimeout.toScala should equal( Some(timeout) ) } @@ -788,24 +789,24 @@ class RelyingPartyStartOperationSpec it("resets username when userHandle is set.") { forAll { (sao: StartAssertionOptions, userHandle: ByteArray) => val result = sao.toBuilder.userHandle(userHandle).build() - result.getUsername.asScala shouldBe empty + result.getUsername.toScala shouldBe empty } forAll { (sao: StartAssertionOptions, userHandle: ByteArray) => - val result = sao.toBuilder.userHandle(Some(userHandle).asJava).build() - result.getUsername.asScala shouldBe empty + val result = sao.toBuilder.userHandle(Some(userHandle).toJava).build() + result.getUsername.toScala shouldBe empty } } it("resets userHandle when username is set.") { forAll { (sao: StartAssertionOptions, username: String) => val result = sao.toBuilder.username(username).build() - result.getUserHandle.asScala shouldBe empty + result.getUserHandle.toScala shouldBe empty } forAll { (sao: StartAssertionOptions, username: String) => - val result = sao.toBuilder.username(Some(username).asJava).build() - result.getUserHandle.asScala shouldBe empty + val result = sao.toBuilder.username(Some(username).toJava).build() + result.getUserHandle.toScala shouldBe empty } } @@ -815,7 +816,7 @@ class RelyingPartyStartOperationSpec .username(username) .userHandle(Optional.empty[ByteArray]) .build() - result.getUsername.asScala should equal(Some(username)) + result.getUsername.toScala should equal(Some(username)) } forAll { (sao: StartAssertionOptions, username: String) => @@ -823,7 +824,7 @@ class RelyingPartyStartOperationSpec .username(username) .userHandle(null: ByteArray) .build() - result.getUsername.asScala should equal(Some(username)) + result.getUsername.toScala should equal(Some(username)) } } @@ -833,7 +834,7 @@ class RelyingPartyStartOperationSpec .userHandle(userHandle) .username(Optional.empty[String]) .build() - result.getUserHandle.asScala should equal(Some(userHandle)) + result.getUserHandle.toScala should equal(Some(userHandle)) } forAll { (sao: StartAssertionOptions, userHandle: ByteArray) => @@ -841,35 +842,35 @@ class RelyingPartyStartOperationSpec .userHandle(userHandle) .username(null: String) .build() - result.getUserHandle.asScala should equal(Some(userHandle)) + result.getUserHandle.toScala should equal(Some(userHandle)) } } it("allows unsetting username.") { forAll { (sao: StartAssertionOptions, username: String) => val preresult = sao.toBuilder.username(username).build() - preresult.getUsername.asScala should equal(Some(username)) + preresult.getUsername.toScala should equal(Some(username)) val result1 = preresult.toBuilder.username(Optional.empty[String]).build() - result1.getUsername.asScala shouldBe empty + result1.getUsername.toScala shouldBe empty val result2 = preresult.toBuilder.username(null: String).build() - result2.getUsername.asScala shouldBe empty + result2.getUsername.toScala shouldBe empty } } it("allows unsetting userHandle.") { forAll { (sao: StartAssertionOptions, userHandle: ByteArray) => val preresult = sao.toBuilder.userHandle(userHandle).build() - preresult.getUserHandle.asScala should equal(Some(userHandle)) + preresult.getUserHandle.toScala should equal(Some(userHandle)) val result1 = preresult.toBuilder.userHandle(Optional.empty[ByteArray]).build() - result1.getUserHandle.asScala shouldBe empty + result1.getUserHandle.toScala shouldBe empty val result2 = preresult.toBuilder.userHandle(null: ByteArray).build() - result2.getUserHandle.asScala shouldBe empty + result2.getUserHandle.toScala shouldBe empty } } } diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyUserIdentificationSpec.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyUserIdentificationSpec.scala index be0863d8a..6eadda8c8 100644 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyUserIdentificationSpec.scala +++ b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyUserIdentificationSpec.scala @@ -25,7 +25,6 @@ package com.yubico.webauthn import com.fasterxml.jackson.databind.node.ObjectNode -import com.yubico.internal.util.scala.JavaConverters._ import com.yubico.webauthn.data.AuthenticatorAssertionResponse import com.yubico.webauthn.data.ByteArray import com.yubico.webauthn.data.ClientAssertionExtensionOutputs @@ -42,6 +41,7 @@ import java.security.KeyPair import java.security.interfaces.ECPublicKey import java.util.Optional import scala.jdk.CollectionConverters._ +import scala.jdk.OptionConverters.RichOption import scala.util.Failure import scala.util.Success import scala.util.Try @@ -111,7 +111,7 @@ class RelyingPartyUserIdentificationSpec extends FunSpec with Matchers { .authenticatorData(authenticatorData) .clientDataJSON(clientDataJsonBytes) .signature(signature) - .userHandle(userHandle.asJava) + .userHandle(userHandle.toJava) .build() def defaultPublicKeyCredential( @@ -162,23 +162,23 @@ class RelyingPartyUserIdentificationSpec extends FunSpec with Matchers { ) .signatureCount(0) .build() - ).asJava + ).toJava else - None.asJava + None.toJava override def lookupAll(credId: ByteArray) = ??? override def getUserHandleForUsername(username: String) : Optional[ByteArray] = if (username == Defaults.username) - Some(Defaults.userHandle).asJava + Some(Defaults.userHandle).toJava else - None.asJava + None.toJava override def getUsernameForUserHandle(userHandle: ByteArray) : Optional[String] = if (userHandle == Defaults.userHandle) - Some(Defaults.username).asJava + Some(Defaults.username).toJava else - None.asJava + None.toJava } ) .preferredPubkeyParams(Nil.asJava) diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/TestAuthenticator.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/TestAuthenticator.scala index 9dd12bd7f..88f06de19 100644 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/TestAuthenticator.scala +++ b/webauthn-server-core/src/test/scala/com/yubico/webauthn/TestAuthenticator.scala @@ -30,7 +30,6 @@ import com.fasterxml.jackson.databind.node.ObjectNode import com.yubico.internal.util.BinaryUtil import com.yubico.internal.util.CertificateParser import com.yubico.internal.util.JacksonCodecs -import com.yubico.internal.util.scala.JavaConverters._ import com.yubico.webauthn.data.AuthenticatorAssertionResponse import com.yubico.webauthn.data.AuthenticatorAttestationResponse import com.yubico.webauthn.data.AuthenticatorData @@ -84,6 +83,7 @@ import java.security.spec.X509EncodedKeySpec import java.time.Instant import java.util.Date import scala.jdk.CollectionConverters._ +import scala.jdk.OptionConverters.RichOption import scala.util.Try object TestAuthenticator { @@ -545,7 +545,7 @@ object TestAuthenticator { alg, ) ) - .userHandle(userHandle.asJava) + .userHandle(userHandle.toJava) .build() PublicKeyCredential diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/AuthenticatorDataSpec.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/AuthenticatorDataSpec.scala index 6fa18bf2e..13f943ed3 100644 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/AuthenticatorDataSpec.scala +++ b/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/AuthenticatorDataSpec.scala @@ -26,7 +26,6 @@ package com.yubico.webauthn.data import com.upokecenter.cbor.CBORObject import com.yubico.internal.util.BinaryUtil -import com.yubico.internal.util.scala.JavaConverters._ import com.yubico.webauthn.WebAuthnTestCodecs import com.yubico.webauthn.data.Generators.byteArray import org.junit.runner.RunWith @@ -38,6 +37,7 @@ import org.scalatestplus.junit.JUnitRunner import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks import java.security.interfaces.ECPublicKey +import scala.jdk.OptionConverters.RichOptional import scala.util.Failure import scala.util.Try @@ -127,7 +127,7 @@ class AuthenticatorDataSpec if (hasAttestation) { it("gets the correct attestation data from the raw bytes.") { - authData.getAttestedCredentialData.asScala shouldBe defined + authData.getAttestedCredentialData.toScala shouldBe defined authData.getAttestedCredentialData.get.getAaguid.getHex should equal( "000102030405060708090a0b0c0d0e0f" ) @@ -150,7 +150,7 @@ class AuthenticatorDataSpec if (hasExtensions) { it("gets the correct extension data from the raw bytes.") { - authData.getExtensions.asScala shouldBe defined + authData.getExtensions.toScala shouldBe defined new ByteArray( authData.getExtensions.get.EncodeToBytes() ) should equal(jsonToCbor("""{ "foo": "bar" }""")) diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/Generators.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/Generators.scala index b2d87cf1b..d83d942fc 100644 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/Generators.scala +++ b/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/Generators.scala @@ -30,7 +30,6 @@ import com.upokecenter.cbor.CBOREncodeOptions import com.upokecenter.cbor.CBORObject import com.yubico.internal.util.BinaryUtil import com.yubico.internal.util.JacksonCodecs -import com.yubico.internal.util.scala.JavaConverters._ import com.yubico.scalacheck.gen.JacksonGenerators import com.yubico.scalacheck.gen.JacksonGenerators._ import com.yubico.scalacheck.gen.JavaGenerators._ @@ -57,6 +56,8 @@ import java.net.URL import java.security.interfaces.ECPublicKey import java.util.Optional import scala.jdk.CollectionConverters._ +import scala.jdk.OptionConverters.RichOption +import scala.jdk.OptionConverters.RichOptional object Generators { @@ -229,7 +230,7 @@ object Generators { .authenticatorData(authenticatorData) .clientDataJSON(clientDataJson) .signature(signature) - .userHandle(userHandle.asJava) + .userHandle(userHandle.toJava) .build() implicit val arbitraryAuthenticatorAttestationResponse @@ -875,7 +876,7 @@ object Generators { : Arbitrary[Option[AuthenticatorAssertionExtensionOutputs]] = Arbitrary( Extensions.anyAssertionExtensions map { case (_, _, aaeo) => - AuthenticatorAssertionExtensionOutputs.fromCbor(aaeo).asScala + AuthenticatorAssertionExtensionOutputs.fromCbor(aaeo).toScala } ) implicit val arbitraryAuthenticatorRegistrationExtensionOutputs @@ -883,7 +884,7 @@ object Generators { Arbitrary( Extensions.anyRegistrationExtensions map { case (_, _, areo) => - AuthenticatorRegistrationExtensionOutputs.fromCbor(areo).asScala + AuthenticatorRegistrationExtensionOutputs.fromCbor(areo).toScala } ) @@ -907,7 +908,7 @@ object Generators { .set("type", jsonFactory.textNode(tpe)) .asInstanceOf[ObjectNode] - tokenBinding.asScala foreach { tb => + tokenBinding.toScala foreach { tb => json.set[ObjectNode]( "tokenBinding", JacksonCodecs @@ -916,7 +917,7 @@ object Generators { ) } - authenticatorExtensions.asScala foreach { ae => + authenticatorExtensions.toScala foreach { ae => json.set[ObjectNode]( "authenticatorExtensions", JacksonCodecs @@ -925,7 +926,7 @@ object Generators { ) } - clientExtensions.asScala foreach { ce => + clientExtensions.toScala foreach { ce => json.set[ObjectNode]( "clientExtensions", JacksonCodecs diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/test/Helpers.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/test/Helpers.scala index 994a8cf77..2a9395fe9 100644 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/test/Helpers.scala +++ b/webauthn-server-core/src/test/scala/com/yubico/webauthn/test/Helpers.scala @@ -1,6 +1,5 @@ package com.yubico.webauthn.test -import com.yubico.internal.util.scala.JavaConverters._ import com.yubico.webauthn.CredentialRepository import com.yubico.webauthn.RegisteredCredential import com.yubico.webauthn.RegistrationResult @@ -10,6 +9,7 @@ import com.yubico.webauthn.data.UserIdentity import java.util.Optional import scala.jdk.CollectionConverters._ +import scala.jdk.OptionConverters.RichOption object Helpers { @@ -20,14 +20,14 @@ object Helpers { ): java.util.Set[PublicKeyCredentialDescriptor] = Set.empty.asJava override def getUserHandleForUsername( username: String - ): Optional[ByteArray] = None.asJava + ): Optional[ByteArray] = None.toJava override def getUsernameForUserHandle( userHandle: ByteArray - ): Optional[String] = None.asJava + ): Optional[String] = None.toJava override def lookup( credentialId: ByteArray, userHandle: ByteArray, - ): Optional[RegisteredCredential] = None.asJava + ): Optional[RegisteredCredential] = None.toJava override def lookupAll( credentialId: ByteArray ): java.util.Set[RegisteredCredential] = Set.empty.asJava @@ -71,14 +71,14 @@ object Helpers { username: String ): Optional[ByteArray] = if (username == user.getName) - Some(user.getId).asJava - else None.asJava + Some(user.getId).toJava + else None.toJava override def getUsernameForUserHandle( userHandle: ByteArray ): Optional[String] = if (userHandle == user.getId) - Some(user.getName).asJava - else None.asJava + Some(user.getName).toJava + else None.toJava override def lookup( credentialId: ByteArray, userHandle: ByteArray, @@ -86,8 +86,8 @@ object Helpers { if ( credentialId == credential.getCredentialId && userHandle == user.getId ) - Some(credential).asJava - else None.asJava + Some(credential).toJava + else None.toJava override def lookupAll( credentialId: ByteArray ): java.util.Set[RegisteredCredential] = diff --git a/webauthn-server-demo/src/test/scala/demo/webauthn/WebAuthnServerSpec.scala b/webauthn-server-demo/src/test/scala/demo/webauthn/WebAuthnServerSpec.scala index 950d415b8..247bdae7e 100644 --- a/webauthn-server-demo/src/test/scala/demo/webauthn/WebAuthnServerSpec.scala +++ b/webauthn-server-demo/src/test/scala/demo/webauthn/WebAuthnServerSpec.scala @@ -27,7 +27,6 @@ package demo.webauthn import com.google.common.cache.Cache import com.google.common.cache.CacheBuilder import com.yubico.internal.util.JacksonCodecs -import com.yubico.internal.util.scala.JavaConverters._ import com.yubico.webauthn.RegisteredCredential import com.yubico.webauthn.RegistrationTestData import com.yubico.webauthn.TestAuthenticator @@ -55,6 +54,8 @@ import java.time.Instant import java.util.Optional import java.util.concurrent.TimeUnit import scala.jdk.CollectionConverters._ +import scala.jdk.OptionConverters.RichOption +import scala.jdk.OptionConverters.RichOptional @RunWith(classOf[JUnitRunner]) class WebAuthnServerSpec @@ -65,7 +66,7 @@ class WebAuthnServerSpec private val jsonMapper = JacksonCodecs.json() private val username = "foo-user" private val displayName = "Foo User" - private val credentialNickname = Some("My Lovely Credential").asJava + private val credentialNickname = Some("My Lovely Credential").toJava private val residentKeyRequirement = ResidentKeyRequirement.DISCOURAGED private val requestId = ByteArray.fromBase64Url("request1") private val rpId = @@ -183,9 +184,9 @@ class WebAuthnServerSpec .startRegistration( username, displayName, - None.asJava, + None.toJava, ResidentKeyRequirement.DISCOURAGED, - None.asJava, + None.toJava, ) .right .get @@ -271,7 +272,7 @@ class WebAuthnServerSpec .rpId(rpId.getId) .build() ) - .username(Some(testData.userId.getName).asJava) + .username(Some(testData.userId.getName).toJava) .build(), ), ) @@ -318,7 +319,7 @@ class WebAuthnServerSpec val creds = assertionRequest.right.get.getPublicKeyCredentialRequestOptions.getAllowCredentials.get.asScala creds should have size 1 - creds.head.getTransports.asScala should equal( + creds.head.getTransports.toScala should equal( Some(transports.asJava) ) } diff --git a/yubico-util-scala/src/main/scala/com/yubico/internal/util/scala/JavaConverters.scala b/yubico-util-scala/src/main/scala/com/yubico/internal/util/scala/JavaConverters.scala deleted file mode 100644 index 626156e58..000000000 --- a/yubico-util-scala/src/main/scala/com/yubico/internal/util/scala/JavaConverters.scala +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2018, Yubico AB -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package com.yubico.internal.util.scala - -import java.util.Optional -import java.util.function.Supplier -import scala.language.implicitConversions - -case class AsJavaOptional[A](a: Option[A]) { - def asJava[B >: A]: Optional[B] = - a match { - case Some(value) => Optional.of(value) - case None => Optional.empty() - } -} -case class AsScalaOption[A](a: Optional[A]) { - def asScala: Option[A] = if (a.isPresent) Some(a.get()) else None -} - -case class AsJavaSupplier[A](a: () => A) { - def asJava[B >: A]: Supplier[B] = - new Supplier[B] { - override def get(): B = a() - } -} - -object JavaConverters { - - implicit def asJavaOptionalConverter[A](a: Option[A]): AsJavaOptional[A] = - AsJavaOptional(a) - implicit def asJavaSupplierConverter[A](a: () => A): AsJavaSupplier[A] = - AsJavaSupplier(a) - implicit def asScalaOptionConverter[A](a: Optional[A]): AsScalaOption[A] = - AsScalaOption(a) - -} diff --git a/yubico-util-scala/src/main/scala/com/yubico/scalacheck/gen/JavaGenerators.scala b/yubico-util-scala/src/main/scala/com/yubico/scalacheck/gen/JavaGenerators.scala index 9dc840291..885515aa4 100644 --- a/yubico-util-scala/src/main/scala/com/yubico/scalacheck/gen/JavaGenerators.scala +++ b/yubico-util-scala/src/main/scala/com/yubico/scalacheck/gen/JavaGenerators.scala @@ -1,6 +1,5 @@ package com.yubico.scalacheck.gen -import com.yubico.internal.util.scala.JavaConverters._ import org.scalacheck.Arbitrary import org.scalacheck.Arbitrary.arbitrary import org.scalacheck.Gen @@ -8,13 +7,14 @@ import org.scalacheck.Gen import java.net.URL import java.util.Optional import scala.jdk.CollectionConverters._ +import scala.jdk.OptionConverters.RichOption object JavaGenerators { implicit def arbitraryOptional[A](implicit a: Arbitrary[A] ): Arbitrary[Optional[A]] = - Arbitrary(Gen.option(a.arbitrary).map(_.asJava)) + Arbitrary(Gen.option(a.arbitrary).map(_.toJava)) implicit def arbitraryList[A](implicit a: Arbitrary[List[A]]