2014-08-27 78 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來處理客戶端。該解決方案運行良好,幾乎逐字地顯示在上面的鏈接上(儘管我稍微重寫了一下自己的喜好)。