#oauth2 security expressions on method level

前端 未结 5 724
囚心锁ツ
囚心锁ツ 2020-12-24 08:34

What should I do to be able to use #oauth2 security expressions on method level like on the example below?

@RequestMapping(value = \"email\", method = Reques         


        
5条回答
  •  醉酒成梦
    2020-12-24 08:56

    To enable #oAuth2 security expressions it is only needed to set default expression handler as OAuth2MethodSecurityExpressionHandler instead of DefaultMethodSecurityExpressionHandler. Because OAuth2MethodSecurityExpressionHandler extends it anyway then the whole previous functionality remains the same. I my configuration I use both GlobalMethodSecurityConfiguration and WebSecurityConfigurerAdapter.

    @Configuration
    @EnableGlobalMethodSecurity
    public class MethodSecurityConfiguration extends GlobalMethodSecurityConfiguration {
    
      @Override
      protected MethodSecurityExpressionHandler createExpressionHandler() {
        return new OAuth2MethodSecurityExpressionHandler();
      }
    }
    
    @Configuration
    @EnableWebSecurity
    public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
      ...
    }
    
    
    @Configuration
    @Import({ SecurityConfiguration.class, MethodSecurityConfiguration.class })
    public class AppConfiguration {
      ...
    }
    

提交回复
热议问题