Skip to content

Commit abd3338

Browse files
nor-ekjzheaux
authored andcommitted
Add UsernamePasswordAuthenticationToken factory methods
- unauthenticated factory method - authenticated factory method - test for unauthenticated factory method - test for authenticated factory method - make existing constructor protected - use newly factory methods in rest of the project - update copyright dates Closes gh-10790
1 parent 28c7a4b commit abd3338

File tree

88 files changed

+439
-346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+439
-346
lines changed

config/src/integration-test/java/org/springframework/security/config/ldap/LdapProviderBeanDefinitionParserTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,7 +56,7 @@ public void simpleProviderAuthenticatesCorrectly() {
5656
AuthenticationManager authenticationManager = this.appCtx.getBean(BeanIds.AUTHENTICATION_MANAGER,
5757
AuthenticationManager.class);
5858
Authentication auth = authenticationManager
59-
.authenticate(new UsernamePasswordAuthenticationToken("ben", "benspassword"));
59+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("ben", "benspassword"));
6060
UserDetails ben = (UserDetails) auth.getPrincipal();
6161
assertThat(ben.getAuthorities()).hasSize(3);
6262
}
@@ -89,7 +89,7 @@ public void supportsPasswordComparisonAuthentication() {
8989
AuthenticationManager authenticationManager = this.appCtx.getBean(BeanIds.AUTHENTICATION_MANAGER,
9090
AuthenticationManager.class);
9191
Authentication auth = authenticationManager
92-
.authenticate(new UsernamePasswordAuthenticationToken("ben", "benspassword"));
92+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("ben", "benspassword"));
9393

9494
assertThat(auth).isNotNull();
9595
}
@@ -104,7 +104,8 @@ public void supportsPasswordComparisonAuthenticationWithPasswordEncoder() {
104104

105105
AuthenticationManager authenticationManager = this.appCtx.getBean(BeanIds.AUTHENTICATION_MANAGER,
106106
AuthenticationManager.class);
107-
Authentication auth = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("ben", "ben"));
107+
Authentication auth = authenticationManager
108+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("ben", "ben"));
108109

109110
assertThat(auth).isNotNull();
110111
}
@@ -121,7 +122,7 @@ public void supportsCryptoPasswordEncoder() {
121122
AuthenticationManager authenticationManager = this.appCtx.getBean(BeanIds.AUTHENTICATION_MANAGER,
122123
AuthenticationManager.class);
123124
Authentication auth = authenticationManager
124-
.authenticate(new UsernamePasswordAuthenticationToken("bcrypt", "password"));
125+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("bcrypt", "password"));
125126

126127
assertThat(auth).isNotNull();
127128
}

config/src/test/java/org/springframework/security/config/annotation/authentication/AuthenticationManagerBuilderTests.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -93,8 +93,8 @@ public void customAuthenticationEventPublisherWithWeb() throws Exception {
9393
given(opp.postProcess(any())).willAnswer((a) -> a.getArgument(0));
9494
AuthenticationManager am = new AuthenticationManagerBuilder(opp).authenticationEventPublisher(aep)
9595
.inMemoryAuthentication().and().build();
96-
assertThatExceptionOfType(AuthenticationException.class)
97-
.isThrownBy(() -> am.authenticate(new UsernamePasswordAuthenticationToken("user", "password")));
96+
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(
97+
() -> am.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "password")));
9898
verify(aep).publishAuthenticationFailure(any(), any());
9999
}
100100

@@ -103,7 +103,8 @@ public void getAuthenticationManagerWhenGlobalPasswordEncoderBeanThenUsed() thro
103103
this.spring.register(PasswordEncoderGlobalConfig.class).autowire();
104104
AuthenticationManager manager = this.spring.getContext().getBean(AuthenticationConfiguration.class)
105105
.getAuthenticationManager();
106-
Authentication auth = manager.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
106+
Authentication auth = manager
107+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "password"));
107108
assertThat(auth.getName()).isEqualTo("user");
108109
assertThat(auth.getAuthorities()).extracting(GrantedAuthority::getAuthority).containsOnly("ROLE_USER");
109110
}
@@ -113,7 +114,8 @@ public void getAuthenticationManagerWhenProtectedPasswordEncoderBeanThenUsed() t
113114
this.spring.register(PasswordEncoderGlobalConfig.class).autowire();
114115
AuthenticationManager manager = this.spring.getContext().getBean(AuthenticationConfiguration.class)
115116
.getAuthenticationManager();
116-
Authentication auth = manager.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
117+
Authentication auth = manager
118+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "password"));
117119
assertThat(auth.getName()).isEqualTo("user");
118120
assertThat(auth.getAuthorities()).extracting(GrantedAuthority::getAuthority).containsOnly("ROLE_USER");
119121
}

