AuthorizationServerConfigurerAdapter 与 WebSecurityConfigurerAdapter

One thing first. OAuth 2 is an authorization framework. It allows an application (client) to obtain limited access to a HTTP service on behalf of a resource owner (user). OAuth 2 is not an authentication protocol.

AuthorizationServerConfigurerAdapter is used to configure how the OAuth authorization server works.

Here are some aspects which can be configured:

  • supported grant types (e.g. authorization code grant)
  • authorization code service, to store authorization codes
  • token store, to store access and refresh tokens (e.g. JwtTokenStore)
  • client details service, which holds the client configurations
  • ...

WebSecurityConfigurerAdapter is used to configure how the OAuth authorization server is secured.

Or in other words, how the user has to authenticate to grant a client access to his resources.

This can be:

  • form authentication
  • authentication via an identity provider (Facebook Login)
  • ...

(I have intentionally omitted some details to keep the answer as simple as possible.)


Example authorization server configuration with an in-memory token store:

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.tokenStore(tokenStore());
    }

    @Bean
    public TokenStore tokenStore() {
        return new InMemoryTokenStore();
    }

    ...

}

Example security configuration with form login:

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/login").permitAll()
                .antMatchers("/oauth/authorize").authenticated()
                .and()
            .formLogin();
    }

    ...

}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值