I’m attempting to create a custom login page, as a first step to automating a header-based login process. When I test my login screen, it comes up blank.
My login looks like this:
public class LoginView extends VerticalLayout {
public LoginView() {
// Create UI components
TextField username = new TextField("Username");
PasswordField password = new PasswordField("Password");
Button loginButton = new Button("Login");
// Layout
add(new H1("Please Login"), username, password, loginButton);
setAlignItems(Alignment.CENTER);
setSizeFull();
// Login logic
loginButton.addClickListener(event -> {
try {
// Attempt authentication
SecurityUtils.authenticate(username.getValue(), password.getValue());
} catch (Exception e) {
Notification.show("Login failed");
}
});
}
}
…and my security setup looks like this:
public class SecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user").password("{noop}password").roles("USER");
}
// If using a custom form, we need to define the UserDetailsService
@Override
protected UserDetailsService userDetailsService() {
return new InMemoryUserDetailsManager(
User.withUsername("user")
.password("{noop}password")
.roles("USER")
.build());
}
}
Any ideas where I might be missing something?