2014-08-27 79 views
0

我的单页Web应用程序使用锚表示在浏览器的地址栏中状态,如:与锚春季JavaConfig形式登录

http://localhost:8080/webapp/index.html#/item/123 

这使得该州作为书签。但是,未认证将被重定向到Spring Security的登录表单的用户,然后验证,然后重定向到原来的页面,如下所示:

http://localhost:8080/webapp/index.html 

这不是我想要的,因为它只是失去了#anchor,和从而书签。

我一直未能找到解决方案,也不认为我完全掌握了Spring Security的内部工作原理,这些工作导致了这种不需要的行为。

我认为以下是我的安全配置的要点是:

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http.csrf().disable() 
    .authorizeRequests() 
     .antMatchers(UNSECURED_RESOURCES).anonymous() 
     .anyRequest().hasRole(KnownRole.USER.name()) 

    .and().formLogin() 
     .loginPage("/backend/authentication/login.htm") 
     .defaultSuccessUrl("/frontend/app/index.html") 
     .permitAll() 

    .and().logout() 
     .logoutUrl("/logout") 
     .logoutSuccessHandler(logoutSuccessHandler()).permitAll() 

    .and().httpBasic() 

    .and().addFilter(concurrentSessionFilter()) 
     .addFilter(usernamePasswordAuthenticationFilter()) 
     .sessionManagement().sessionAuthenticationStrategy(sessionAuthenticationStrategy()); 

春天4.0.4.RELEASE,春季安全3.2.3-RELEASE。

您的帮助非常感谢。

回答

0

我选择使用following example code来实现这一点。我花了一段时间才明白,锚点显然是客户端问题。在我问这个问题之前,我已经看到了这个解决方案,但当时我不想买这个,需要用一些Javascript来处理客户端。该解决方案运行良好,几乎逐字地显示在上面的链接上(尽管我稍微重写了一下自己的喜好)。