在Spring安全应用程序中测试身份验证的最简单方法

时间:2016-07-15 12:08:09

标签: java spring junit spring-security

我有一个简单的方法来验证我的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

0 个答案:

没有答案