我有一个简单的方法来验证我的Web应用程序上的用户
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String name = authentication.getName();
String password = authentication.getCredentials().toString();
if (name.contains("@mydomain.com")) {
List<GrantedAuthority> grantedAuths = new ArrayList<>();
grantedAuths.add(new SimpleGrantedAuthority("ROLE_USER"));
Authentication auth = new UsernamePasswordAuthenticationToken(name, password, grantedAuths);
return auth;
} else {
throw new BadCredentialsException("Invalid username/password");
}
}
我想知道有没有办法测试它(最好是在JUnit中)而不使用像MockMvc这样的编译工具(https://spring.io/blog/2014/05/23/preview-spring-security-test-web-security)