spring security oauth 自定义过滤器顺序_spring-security-oauth2官方jwt-demo运行实例解析...

本文介绍了如何运行spring-security-oauth2官方提供的JWT demo,并探讨了自定义过滤器的顺序。通过分析官方源码,可以更好地理解此权限框架在实际应用中的工作流程。
摘要由CSDN通过智能技术生成

简述

在开发过程中权限控制必不可少,如何选择一款优秀的权限架构是一份很头疼的事,而shiro和spring-security则是市面上比较优秀的两款权限开源框架,通过改造对应的定制化源码扩展出自己业务所需的架构。下面主要来运行一下官方spring-security-oauth2权限框架的测试demo,通过运行的效果来初步认识这款权限架构。

1、下面是从官方下载[源码地址:https://github.com/spring-projects/spring-security-oauth]的源码导入到Idea中的工程目录:

aa23731e88a35c2dd1d5c745a2373bd2.png
68a799de7e4fc0912052c70e0c3fd650.png

2、本实例运行的demo为上图只向的jwt[spring-oauth2-jwt],打开demo工程可以看到是个简单的springboot工程:

@SpringBootApplication@EnableResourceServer@RestControllerpublic class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}@RequestMapping("/")public String home() {return "Hello World";}@Configuration@EnableAuthorizationServerprotected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {@Autowiredprivate AuthenticationManager authenticationManager;@Beanpublic JwtAccessTokenConverter accessTokenConverter() {// 返回jwt模式return new JwtAccessTokenConverter();}@Overridepublic void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {// 开启token和token_key授权oauthServer.tokenKeyAccess("isAnonymous() || hasAuthority('ROLE_TRUSTED_CLIENT')").checkTokenAccess("hasAuthority('ROLE_TRUSTED_CLIENT')");}@Overridepublic void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {endpoints.authenticationManager(authenticationManager).accessTokenConverter(accessTokenConverter());}@Overridepublic void configure(ClientDetailsServiceConfigurer clients) throws Exception {// @formatter:offclients.inMemory()// 客户端名称.withClient("my-trusted-client")// 授权客户端 拥有密码模式授权、客户端模式、刷新token、隐式模式.authorizedGrantTypes("password
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值