【发布时间】:2019-01-05 05:23:56
【问题描述】:
在我的 spring-boot + reactjs 应用程序中,我使用 spring security 进行身份验证和角色管理。
应用程序运行良好,但需要成功的身份验证才能加载下拉列表的值,这些下拉列表是动态的,它们是从数据库表中加载的。实际上,我并没有为查询数据库添加任何安全限制。
谁能帮我找出问题所在?
这是我的git url
请以'src/main/java/com/example/polls/controller/FamilyController.java'为例
我尝试将以下代码放入 SecurityConfig.java 但它不起作用
http.authorizeRequests()
.antMatchers("/brands").permitAll()
.antMatchers("/familys").permitAll()
.antMatchers("/models").permitAll();
在控制台显示
ERROR 9640 --- [io-8080-exec-10] c.e.p.s.JwtAuthenticationEntryPoint : Responding with unauthorized error. Message - Full authentication is required to access this resource
ERROR 9640 --- [nio-8080-exec-1] c.e.p.s.JwtAuthenticationEntryPoint : Responding with unauthorized error. Message - Full authentication is required to access this resource
修改代码:
http
.cors()
.and()
.csrf()
.disable()
.exceptionHandling()
.authenticationEntryPoint(unauthorizedHandler)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers(
"/",
"/favicon.ico",
"/**/*.png",
"/**/*.gif",
"/**/*.svg",
"/**/*.jpg",
"/**/*.html",
"/**/*.css",
"/**/*.js"
) .permitAll()
.antMatchers("/api/auth/**")
.permitAll()
.antMatchers("/api/user/checkUsernameAvailability", "/api/user/checkEmailAvailability")
.permitAll()
.antMatchers(HttpMethod.GET, "/api/polls/**", "/api/users/**")
.permitAll()
.antMatchers("/api/brands").permitAll()
.antMatchers("/api/familys").permitAll()
.antMatchers("/api/models").permitAll()
.anyRequest()
.authenticated();
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
【问题讨论】:
标签: java spring reactjs spring-boot spring-security