Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.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/1/angular/26.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
Java 尝试某些请求时出现Spring安全性和错误_Java_Angular_Spring_Security - Fatal编程技术网

Java 尝试某些请求时出现Spring安全性和错误

Java 尝试某些请求时出现Spring安全性和错误,java,angular,spring,security,Java,Angular,Spring,Security,我有一个restful应用程序/Jee。 我正在使用spring Boot和安全性 所有请求都在localhost:8080 从angular(localhost:4200/),登录/注销和注册请求工作正常,但当我尝试另一个请求时,如localhost:8080/getUserBooks 它失败,出现401错误 注意: -我试图从Chrome上分离CORS,但没有成功。 -我读了很多相同的问题,但没有一个解决方案对我的情况起作用。 -我已经将注释@CrossOrigin(“*”)添加到我的res

我有一个restful应用程序/Jee。 我正在使用spring Boot和安全性

所有请求都在
localhost:8080

从angular(
localhost:4200/
),登录/注销和注册请求工作正常,但当我尝试另一个请求时,如
localhost:8080/getUserBooks
它失败,出现
401错误

注意: -我试图从Chrome上分离CORS,但没有成功。 -我读了很多相同的问题,但没有一个解决方案对我的情况起作用。 -我已经将注释@CrossOrigin(“*”)添加到我的rest控制器中

这是我的网站安全配置

@Override
protected void configure(HttpSecurity http) throws Exception {
    // http.cors().and().csrf().disable().authorizeRequests()
    http.csrf().disable().httpBasic().and().authorizeRequests().antMatchers(HttpMethod.POST, SIGN_UP_URL)
            .permitAll().anyRequest().authenticated().and()
            .addFilter(new JWTAuthenticationFilter(authenticationManager()))
            .addFilter(new JWTAuthorizationFilter(authenticationManager())).sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}

@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder);
}

@Bean
CorsConfigurationSource corsConfigurationSource() {
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues());
    return source;
}

您必须允许端口号为8080的交叉原点

您必须允许端口号为8080的交叉原点

即使我将注释@CrossOrigin(“*”)添加到我的rest控制器中,它也不起作用即使我添加注释@CrossOrigin(“*”)也不起作用对于我的rest控制器请参阅此链接,我使用的是RestController而不是servlet。谢谢你是的,我也会这样做,请参考该链接的问题,你只需要在你的项目中添加该类。谢谢你的帮助,我添加了该类,但它不起作用:/refered此链接我使用的不是servlet。谢谢是的,我也会为之工作,请参考该链接的问题,您只需要在项目中添加该类。谢谢您的帮助,我添加了该类,但它不起作用:/