package com.peterwanghao.spring.cloud.oauth.authserver.config;
import java.security.KeyPair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.Resource;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory;
/**
* @ClassName: AuthServerConfigurer
* @Description:OAuth认证服务配置
* @author: wanghao
* @date: 2018年7月19日 下午2:10:07
* @version V1.0
*
*/
@Configuration
@EnableAuthorizationServer
@Order(6)
public class AuthServerConfigurer extends AuthorizationServerConfigurerAdapter {
@Value("${jwt.certificate.store.file}")
private Resource keystore;
@Value("${jwt.certificate.store.password}")
private String keystorePassword;
@Value("${jwt.certificate.key.alias}")
private String keyAlias;
@Value("${jwt.certificate.key.password}")
private String keyPassword;
@Autowired
private UserDetailsService userDetailsService;
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("first").secret("passwordforauthserver")
.redirectUris("http://localhost:8080/").authorizedGrantTypes("authorization_code", "refresh_token")
.scopes("myscope").autoApprove(true).accessTokenValiditySeconds(30).refreshTokenValiditySeconds(1800)
.and()
.withClient("second").secret("passwordforauthserver")
.redirectUris("http://localhost:8081/").authorizedGrantTypes("authorization_code", "refresh_token")
.scopes("myscope").autoApprove(true).accessTokenValiditySeconds(30).refreshTokenValiditySeconds(1800);
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.accessTokenConverter(jwtAccessTokenConverter()).userDetailsService(userDetailsService);
}
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(keystore, keystorePassword.toCharArray());
KeyPair keyPair = keyStoreKeyFactory.getKeyPair(keyAlias, keyPassword.toCharArray());
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setKeyPair(keyPair);
return converter;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
spring-cloud-examples-master.zip (33个子文件)
spring-cloud-examples-master
spring-cloud-oauth
auth-resource
src
main
resources
application.yml 799B
java
com
peterwanghao
spring
cloud
oauth
authresource
controller
PersonInfoController.java 868B
ResourceController.java 597B
model
Person.java 1KB
config
ResourceConfigurer.java 1KB
Application.java 548B
pom.xml 2KB
auth-server
src
main
resources
certificate
mykeystore.jks 2KB
templates
login.html 745B
application.yml 407B
java
com
peterwanghao
spring
cloud
oauth
authserver
AuthServer.java 492B
config
AuthServerConfigurer.java 3KB
WebSecurityConfigurer.java 2KB
WebMvcConfigurer.java 727B
pom.xml 2KB
auth-client
src
main
resources
templates
personinfo.html 299B
application.properties 0B
application.yml 1KB
java
com
peterwanghao
spring
cloud
oauth
authclient
controller
CloudSiteController.java 1KB
config
SiteSecurityConfigurer.java 2KB
filters
SimpleFilter.java 1KB
AuthClient.java 776B
pom.xml 3KB
pom.xml 663B
auth-client2
src
main
resources
templates
personinfo.html 299B
application.properties 0B
application.yml 1KB
java
com
peterwanghao
spring
cloud
oauth
authclient
controller
CloudSiteController.java 1KB
AuthClient2.java 778B
config
SiteSecurityConfigurer.java 2KB
filters
SimpleFilter.java 1KB
pom.xml 3KB
pom.xml 2KB
共 33 条
- 1
peterwanghao
- 粉丝: 642
- 资源: 25
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页