import org.springframework.security.oauth2.provider.password.ResourceOwnerPasswordTokenGranter;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
-
授权服务器配置
-
@author 向振华
-
@date 2020/11/05 17:43
*/
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
@Qualifier(“dataSource”)
private DataSource dataSource;
@Autowired
private RedisConnectionFactory redisConnectionFactory;
@Autowired
private UserDetailsServiceImpl userDetailsService;
@Autowired
private AuthenticationManager authenticationManager;
/**
-
配置令牌端点(内置的/oauth/* 接口)的安全约束
-
@param security
*/
@Override
public void configure(AuthorizationServerSecurityConfigurer security) {
security
// 允许访问/oauth/token授权接口
.allowFormAuthenticationForClients()
// 开启/oauth/check_token访问
.checkTokenAccess(“permitAll()”);
}
/**
-
配置客户端详情
-
@param clients
-
@throws Exception
*/
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
// 读DB客户端详情
clients.withClientDetails(new RedisClientDetailsService(dataSource));
// 客户端详情配置
// clients
// .inMemory()
// // 客户端ID
// .withClient(“order-client-id”)
// // 客户端密码
// .secret(passwordEncoder.encode(“123456”))
// // 授权的类型
// .authorizedGrantTypes(“password”, “refresh_token”)
// // 令牌有效期
// .accessTokenValiditySeconds(120)
// // 范围
// .scopes(“all”);
}
/**
-
配置令牌管理
-
@param endpoints
*/
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
List tokenGranters = getTokenGranters(endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory());
endpoints
// 登录模式
.tokenGranter(new CompositeTokenGranter(tokenGranters))
// 请求方式
.allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST)
// 用户账号密码认证
.userDetailsService(userDetailsService)
// 指定认证管理器
.authenticationManager(authenticationManager)
// 指定token存储位置
.tokenStore(tokenStore())
// JWTToken
.tokenEnhancer(jwtTokenConverter())
// 是否重复使用refresh_token
.reuseRefreshTokens(false)
// 自定义异常翻译
.exceptionTranslator(new CustomWebResponseExceptionTranslator());
}
/**
-
获取登录类型
-
@param tokenServices
-
@param clientDetailsService
-
@param requestFactory
-
@return
*/
private List getTokenGranters(
AuthorizationServerTokenServices tokenServices,
ClientDetailsService clientDetailsService,
OAuth2RequestFactory requestFactory) {
return new ArrayList<>(Arrays.asList(
// 内置的密码模式登录
new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices, clientDetailsService, requestFactory),
// 短信验证码登录
new ResourceOwnerSmsTokenGranter(tokenServices, clientDetailsService, requestFactory)
));
}
/**
-
于Redis实现,令牌保存到缓存
-
@return
*/
@Bean
public TokenStore tokenStore() {
RedisTokenStore tokenStore = new RedisTokenStore(redisConnectionFactory);
// redis key 前缀
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)
![img](https://img-blog.csdnimg.cn/img_convert/ab9c06f5237940357fb6c3861ff57479.jpeg)
Java核心架构进阶知识点
面试成功其实都是必然发生的事情,因为在此之前我做足了充分的准备工作,不单单是纯粹的刷题,更多的还会去刷一些Java核心架构进阶知识点,比如:JVM、高并发、多线程、缓存、Spring相关、分布式、微服务、RPC、网络、设计模式、MQ、Redis、MySQL、设计模式、负载均衡、算法、数据结构、kafka、ZK、集群等。而这些也全被整理浓缩到了一份pdf——《Java核心架构进阶知识点整理》,全部都是精华中的精华,本着共赢的心态,好东西自然也是要分享的
内容颇多,篇幅却有限,这就不在过多的介绍了,大家可根据以上截图自行脑补
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
[外链图片转存中…(img-VvC1hzJD-1713391215912)]
[外链图片转存中…(img-OxX99uEq-1713391215913)]
[外链图片转存中…(img-mhRy9IyG-1713391215913)]
内容颇多,篇幅却有限,这就不在过多的介绍了,大家可根据以上截图自行脑补
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!