Skip to content
Mario Arias edited this page Feb 22, 2016 · 4 revisions

This module offers a more friendly DSL for HttpSecurity configuration

Instead of this:

@Override
protected void configure(HttpSecurity http) throws Exception {

	http
		.formLogin()
			.loginPage("/login")
			.permitAll()
			.and()
		.exceptionHandling()
			.accessDeniedPage("/denied")
			.and()
		.authorizeRequests()
			.antMatchers("/accounts/resources/**").permitAll()
			.antMatchers("/accounts/edit*").hasRole("EDITOR")
			.antMatchers("/accounts/account*").hasAnyRole("VIEWER", "EDITOR")
			.antMatchers("/accounts/**").authenticated()
			.and()
		.logout()
			.permitAll()
			.logoutSuccessUrl("/index.html");
}

You could write it in a more natural way

override fun configure(http: HttpSecurity) {

    http.formLogin {
        loginPage("/login")
        .permitAll()
    }.exceptionHandling {
        accessDeniedPage("/denied")
    }.authorizeRequests {
        antMatchers("/accounts/resources/**").permitAll()
        .antMatchers("/accounts/edit*").hasRole("EDITOR")
        .antMatchers("/accounts/account*").hasAnyRole("VIEWER", "EDITOR")
        .antMatchers("/accounts/**").authenticated()
    }.logout {
        permitAll()
        .logoutSuccessUrl("/index.html")
    }
}

Maven

To use this module in your project

<dependency>
    <groupId>org.kotlinprimavera</groupId>
    <artifactId>security</artifactId>
    <version>0.5</version>
</dependency>
Clone this wiki locally