使用SpringSecurity在AngularJS中登录弹出窗口

时间:2015-09-13 14:55:50

标签: javascript java angularjs spring spring-security

我已使用Rest API在我的AngularJS页面上实现了spring security。但是,问题是每当我尝试从我的自定义登录页面使用rest api登录时,它会在弹出窗口中询问我的登录名和密码:

enter image description here

Spring安全配置文件:

@Override
  protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable().exceptionHandling().and()
                .anonymous().and()
                .servletApi().and()
                .headers().cacheControl().and()
                .authorizeRequests()

                //allow anonymous resource requests
                .antMatchers("/").permitAll()
                .antMatchers("/favicon.ico").permitAll()

                //allow anonymous POSTs to login
                .antMatchers(HttpMethod.POST,     "/webresources/login").permitAll()

                    .anyRequest().hasRole("USER").and()             

                    .addFilterBefore(new StatelessLoginFilter("/login", new TokenAuthenticationService("123abc"), new CustomJDBCDaoImpl() , authenticationManager()), UsernamePasswordAuthenticationFilter.class)
                    .addFilterBefore(new StatelessAuthenticationFilter(new TokenAuthenticationService("123abc")), UsernamePasswordAuthenticationFilter.class).httpBasic();
    }

登录按钮单击控制器将:

app.controller('SigninFormController', ['$scope', '$http', '$state', function($scope, $http, $state) {
    $scope.user = {};
    $scope.authError = null;
    $scope.login = function() {
      $scope.authError = null;
      // Try to login
      $http.post('../api/verifyUser'+$scope.user.email+'&'+$scope.user.password, {},{
      headers : { "Authorization" : "BasicCustom" }
    })
      .then(function(response) {
          console.log(response);
        if ( !response.data.user ) {
          $scope.authError = 'Email or Password not right';
        }else{
          $state.go('home.go');
        }
      }, function(x) {
        $scope.authError = 'Server Error';
      });
    };
  }])

我知道为什么我得到这个弹出窗口而不是主页?

0 个答案:

没有答案