config/src/test/java/org/springframework/security/config/annotation/authentication/configuration/AuthenticationConfigurationPublishTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,8 @@ public class AuthenticationConfigurationPublishTests {
4747
// gh-4940
4848
@Test
4949
public void authenticationEventPublisherBeanUsedByDefault() {
50-
this.authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
50+
this.authenticationManager
51+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "password"));
5152
assertThat(this.listener.getEvents()).hasSize(1);
5253
}
5354

config/src/test/java/org/springframework/security/config/annotation/authentication/configuration/AuthenticationConfigurationTests.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -129,7 +129,8 @@ public void getAuthenticationManagerWhenNoOpGlobalAuthenticationConfigurerAdapte
129129

130130
@Test
131131
public void getAuthenticationWhenGlobalAuthenticationConfigurerAdapterThenAuthenticates() throws Exception {
132-
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("user", "password");
132+
UsernamePasswordAuthenticationToken token = UsernamePasswordAuthenticationToken.unauthenticated("user",
133+
"password");
133134
this.spring.register(AuthenticationConfiguration.class, ObjectPostProcessorConfiguration.class,
134135
UserGlobalAuthenticationConfigurerAdapter.class).autowire();
135136
AuthenticationManager authentication = this.spring.getContext().getBean(AuthenticationConfiguration.class)
@@ -139,7 +140,8 @@ public void getAuthenticationWhenGlobalAuthenticationConfigurerAdapterThenAuthen
139140

140141
@Test
141142
public void getAuthenticationWhenAuthenticationManagerBeanThenAuthenticates() throws Exception {
142-
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("user", "password");
143+
UsernamePasswordAuthenticationToken token = UsernamePasswordAuthenticationToken.unauthenticated("user",
144+
"password");
143145
this.spring.register(AuthenticationConfiguration.class, ObjectPostProcessorConfiguration.class,
144146
AuthenticationManagerBeanConfig.class).autowire();
145147
AuthenticationManager authentication = this.spring.getContext().getBean(AuthenticationConfiguration.class)
@@ -165,9 +167,9 @@ public void getAuthenticationWhenConfiguredThenBootNotTrigger() throws Exception
165167
config.setGlobalAuthenticationConfigurers(Arrays.asList(new ConfiguresInMemoryConfigurerAdapter(),
166168
new BootGlobalAuthenticationConfigurerAdapter()));
167169
AuthenticationManager authenticationManager = config.getAuthenticationManager();
168-
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
169-
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(
170-
() -> authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("boot", "password")));
170+
authenticationManager.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "password"));
171+
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() -> authenticationManager
172+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("boot", "password")));
171173
}
172174

173175
@Test
@@ -176,7 +178,7 @@ public void getAuthenticationWhenNotConfiguredThenBootTrigger() throws Exception
176178
AuthenticationConfiguration config = this.spring.getContext().getBean(AuthenticationConfiguration.class);
177179
config.setGlobalAuthenticationConfigurers(Arrays.asList(new BootGlobalAuthenticationConfigurerAdapter()));
178180
AuthenticationManager authenticationManager = config.getAuthenticationManager();
179-
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("boot", "password"));
181+
authenticationManager.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("boot", "password"));
180182
}
181183

182184
// gh-2531
@@ -206,9 +208,9 @@ public void getAuthenticationWhenUserDetailsServiceBeanThenAuthenticationManager
206208
AuthenticationManager am = this.spring.getContext().getBean(AuthenticationConfiguration.class)
207209
.getAuthenticationManager();
208210
given(uds.loadUserByUsername("user")).willReturn(PasswordEncodedUser.user(), PasswordEncodedUser.user());
209-
am.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
210-
assertThatExceptionOfType(AuthenticationException.class)
211-
.isThrownBy(() -> am.authenticate(new UsernamePasswordAuthenticationToken("user", "invalid")));
211+
am.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "password"));
212+
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(
213+
() -> am.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "invalid")));
212214
}
213215

