springboot oauth2自定义authenticationmanager和认证path

更新时间:2024-03-26 18:47:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

springboot+oauth2自定义authenticationmanager和认证path

@Configurationpublic class OAuth2Configuration { @SpringBootApplication @RestController @EnableResourceServer @Configuration @EnableAuthorizationServer

protected static class

AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter implements EnvironmentAware { private static final String ENV_OAUTH = \ private static final String PROP_CLIENTID = \ private static final String PROP_SECRET = \ private static final String

PROP_TOKEN_VALIDITY_SECONDS = \ private RelaxedPropertyResolver propertyResolver; @Autowired private DataSource dataSource; @Bean public TokenStore tokenStore() { return new JdbcTokenStore(dataSource); }// @Autowired//

@Qualifier(\ //

private AuthenticationManager authenticationManager;

@Autowired

@Qualifier(\

private AuthenticationProvider daoAuhthenticationOauthProvider;

public void

@Override

configure(AuthorizationServerEndpointsConfigurer endpoints)

throws Exception {

// @formatter:off

endpoints .tokenStore(tokenStore())

.authenticationManager(new AuthenticationManager(){

@Override

public Authentication

authenticate(Authentication authentication) throws AuthenticationException { Auto-generated method stub

// TODO return

daoAuhthenticationOauthProvider.authenticate(authentication); }

});

// @formatter:on

} @Override public void

configure(ClientDetailsServiceConfigurer clients) throws Exception { clients

.inMemory()

.withClient(propertyResolver.getProperty

(PROP_CLIENTID)) .scopes(\\

.authorities(Authorities.ROLE_CHANN

EL.name())

.authorizedGrantTypes(\

\

.secret(propertyResolver.getProperty(PR

OP_SECRET))

.accessTokenValiditySeconds(propertyRe

solver.getProperty(PROP_TOKEN_VALIDITY_SECONDS, Integer.class, 1800)); } @Override public void setEnvironment(Environment environment) { this.propertyResolver = new

RelaxedPropertyResolver(environment, ENV_OAUTH);

} @Configuration

@EnableResourceServer protected static class ResourceServerConfiguration extends

ResourceServerConfigurerAdapter {

@Override public void configure(HttpSecurity http) throws Exception { http

.antMatcher(\ .authorizeRequests() .anyRequest()

.hasRole(\

.and()

.antMatcher(\ .authorizeRequests() .anyRequest()

.hasRole(\ } }

}

}

本文来源:https://www.bwwdw.com/article/aacr.html

Top