Skip to content

Commit cd22804

Browse files
authored
Merge pull request #1137 from webauthn4j/dependabot/gradle/org.springframework.security-spring-security-bom-5.8.2
chore(deps): bump org.springframework.security:spring-security-bom from 5.7.6 to 5.8.2
2 parents 385516c + 2bf1a32 commit cd22804

File tree

11 files changed

+116
-54
lines changed

11 files changed

+116
-54
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ buildscript {
2727

2828
//Libraries
2929
webauthn4jVersion = '0.21.0.RELEASE'
30-
springSecurityVersion = '5.7.6'
30+
springSecurityVersion = '5.8.2'
3131
hibernateValidatorVersion = '6.2.5.Final'
3232
thymeleafVersion = '3.0.4.RELEASE'
3333
modelMapperVersion = '3.1.1'

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public AuthenticationManager authenticationManager(List<AuthenticationProvider>
103103
public WebSecurityCustomizer webSecurityCustomizer() {
104104
return (web) -> {
105105
// ignore static resources
106-
web.ignoring().antMatchers(
106+
web.ignoring().requestMatchers(
107107
"/favicon.ico",
108108
"/static/**",
109109
"/webjars/**");
@@ -144,21 +144,21 @@ public SecurityFilterChain filterChain(HttpSecurity http, AuthenticationManager
144144
http.addFilterAfter(fidoServerAssertionResultEndpointFilter, SessionManagementFilter.class);
145145

146146
// Authorization
147-
http.authorizeRequests()
148-
.mvcMatchers("/").permitAll()
149-
.mvcMatchers("/api/auth/status").permitAll()
150-
.mvcMatchers(HttpMethod.GET, "/login").permitAll()
151-
.mvcMatchers(HttpMethod.POST, "/api/profile").permitAll()
152-
.mvcMatchers("/health/**").permitAll()
153-
.mvcMatchers("/info/**").permitAll()
154-
.mvcMatchers("/h2-console/**").denyAll()
155-
.mvcMatchers("/api/admin/**").hasRole(ADMIN_ROLE)
147+
http.authorizeHttpRequests()
148+
.requestMatchers("/").permitAll()
149+
.requestMatchers("/api/auth/status").permitAll()
150+
.requestMatchers(HttpMethod.GET, "/login").permitAll()
151+
.requestMatchers(HttpMethod.POST, "/api/profile").permitAll()
152+
.requestMatchers("/health/**").permitAll()
153+
.requestMatchers("/info/**").permitAll()
154+
.requestMatchers("/h2-console/**").denyAll()
155+
.requestMatchers("/api/admin/**").hasRole(ADMIN_ROLE)
156156
.anyRequest().fullyAuthenticated();
157157

158158
//TODO:
159159
http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
160160

161-
http.csrf().ignoringAntMatchers("/webauthn/**");
161+
http.csrf().ignoringRequestMatchers("/webauthn/**");
162162

163163
http.authenticationManager(authenticationManager);
164164

samples/mpa/src/main/java/com/webauthn4j/springframework/security/webauthn/sample/app/config/WebSecurityBeanConfig.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
2121
import com.webauthn4j.WebAuthnManager;
2222
import com.webauthn4j.converter.util.ObjectConverter;
23-
import com.webauthn4j.data.PublicKeyCredentialUserEntity;
2423
import com.webauthn4j.metadata.converter.jackson.WebAuthnMetadataJSONModule;
2524
import com.webauthn4j.springframework.security.WebAuthnRegistrationRequestValidator;
2625
import com.webauthn4j.springframework.security.WebAuthnSecurityExpression;
@@ -35,7 +34,6 @@
3534
import com.webauthn4j.springframework.security.server.ServerPropertyProviderImpl;
3635
import org.springframework.context.annotation.Bean;
3736
import org.springframework.context.annotation.Configuration;
38-
import org.springframework.security.core.Authentication;
3937
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
4038
import org.springframework.security.crypto.password.PasswordEncoder;
4139
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

samples/mpa/src/main/java/com/webauthn4j/springframework/security/webauthn/sample/app/config/WebSecurityConfig.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import com.webauthn4j.springframework.security.WebAuthnAuthenticationProvider;
2525
import com.webauthn4j.springframework.security.authenticator.WebAuthnAuthenticatorService;
2626
import com.webauthn4j.springframework.security.config.configurers.WebAuthnLoginConfigurer;
27+
import org.springframework.beans.factory.annotation.Autowired;
28+
import org.springframework.context.ApplicationContext;
2729
import org.springframework.context.annotation.Bean;
2830
import org.springframework.context.annotation.Configuration;
2931
import org.springframework.http.HttpMethod;
@@ -34,6 +36,8 @@
3436
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
3537
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
3638
import org.springframework.security.web.SecurityFilterChain;
39+
import org.springframework.security.web.access.expression.DefaultHttpSecurityExpressionHandler;
40+
import org.springframework.security.web.access.expression.WebExpressionAuthorizationManager;
3741
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
3842

3943
import java.util.List;
@@ -42,6 +46,9 @@
4246
@EnableWebSecurity
4347
public class WebSecurityConfig {
4448

49+
@Autowired
50+
private ApplicationContext applicationContext;
51+
4552
@Bean
4653
public WebAuthnAuthenticationProvider webAuthnAuthenticationProvider(WebAuthnAuthenticatorService authenticatorService, WebAuthnManager webAuthnManager){
4754
return new WebAuthnAuthenticationProvider(authenticatorService, webAuthnManager);
@@ -56,7 +63,7 @@ public AuthenticationManager authenticationManager(List<AuthenticationProvider>
5663
public WebSecurityCustomizer webSecurityCustomizer() {
5764
return (web) -> {
5865
// ignore static resources
59-
web.ignoring().antMatchers(
66+
web.ignoring().requestMatchers(
6067
"/favicon.ico",
6168
"/js/**",
6269
"/css/**",
@@ -97,11 +104,12 @@ public SecurityFilterChain filterChain(HttpSecurity http, AuthenticationManager
97104

98105

99106
// Authorization
100-
http.authorizeRequests()
101-
.mvcMatchers(HttpMethod.GET, "/login").permitAll()
102-
.mvcMatchers(HttpMethod.GET, "/signup").permitAll()
103-
.mvcMatchers(HttpMethod.POST, "/signup").permitAll()
104-
.anyRequest().access("@webAuthnSecurityExpression.isWebAuthnAuthenticated(authentication) || hasAuthority('SINGLE_FACTOR_AUTHN_ALLOWED')");
107+
http.authorizeHttpRequests(authz -> authz
108+
.requestMatchers(HttpMethod.GET, "/login").permitAll()
109+
.requestMatchers(HttpMethod.GET, "/signup").permitAll()
110+
.requestMatchers(HttpMethod.POST, "/signup").permitAll()
111+
.anyRequest().access(getWebExpressionAuthorizationManager("@webAuthnSecurityExpression.isWebAuthnAuthenticated(authentication) || hasAuthority('SINGLE_FACTOR_AUTHN_ALLOWED')"))
112+
);
105113

106114
http.exceptionHandling()
107115
.accessDeniedHandler((request, response, accessDeniedException) -> response.sendRedirect("/login"));
@@ -110,9 +118,17 @@ public SecurityFilterChain filterChain(HttpSecurity http, AuthenticationManager
110118

111119
// As WebAuthn has its own CSRF protection mechanism (challenge), CSRF token is disabled here
112120
http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
113-
http.csrf().ignoringAntMatchers("/webauthn/**");
121+
http.csrf().ignoringRequestMatchers("/webauthn/**");
114122

115123
return http.build();
116124

117125
}
126+
127+
private WebExpressionAuthorizationManager getWebExpressionAuthorizationManager(final String expression) {
128+
DefaultHttpSecurityExpressionHandler expressionHandler = new DefaultHttpSecurityExpressionHandler();
129+
expressionHandler.setApplicationContext(applicationContext);
130+
WebExpressionAuthorizationManager authorizationManager = new WebExpressionAuthorizationManager(expression);
131+
authorizationManager.setExpressionHandler(expressionHandler);
132+
return authorizationManager;
133+
}
118134
}

samples/spa/src/main/java/com/webauthn4j/springframework/security/webauthn/sample/app/config/WebSecurityConfig.java

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.webauthn4j.springframework.security.authenticator.WebAuthnAuthenticatorService;
2525
import com.webauthn4j.springframework.security.config.configurers.WebAuthnLoginConfigurer;
2626
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.context.ApplicationContext;
2728
import org.springframework.context.annotation.Bean;
2829
import org.springframework.context.annotation.Configuration;
2930
import org.springframework.context.annotation.Import;
@@ -39,10 +40,13 @@
3940
import org.springframework.security.web.AuthenticationEntryPoint;
4041
import org.springframework.security.web.SecurityFilterChain;
4142
import org.springframework.security.web.access.AccessDeniedHandler;
43+
import org.springframework.security.web.access.expression.DefaultHttpSecurityExpressionHandler;
44+
import org.springframework.security.web.access.expression.WebExpressionAuthorizationManager;
4245
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
4346
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
4447
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
4548
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
49+
import org.springframework.security.web.csrf.CsrfTokenRequestAttributeHandler;
4650

4751
import java.util.List;
4852

@@ -55,6 +59,9 @@
5559
@EnableWebSecurity
5660
public class WebSecurityConfig {
5761

62+
@Autowired
63+
private ApplicationContext applicationContext;
64+
5865
@Autowired
5966
private AuthenticationSuccessHandler authenticationSuccessHandler;
6067

@@ -125,27 +132,29 @@ public SecurityFilterChain filterChain(HttpSecurity http, AuthenticationManager
125132
headers.frameOptions().disable();
126133
});
127134

135+
// Authorization
136+
http.authorizeHttpRequests(authz -> authz
137+
.requestMatchers("/").permitAll()
138+
.requestMatchers("/static/**").permitAll()
139+
.requestMatchers("/angular/**").permitAll()
140+
.requestMatchers("/webjars/**").permitAll()
141+
.requestMatchers("/favicon.ico").permitAll()
142+
.requestMatchers("/api/auth/status").permitAll()
143+
.requestMatchers(HttpMethod.GET, "/login").permitAll()
144+
.requestMatchers(HttpMethod.POST, "/api/profile").permitAll()
145+
.requestMatchers("/api/status/**").permitAll()
146+
.requestMatchers("/health/**").permitAll()
147+
.requestMatchers("/info/**").permitAll()
148+
.requestMatchers("/h2-console/**").denyAll()
149+
.requestMatchers("/api/admin/**").access(getWebExpressionAuthorizationManager("hasRole('ADMIN_ROLE') and isAuthenticated()"))
150+
.anyRequest().access(getWebExpressionAuthorizationManager("@webAuthnSecurityExpression.isWebAuthnAuthenticated(authentication) || hasAuthority('SINGLE_FACTOR_AUTHN_ALLOWED')"))
151+
);
152+
128153
// Logout
129154
http.logout()
130155
.logoutUrl("/logout")
131156
.logoutSuccessHandler(logoutSuccessHandler);
132157

133-
// Authorization
134-
http.authorizeRequests()
135-
.mvcMatchers("/").permitAll()
136-
.mvcMatchers("/static/**").permitAll()
137-
.mvcMatchers("/angular/**").permitAll()
138-
.mvcMatchers("/webjars/**").permitAll()
139-
.mvcMatchers("/favicon.ico").permitAll()
140-
.mvcMatchers("/api/auth/status").permitAll()
141-
.mvcMatchers(HttpMethod.GET, "/login").permitAll()
142-
.mvcMatchers(HttpMethod.POST, "/api/profile").permitAll()
143-
.mvcMatchers("/health/**").permitAll()
144-
.mvcMatchers("/info/**").permitAll()
145-
.mvcMatchers("/h2-console/**").denyAll()
146-
.mvcMatchers("/api/admin/**").access("hasRole('ADMIN_ROLE') and isAuthenticated()")
147-
.anyRequest().access("@webAuthnSecurityExpression.isWebAuthnAuthenticated(authentication) || hasAuthority('SINGLE_FACTOR_AUTHN_ALLOWED')");
148-
149158
http.sessionManagement()
150159
.sessionAuthenticationFailureHandler(authenticationFailureHandler);
151160

@@ -154,9 +163,20 @@ public SecurityFilterChain filterChain(HttpSecurity http, AuthenticationManager
154163
.accessDeniedHandler(accessDeniedHandler);
155164

156165
// As WebAuthn has its own CSRF protection mechanism (challenge), CSRF token is disabled here
166+
CsrfTokenRequestAttributeHandler csrfTokenRequestAttributeHandler = new CsrfTokenRequestAttributeHandler();
167+
csrfTokenRequestAttributeHandler.setCsrfRequestAttributeName(null);
168+
http.csrf().csrfTokenRequestHandler(csrfTokenRequestAttributeHandler);
157169
http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
158-
http.csrf().ignoringAntMatchers("/webauthn/**");
170+
http.csrf().ignoringRequestMatchers("/webauthn/**");
159171

160172
return http.build();
161173
}
174+
175+
private WebExpressionAuthorizationManager getWebExpressionAuthorizationManager(final String expression) {
176+
DefaultHttpSecurityExpressionHandler expressionHandler = new DefaultHttpSecurityExpressionHandler();
177+
expressionHandler.setApplicationContext(applicationContext);
178+
WebExpressionAuthorizationManager authorizationManager = new WebExpressionAuthorizationManager(expression);
179+
authorizationManager.setExpressionHandler(expressionHandler);
180+
return authorizationManager;
181+
}
162182
}

samples/spa/src/main/java/com/webauthn4j/springframework/security/webauthn/sample/app/util/modelmapper/StringToChallengeConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import com.webauthn4j.data.client.challenge.Challenge;
2020
import com.webauthn4j.data.client.challenge.DefaultChallenge;
21+
import com.webauthn4j.util.Base64UrlUtil;
2122
import org.modelmapper.AbstractConverter;
22-
import org.springframework.util.Base64Utils;
2323

2424
/**
2525
* Converter which converts from {@link String} to {@link Challenge}
@@ -28,7 +28,7 @@ public class StringToChallengeConverter extends AbstractConverter<String, Challe
2828

2929
@Override
3030
protected Challenge convert(String source) {
31-
byte[] challenge = Base64Utils.decodeFromUrlSafeString(source);
31+
byte[] challenge = Base64UrlUtil.decode(source);
3232
return new DefaultChallenge(challenge);
3333
}
3434
}

webauthn4j-spring-security-core/src/main/java/com/webauthn4j/springframework/security/WebAuthnProcessingFilter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.webauthn4j.server.ServerProperty;
2020
import com.webauthn4j.springframework.security.server.ServerPropertyProvider;
21+
import com.webauthn4j.util.Base64UrlUtil;
2122
import org.springframework.http.HttpMethod;
2223
import org.springframework.security.authentication.AbstractAuthenticationToken;
2324
import org.springframework.security.authentication.AuthenticationServiceException;
@@ -27,7 +28,6 @@
2728
import org.springframework.security.core.authority.AuthorityUtils;
2829
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
2930
import org.springframework.util.Assert;
30-
import org.springframework.util.Base64Utils;
3131
import org.springframework.util.StringUtils;
3232

3333
import javax.servlet.http.HttpServletRequest;
@@ -143,10 +143,10 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
143143
String signature = obtainSignatureData(request);
144144
String clientExtensionsJSON = obtainClientExtensionsJSON(request);
145145

146-
byte[] rawId = Base64Utils.decodeFromUrlSafeString(credentialId);
147-
byte[] rawClientData = Base64Utils.decodeFromUrlSafeString(clientDataJSON);
148-
byte[] rawAuthenticatorData = Base64Utils.decodeFromUrlSafeString(authenticatorData);
149-
byte[] signatureBytes = Base64Utils.decodeFromUrlSafeString(signature);
146+
byte[] rawId = Base64UrlUtil.decode(credentialId);
147+
byte[] rawClientData = Base64UrlUtil.decode(clientDataJSON);
148+
byte[] rawAuthenticatorData = Base64UrlUtil.decode(authenticatorData);
149+
byte[] signatureBytes = Base64UrlUtil.decode(signature);
150150

151151
ServerProperty serverProperty = serverPropertyProvider.provide(request);
152152

webauthn4j-spring-security-core/src/test/java/com/webauthn4j/springframework/security/config/configurers/WebAuthnAuthenticationProviderConfigurerSpringTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
import org.springframework.beans.factory.annotation.Autowired;
3030
import org.springframework.boot.test.mock.mockito.MockBean;
3131
import org.springframework.context.annotation.Bean;
32+
import org.springframework.context.annotation.Configuration;
3233
import org.springframework.security.authentication.AuthenticationManager;
3334
import org.springframework.security.authentication.ProviderManager;
3435
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
3536
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
3637
import org.springframework.security.web.SecurityFilterChain;
3738
import org.springframework.test.context.junit4.SpringRunner;
39+
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
3840

3941
import static org.assertj.core.api.Assertions.assertThat;
4042

@@ -49,6 +51,7 @@ public void test() {
4951
assertThat(providerManager.getProviders()).extracting("class").contains(WebAuthnAuthenticationProvider.class);
5052
}
5153

54+
@Configuration
5255
@EnableWebSecurity
5356
static class Config {
5457

@@ -86,8 +89,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
8689
http.apply(WebAuthnLoginConfigurer.webAuthnLogin());
8790

8891
// Authorization
89-
http.authorizeRequests()
90-
.antMatchers("/login").permitAll()
92+
http.authorizeHttpRequests()
93+
.requestMatchers("/login").permitAll()
9194
.anyRequest().authenticated();
9295

9396
return http.build();
@@ -97,5 +100,10 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
97100
public AuthenticationManager authenticationManager(){
98101
return new ProviderManager(new WebAuthnAuthenticationProvider(authenticatorService, WebAuthnManager.createNonStrictWebAuthnManager()));
99102
}
103+
104+
@Bean(name = "mvcHandlerMappingIntrospector")
105+
public HandlerMappingIntrospector mvcHandlerMappingIntrospector() {
106+
return new HandlerMappingIntrospector();
107+
}
100108
}
101109
}

webauthn4j-spring-security-core/src/test/java/com/webauthn4j/springframework/security/config/configurers/WebAuthnLoginConfigurerAnotherSpringTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.springframework.test.context.junit4.SpringRunner;
4444
import org.springframework.test.web.servlet.MockMvc;
4545
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
46+
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
4647

4748
import static org.mockito.ArgumentMatchers.any;
4849
import static org.mockito.Mockito.mock;
@@ -74,7 +75,7 @@ public void rootPath_with_authenticated_user_test() throws Exception {
7475

7576
}
7677

77-
78+
@Configuration
7879
@EnableWebSecurity
7980
static class Config {
8081

@@ -83,8 +84,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
8384
http.apply(WebAuthnLoginConfigurer.webAuthnLogin());
8485

8586
// Authorization
86-
http.authorizeRequests()
87-
.antMatchers("/login").permitAll()
87+
http.authorizeHttpRequests()
88+
.requestMatchers("/login").permitAll()
8889
.anyRequest().authenticated();
8990

9091
return http.build();
@@ -144,6 +145,11 @@ public AssertionOptionsEndpointFilter assertionOptionsEndpointFilter(AssertionOp
144145
return new AssertionOptionsEndpointFilter(optionsProvider, objectConverter);
145146
}
146147

148+
@Bean(name = "mvcHandlerMappingIntrospector")
149+
public HandlerMappingIntrospector mvcHandlerMappingIntrospector() {
150+
return new HandlerMappingIntrospector();
151+
}
152+
147153
}
148154

149155
}

0 commit comments

Comments
 (0)