Andrey K
Andrey K

Reputation: 51

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.

Upvotes: 0

Views: 582

Answers (1)

Afridi
Afridi

Reputation: 6932

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()");

Upvotes: 1

Related Questions