apache olut oauth2 (server、client)集成配置
来源:互联网 发布:湘北vs山王球员数据 编辑:程序博客网 时间:2024/05/18 02:07
在网上找了很多关于oauth2的资料,试过spring security oauth2 和 Apache olut oauth2 的整合。发现security 的整合比较繁琐也比较复杂,里面涉及到的东西比较多。这边就主要说一下Apache olut 、shiro、 oauth2 的整合和实例。
https://github.com/qineasy/shiro-oauth2-server.git,这个是服务端的代码。
spring-config-shiro.xml ,这个配置文件很重要。权限验证的配置基本上都在这里了。
<!-- 缓存管理器 --> <bean id="cacheManager" class="com.github.shiro.spring.SpringCacheManagerWrapper"> <property name="cacheManager" ref="springCacheManager"/> </bean>这个缓存服务用来存储授权码 code、token令牌。
<!-- Realm实现 --> <bean id="userRealm" class="com.github.shiro.chapter.realm.UserRealm"> <property name="cachingEnabled" value="false"/> </bean>这个是用来在权限认证的,重写了AuthorizingRealm这个类。
<!-- Shiro的Web过滤器 --> <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> <property name="securityManager" ref="securityManager"/> <property name="loginUrl" value="/login"/> <property name="filters"> <util:map> <entry key="authc" value-ref="formAuthenticationFilter"/> </util:map> </property> <property name="filterChainDefinitions"> <value> / = anon //匿名用户可以请求 /login = authc // 需要验证权限 /logout = logout /authorize=anon /accessToken=anon /userInfo=anon /** = user // user用户可以请求 </value> </property> </bean>这个配置是必须的。
其他spring配置跟我们基本的mvc是一样的基础配置。需要注意的一点 spring-mvc-shiro.xml 这个配置文件
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"> <property name="securityManager" ref="securityManager"/> </bean>这个配置必须要有否则在AuthorizingRealm.doGetAuthenticationInfo 这个鉴权是不会进入。
所有的操作都放到了web/controller 下面的controller类中
AuthorizeController 这个是用来做授权认证的,通过OAuthAuthzRequest来接收请求的request,经过验证客户端传过来的参数。生成code授权码。服务端在将code写入数据库、或者是缓存。通过OAuthResponse组装响应信息。通过response的302来回调,回调的url是从request中获取。
AccessTokenController这个是用来做授权认证的,通过OAuthAuthzRequest来接收请求的request,经过验证客户端传过来的参数。获取缓存中或者数据库中的授权码code。验证通过后在使用MD5的方式自动生成token,token的存储方式与授权码的类似。这边需要将授权码进行一次清理的操作。保证每个授权码只会使用一次。通过OAuthResponse组装响应信息。通过response的302来回调,回调的url是从request中获取。
UserInfoController 这个是受保护的资源获取,请求这个资源需要将之前获取到的token做为参数传入。因为获取资源需要验证当前的请求是否有权限。
数据库使用的是mysql5.6,数据库脚本可以在服务端的源码中找到。数据库配置文件为resources.properties
整个demo是用maven来管理。如果ide没有配置maven的插件可以在网上找一些资料,配置还是很简单的。
这边就不细致的说client端了。
这个是客户端的代码https://github.com/qineasy/shiro-oauth2-client.git
- apache olut oauth2 (server、client)集成配置
- apache oauth2 集成
- Apache Server + Tomcat 集成配置
- Apache Server + Tomcat 集成配置
- Apache Server + Tomcat 集成配置
- CAS3.5.2 Server 集成 OAuth2.0 Server 详细介绍
- spring cxf 进行webservice的集成(server+client)
- tftp(client、server)配置详解
- rsync server client配置
- apache oauth2
- MQTT Server搭建(apache-apollo)和MQtt Client搭建
- MQTT Server搭建(apache-apollo)和MQtt Client搭建
- MQTT Server搭建(apache-apollo)和MQtt Client搭建
- MQTT Server搭建(apache-apollo)和MQtt Client搭建
- CAS4.0.x server 集成微信扫码登录和Oauth2登录
- Shiro学习(17)OAuth2集成
- Shiro学习(17)OAuth2集成
- OAuth2授权(Client Credentials)
- Android--<String>XX</String>类型的XML解析
- 浅C#中的装箱和拆箱
- EAX、ECX、EDX、EBX寄存器的作用
- android自定义渐变色等待条
- 使用fstream时,提示未定义的标识符
- apache olut oauth2 (server、client)集成配置
- 【BZOJ1318】[Spoj744] Longest Permutation【杂项】
- 关于u3d中需要注意一些地方
- const、static变量存放位置
- Android APP 开始的动画效果
- 解决下拉刷新偏移
- 服务注册问题--未能加载文件和程序集
- POJ Area 1265(pick定理)
- 自动化测试关键字驱动的原理及实现