jhipsterを使用してWebアプリケーションを書き込んでいます。そしてそれは春を使用しています。私は、同じユーザーが自分のアプリケーションにログインできる回数を制限しようとしていた、それはこれでServerConfiguration.java
という名前のファイルに動作するようになった:アプリケーションでの最大セッション数ではなく、アプリケーションでの最大セッション数ではありません。
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.and()
.formLogin()
.loginProcessingUrl("/api/authentication")
.successHandler(ajaxAuthenticationSuccessHandler)
.failureHandler(ajaxAuthenticationFailureHandler)
.usernameParameter("j_username")
.passwordParameter("j_password")
.permitAll()
.
.
.
.
.and()
.sessionManagement()
.maximumSessions(Integer.parseInt(env.getProperty("spring.maxuser.sessions")))
.maxSessionsPreventsLogin(true);
}
@Bean
public HttpSessionEventPublisher httpSessionEventPublisher() {
return new HttpSessionEventPublisher();
}
これは、特定のユーザーだけに何度もログインします私のアプリケーション。
今、私の質問は、x
番のdifferent
ユーザーのためだけに自分のアプリケーションを開いてアクセスできるようにする方法です。たとえば、私のアプリケーションに200人のユーザーしかアクセスしないようにしたいとします。ユーザ201が来てログインしようとすると、それはできません。
私はこの他の投稿spring limit max sessions ; limit max usersの投稿を見ましたが、私はこのコードを正確にどこに置くべきかわかりません。
public class MySessionAuthenticationStrategy extends ConcurrentSessionControlStrategy {
int MAX_USERS = 1000; // Whatever
SessionRegistry sr;
public MySessionAuthenticationStrategy(SessionRegistry sr) {
super(sr);
this.sr = sr;
}
@Override
public void onAuthentication(Authentication authentication, HttpServletRequest request, HttpServletResponse response) {
if (sr.getAllPrincipals().size() > MAX_USERS) {
throw new SessionAuthenticationException("Maximum number of users exceeded");
}
super.onAuthentication(authentication, request, response);
}
}
私はこの新しいクラスMySessionAuthenticationStrategy
作成する必要がありますし、どのように私は、この新しいクラスに私のhttpConfigureクラスから行くのですかMySessionAuthenticationStrategy
はどうもありがとうございました。
ご回答いただきありがとうございます。 1-この空のクラスを作成するだけです 2次に、私の新しく作成したクラスの新しいインスタンスを 'SecurityConfiguration.java'カルルスに追加します。私はAutowiredがどのように正確に動作するのか分かりません。この新しい属性を追加してください: 'sessionsRegistry(myNewlyCreatedClassInstance)' 3ログイン/認証の正確な場所はわかりません.... :(これは私がこの春のものを見るのは初めてです。 ? もう一度ありがとうございます – Torre