В моем приложении spring-boot
+ reactjs
я использовал Spring Security для проверки подлинности и управления ролями.
Приложение работает нормально, но для загрузки значений раскрывающихся списков требуется успешная проверка подлинности, эти раскрывающиеся списки являются динамическими и загружаются из таблицы БД. На самом деле я не добавил никаких ограничений безопасности для базы данных запросов.
Кто-нибудь может помочь мне определить проблему?
Это мой URL-адрес git
Пожалуйста, посмотрите на '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);