我已經開發了一個應用程序與春季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