简体   繁体   中英

Ip authentication in Spring Security

I have Spring Security 4.2.2 in my web-app and configured LDAP based authentication. In addition i also need to authenticate all users with specified ip without log-in form and set the "local_user" role for them. How can i perform that authentication scenario?

upd: I mean, that "local users" must view the same content as the users that have authorized through login form.

You can do that using antMatchers like below code:

    @EnableWebSecurity
    @Configuration
    public class BasicSecurityConfig extends WebSecurityConfigurerAdapter{

    @Override
    protected void configure(HttpSecurity http) throws Exception {
         http.authorizeRequests().antMatchers("/baseUrl/anything-else/**").hasIpAddress("ipAddressExpression")
    }
}

Updated

http.authorizeRequests()
        .antMatchers("/baseUrl/anything-else/**").access("hasIpAddress('ipAddressExpression') or fullyAuthenticated()");

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