私は高ユーザトラフィック用にspring mvcを使用してアプリケーションを開発しました。同時ユーザーが20,000人以上あるとします。私は春のセキュリティカスタム認証プロバイダを2つの方法で実装しました。
第一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);
}
第二1は次のようになります。
@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