214216
@Test
@@ -221,9 +223,9 @@ public void getAuthenticationWhenUserDetailsServiceAndPasswordEncoderBeanThenEnc
221223
.getAuthenticationManager();
222224
given(uds.loadUserByUsername("user")).willReturn(User.withUserDetails(user).build(),
223225
User.withUserDetails(user).build());
224-
am.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
225-
assertThatExceptionOfType(AuthenticationException.class)
226-
.isThrownBy(() -> am.authenticate(new UsernamePasswordAuthenticationToken("user", "invalid")));
226+
am.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "password"));
227+
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(
228+
() -> am.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "invalid")));
227229
}
228230

229231
@Test
@@ -237,7 +239,7 @@ public void getAuthenticationWhenUserDetailsServiceAndPasswordManagerThenManager
237239
given(manager.loadUserByUsername("user")).willReturn(User.withUserDetails(user).build(),
238240
User.withUserDetails(user).build());
239241
given(manager.updatePassword(any(), any())).willReturn(user);
240-
am.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
242+
am.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "password"));
241243
verify(manager).updatePassword(eq(user), startsWith("{bcrypt}"));
242244
}
243245

@@ -250,7 +252,7 @@ public void getAuthenticationWhenAuthenticationProviderAndUserDetailsBeanThenAut
250252
.getAuthenticationManager();
251253
given(ap.supports(any())).willReturn(true);
252254
given(ap.authenticate(any())).willReturn(TestAuthentication.authenticatedUser());
253-
am.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
255+
am.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "password"));
254256
}
255257

256258
// gh-3091
@@ -262,7 +264,7 @@ public void getAuthenticationWhenAuthenticationProviderBeanThenUsed() throws Exc
262264
.getAuthenticationManager();
263265
given(ap.supports(any())).willReturn(true);
264266
given(ap.authenticate(any())).willReturn(TestAuthentication.authenticatedUser());
265-
am.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
267+
am.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "password"));
266268
}
267269

268270
@Test

config/src/test/java/org/springframework/security/config/annotation/issue50/Issue50Tests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -75,21 +75,21 @@ public void loadWhenGlobalMethodSecurityConfigurationThenAuthenticationManagerLa
7575
@Test
7676
public void authenticateWhenMissingUserThenUsernameNotFoundException() {
7777
assertThatExceptionOfType(UsernameNotFoundException.class).isThrownBy(() -> this.authenticationManager
78-
.authenticate(new UsernamePasswordAuthenticationToken("test", "password")));
78+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("test", "password")));
7979
}
8080

8181
@Test
8282
public void authenticateWhenInvalidPasswordThenBadCredentialsException() {
8383
this.userRepo.save(User.withUsernameAndPassword("test", "password"));
8484
assertThatExceptionOfType(BadCredentialsException.class).isThrownBy(() -> this.authenticationManager
85-
.authenticate(new UsernamePasswordAuthenticationToken("test", "invalid")));
85+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("test", "invalid")));
8686
}
8787

8888
@Test
8989
public void authenticateWhenValidUserThenAuthenticates() {
9090
this.userRepo.save(User.withUsernameAndPassword("test", "password"));
9191
Authentication result = this.authenticationManager
92-
.authenticate(new UsernamePasswordAuthenticationToken("test", "password"));
92+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("test", "password"));
9393
assertThat(result.getName()).isEqualTo("test");
9494
}
9595

@@ -98,7 +98,7 @@ public void globalMethodSecurityIsEnabledWhenNotAllowedThenAccessDenied() {
9898
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("test", null, "ROLE_USER"));
9999
this.userRepo.save(User.withUsernameAndPassword("denied", "password"));
100100
assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> this.authenticationManager
101-
.authenticate(new UsernamePasswordAuthenticationToken("test", "password")));
101+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("test", "password")));
102102
}
103103

104104
}

config/src/test/java/org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfigurationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -106,8 +106,8 @@ public void configureWhenGlobalMethodSecurityHasCustomMetadataSourceThenNoEnabli
106106
@Test
107107
public void methodSecurityAuthenticationManagerPublishesEvent() {
108108
this.spring.register(InMemoryAuthWithGlobalMethodSecurityConfig.class).autowire();
109-
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(
110-
() -> this.authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("foo", "bar")));
109+
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() -> this.authenticationManager
110+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("foo", "bar")));
111111
assertThat(this.events.getEvents()).extracting(Object::getClass)
112112
.containsOnly((Class) AuthenticationFailureBadCredentialsEvent.class);
113113
}

