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
This commit is contained in:
committed by
Josh Cummings
parent
d2f24ae5f5
commit
ac9c29b2a0
@@ -137,7 +137,7 @@ You can see an example of how it might be used below:
|
||||
----
|
||||
SecurityContext context = SecurityContextHolder.createEmptyContext();
|
||||
Authentication authentication =
|
||||
new UsernamePasswordAuthenticationToken("user","doesnotmatter", AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||
UsernamePasswordAuthenticationToken.authenticated("user","doesnotmatter", AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||
context.setAuthentication(authentication);
|
||||
|
||||
SimpleAsyncTaskExecutor delegateExecutor =
|
||||
|
||||
@@ -89,7 +89,7 @@ You can see an example of how it might be used below:
|
||||
----
|
||||
SecurityContext context = SecurityContextHolder.createEmptyContext();
|
||||
Authentication authentication =
|
||||
new UsernamePasswordAuthenticationToken("user","doesnotmatter", AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||
UsernamePasswordAuthenticationToken.authenticated("user","doesnotmatter", AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||
context.setAuthentication(authentication);
|
||||
|
||||
SimpleAsyncTaskExecutor delegateExecutor =
|
||||
|
||||
@@ -512,7 +512,7 @@ public class WithMockCustomUserSecurityContextFactory
|
||||
CustomUserDetails principal =
|
||||
new CustomUserDetails(customUser.name(), customUser.username());
|
||||
Authentication auth =
|
||||
new UsernamePasswordAuthenticationToken(principal, "password", principal.getAuthorities());
|
||||
UsernamePasswordAuthenticationToken.authenticated(principal, "password", principal.getAuthorities());
|
||||
context.setAuthentication(auth);
|
||||
return context;
|
||||
}
|
||||
@@ -558,7 +558,7 @@ final class WithUserDetailsSecurityContextFactory
|
||||
String username = withUser.value();
|
||||
Assert.hasLength(username, "value() must be non-empty String");
|
||||
UserDetails principal = userDetailsService.loadUserByUsername(username);
|
||||
Authentication authentication = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), principal.getAuthorities());
|
||||
Authentication authentication = UsernamePasswordAuthenticationToken.authenticated(principal, principal.getPassword(), principal.getAuthorities());
|
||||
SecurityContext context = SecurityContextHolder.createEmptyContext();
|
||||
context.setAuthentication(authentication);
|
||||
return context;
|
||||
|
||||
Reference in New Issue
Block a user