Как перенаправить домашнюю страницу, которая не соответствует неправильному тексту на URL в приложении - PullRequest
0 голосов
/ 17 октября 2018

Я новичок в Java, я разработал приложение с весенней загрузкой и весенней безопасностью.Приложение работает нормально, но у меня проблемы с уязвимостями.

т. Е. После того, как страница входа переходит http://localhost:8080/login на http://localhost:8080/home страницу, но когда я пытаюсь ввести неправильный текст в URL, например http://localhost:8080/home на http://localhost:8080/sdghgdj, он выбрасывает Whitelabel Error Page, но я хочу перенаправить на *Страница 1008 *, потому что сеанс активирован.

Что не так в моем коде

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .antMatchers("/resources/**", "/webjars/**","/assets/**").permitAll()
            .antMatchers("/", "/forgotPwd","/resetPwd","/register").permitAll()
            .antMatchers(HttpMethod.POST,"/register","/register/**").permitAll()               
            .anyRequest().authenticated()              
            .and()
        .formLogin()
            .loginPage("/login")
            .defaultSuccessUrl("/home")
            .failureUrl("/login?error")
            .permitAll()
            .and()
        .logout()
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
            .permitAll()
            .and()
        .exceptionHandling().accessDeniedPage("/403");   
}

1 Ответ

0 голосов
/ 17 октября 2018

0,1.Spring Boot - перенаправление, например, путь /foo перенаправление на /home:

@SpringBootApplication(exclude = {ErrorMvcAutoConfiguration.class})
public class DemoApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addRedirectViewController("/notFound", "/home");
    }


    @Bean
    public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> containerCustomizer() {
        return container -> container.addErrorPages(new ErrorPage("/notFound"));
    }

    @RestController
    public static class MyController {

        @GetMapping("/home")
        public String home() {
            return "Hello World";
        }

    }

}

enter image description here

.2.Spring Boot - без перенаправления, например путь /foo будет таким же, но будет называться @GetMapping("/home"):

@SpringBootApplication(exclude = {ErrorMvcAutoConfiguration.class})
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Bean
    public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> containerCustomizer() {
        return container -> container.addErrorPages(new ErrorPage("/home"));
    }

    @RestController
    public static class MyController {

        @GetMapping("/home")
        public String home() {
            return "Hello World";
        }

    }

}

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...