skyman
skyman

Reputation: 2335

Spring 4 Restful Security

I have just been experimenting with Spring 4 security. I am using the following method to map the secured endpoints:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .csrf().disable()
        .authorizeRequests()
            .antMatchers(HttpMethod.GET, "/hello/*").hasRole("ADMIN")
            .antMatchers(HttpMethod.GET, "/hello/**").hasRole("ADMIN")
        .and()
        .httpBasic()
        .and()
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}

It occurred to me that if I had a lot of endpoints that the .antMatchers structure could become cumbersome.

Just curious to know if there is an alternative approach that may be more "manageable" - I guess this is a bit subjective?

Upvotes: 0

Views: 34

Answers (1)

Naresh
Naresh

Reputation: 3179

I can suggest to have a method to just add the ant matchers. May be a Map for the path to role mapping and feed the map into that method to add the matchers.

Upvotes: 1

Related Questions