Я использую nwb с моим приложением реакции.Я пытаюсь совместить свое приложение реакции и весенней загрузки с защитой весны.Каждый работает нормально отдельно.Я думаю, что у меня есть правильная конфигурация, но когда я создаю приложение, я не могу просмотреть страницы реакции.Я получаю ответ 401.
Я думаю, это как-то связано с моей конфигурацией безопасности приложения весенней загрузки.
@EnableWebSecurity
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@ComponentScan("com.principleauto.rfid.config")
public class ActuatorSecurity extends WebSecurityConfigurerAdapter {
@Autowired
private CustomAccessDeniedHandler accessDeniedHandler;
@Autowired
private RestAuthenticationEntryPoint restAuthenticationEntryPoint;
@Autowired
private RfidRestSavedRequestAwareAuthenticationSuccessHandler
mySuccessHandler;
private SimpleUrlAuthenticationFailureHandler myFailureHandler =
new SimpleUrlAuthenticationFailureHandler();
public ActuatorSecurity() {
super();
SecurityContextHolder.setStrategyName
(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
//.csrf().disable()
.cors()
.and()
.csrf().disable()
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.antMatchers("/anonymous*").anonymous()
.antMatchers(HttpMethod.GET, "/index*", "/dist/**", "/*.js",
"/*.json", "/*.ico").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/index.html")
.loginProcessingUrl("/perform_login")
.defaultSuccessUrl("/homepage.html",true)
.failureUrl("/index.html?error=true")
.and()
.logout()
.logoutUrl("/perform_logout")
.deleteCookies("JSESSIONID")
.and()
.exceptionHandling()
.accessDeniedHandler(accessDeniedHandler)
.authenticationEntryPoint(restAuthenticationEntryPoint)
.and()
.authorizeRequests()
.antMatchers("/api/csrfAttacker*").permitAll()
.antMatchers("/api/**").authenticated()
.and()
.authorizeRequests()
.requestMatchers(EndpointRequest.to(ShutdownEndpoint.class))
.hasRole("ENDPOINT_ADMIN")
.requestMatchers(EndpointRequest.to(InfoEndpoint.class))
.permitAll()
.requestMatchers(EndpointRequest.toAnyEndpoint())
.hasRole("ENDPOINT_ADMIN")
.and()
.formLogin()
.successHandler(mySuccessHandler)
.failureHandler(myFailureHandler)
.and()
.logout()
.and().httpBasic();
}
@Bean
CorsConfigurationSource corsConfigurationSource(){
CorsConfiguration config=new CorsConfiguration();
config.addAllowedOrigin("http://localhost:3000/");
//config.setAllowedOrigins(Arrays.asList("*"));
config.setAllowCredentials(true);
config.setAllowedHeaders(Arrays.asList("Access-Control-Allow-
Headers","Access-Control-Allow-Origin","Access-Control-Request-
Method", "Access-Control-Request-Headers","Origin","Cache-Control",
"Content-Type", "Authorization"));
config.setAllowedMethods(Arrays.asList("DELETE", "GET", "POST",
"PATCH", "PUT"));
UrlBasedCorsConfigurationSource source = new
UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return source;
}
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth)
throws Exception {
BCryptPasswordEncoder encoder = passwordEncoder();
auth.inMemoryAuthentication()
.withUser("admin").password(encoder.encode("admin")).roles("ADMIN")
.and()
.withUser("user").password(encoder.encode("password")).roles("USER")
.and()
.withUser("user").password("password").roles("ENDPOINT_ADMIN");
}
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
@Configuration // mark as configuration class
@ComponentScan(basePackages={"com.principleauto.rfid",
"com.principleauto.rfid.controller"})
@Profile("prod")
public class WebConfig implements WebMvcConfigurer {
private final ApplicationContext applicationContext;
private final EntityManager entityManager;
@Autowired
public WebConfig(ApplicationContext applicationContext, EntityManager
entityManager) {
super();
this.applicationContext = applicationContext;
this.entityManager = entityManager;
}
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver>
argumentResolvers) {
// argumentResolvers.add(argumentResolvers);
ObjectMapper objectMapper =
Jackson2ObjectMapperBuilder.json().applicationContext
(this.applicationContext).build();
argumentResolvers.add(new DTOModelMapper(objectMapper, entityManager));
}
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new
InternalResourceViewResolver();
// views are in the folder "/WEB-INF/views/"
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setViewClass(JstlView.class);
// all view files are HTML documents
viewResolver.setSuffix(".jsp");
viewResolver.setExposeContextBeansAsAttributes(true);
return viewResolver;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry){
registry.addResourceHandler("/static/**").addResourceLocations
("/ src / main / js / dist /");
registry.addResourceHandler("/*.js").addResourceLocations
("/src/main/js/dist/");
registry.addResourceHandler("/*.json").addResourceLocations
("/src/main/js/dist/");
registry.addResourceHandler("/*.ico").addResourceLocations
("/src/main/js/dist/");
registry.addResourceHandler("/index").addResourceLocations
("/templates/index.html");
registry.addResourceHandler("/*.js").addResourceLocations
("/src/main/js/src/");
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
//super.addViewControllers(registry);
registry.addViewController("/login.html");
registry.addViewController("/index").setViewName("/index");
registry.addViewController("/").setViewName("/home");
registry.addViewController("/anonymous.html");
registry.addViewController("/homepage.html");
registry.addViewController("/allbmwreaders").setViewName
("/allbmwreaders");;
registry.addViewController("/admin/adminpage.html");
registry.addViewController("/accessDenied");
registry.addViewController("/csrfAttacker.html");
}
@Override
// configure static file handling
public void configureDefaultServletHandling
(DefaultServletHandlerConfigurer configurer) {
// DispatcherServlet: forward requests for static resources to the
default servlet
// requests for static resources are forwarded to the default servlet
configurer.enable();
}
}
Я хотел бы иметь возможность просматривать приложение реакциии весеннее загрузочное приложение вместе.