0

これは、Spring Security 4.0 RELEASE と Spring Security CAS を使用しています。

Java Config を使用してセッション同時実行管理をセットアップしています。

http
  .sessionManagement()
  .maximumSessions(1)
  .maxSessionsPreventsLogin(false)
  .expiredUrl("/tooManySessions")
  .and()
  .and();

HttpSessionEventublisherで有効になっており、WebApplicationInitializer機能している他のものにも使用しているため、機能していることを確認できます。

@Override
protected void registerDispatcherServlet(ServletContext servletContext) {
    super.registerDispatcherServlet(servletContext);


    // to handle session creation and destruction events
    servletContext.addListener(new HttpSessionEventPublisher());
}

ただし、実行時には、コードが呼び出されないように見えます。

Spring Security CA を使用していることに注意してください。これは、セッションの同時実行管理に影響を与える可能性がありますか?

4

1 に答える 1

1

SessionAuthenticationStrategyJava Config を使用しているときにセッション管理を CAS と連携させるには (XML 構成については知りません)、明示的に on を設定する必要がありますCASAuthorizationFilter

私は ObjectPostProcessor を使用してこれを解決しましたCsfrFilter(セッション管理セットアップでそれを行うと、Csrf 固有の情報が取得されませんSessionAuthenticationStrategy):

final CasAuthenticationFilter casAuthenticationFilter = casAuthenticationFilter();

http
        .csrf()
            .withObjectPostProcessor(new ObjectPostProcessor<CsrfFilter>() {
                @Override
                public <O extends CsrfFilter> O postProcess(O csrfFilter) {

                    try {
                        final SessionAuthenticationStrategy sessionAuthenticationStrategy = httpFinal.getSharedObject(SessionAuthenticationStrategy.class);
                        if (sessionAuthenticationStrategy == null || !(sessionAuthenticationStrategy instanceof CompositeSessionAuthenticationStrategy)) {
                            throw new IllegalStateException("Cannot get CompositeSessionAuthenticationStrategy");
                        }
                        casAuthenticationFilter.setSessionAuthenticationStrategy(sessionAuthenticationStrategy);
                    } catch (Exception e) {
                        throw new IllegalStateException("Cannot get ahold of CasAuthenticationFilter in CsrfFilter post-processor");
                    }

                    return csrfFilter;

                }
            });
}
于 2015-04-14T15:30:19.313 に答える