Ошибка 404 после авторизации

128
27 февраля 2021, 15:40

Я когда хочу админом войти на страницу в своем проекте он выдает ошибку 404

Security Config

    package adil.java.schoolmaven.config;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
    import org.springframework.security.config.annotation.web.builders.HttpSecurity;
    import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
    import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
    import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
    import org.springframework.security.crypto.password.PasswordEncoder;
    @Configuration
    @EnableWebSecurity
    public class SecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
            auth.inMemoryAuthentication()
                    .withUser("admin").password(passwordEncoder().encode("1234")).roles("ADMIN")
                    .and()
                    .withUser("user").password(passwordEncoder().encode("user1234")).roles("USER")
                    .and();
        }
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests()
                    .antMatchers("/allStudents**").permitAll()
                    .antMatchers("/addStudent/**").hasRole("ADMIN")
                    .antMatchers("/editStudent/**").hasRole("ADMIN")
                    .antMatchers("/deleteStudent/**").hasRole("ADMIN")
                    .and()
                    .formLogin()
                    .loginPage("/login")
                    .defaultSuccessUrl("/allStudents")
                    .failureUrl("/login?error=true")
                    .and()
                    .logout()
                    .logoutSuccessUrl("/login?logout=true")
                    .and()
                    .csrf().disable();
        }
        @Bean
        public PasswordEncoder passwordEncoder() {
            return new BCryptPasswordEncoder();
        }
    }

Login.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<body onload='document.loginForm.username.focus();'>
    <h1>Login Form</h1>
    <c:if test="${not empty errorMessge}"><div style="color:red; font-weight: bold; margin: 30px 0px;">${errorMessge}</div></c:if>
    <form name='login' action="/login" method='POST'>
        <table>
            <tr>
                <td>UserName:</td>
                <td><input type='text' name='username' value=''></td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><input type='password' name='password' /></td>
            </tr>
            <tr>
                <td colspan='2'><input name="submit" type="submit" value="submit" /></td>
            </tr>
        </table>
        <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
    </form>
</body>
</html>

Контроллер авторизации

package adil.java.schoolmaven.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class AuthorizationController {
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index() {
        return "redirect:/allStudents";
    }
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String loginPage(@RequestParam(value = "error", required = false) String error,
            @RequestParam(value = "logout", required = false) String logout,
            Model model) {
        String errorMessge = null;
        if (error != null) {
            errorMessge = "Username or Password is incorrect !!";
        }
        if (logout != null) {
            errorMessge = "You have been successfully logged out !!";
        }
        model.addAttribute("errorMessge", errorMessge);
        return "login";
    }
    @RequestMapping(value = "/logout", method = RequestMethod.GET)
    public String logoutPage(HttpServletRequest request, HttpServletResponse response) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth != null) {
            new SecurityContextLogoutHandler().logout(request, response, auth);
        }
        return "redirect:/login?logout=true";
    }
}  

Я в проекте полностью работаю без web.xml

READ ALSO
Как создать двухмерный штрихкод в виде векторного изображения?

Как создать двухмерный штрихкод в виде векторного изображения?

Я создаю двухмерные штрихкоды с помощью API-интерфейса iText, но они попадают в PDF-документ как растровые изображения, а во время печати на принтерах...

105
Как вытащить определенное значение из map

Как вытащить определенное значение из map

Есть класс Person, он имеет три поля - name, age и surnameЯ создаю HashMap из Person'ов и хочу вытащить все surname записать в отдельный лист

174
Непонятный класс EntrySet

Непонятный класс EntrySet

В java создаю такую конструкциюПо документации метод entrySet возвращает объект типа Set, но под отладчиком что-то непонятное

113
Переход во вторую activity

Переход во вторую activity

Данное приложение сканирует штрих и qr код, как сделать так, чтобы после сканирования, результат сканирования выводился во второй Activity?

112