config/src/test/java/org/springframework/security/config/annotation/web/configuration/AuthenticationPrincipalArgumentResolverTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,7 +65,7 @@ public void authenticationPrincipalExpressionWhenBeanExpressionSuppliedThenBeanU
6565
User user = new User("user", "password", AuthorityUtils.createAuthorityList("ROLE_USER"));
6666
SecurityContext context = SecurityContextHolder.createEmptyContext();
6767
context.setAuthentication(
68-
new UsernamePasswordAuthenticationToken(user, user.getPassword(), user.getAuthorities()));
68+
UsernamePasswordAuthenticationToken.authenticated(user, user.getPassword(), user.getAuthorities()));
6969
SecurityContextHolder.setContext(context);
7070
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
7171
// @formatter:off

config/src/test/java/org/springframework/security/config/annotation/web/configuration/EnableWebSecurityTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,7 +60,7 @@ public void configureWhenOverrideAuthenticationManagerBeanThenAuthenticationMana
6060
this.spring.register(SecurityConfig.class).autowire();
6161
AuthenticationManager authenticationManager = this.spring.getContext().getBean(AuthenticationManager.class);
6262
Authentication authentication = authenticationManager
63-
.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
63+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "password"));
6464
assertThat(authentication.isAuthenticated()).isTrue();
6565
}
6666

config/src/test/java/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1013,7 +1013,7 @@ static AuthenticationManager authenticationManager1() {
10131013
return new ProviderManager(new AuthenticationProvider() {
10141014
@Override
10151015
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
1016-
return new UsernamePasswordAuthenticationToken("user", "credentials");
1016+
return UsernamePasswordAuthenticationToken.unauthenticated("user", "credentials");
10171017
}
10181018

10191019
@Override
@@ -1028,7 +1028,7 @@ static AuthenticationManager authenticationManager2() {
10281028
return new ProviderManager(new AuthenticationProvider() {
10291029
@Override
10301030
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
1031-
return new UsernamePasswordAuthenticationToken("subuser", "credentials");
1031+
return UsernamePasswordAuthenticationToken.unauthenticated("subuser", "credentials");
10321032
}
10331033

10341034
@Override

config/src/test/java/org/springframework/security/config/annotation/web/configurers/AuthorizeRequestsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -150,7 +150,7 @@ public void antMatchersPathVariablesCaseInsensitiveCamelCaseVariables() throws E
150150
public void roleHiearchy() throws Exception {
151151
loadConfig(RoleHiearchyConfig.class);
152152
SecurityContext securityContext = new SecurityContextImpl();
153-
securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("test", "notused",
153+
securityContext.setAuthentication(UsernamePasswordAuthenticationToken.authenticated("test", "notused",
154154
AuthorityUtils.createAuthorityList("ROLE_USER")));
155155
this.request.getSession().setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
156156
securityContext);

config/src/test/java/org/springframework/security/config/annotation/web/configurers/NamespaceHttpInterceptUrlTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -100,7 +100,8 @@ public void requestWhenRequiresChannelThenBehaviorMatchesNamespace() throws Exce
100100
}
101101

102102
private static Authentication user(String role) {
103-
return new UsernamePasswordAuthenticationToken("user", null, AuthorityUtils.createAuthorityList(role));
103+
return UsernamePasswordAuthenticationToken.authenticated("user", null,
104+
AuthorityUtils.createAuthorityList(role));
104105
}
105106

106107
@EnableWebSecurity

config/src/test/java/org/springframework/security/config/annotation/web/configurers/NamespaceHttpServerAccessDeniedHandlerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -97,7 +97,7 @@ public void requestWhenCustomAccessDeniedHandlerInLambdaThenBehaviorMatchesNames
9797
}
9898

9999
private static Authentication user() {
100-
return new UsernamePasswordAuthenticationToken("user", null, AuthorityUtils.NO_AUTHORITIES);
100+
return UsernamePasswordAuthenticationToken.authenticated("user", null, AuthorityUtils.NO_AUTHORITIES);
101101
}
102102

103103
private <T> T verifyBean(Class<T> beanClass) {

0 commit comments

Comments
 (0)