我已经开发了一个应用程序与春季mvc高用户流量。假设至少有20,000个并发用户。我已经通过两种方式实现了Spring安全定制认证提供程序。
1个是:春季安全:自定义身份验证提供程序
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
String username = authentication.getName();
String password = authentication.getCredentials().toString();
CustomUser user = _userDetailService.loadUserByUsername(username);
if (user == null || !user.getUsername().equalsIgnoreCase(username)) {
throw new BadCredentialsException("Username not found.");
}
if (!BCrypt.checkpw(password, user.getPassword())) {
throw new BadCredentialsException("Wrong password.");
}
Collection < ? extends GrantedAuthority > authorities = user.getAuthorities();
return new UsernamePasswordAuthenticationToken(user, password, authorities);
}
第二个是:
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
try {
Authentication auth = super.authenticate(authentication);
//if reach here, means login success, else an exception will be thrown
//reset the user_attempts
return auth;
} catch (BadCredentialsException e) {
//invalid login, update to user_attempts
throw e;
}
}
现在的问题是whice实施会给我更快的输出?
Spring已经在第1版中执行了相同的操作(在DaoAuthenticationProvider中)。所以不需要customAuthentication提供程序。 – Afridi
我必须在登录时检查更多条件。但是DaoAuthenticationProvider有一些特定的条件。那就是为什么我需要实现自定义身份验证提供程序@Afridi –
最快的?用20000次迭代计时测试,你会看到。 – holmis83