У меня есть внутреннее загрузочное приложение Spring с включенной защитой Spring с проверкой подлинности FormLogin.Ниже приведена моя Конфигурация безопасности.
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(final HttpSecurity http) throws Exception {
http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint());
http.authorizeRequests().antMatchers("/index.html").permitAll().antMatchers("/j_security_check").permitAll().antMatchers("/api/**").authenticated();
http.csrf().disable();
http.formLogin().usernameParameter("j_username")
.passwordParameter("j_password").loginPage("/index.html").loginProcessingUrl("/j_security_check")
.defaultSuccessUrl("/index.html", true).permitAll().failureUrl("/index.html?error=true");
http.logout().logoutUrl("/dashboard/logout").invalidateHttpSession(true).clearAuthentication(true)
.logoutSuccessUrl("/index.html").deleteCookies("JSESSIONID");
}
}
И мой класс View Contoller, как показано ниже:
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/")
.setViewName("forward:/index.html");
registry.addViewController("/home")
.setViewName("forward:/index.html");
}
@Override
public void addResourceHandlers(
ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**")
.addResourceLocations("/WEB-INF/view/react/build/static/");
registry.addResourceHandler("/*.*")
.addResourceLocations("/WEB-INF/view/react/build/");
registry.addResourceHandler("/index.html")
.addResourceLocations("/WEB-INF/view/react/build/index.html");
}
}
index.html создается приложением npm run build в приложении реагирования.И сгенерированная сборочная папка перемещается в статические ресурсы загрузочного проекта Spring.У меня есть маршруты, настроенные в приложении реагировать, как / логин / дом.После успешного входа в систему / компонент входа в систему пользователь будет перенаправлен на домашнюю страницу, используя:
this.props.history.push("/home");
После запуска Spring Spring я могу получить доступ к странице входа в index.html и один разЯ нажимаю на кнопку «Войти», меня перенаправляют в / home и на секунду я вижу «Домашний компонент», а затем снова перенаправляем на localhost: 8080 / ?.Я не уверен, как его перенаправить localhost: 8080 / ?.