Search in sources :

Example 1 with AuthenticationExtensionClientInput

use of com.webauthn4j.data.extension.client.AuthenticationExtensionClientInput in project webauthn4j by webauthn4j.

the class AuthenticationExtensionsClientInputsConverterTest method convert_test.

@Test
void convert_test() {
    String source = "{\"appid\":\"dummy\"}";
    AuthenticationExtensionsClientInputs<AuthenticationExtensionClientInput> clientInputs = authenticationExtensionsClientInputsConverter.convert(source);
    assertThat(clientInputs.getExtension(FIDOAppIDExtensionClientInput.class)).isEqualTo(new FIDOAppIDExtensionClientInput("dummy"));
}
Also used : AuthenticationExtensionClientInput(com.webauthn4j.data.extension.client.AuthenticationExtensionClientInput) FIDOAppIDExtensionClientInput(com.webauthn4j.data.extension.client.FIDOAppIDExtensionClientInput) Test(org.junit.jupiter.api.Test)

Example 2 with AuthenticationExtensionClientInput

use of com.webauthn4j.data.extension.client.AuthenticationExtensionClientInput in project webauthn4j-spring-security by webauthn4j.

the class FidoServerAssertionOptionsEndpointFilter method processRequest.

@Override
protected ServerResponse processRequest(HttpServletRequest request) {
    InputStream inputStream;
    try {
        inputStream = request.getInputStream();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    try {
        ServerPublicKeyCredentialGetOptionsRequest serverRequest = objectConverter.getJsonConverter().readValue(inputStream, ServerPublicKeyCredentialGetOptionsRequest.class);
        Challenge challenge = serverEndpointFilterUtil.encodeUserVerification(new DefaultChallenge(), serverRequest.getUserVerification());
        challengeRepository.saveChallenge(challenge, request);
        // TODO: UsernamePasswordAuthenticationToken should not be used here in this way
        AssertionOptions options = optionsProvider.getAssertionOptions(request, new UsernamePasswordAuthenticationToken(serverRequest.getUsername(), null, Collections.emptyList()));
        List<ServerPublicKeyCredentialDescriptor> credentials = options.getAllowCredentials().stream().map(credential -> new ServerPublicKeyCredentialDescriptor(credential.getType(), Base64UrlUtil.encodeToString(credential.getId()), credential.getTransports())).collect(Collectors.toList());
        AuthenticationExtensionsClientInputs<AuthenticationExtensionClientInput> authenticationExtensionsClientInputs;
        if (serverRequest.getExtensions() != null) {
            authenticationExtensionsClientInputs = serverRequest.getExtensions();
        } else {
            authenticationExtensionsClientInputs = options.getExtensions();
        }
        return new ServerPublicKeyCredentialGetOptionsResponse(Base64UrlUtil.encodeToString(options.getChallenge().getValue()), options.getTimeout(), options.getRpId(), credentials, serverRequest.getUserVerification(), authenticationExtensionsClientInputs);
    } catch (DataConversionException e) {
        throw new com.webauthn4j.springframework.security.exception.DataConversionException("Failed to convert data", e);
    }
}
Also used : AssertionOptionsProvider(com.webauthn4j.springframework.security.options.AssertionOptionsProvider) AssertionOptions(com.webauthn4j.springframework.security.options.AssertionOptions) IOException(java.io.IOException) Challenge(com.webauthn4j.data.client.challenge.Challenge) AuthenticationExtensionClientInput(com.webauthn4j.data.extension.client.AuthenticationExtensionClientInput) ChallengeRepository(com.webauthn4j.springframework.security.challenge.ChallengeRepository) Base64UrlUtil(com.webauthn4j.util.Base64UrlUtil) Collectors(java.util.stream.Collectors) AuthenticationExtensionsClientInputs(com.webauthn4j.data.extension.client.AuthenticationExtensionsClientInputs) UncheckedIOException(java.io.UncheckedIOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) ObjectConverter(com.webauthn4j.converter.util.ObjectConverter) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) DefaultChallenge(com.webauthn4j.data.client.challenge.DefaultChallenge) DataConversionException(com.webauthn4j.converter.exception.DataConversionException) Collections(java.util.Collections) Assert(org.springframework.util.Assert) InputStream(java.io.InputStream) InputStream(java.io.InputStream) AssertionOptions(com.webauthn4j.springframework.security.options.AssertionOptions) UncheckedIOException(java.io.UncheckedIOException) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Challenge(com.webauthn4j.data.client.challenge.Challenge) DefaultChallenge(com.webauthn4j.data.client.challenge.DefaultChallenge) DefaultChallenge(com.webauthn4j.data.client.challenge.DefaultChallenge) AuthenticationExtensionClientInput(com.webauthn4j.data.extension.client.AuthenticationExtensionClientInput) DataConversionException(com.webauthn4j.converter.exception.DataConversionException)

Aggregations

AuthenticationExtensionClientInput (com.webauthn4j.data.extension.client.AuthenticationExtensionClientInput)2 DataConversionException (com.webauthn4j.converter.exception.DataConversionException)1 ObjectConverter (com.webauthn4j.converter.util.ObjectConverter)1 Challenge (com.webauthn4j.data.client.challenge.Challenge)1 DefaultChallenge (com.webauthn4j.data.client.challenge.DefaultChallenge)1 AuthenticationExtensionsClientInputs (com.webauthn4j.data.extension.client.AuthenticationExtensionsClientInputs)1 FIDOAppIDExtensionClientInput (com.webauthn4j.data.extension.client.FIDOAppIDExtensionClientInput)1 ChallengeRepository (com.webauthn4j.springframework.security.challenge.ChallengeRepository)1 AssertionOptions (com.webauthn4j.springframework.security.options.AssertionOptions)1 AssertionOptionsProvider (com.webauthn4j.springframework.security.options.AssertionOptionsProvider)1 Base64UrlUtil (com.webauthn4j.util.Base64UrlUtil)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Test (org.junit.jupiter.api.Test)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1