<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[阿Tim日志]]></title> 
<link>https://atim.cn/index.php</link> 
<description><![CDATA[专业的php开发者.开发团队的带队人]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[阿Tim日志]]></copyright>
<item>
<link>https://atim.cn/post//</link>
<title><![CDATA[若依后台系统整合oauth]]></title> 
<author>bkkkd &lt;partybase@gmail.com&gt;</author>
<category><![CDATA[开发应用]]></category>
<pubDate>Mon, 21 Jun 2021 03:15:18 +0000</pubDate> 
<guid>https://atim.cn/post//</guid> 
<description>
<![CDATA[ 
	最近公司准备开始一个新项目,而这次客户要求是使用java.<br/>为了节省时间的我,选择了若依后台系统.但发现没有整合oauth<br/>(虽然其它版本有整合,但使用分离开发成本有点高.对于我们这种没有前后端分离的小团队不划算.)<br/><br/>在 ruoyi-framework/pom.xml添加以下的依赖<br/><div class="code"><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;dependency&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/dependency&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;dependency&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;org.springframework.security.oauth&lt;/groupId&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;spring-security-oauth2&lt;/artifactId&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;version&gt;2.3.8.RELEASE&lt;/version&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/dependency&gt;<br/></div><br/><br/>ruoyi-framework/src/main/java/com/ruoyi.framework/config/AuthorizationServerConfiguration.java<br/>这个文件主要的作用是启用认证服务,其中的关键代码以下内容.其它的都是配置Bean<br/>[quote]<br/>// 启动认证服务<br/>@EnableAuthorizationServer<br/>//用来配置令牌端点(Token Endpoint)的安全约束。<br/>public void configure(AuthorizationServerSecurityConfigurer security);<br/>//配置OAuth2的客户端相关信息<br/>public void configure(AuthorizationServerEndpointsConfigurer endpoints);<br/>//配置授权服务器端点的属性<br/>public void configure(ClientDetailsServiceConfigurer clients)<br/>[/code]<br/>ruoyi-framework/src/main/java/com/ruoyi.framework/config/ResourceServerConfiguration.java<br/>这里主要配置资源route的拦截.<br/><div class="code"><br/>// 启动资源服务<br/>@EnableResourceServer<br/>&nbsp;&nbsp;&nbsp;&nbsp;public void configure(HttpSecurity http) throws Exception &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http.requestMatchers().antMatchers(&quot;/api/**&quot;) //仅拦截资源服务相关请求<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.and().authorizeRequests().anyRequest().authenticated();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/></div><br/><br/>另外要修改ShiroConfig.java.因为若依的后台是使用shiro进行验证.与spring-security-oauth不是同一个拦截器.所以先要在ShiroConfig.java中忽略/oauth/**和/api/**.<br/>ruoyi-framework/src/main/java/com/ruoyi.framework/config/ShiroConfig.java<br/><div class="code"><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filterChainDefinitionMap.put(&quot;/oauth/**&quot;, &quot;anon&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filterChainDefinitionMap.put(&quot;/api2/**&quot;, &quot;anon&quot;);<br/></div><br/><br/>具体的接口类<br/><div class="code"><br/><br/>@RestController // 直接返回数据<br/>@RequestMapping(&quot;/api/group&quot;) // 路由地址<br/>public class Group &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;@RequestMapping(&quot;hello&quot;) // 方法的处理项<br/>&nbsp;&nbsp;&nbsp;&nbsp;public AjaxResult hello() &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return AjaxResult.success(&quot;success&quot;); // 返回成功<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&#125;<br/></div><br/><br/>后记:<br/>org.springframework.security.oauth 将会被放弃.而会统一使用spring 
]]>
</description>
</item><item>
<link>https://atim.cn/post//#blogcomment</link>
<title><![CDATA[[评论] 若依后台系统整合oauth]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://atim.cn/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>