简体   繁体   中英

Programmatically set login-url in Spring Security

Is there a programmatic equivalent to this XML configuration:

<logout logout-url="/logout"/>

While I can set the login page url like this:

@Configuration
public static class ApplicationSecurity extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
            http
                 ...
                 .formLogin()
                 .loginPage("/login");
}

I can't find an equivalent for logout-url.

You need and() .

@Configuration
public static class ApplicationSecurity extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
            http
                 ...
                 .formLogin()
                 .loginPage("/login")
                 .and()
                   .logout().logoutUrl("/logout");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM