Skip to content

Commit 28514fd

Browse files
committed
Make FIDO conformance test tool pass again
1 parent d1f837a commit 28514fd

File tree

4 files changed

+9
-54
lines changed

4 files changed

+9
-54
lines changed

samples/fido-server-conformance-test-app/src/main/java/com/webauthn4j/springframework/security/fido/server/endpoint/FidoServerAssertionOptionsEndpointFilter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
import com.webauthn4j.springframework.security.challenge.ChallengeRepository;
2727
import com.webauthn4j.springframework.security.options.AssertionOptionsProvider;
2828
import com.webauthn4j.util.Base64UrlUtil;
29-
import org.springframework.security.core.Authentication;
30-
import org.springframework.security.core.context.SecurityContextHolder;
29+
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
3130
import org.springframework.util.Assert;
3231

3332
import javax.servlet.http.HttpServletRequest;
3433
import java.io.IOException;
3534
import java.io.InputStream;
3635
import java.io.UncheckedIOException;
36+
import java.util.Collections;
3737
import java.util.List;
3838
import java.util.stream.Collectors;
3939

@@ -86,8 +86,8 @@ protected ServerResponse processRequest(HttpServletRequest request) {
8686
objectConverter.getJsonConverter().readValue(inputStream, ServerPublicKeyCredentialGetOptionsRequest.class);
8787
Challenge challenge = serverEndpointFilterUtil.encodeUserVerification(new DefaultChallenge(), serverRequest.getUserVerification());
8888
challengeRepository.saveChallenge(challenge, request);
89-
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
90-
PublicKeyCredentialRequestOptions options = optionsProvider.getAssertionOptions(request, authentication);
89+
//TODO: UsernamePasswordAuthenticationToken should not be used here in this way
90+
PublicKeyCredentialRequestOptions options = optionsProvider.getAssertionOptions(request, new UsernamePasswordAuthenticationToken(serverRequest.getUsername(), null, Collections.emptyList()));
9191
List<ServerPublicKeyCredentialDescriptor> credentials = options.getAllowCredentials().stream()
9292
.map(credential -> new ServerPublicKeyCredentialDescriptor(credential.getType(), Base64UrlUtil.encodeToString(credential.getId()), credential.getTransports()))
9393
.collect(Collectors.toList());

samples/fido-server-conformance-test-app/src/main/java/com/webauthn4j/springframework/security/fido/server/endpoint/FidoServerAttestationOptionsEndpointFilter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
import com.webauthn4j.springframework.security.challenge.ChallengeRepository;
2727
import com.webauthn4j.springframework.security.options.AttestationOptionsProvider;
2828
import com.webauthn4j.util.Base64UrlUtil;
29-
import org.springframework.security.core.Authentication;
30-
import org.springframework.security.core.context.SecurityContextHolder;
29+
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
3130
import org.springframework.util.Assert;
3231

3332
import javax.servlet.http.HttpServletRequest;
3433
import java.io.IOException;
3534
import java.io.InputStream;
3635
import java.io.UncheckedIOException;
3736
import java.nio.ByteBuffer;
37+
import java.util.Collections;
3838
import java.util.List;
3939
import java.util.UUID;
4040
import java.util.stream.Collectors;
@@ -85,12 +85,12 @@ protected ServerResponse processRequest(HttpServletRequest request) {
8585
try {
8686
ServerPublicKeyCredentialCreationOptionsRequest serverRequest = objectConverter.getJsonConverter()
8787
.readValue(inputStream, ServerPublicKeyCredentialCreationOptionsRequest.class);
88-
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
89-
String username = authentication.getName();
88+
String username = serverRequest.getUsername();
9089
String displayName = serverRequest.getDisplayName();
9190
Challenge challenge = serverEndpointFilterUtil.encodeUsername(new DefaultChallenge(), username);
9291
challengeRepository.saveChallenge(challenge, request);
93-
PublicKeyCredentialCreationOptions attestationOptions = optionsProvider.getAttestationOptions(request, authentication);
92+
//TODO: UsernamePasswordAuthenticationToken should not be used here in this way
93+
PublicKeyCredentialCreationOptions attestationOptions = optionsProvider.getAttestationOptions(request, new UsernamePasswordAuthenticationToken(username, null, Collections.emptyList()));
9494
String userHandle;
9595
if (attestationOptions.getUser() == null) {
9696
userHandle = Base64UrlUtil.encodeToString(generateUserHandle());

samples/fido-server-conformance-test-app/src/main/java/com/webauthn4j/springframework/security/webauthn/sample/app/config/WebSecurityConfig.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,6 @@ protected void configure(HttpSecurity http) throws Exception {
175175
http.addFilterAfter(fidoServerAssertionOptionsEndpointFilter, SessionManagementFilter.class);
176176
http.addFilterAfter(fidoServerAssertionResultEndpointFilter, SessionManagementFilter.class);
177177

178-
179-
// // FIDO Server Endpoints
180-
// http.apply(fidoServer())
181-
// .fidoServerAttestationOptionsEndpoint()
182-
// .and()
183-
// .fidoServerAttestationResultEndpointConfig()
184-
// .webAuthnRegistrationRequestValidator(webAuthnRegistrationRequestValidator)
185-
// .usernameNotFoundHandler(new SampleUsernameNotFoundHandler(userManager))
186-
// .and()
187-
// .fidoServerAssertionOptionsEndpointConfig()
188-
// .and()
189-
// .fidoServerAssertionResultEndpoint();
190-
191178
// Authorization
192179
http.authorizeRequests()
193180
.mvcMatchers("/").permitAll()

samples/fido-server-conformance-test-app/src/main/java/com/webauthn4j/springframework/security/webauthn/sample/domain/component/UserManagerImpl.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package com.webauthn4j.springframework.security.webauthn.sample.domain.component;
1818

19-
import com.webauthn4j.authenticator.Authenticator;
20-
import com.webauthn4j.springframework.security.webauthn.sample.domain.entity.AuthenticatorEntity;
2119
import com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity;
2220
import com.webauthn4j.springframework.security.webauthn.sample.domain.exception.WebAuthnSampleBusinessException;
2321
import com.webauthn4j.springframework.security.webauthn.sample.domain.exception.WebAuthnSampleEntityNotFoundException;
@@ -31,8 +29,6 @@
3129
import org.springframework.stereotype.Component;
3230
import org.springframework.transaction.annotation.Transactional;
3331

34-
import java.util.Arrays;
35-
3632
/**
3733
* {@inheritDoc}
3834
*/
@@ -143,32 +139,4 @@ public boolean userExists(String username) {
143139
private UserEntity getCurrentUser() {
144140
return (UserEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
145141
}
146-
147-
148-
public void addAuthenticator(String username, Authenticator authenticator) {
149-
UserEntity userEntity = userEntityRepository.findOneByEmailAddress(username)
150-
.orElseThrow(() -> new WebAuthnSampleEntityNotFoundException("User not found."));
151-
AuthenticatorEntity authenticatorEntity = modelMapper.map(authenticator, AuthenticatorEntity.class);
152-
authenticatorEntity.setUser(userEntity);
153-
userEntity.getAuthenticators().add(authenticatorEntity);
154-
}
155-
156-
public void removeAuthenticator(String username, Authenticator authenticator) {
157-
UserEntity userEntity = userEntityRepository.findOneByEmailAddress(username)
158-
.orElseThrow(() -> new WebAuthnSampleEntityNotFoundException("User not found."));
159-
boolean found = userEntity.getAuthenticators().remove(authenticator);
160-
if (!found) {
161-
throw new WebAuthnSampleEntityNotFoundException("Authenticator not found.");
162-
}
163-
}
164-
165-
public void removeAuthenticator(String username, byte[] credentialId) {
166-
UserEntity userEntity = userEntityRepository.findOneByEmailAddress(username)
167-
.orElseThrow(() -> new WebAuthnSampleEntityNotFoundException("User not found."));
168-
boolean found = userEntity.getAuthenticators().removeIf(item -> Arrays.equals(item.getAttestedCredentialData().getCredentialId(), credentialId));
169-
if (!found) {
170-
throw new WebAuthnSampleEntityNotFoundException("Authenticator not found.");
171-
}
172-
}
173-
174142
}

0 commit comments

Comments
 (0)