下面列出了怎么用org.springframework.security.core.userdetails.UserDetailsChecker的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void getter_setter_test() {
WebAuthnUserDetailsService userDetailsService = mock(WebAuthnUserDetailsService.class);
UserDetailsChecker preAuthenticationChecker = mock(UserDetailsChecker.class);
UserDetailsChecker postAuthenticationChecker = mock(UserDetailsChecker.class);
authenticationProvider.setForcePrincipalAsString(true);
assertThat(authenticationProvider.isForcePrincipalAsString()).isTrue();
authenticationProvider.setHideCredentialIdNotFoundExceptions(true);
assertThat(authenticationProvider.isHideCredentialIdNotFoundExceptions()).isTrue();
authenticationProvider.setUserDetailsService(userDetailsService);
Assertions.assertThat(authenticationProvider.getUserDetailsService()).isEqualTo(userDetailsService);
authenticationProvider.setPreAuthenticationChecks(preAuthenticationChecker);
assertThat(authenticationProvider.getPreAuthenticationChecks()).isEqualTo(preAuthenticationChecker);
authenticationProvider.setPostAuthenticationChecks(postAuthenticationChecker);
assertThat(authenticationProvider.getPostAuthenticationChecks()).isEqualTo(postAuthenticationChecker);
}
protected UserDetailsChecker getPreAuthenticationChecks() {
return preAuthenticationChecks;
}
protected UserDetailsChecker getPostAuthenticationChecks() {
return postAuthenticationChecks;
}
public void setPostAuthenticationChecks(UserDetailsChecker postAuthenticationChecks) {
this.postAuthenticationChecks = postAuthenticationChecks;
}
protected UserDetailsChecker getPreAuthenticationChecks() {
return this.preAuthenticationChecks;
}
public void setPreAuthenticationChecks(UserDetailsChecker preAuthenticationChecks) {
this.preAuthenticationChecks = preAuthenticationChecks;
}
protected UserDetailsChecker getPostAuthenticationChecks() {
return this.postAuthenticationChecks;
}
public void setPostAuthenticationChecks(UserDetailsChecker postAuthenticationChecks) {
this.postAuthenticationChecks = postAuthenticationChecks;
}
@Autowired(required = false)
public void setUserDetailsChecker(UserDetailsChecker userDetailsChecker) {
this.userDetailsChecker = userDetailsChecker;
}
public TokenAuthenticationProvider(
TokenService tokenService, UserDetailsChecker userDetailsChecker) {
this.tokenService = requireNonNull(tokenService);
this.userDetailsChecker = requireNonNull(userDetailsChecker);
}
public RunAsUserTokenFactory(UserDetailsChecker userDetailsChecker) {
this.userDetailsChecker = requireNonNull(userDetailsChecker);
}
@Bean
public UserDetailsChecker userDetailsChecker() {
return new MolgenisUserDetailsChecker();
}
@BeforeEach
void beforeMethod() {
tokenService = mock(TokenService.class);
tokenAuthenticationProvider =
new TokenAuthenticationProvider(tokenService, mock(UserDetailsChecker.class));
}
@BeforeEach
void setupBeforeMethod() {
userDetailsChecker = mock(UserDetailsChecker.class);
runAsUserTokenFactory = new RunAsUserTokenFactory(userDetailsChecker);
}
/**
* Sets the policy will be used to verify the status of the loaded
* <code>UserDetails</code> <em>before</em> validation of the credentials takes place.
*
* @param preAuthenticationChecks strategy to be invoked prior to authentication.
*/
public void setPreAuthenticationChecks(UserDetailsChecker preAuthenticationChecks) {
this.preAuthenticationChecks = preAuthenticationChecks;
}