2016-08-12 159 views
3

我與教程,介紹如何編寫使用Spring啓動,春季安全和AngularJS春季啓動與退出Angularjs錯誤

https://github.com/spring-guides/tut-spring-security-and-angular-js/tree/master/oauth2-vanilla

,該項目

模塊化項目單頁的應用程序工作

https://github.com/sharmaritesh/spring-angularjs-oauth2-sample

我無法註銷當前登錄的用戶。 如果您單擊「註銷」鏈接,您將看到主頁更改(不再顯示問候語),因此用戶不再使用UI服務器進行身份驗證。雖然點擊「登錄」,但實際上並不需要通過授權服務器中的認證和批准週期(因爲您尚未註銷)。

我是Spring的新手,希望有些用戶可以註銷,然後再回到登錄頁面。 請有人可以幫助我或提出一些建議來解決這個問題?

回答

0

這是我們的項目code.its正常工作。試試這一次。

安全配置:

@Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http.httpBasic().and().authorizeRequests().antMatchers("/public/**") 
       .permitAll().antMatchers("/admin/**").hasAuthority("admin") 
       .antMatchers("/user/**").hasAuthority("user") 
       .and() 
       .logout() 
       // Logout requires form submit. Bypassing the same. 
       .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) 
       .logoutSuccessUrl("/index.html").and() 
       .addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class) 
       .csrf().disable();/* 
           * requireCsrfProtectionMatcher(new 
           * CsrfRequestMatcher()) 
           * .csrfTokenRepository(csrfTokenRepository()); 
           */ 

    } 

angularjs:

$scope.logout = function() { 
       $http.get('/logout').then(function() { 

        $location.url('/'); 
       }) 
      } 

路由:

app.config([ '$routeProvider', function($routeProvider) { 

    $routeProvider.when('/admin', { 
     templateUrl : 'admin.html', 

    }).when('/dashboard', { 
     templateUrl : 'dashboard.html' 
    }).when('/preferences', { 
     templateUrl : 'preferences.html', 
    }).otherwise('/', { 
     templateUrl : 'index.html', 
    }) 
} ]); 
+0

喂納雷什vadlakonda, 感謝您的回答,我嘗試使用,但心不是解決我的問題。 請你嘗試在github代碼鏈接中使用,我把我的問題描述? 謝謝 – user2657234