【问题标题】:Spring Boot with Angularjs Logout Error带有Angularjs注销错误的Spring Boot
【发布时间】:2016-12-19 00:20:36
【问题描述】:

我正在编写描述如何使用 Spring Boot、Spring Security 和 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 新手,希望某些用户可以注销并再次返回登录页面。 请有人可以帮助我或提出一些建议来解决这个问题?

【问题讨论】:

    标签: angularjs spring spring-security spring-boot logout


    【解决方案1】:

    这是我们的项目代码。它对我们来说工作正常。试试这个。

    安全配置:

    @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',
        })
    } ]);
    

    【讨论】:

    • 你好 naresh vadlakonda,谢谢你的回答,我尝试使用它,但不能解决我的问题。请问您是否尝试在我放在问题描述中的 github 代码链接中使用?谢谢
    • 您好 Naresh,如果我需要在启用 CSRF 的情况下进行注销,我该怎么做?我收到 406 - 使用 post 方法时不支持 POST
    猜你喜欢
    • 2017-03-07
    • 2016-05-29
    • 2016-04-01
    • 2017-08-21
    • 2018-11-16
    • 2018-02-19
    • 1970-01-01
    • 2017-03-26
    相关资源
    最近更新 更多