Почему у вас не получается войти? Java весенняя охрана и талеаф. Я попытался и нашел причину, но это не сработало - PullRequest
0 голосов
/ 16 апреля 2020

Я делаю логин с Spring security и thealeaf. Я зарегистрировал учетную запись и пароль и зашифровал пароль. Я попытался войти в систему, но не смог. Пожалуйста, помогите мне

Это файл конфигурации

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

  @Autowired private UserDetailsService userDetailsService;

  @Bean
  public BCryptPasswordEncoder passwordEncoder() {
    BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
    return bCryptPasswordEncoder;
  }

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
        .antMatchers("/")
        .permitAll()
        .antMatchers("/admin")
        .hasRole("ADMIN")
        .and()
        .exceptionHandling()
        .accessDeniedPage("/403")
        .and()
        .formLogin()
        .loginPage("/login")
        .defaultSuccessUrl("/home")
        .failureUrl("/login?error")
        .usernameParameter("username")
        .passwordParameter("password")
        .and()
        .exceptionHandling()
        .accessDeniedPage("/403");
  }

  @Autowired
  public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
  }
}

Это файловый контроллер

@GetMapping("/login")
  public String login() {
    return "login";
  }

Это файл html

<form th:action="@{/login}" method="POST">
        <input type="text" name="username" placeholder="username"/><br/>
        <input type="password" name="password" placeholder="password"/><br/>
        <button type="submit">Login</button>
    </form>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...