Spring Security - ссылка (href) в jsp на странице входа не работает - PullRequest
0 голосов
/ 17 июня 2020

Я только начал работать с Spring Security, на моей странице входа есть ссылка (href) на страницу регистрации, но после запуска (стартовая страница входа) ссылка на страницу регистрации не работает (ничего не происходит). Причем после аутентификации переход осуществляется не всегда на главную страницу, а на страницу регистрации. Не могли бы вы помочь, что я не улавливаю.

protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers( HttpMethod.GET, "registration").anonymous()
                .antMatchers("/userPages**").permitAll()
                .antMatchers("/adminPages/**").hasRole("ADMIN")
                .anyRequest().hasAnyRole("ADMIN", "USER")
                .and()
                .formLogin().loginPage("/login").loginProcessingUrl("/loginAction").permitAll()
                .and()
                .logout().logoutSuccessUrl("/login").permitAll()
                .deleteCookies("JSESSIONID")
                .and()
                .csrf().disable();

Контроллеры

@Controller
public class UsersEntryPointControllers {
    SeriesServiceImpl seriesService = new SeriesServiceImpl();
    UserServiceImpl userService = new UserServiceImpl();

    @GetMapping("/") 
   public String getHomePage(Model model, Principal principal) {
        model.addAttribute("message", "Hello " + principal.getName());
        return "userPages/homePageSuccessfully";
    }

    @GetMapping(value = "registration")
    public String getRegistrationPage() {
        return "userPages/registration";
    }

В webConfig

@Override 
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/login").setViewName("userPages/authentication");

//    registry.addViewController("/").setViewName("userPages/homePage");
//    registry.addViewController("/registration").setViewName("/userPages/registration");
}}

и JSP (логин)

<html>
<head>
    <link rel="shortcut icon" href="<spring:url value="../images/favicon.ico.png"/>">
</head>

<body>

<h2 > Вход </h2>

<hr style="border-width: 3px;">
<security:authorize access="isAuthenticated()">
    <% response.sendRedirect("/"); %>
</security:authorize>
<form action='<spring:url value="/loginAction"/>' method="post">

    <p> E-mail:</b> <br>
        <input type="text" size="40" name="username" title="Поле должно быть заполнено" required>
    </p>
    <p >Пароль</b><br>
        <input type="password" size="40" name="password" title="Поле должно быть заполнено" required>
    </p>
    <p >Запомнить</b><br>
        <input type="checkbox" name="remember-me"/>
    </p>
    <p style="text-align: center;">
        <button> OK</button>
    </p>
    <security:authorize access="!isAuthenticated()">
        <p style="text-align: center;"><a href="${pageContext.request.contextPath}/registration">Registration </a></p>
    </security:authorize>
</form>

</body>
</html>

Думаю проблема в конфигурации или в контроллере

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