{"id":309663,"date":"2024-05-20T21:31:45","date_gmt":"2024-05-20T13:31:45","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/309663.html"},"modified":"2024-05-20T21:32:01","modified_gmt":"2024-05-20T13:32:01","slug":"springboot-%e6%80%8e%e4%b9%88%e6%95%b4%e5%90%88-shiro","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/309663.html","title":{"rendered":"SpringBoot \u600e\u4e48\u6574\u5408 Shiro"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26230136\/fe856fec-a3f7-4d0c-911f-2602650cea2e.webp\" alt=\"SpringBoot \u600e\u4e48\u6574\u5408 Shiro\" \/><\/p>\n<p><p>\u5b89\u5168\u662f\u4efb\u4f55Web\u5e94\u7528\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0c\u800cApache Shiro\u662f\u4e00\u4e2a\u5f3a\u5927\u6613\u7528\u7684\u5b89\u5168\u6846\u67b6\uff0c\u7528\u4ee5\u5b9e\u73b0\u8eab\u4efd\u9a8c\u8bc1\u3001\u6388\u6743\u3001\u5bc6\u7801\u5b66\u548c\u4f1a\u8bdd\u7ba1\u7406\u3002<strong>SpringBoot\u6574\u5408Shiro<\/strong>\u4e3b\u8981\u6d89\u53ca\u6dfb\u52a0Shiro\u4f9d\u8d56\u3001\u914d\u7f6eShiro\u6838\u5fc3\u7ec4\u4ef6\u3001\u6574\u5408Shiro\u6807\u7b7e\u4e0eSpringBoot\u3001\u5b9e\u73b0\u52a8\u6001\u6743\u9650\u66f4\u65b0\u7b49\u6b65\u9aa4\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u5bf9SpringBoot\u6574\u5408Shiro\u7684\u6838\u5fc3\u6b65\u9aa4\u8fdb\u884c\u8be6\u7ec6\u63cf\u8ff0\uff0c\u4ee5\u4fbf\u4e3a\u4f60\u7684Web\u5e94\u7528\u63d0\u4f9b\u5fc5\u8981\u7684\u5b89\u5168\u4fdd\u969c\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u6dfb\u52a0SHIRO\u4f9d\u8d56<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u8981\u5728Spring Boot\u9879\u76ee\u4e2d\u4f7f\u7528Shiro\uff0c\u9700\u8981\u5728<code>pom.xml<\/code>\u6587\u4ef6\u4e2d\u6dfb\u52a0Shiro\u7684\u76f8\u5173\u4f9d\u8d56\u3002\u4e0b\u9762\u662fShiro\u548cSpring Boot\u6574\u5408\u4f7f\u7528\u65f6\u7684\u57fa\u672c\u4f9d\u8d56\u914d\u7f6e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-xml\">&lt;dependencies&gt;<\/p>\n<p>    &lt;!-- Shiro\u6838\u5fc3\u4f9d\u8d56 --&gt;<\/p>\n<p>    &lt;dependency&gt;<\/p>\n<p>        &lt;groupId&gt;org.apache.shiro&lt;\/groupId&gt;<\/p>\n<p>        &lt;artifactId&gt;shiro-spring&lt;\/artifactId&gt;<\/p>\n<p>        &lt;version&gt;1.7.1&lt;\/version&gt;<\/p>\n<p>    &lt;\/dependency&gt;<\/p>\n<p>    &lt;!-- Spring Boot\u542f\u52a8\u5668\u4f9d\u8d56 --&gt;<\/p>\n<p>    &lt;dependency&gt;<\/p>\n<p>        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;<\/p>\n<p>        &lt;artifactId&gt;spring-boot-starter&lt;\/artifactId&gt;<\/p>\n<p>    &lt;\/dependency&gt;<\/p>\n<p>    &lt;!-- \u5176\u4ed6\u5fc5\u987b\u7684\u4f9d\u8d56 --&gt;<\/p>\n<p>    &lt;!-- ... --&gt;<\/p>\n<p>&lt;\/dependencies&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u914d\u7f6eSHIRO\u6838\u5fc3\u7ec4\u4ef6<\/p>\n<\/p>\n<p><p>\u5728\u6574\u5408SpringBoot\u548cShiro\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6838\u5fc3\u7ec4\u4ef6\u914d\u7f6e\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u4f60\u9700\u8981\u914d\u7f6e<code>Realm<\/code>\u3001<code>SecurityManager<\/code>\u4ee5\u53ca<code>ShiroFilter<\/code>\u7b49\u3002<\/p>\n<\/p>\n<p><h3>Realm<\/h3>\n<\/p>\n<p><p>Realm\u662fShiro\u4e0e\u5e94\u7528\u5b89\u5168\u6570\u636e\u4e4b\u95f4\u7684\u201c\u6865\u6881\u201d\u6216\u201c\u8fde\u63a5\u5668\u201d\u3002\u901a\u8fc7\u5b9e\u73b0Realm\u63a5\u53e3\uff0c\u4f60\u53ef\u4ee5\u5c06Shiro\u6846\u67b6\u4e0e\u5e94\u7528\u7684\u5b89\u5168\u6570\u636e\u8fde\u63a5\u8d77\u6765\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">public class CustomRealm extends AuthorizingRealm {<\/p>\n<p>    @Override<\/p>\n<p>    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {<\/p>\n<p>        \/\/ \u5728\u8fd9\u91cc\u5b9e\u73b0\u7528\u6237\u6388\u6743\u4fe1\u606f\u7684\u52a0\u8f7d<\/p>\n<p>        SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();<\/p>\n<p>        \/\/ \u6dfb\u52a0\u89d2\u8272\u548c\u6743\u9650<\/p>\n<p>        \/\/ authorizationInfo.addRole(...);<\/p>\n<p>        \/\/ authorizationInfo.addStringPermission(...);<\/p>\n<p>        return authorizationInfo;<\/p>\n<p>    }<\/p>\n<p>    @Override<\/p>\n<p>    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {<\/p>\n<p>        \/\/ \u5728\u8fd9\u91cc\u5b9e\u73b0\u7528\u6237\u8eab\u4efd\u8ba4\u8bc1\u7684\u903b\u8f91<\/p>\n<p>        UsernamePasswordToken upToken = (UsernamePasswordToken) token;<\/p>\n<p>        String username = upToken.getUsername();<\/p>\n<p>        \/\/ \u6839\u636e\u7528\u6237\u540d\u67e5\u627e\u7528\u6237\u4fe1\u606f<\/p>\n<p>        \/\/ User user = ...<\/p>\n<p>        if (user == null) {<\/p>\n<p>            throw new UnknownAccountException(&quot;\u7528\u6237\u4e0d\u5b58\u5728\uff01&quot;);<\/p>\n<p>        }<\/p>\n<p>        \/\/ \u7528\u6237\u540d\u4f5c\u4e3a\u76d0\u503c<\/p>\n<p>        ByteSource credentialsSalt = ByteSource.Util.bytes(username);<\/p>\n<p>        \/\/ \u6784\u5efaAuthenticationInfo\u5bf9\u8c61\u5e76\u8fd4\u56de<\/p>\n<p>        return new SimpleAuthenticationInfo(username, user.getPassword(), credentialsSalt, getName());<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>SecurityManager<\/h3>\n<\/p>\n<p><p>\u5b89\u5168\u7ba1\u7406\u5668<code>SecurityManager<\/code>\u662fShiro\u7684\u6838\u5fc3\uff0c\u5b83\u534f\u8c03\u5185\u90e8\u7684\u5404\u79cd\u5b89\u5168\u7ec4\u4ef6\u3002\u4f60\u53ef\u4ee5\u5728\u914d\u7f6e\u7c7b\u4e2d\u5b9a\u4e49\u5e76\u914d\u7f6e\u5b83\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">@Configuration<\/p>\n<p>public class ShiroConfig {<\/p>\n<p>    @Bean<\/p>\n<p>    public SecurityManager securityManager(CustomRealm customRealm) {<\/p>\n<p>        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();<\/p>\n<p>        \/\/ \u8bbe\u7f6e\u81ea\u5b9a\u4e49Realm<\/p>\n<p>        securityManager.setRealm(customRealm);<\/p>\n<p>        return securityManager;<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>ShiroFilter<\/h3>\n<\/p>\n<p><p>Shiro\u7684<code>ShiroFilter<\/code>\u8d1f\u8d23\u62e6\u622a\u6240\u6709\u7684\u8bf7\u6c42\u5e76\u901a\u8fc7\u5b89\u5168\u7ba1\u7406\u5668\u8fdb\u884c\u5b89\u5168\u6821\u9a8c\u3002Shiro\u63d0\u4f9b\u4e86\u4e00\u4e2aShiroFilterFactoryBean\u6765\u5e2e\u52a9\u521b\u5efa\u548c\u914d\u7f6eShiroFilter\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">@Bean<\/p>\n<p>public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {<\/p>\n<p>    ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();<\/p>\n<p>    \/\/ \u8bbe\u7f6e\u5b89\u5168\u7ba1\u7406\u5668<\/p>\n<p>    shiroFilterFactoryBean.setSecurityManager(securityManager);<\/p>\n<p>    \/\/ \u914d\u7f6e\u62e6\u622a\u5668\u94fe<\/p>\n<p>    Map&lt;String, String&gt; filterCh<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>nDefinitionMap = new LinkedHashMap&lt;&gt;();<\/p>\n<p>    filterChainDefinitionMap.put(&quot;\/static\/&quot;, &quot;anon&quot;);<\/p>\n<p>    filterChainDefinitionMap.put(&quot;\/login&quot;, &quot;anon&quot;);<\/p>\n<p>    filterChainDefinitionMap.put(&quot;\/&quot;, &quot;authc&quot;);<\/p>\n<p>    shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);<\/p>\n<p>    \/\/ \u914d\u7f6e\u767b\u5f55\u7684URL<\/p>\n<p>    shiroFilterFactoryBean.setLoginUrl(&quot;\/login&quot;);<\/p>\n<p>    \/\/ \u914d\u7f6e\u767b\u5f55\u6210\u529f\u7684URL<\/p>\n<p>    shiroFilterFactoryBean.setSuccessUrl(&quot;\/index&quot;);<\/p>\n<p>    \/\/ \u914d\u7f6e\u672a\u6388\u6743\u7684URL<\/p>\n<p>    shiroFilterFactoryBean.setUnauthorizedUrl(&quot;\/unauthorized&quot;);<\/p>\n<p>    return shiroFilterFactoryBean;<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u6574\u5408SHIRO\u6807\u7b7e\u4e0eSPRING BOOT<\/p>\n<\/p>\n<p><p>Shiro\u63d0\u4f9b\u4e86\u5f88\u591a\u6709\u7528\u7684\u6807\u7b7e\uff0c\u7528\u4e8e\u5728\u9875\u9762\u4e0a\u8fdb\u884c\u6743\u9650\u63a7\u5236\u3002\u4e3a\u4e86\u5728Spring Boot\u5e94\u7528\u7684Thymeleaf\u6a21\u677f\u4e2d\u4f7f\u7528Shiro\u6807\u7b7e\u5e93\uff0c\u4f60\u9700\u8981\u6dfb\u52a0\u4e00\u4e2aShiro\u7684dialect\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u5728\u6a21\u677f\u4e2d\u4f7f\u7528Shiro\u63d0\u4f9b\u7684\u6743\u9650\u63a7\u5236\u6807\u7b7e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-xml\">&lt;!-- \u6dfb\u52a0\u5bf9thyemeleaf\u652f\u6301\u7684shiro\u65b9\u8a00\u4f9d\u8d56 --&gt;<\/p>\n<p>&lt;dependency&gt;<\/p>\n<p>    &lt;groupId&gt;com.github.theborakompanioni&lt;\/groupId&gt;<\/p>\n<p>    &lt;artifactId&gt;thymeleaf-extras-shiro&lt;\/artifactId&gt;<\/p>\n<p>    &lt;version&gt;2.0.0&lt;\/version&gt;<\/p>\n<p>&lt;\/dependency&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5728\u914d\u7f6e\u7c7b\u4e2d\u914d\u7f6eThymeleaf\u7684Shiro\u65b9\u8a00\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">@Configuration<\/p>\n<p>public class ThymeleafConfig {<\/p>\n<p>    @Bean<\/p>\n<p>    public ShiroDialect shiroDialect() {<\/p>\n<p>        return new ShiroDialect();<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u5b9e\u73b0\u52a8\u6001\u6743\u9650\u66f4\u65b0<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u6839\u636e\u4e0d\u540c\u65f6\u95f4\u6216\u6761\u4ef6\u52a8\u6001\u8c03\u6574\u6743\u9650\u89c4\u5219\u3002\u8981\u8fbe\u5230\u8fd9\u4e2a\u76ee\u7684\uff0c\u53ef\u4ee5\u81ea\u5b9a\u4e49\u4e00\u4e2aservice\uff0c\u7528\u4e8e\u5728\u4e0d\u91cd\u542f\u670d\u52a1\u7684\u60c5\u51b5\u4e0b\u91cd\u65b0\u52a0\u8f7d\u6743\u9650\u89c4\u5219\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">@Service<\/p>\n<p>public class ShiroService {<\/p>\n<p>    @Autowired<\/p>\n<p>    private ShiroFilterFactoryBean shiroFilterFactoryBean;<\/p>\n<p>    \/\/ \u52a8\u6001\u66f4\u65b0\u65b0\u7684\u6743\u9650<\/p>\n<p>    public void updatePermission() {<\/p>\n<p>        synchronized (shiroFilterFactoryBean) {<\/p>\n<p>            AbstractShiroFilter shiroFilter;<\/p>\n<p>            try {<\/p>\n<p>                shiroFilter = (AbstractShiroFilter) shiroFilterFactoryBean.getObject();<\/p>\n<p>            } catch (Exception e) {<\/p>\n<p>                throw new RuntimeException(&quot;get ShiroFilter from shiroFilterFactoryBean error!&quot;, e);<\/p>\n<p>            }<\/p>\n<p>            \/\/ \u83b7\u53d6\u8fc7\u6ee4\u5668\u94fe<\/p>\n<p>            PathMatchingFilterChainResolver filterChainResolver = (PathMatchingFilterChainResolver) shiroFilter.getFilterChainResolver();<\/p>\n<p>            DefaultFilterChainManager manager = (DefaultFilterChainManager) filterChainResolver.getFilterChainManager();<\/p>\n<p>            \/\/ \u6e05\u7a7a\u65e7\u7684\u6743\u9650\u63a7\u5236<\/p>\n<p>            manager.getFilterChains().clear();<\/p>\n<p>            shiroFilterFactoryBean.getFilterChainDefinitionMap().clear();<\/p>\n<p>            \/\/ \u52a8\u6001\u91cd\u65b0\u52a0\u8f7d\u6743\u9650<\/p>\n<p>            \/\/ loadNewPermissions(manager, newPermissions);<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2aservice\u4e2d\uff0c\u5f53\u8c03\u7528<code>updatePermission<\/code>\u65b9\u6cd5\u65f6\uff0c\u65e7\u7684\u6743\u9650\u89c4\u5219\u4f1a\u88ab\u6e05\u9664\uff0c\u5e76\u52a0\u8f7d\u65b0\u7684\u6743\u9650\u89c4\u5219\u3002\u8fd9\u5141\u8bb8\u7cfb\u7edf\u5728\u4e0d\u4e2d\u65ad\u7528\u6237\u5f53\u524d\u64cd\u4f5c\u7684\u60c5\u51b5\u4e0b\uff0c\u5b9e\u73b0\u6743\u9650\u7684\u5373\u65f6\u66f4\u65b0\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u7ed3\u8bba<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u9010\u6b65\u914d\u7f6e\u4e0e\u7ec6\u5316\u5404\u9879Shiro\u7ec4\u4ef6\uff0c\u4f60\u53ef\u4ee5\u5c06Shiro\u6210\u529f\u6574\u5408\u5230Spring Boot\u5e94\u7528\u4e2d\uff0c\u4ece\u800c\u4e3a\u4f60\u7684\u5e94\u7528\u63d0\u4f9b\u53ef\u9760\u7684\u5b89\u5168\u63aa\u65bd\u3002\u6210\u529f\u6574\u5408\u540e\uff0c\u4f60\u5c06\u80fd\u5229\u7528Shiro\u63d0\u4f9b\u7684\u529f\u80fd\uff0c\u786e\u4fdd\u5e94\u7528\u7684\u5b89\u5168\u6027\u3001\u7a33\u5b9a\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002<\/p>\n<\/p>\n<p><p>\u5c3d\u7ba1\u6574\u5408\u8fc7\u7a0b\u53ef\u80fd\u770b\u8d77\u6765\u6709\u4e9b\u590d\u6742\uff0c\u4f46\u9075\u5faa\u4ee5\u4e0a\u6b65\u9aa4\u5c06\u5e2e\u52a9\u4f60\u9010\u6e10\u6784\u5efa\u4e00\u4e2a\u5065\u58ee\u7684\u5b89\u5168\u7cfb\u7edf\u3002\u4e00\u65e6\u5b8c\u6210\u6574\u5408\uff0c\u4f60\u5c31\u53ef\u4ee5\u6839\u636e\u9700\u8981\u81ea\u7531\u5730\u5b9a\u5236\u548c\u6269\u5c55Shiro\u7684\u529f\u80fd\uff0c\u4ee5\u6ee1\u8db3\u66f4\u4e3a\u590d\u6742\u7684\u5b89\u5168\u9700\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. Shiro \u662f\u4ec0\u4e48\uff1fSpringBoot \u5982\u4f55\u6574\u5408 Shiro\uff1f<\/strong><\/p>\n<p>Shiro \u662f\u4e00\u4e2a\u5f3a\u5927\u4e14\u6613\u7528\u7684 Java \u5b89\u5168\u6846\u67b6\uff0c\u53ef\u4ee5\u63d0\u4f9b\u8eab\u4efd\u8ba4\u8bc1\u3001\u6743\u9650\u63a7\u5236\u3001\u4f1a\u8bdd\u7ba1\u7406\u7b49\u529f\u80fd\u3002\u800c SpringBoot \u662f\u4e00\u4e2a\u5feb\u901f\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f\u7684\u6846\u67b6\u3002\u8981\u5728 SpringBoot \u4e2d\u6574\u5408 Shiro\uff0c\u9996\u5148\u9700\u8981\u6dfb\u52a0 Shiro \u7684\u4f9d\u8d56\u9879\u5230\u9879\u76ee\u7684 Maven \u6216 Gradle \u6587\u4ef6\u4e2d\uff0c\u63a5\u7740\u914d\u7f6e Shiro \u7684\u76f8\u5173\u5c5e\u6027\u548c\u8fc7\u6ee4\u5668\u94fe\uff0c\u6700\u540e\u7f16\u5199\u8ba4\u8bc1\u3001\u6388\u6743\u7b49\u76f8\u5173\u4ee3\u7801\u5373\u53ef\u3002<\/p>\n<p><strong>2. SpringBoot \u6574\u5408 Shiro \u7684\u4f18\u52bf\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n<p>\u6574\u5408 SpringBoot \u548c Shiro \u53ef\u4ee5\u4e3a\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4e00\u5957\u5b8c\u5584\u7684\u5b89\u5168\u89e3\u51b3\u65b9\u6848\u3002\u7531\u4e8e SpringBoot \u7684\u81ea\u52a8\u914d\u7f6e\u7279\u6027\uff0c\u53ef\u4ee5\u5927\u5927\u7b80\u5316 Shiro \u7684\u914d\u7f6e\u5de5\u4f5c\uff0c\u4f7f\u5f00\u53d1\u8005\u80fd\u591f\u66f4\u5feb\u5730\u642d\u5efa\u5b89\u5168\u53ef\u9760\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u540c\u65f6\uff0cSpringBoot \u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u751f\u6001\u7cfb\u7edf\u548c\u793e\u533a\u652f\u6301\uff0c\u53ef\u4ee5\u4e3a\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u66f4\u591a\u7684\u5b89\u5168\u63d2\u4ef6\u548c\u62d3\u5c55\u3002<\/p>\n<p><strong>3. \u5982\u4f55\u5b9e\u73b0\u57fa\u4e8e Shiro \u7684\u7528\u6237\u8ba4\u8bc1\u548c\u6743\u9650\u63a7\u5236\uff1f<\/strong><\/p>\n<p>\u5728 SpringBoot \u4e2d\u6574\u5408 Shiro \u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u76f8\u5e94\u7684\u4ee3\u7801\u6765\u5b9e\u73b0\u7528\u6237\u8ba4\u8bc1\u548c\u6743\u9650\u63a7\u5236\u3002\u9996\u5148\uff0c\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a Realm \u7c7b\u6765\u5904\u7406\u8eab\u4efd\u8ba4\u8bc1\u548c\u6388\u6743\u7684\u903b\u8f91\u3002\u7136\u540e\uff0c\u5728\u63a7\u5236\u5668\u6216\u670d\u52a1\u5c42\u7684\u65b9\u6cd5\u4e0a\u4f7f\u7528 Shiro \u7684\u6ce8\u89e3\u6765\u8fdb\u884c\u6743\u9650\u63a7\u5236\uff0c\u5982 <code>@RequiresRoles<\/code> \u548c <code>@RequiresPermissions<\/code> \u7b49\u3002\u5728\u8ba4\u8bc1\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 Shiro \u63d0\u4f9b\u7684 AuthenticationToken \u6765\u5c01\u88c5\u7528\u6237\u7684\u8eab\u4efd\u548c\u51ed\u8bc1\uff0c\u5728 Realm \u4e2d\u8fdb\u884c\u9a8c\u8bc1\u3002\u5728\u6388\u6743\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199 Shiro \u7684\u81ea\u5b9a\u4e49\u8fc7\u6ee4\u5668\u548c Realm \u7684\u6388\u6743\u903b\u8f91\u6765\u5b9e\u73b0\u7cbe\u786e\u7684\u6743\u9650\u63a7\u5236\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5b89\u5168\u662f\u4efb\u4f55Web\u5e94\u7528\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0c\u800cApache Shiro\u662f\u4e00\u4e2a\u5f3a\u5927\u6613\u7528\u7684\u5b89\u5168\u6846\u67b6\uff0c\u7528\u4ee5\u5b9e\u73b0\u8eab\u4efd\u9a8c\u8bc1\u3001\u6388\u6743 [&hellip;]","protected":false},"author":3,"featured_media":309683,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/309663"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=309663"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/309663\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/309683"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=309663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=309663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=309663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}