Я пытаюсь сделать первые шаги с помощью Spring Boot Security.
Я пытаюсь объединить пользовательский Аутентификатор с пользовательской страницей входа, и я не уверен, как их объединить. Оба они работают хорошо.
Мой пользовательский аутентификатор (Auth)
@Component
public class Auth implements AuthenticationProvider
{
@Override
public Authentication authenticate (Authentication authentication) throws AuthenticationException
{
String name = authentication.getName ();
String password = authentication.getCredentials().toString ();
System.out.println ("auth: " + name + " / " + password);
// no checks for now - any input is ok
return new UsernamePasswordAuthenticationToken (name, password, new ArrayList <GrantedAuthority> ());
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
}
Мой конфигурационный файл безопасности (WebSecurity)
@Configuration
@EnableWebSecurity
public class WebSecurity extends WebSecurityConfigurerAdapter
{
@Override
protected void configure (HttpSecurity http) throws Exception
{
http.authorizeRequests ()
.anyRequest ().authenticated ()
.and ()
.formLogin ()
// .loginPage("/login").usernameParameter("username").passwordParameter("password")
.permitAll ();
}
@Autowired
private Auth authProvider;
@Override
protected void configure (AuthenticationManagerBuilder auth) throws Exception
{
// register my custom authenticator here
auth.authenticationProvider(authProvider);
}
}
Мой обработчик для / логин (логин)
@RequestMapping ("/login")
public String login (HttpServletRequest request, Model model)
{
System.out.println("login")
return "login";
}
Если я не использую пользовательскую страницу входа (.loginPage et c. В комментариях) мой кастом Аутентификатор используется, и встроенная страница входа в систему появляется.
Если я использую пользовательскую страницу входа в систему, тогда используется мой пользовательский логин. jsp, но я не вижу использования моего собственного аутентификатора. Но вызывается обработчик для / login.
Так должна ли комбинация пользовательского аутентификатора и страницы входа custon работать из коробки ИЛИ мне нужно склеивать их (возможно, в обработчике входа в систему) ??
РЕДАКТИРОВАТЬ
логин. jsp
<html>
<body>
MyLogin
<form action="/security_check" method="post">
username<input type="text" id="username" name="username"/>
<br/>
password<input type="password" id="password" name="password"/>
<br/>
<input type="submit" value="login"/>
</form>
</body>
</html>
Моя новая конфигурация безопасности:
http.authorizeRequests ()
.antMatchers ("/sec*").permitAll ()
.anyRequest ().authenticated ()
.and ()
.formLogin ().loginPage("/login").loginProcessingUrl("/security_check")
.permitAll ();