Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用SpringSecurity在AngularJS中弹出登录窗口_Javascript_Java_Angularjs_Spring_Spring Security - Fatal编程技术网

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

Javascript 使用SpringSecurity在AngularJS中弹出登录窗口,javascript,java,angularjs,spring,spring-security,Javascript,Java,Angularjs,Spring,Spring Security,我已经使用RESTAPI在AngularJS页面上实现了spring安全性。但是,问题是每当我尝试从自定义登录页面使用rest api登录时,它都会在弹出窗口中询问登录名和密码,如下所示: Spring安全配置文件: @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable().exceptionHandling().and()

我已经使用RESTAPI在AngularJS页面上实现了spring安全性。但是,问题是每当我尝试从自定义登录页面使用rest api登录时,它都会在弹出窗口中询问登录名和密码,如下所示:

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

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

这是因为您的基本授权失败,请查看web控制台您可能会看到
选项的问题
请求

我还没有检查它,但如果有问题,我该如何解决?只需确保您传递了正确的授权头,并且我遗漏了一件事,只需检查您的服务器上是否启用了CORS。这可能是因为启用了CORS颁发者,并且我正在使用nginx共享请求和响应。您是否检查了是否启用了允许选项请求的访问控制允许方法和允许授权标头的访问控制允许标头?不,我没有,但我怎么可以这样做?您的头是错误的,{“Authorization”:“BasicCustom”},应该是{Authorization:Basic BASE64\u USER:PASS}。。。您正在将其发送给verifyUser,并且登录在您的spring应用程序中是不同的url。但我没有使用spring应用程序登录页面。我想使用AngularJS登录而不是spring安全登录。我怎样才能解决这个问题呢?我想你在这里混合了身份验证的基本概念。然而,很难在一篇评论中澄清这一点。我知道它很长,但试着读一读:这一节的内容更少:“它是如何工作的?”或“创建角度应用程序”如果我错了,请纠正我,但您想使用BasicAuth,对吗?不,我想使用数据库进行自定义身份验证