Hilla Spring Security Auth LDAP

Viewed 22

Could you help me with setup Hilla + Spring Security (LDAP)? I have created demo project from https://hilla.dev/docs/getting-started

npx @vaadin/cli init --hilla --auth hilla-with-auth

This project has simple auth, but i would like LDAP auth. Like in my another application without Hilla:

@Configuration
@EnableAutoConfiguration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
class WebSecurityConfig extends VaadinWebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception  {
    http
            .authorizeRequests()
            .antMatchers("/logout/**", "/logout-success", "/login/**", "/static/**", "/**.png").permitAll()
            .anyRequest()
            .authenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .defaultSuccessUrl("/grocery", true)
            .failureUrl("/login?error=true")
            .permitAll()
            .and()
            .logout()
            .logoutUrl("/logout")
            .logoutSuccessUrl("/login?logout=true")
            .invalidateHttpSession(true)
            .deleteCookies("JSESSIONID")
            .permitAll()
            .and()
            .exceptionHandling().accessDeniedPage("/403")
            .and()
            .httpBasic();
    http.addFilterAfter(new CsrfLoggerFilter(), CsrfFilter.class);
}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder authBuilder) throws Exception {
    authBuilder
            .ldapAuthentication()
            .userSearchFilter(new ParseConfigFile().getConf("AuthenticationManagerBuilder.userSearchFilter"))
            .userSearchBase(new ParseConfigFile().getConf("AuthenticationManagerBuilder.userSearchBase"))
            .groupSearchBase(new ParseConfigFile().getConf("AuthenticationManagerBuilder.groupSearchBase"))
            .groupSearchFilter(new ParseConfigFile().getConf("AuthenticationManagerBuilder.groupSearchFilter"))
            .contextSource()
            .url(new ParseConfigFile().getConf("AuthenticationManagerBuilder.url"))
            .managerDn(new ParseConfigFile().getConf("AuthenticationManagerBuilder.managerDn"))
            .managerPassword(new ParseConfigFile().getConf("AuthenticationManagerBuilder.managerPassword"));
}
}

What I must change in config file for get LDAP auth?

1 Answers

LDAP uses a different protocol for communication. So you must have an LDAP server running first and foremost, and then use Spring Security to authenticate using what Spring Security offers.

The spring boot doc have an config file similar to what you may be looking for :Ldap Auth example

Related