{"id":10006153,"date":"2022-08-09T15:24:13","date_gmt":"2022-08-09T07:24:13","guid":{"rendered":"https:\/\/ityet.com\/?p=10006153"},"modified":"2022-08-09T15:24:13","modified_gmt":"2022-08-09T07:24:13","slug":"spring-security-%e6%9c%80%e4%bd%b3%e5%ae%9e%e8%b7%b5%ef%bc%8c%e7%9c%8b%e4%ba%86%e5%bf%85%e6%87%82%ef%bc%81","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006153","title":{"rendered":"Spring Security \u6700\u4f73\u5b9e\u8df5\uff0c\u770b\u4e86\u5fc5\u61c2\uff01"},"content":{"rendered":"<p>\u4f5c\u8005\uff1a\u6e05\u8336\u6de1\u7ca5\u9171\/<br \/>\u94fe\u63a5\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=yWP6DSdOJfuPZQNqv3HQEA%3D%3D.wWnQLoEJY2xwimAM68GBF3%2BVaXvSDSjTov59XBvsLbRJG%2BYiJMbQUCibLDB8bAVr\" rel=\"nofollow\">https:\/\/juejin.cn\/post\/702673&#8230;<\/a><\/p>\n<h2>Spring Security\u7b80\u4ecb<\/h2>\n<p>Spring Security \u662f\u4e00\u79cd\u9ad8\u5ea6\u81ea\u5b9a\u4e49\u7684\u5b89\u5168\u6846\u67b6\uff0c\u5229\u7528\uff08\u57fa\u4e8e\uff09SpringIOC\/DI\u548cAOP\u529f\u80fd\uff0c\u4e3a\u7cfb\u7edf\u63d0\u4f9b\u4e86\u58f0\u660e\u5f0f\u5b89\u5168\u8bbf\u95ee\u63a7\u5236\u529f\u80fd\uff0c<strong>\u51cf\u5c11\u4e86\u4e3a\u7cfb\u7edf\u5b89\u5168\u800c\u7f16\u5199\u5927\u91cf\u91cd\u590d\u4ee3\u7801\u7684\u5de5\u4f5c<\/strong>\u3002<\/p>\n<p><strong>\u6838\u5fc3\u529f\u80fd\uff1a\u8ba4\u8bc1\u548c\u6388\u6743<\/strong><\/p>\n<h2>Spring Security \u8ba4\u8bc1\u6d41\u7a0b<\/h2>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042290893\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>Spring Security \u9879\u76ee\u642d\u5efa<\/h2>\n<h3>\u5bfc\u5165\u4f9d\u8d56<\/h3>\n<p>Spring Security\u5df2\u7ecf\u88abSpring boot\u8fdb\u884c\u96c6\u6210\uff0c\u4f7f\u7528\u65f6\u76f4\u63a5\u5f15\u5165\u542f\u52a8\u5668\u5373\u53ef<\/p>\n<pre><code class=\"xml\">&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-security&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n<p>Spring Boot \u57fa\u7840\u5c31\u4e0d\u4ecb\u7ecd\u4e86\uff0c\u63a8\u8350\u4e0b\u8fd9\u4e2a\u5b9e\u6218\u6559\u7a0b\uff1a<\/p>\n<blockquote><p><a href=\"https:\/\/link.segmentfault.com\/?enc=aeAGUamA1cREHFrVEQTy9Q%3D%3D.I7AJMJ%2Fcz1WLankoH4H2XyKzBQUwmN2TzhVrdGS%2FBIJ3EVs%2Bix%2FgxBMWZTUnIkxeOT5pqS43dwyqBUOJ%2F2zM1g%3D%3D\" rel=\"nofollow\">https:\/\/github.com\/javastacks&#8230;<\/a><\/p><\/blockquote>\n<h3>\u8bbf\u95ee\u9875\u9762<\/h3>\n<p>\u5bfc\u5165spring-boot-starter-security\u542f\u52a8\u5668\u540e\uff0cSpring Security\u5df2\u7ecf\u751f\u6548\uff0c\u9ed8\u8ba4\u62e6\u622a\u5168\u90e8\u8bf7\u6c42\uff0c\u5982\u679c\u7528\u6237\u6ca1\u6709\u767b\u5f55\uff0c\u8df3\u8f6c\u5230\u5185\u7f6e\u767b\u5f55\u9875\u9762\u3002<\/p>\n<p>\u5728\u6d4f\u89c8\u5668\u8f93\u5165\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=zZQhzfcULmti6OcIg5w1wg%3D%3D.2qRNhXGSaoK%2Bd%2FwZghd5LIpV8K%2BrcPgHSrHPGx7eWEbek47l6eyd%2BH76W%2B%2FkEmTF9UK7cCf%2FAXXAr4oMzJ6YuA%3D%3D\" rel=\"nofollow\">http:\/\/localhost:8080\/<\/a> \u8fdb\u5165Spring Security\u5185\u7f6e\u767b\u5f55\u9875\u9762<\/p>\n<p>\u7528\u6237\u540d\uff1a user<\/p>\n<p>\u5bc6\u7801\uff1a\u9879\u76ee\u542f\u52a8\uff0c\u6253\u5370\u5728\u63a7\u5236\u53f0\u4e2d<\/p>\n<h3>\u81ea\u5b9a\u4e49\u7528\u6237\u540d\u548c\u5bc6\u7801<\/h3>\n<p>\u4fee\u6539<strong>application.yml<\/strong> \u6587\u4ef6<\/p>\n<pre><code class=\"yml\"># \u9759\u6001\u7528\u6237\uff0c\u4e00\u822c\u53ea\u5728\u5185\u90e8\u7f51\u7edc\u8ba4\u8bc1\u4e2d\u4f7f\u7528\uff0c\u5982\uff1a\u5185\u90e8\u670d\u52a1\u56681\uff0c\u8bbf\u95ee\u670d\u52a1\u56682\nspring:\n  security:\n    user:\n      name: test  # \u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\uff0c\u8bbe\u7f6e\u9759\u6001\u7528\u6237\u540d\n      password: test # \u914d\u7f6e\u6587\u4ef6\uff0c\u8bbe\u7f6e\u9759\u6001\u767b\u5f55\u5bc6\u7801<\/code><\/pre>\n<h2>UserDetailsService\u8be6\u89e3<\/h2>\n<p>\u4ec0\u4e48\u4e5f\u6ca1\u6709\u914d\u7f6e\u7684\u65f6\u5019\uff0c\u8d26\u53f7\u548c\u5bc6\u7801\u662f\u7531Spring Security\u5b9a\u4e49\u751f\u6210\u7684\u3002\u800c\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u8d26\u53f7\u548c\u5bc6\u7801\u90fd\u662f\u4ece\u6570\u636e\u5e93\u4e2d\u67e5\u8be2\u51fa\u6765\u7684\u3002 \u6240\u4ee5\u6211\u4eec\u8981\u901a\u8fc7<strong>\u81ea\u5b9a\u4e49\u903b\u8f91\u63a7\u5236\u8ba4\u8bc1\u903b\u8f91<\/strong>\u3002\u5982\u679c\u9700\u8981\u81ea\u5b9a\u4e49\u903b\u8f91\u65f6\uff0c\u53ea\u9700\u8981\u5b9e\u73b0UserDetailsService\u63a5\u53e3<\/p>\n<pre><code class=\"java\">@Component\npublic class UserSecurity implements UserDetailsService {\n\n    @Autowired\n    private UserService userService;\n\n    @Override\n    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {\n\n        User user = userService.login(userName);\n        System.out.println(user);\n        if (null==user){\n            throw new UsernameNotFoundException(&quot;\u7528\u6237\u540d\u9519\u8bef&quot;);\n        }\n        org.springframework.security.core.userdetails.User result =\n                new org.springframework.security.core.userdetails.User(\n                        userName,user.getPassword(), AuthorityUtils.createAuthorityList()\n                );\n        return result;\n    }\n\n}<\/code><\/pre>\n<p>\u63a8\u8350\u4e00\u4e2a Spring Boot \u57fa\u7840\u6559\u7a0b\uff1a<\/p>\n<blockquote><p><a href=\"https:\/\/link.segmentfault.com\/?enc=%2BK%2BLGsaTn19KMidw0Z496Q%3D%3D.9D6Me0ZTfg7oAmN7PCsSweFnnqfPjaoOVRGkowFuX5Ii5jc5%2FPsdz7eDICkuGe43vV6iVKArwhVBV6qLgAZI%2Bw%3D%3D\" rel=\"nofollow\">https:\/\/github.com\/javastacks&#8230;<\/a><\/p><\/blockquote>\n<h2>PasswordEncoder\u5bc6\u7801\u89e3\u6790\u5668\u8be6\u89e3<\/h2>\n<h3>PasswordEncoder<\/h3>\n<p><strong>PasswordEncoder<\/strong> \u662fSpringSecurity  \u7684\u5bc6\u7801\u89e3\u6790\u5668\uff0c\u7528\u6237\u5bc6\u7801\u6821\u9a8c\u3001\u52a0\u5bc6 \u3002 \u81ea\u5b9a\u4e49\u767b\u5f55\u903b\u8f91\u65f6\u8981\u6c42\u5fc5\u987b\u7ed9\u5bb9\u5668\u6ce8\u5165PaswordEncoder\u7684bean\u5bf9\u8c61<\/p>\n<p>SpringSecurity \u5b9a\u4e49\u4e86\u5f88\u591a\u5b9e\u73b0\u63a5\u53e3<strong>PasswordEncoder<\/strong>  \u6ee1\u8db3\u6211\u4eec\u5bc6\u7801\u52a0\u5bc6\u3001\u5bc6\u7801\u6821\u9a8c \u4f7f\u7528\u9700\u6c42<\/p>\n<h3>\u81ea\u5b9a\u4e49\u5bc6\u7801\u89e3\u6790\u5668<\/h3>\n<ol>\n<li>\u7f16\u5199\u7c7b\uff0c\u5b9e\u73b0PasswordEncoder \u63a5\u53e3<\/li>\n<\/ol>\n<pre><code class=\"java\">\/**\n * \u51ed\u8bc1\u5339\u914d\u5668\uff0c\u7528\u4e8e\u505a\u8ba4\u8bc1\u6d41\u7a0b\u7684\u51ed\u8bc1\u6821\u9a8c\u4f7f\u7528\u7684\u7c7b\u578b\n * \u5176\u4e2d\u67092\u4e2a\u6838\u5fc3\u65b9\u6cd5\n * 1. encode - \u628a\u660e\u6587\u5bc6\u7801\uff0c\u52a0\u5bc6\u6210\u5bc6\u6587\u5bc6\u7801\n * 2. matches - \u6821\u9a8c\u660e\u6587\u548c\u5bc6\u6587\u662f\u5426\u5339\u914d\n * *\/\npublic class MyMD5PasswordEncoder implements PasswordEncoder {\n\n    \/**\n     * \u52a0\u5bc6\n     * @param charSequence  \u660e\u6587\u5b57\u7b26\u4e32\n     * @return\n     *\/\n    @Override\n    public String encode(CharSequence charSequence) {\n        try {\n            MessageDigest digest = MessageDigest.getInstance(&quot;MD5&quot;);\n            return toHexString(digest.digest(charSequence.toString().getBytes()));\n        } catch (NoSuchAlgorithmException e) {\n            e.printStackTrace();\n            return &quot;&quot;;\n        }\n    }\n\n    \/**\n     * \u5bc6\u7801\u6821\u9a8c\n     * @param charSequence \u660e\u6587\uff0c\u9875\u9762\u6536\u96c6\u5bc6\u7801\n     * @param s \u5bc6\u6587 \uff0c\u6570\u636e\u5e93\u4e2d\u5b58\u653e\u5bc6\u7801\n     * @return\n     *\/\n    @Override\n    public boolean matches(CharSequence charSequence, String s) {\n        return s.equals(encode(charSequence));\n    }\n\n     \/**\n     * @param tmp \u8f6c16\u8fdb\u5236\u5b57\u8282\u6570\u7ec4\n     * @return \u996d\u56de16\u8fdb\u5236\u5b57\u7b26\u4e32\n     *\/\n    private String toHexString(byte [] tmp){\n        StringBuilder builder = new StringBuilder();\n        for (byte b :tmp){\n            String s = Integer.toHexString(b &amp; 0xFF);\n            if (s.length()==1){\n                builder.append(&quot;0&quot;);\n            }\n            builder.append(s);\n        }\n\n        return builder.toString();\n\n    }\n}<\/code><\/pre>\n<p>2.\u5728\u914d\u7f6e\u7c7b\u4e2d\u6307\u5b9a\u81ea\u5b9a\u4e49\u5bc6\u7801\u51ed\u8bc1\u5339\u914d\u5668<\/p>\n<pre><code class=\"java\">\/**\n  * \u52a0\u5bc6\n  * @return \u52a0\u5bc6\u5bf9\u8c61\n  * \u5982\u9700\u4f7f\u7528\u81ea\u5b9a\u4e49\u5bc6\u7801\u51ed\u8bc1\u5339\u914d\u5668 \u8fd4\u56de\u81ea\u5b9a\u4e49\u52a0\u5bc6\u5bf9\u8c61\n  * \u4f8b\u5982: return new MD5PasswordEncoder(); \n  *\/\n@Bean\npublic PasswordEncoder passwordEncoder() {\n    return new BCryptPasswordEncoder(); \/\/Spring Security \u81ea\u5e26\n}<\/code><\/pre>\n<h2>\u767b\u5f55\u914d\u7f6e<\/h2>\n<h3>\u65b9\u5f0f\u4e00 \u8f6c\u53d1<\/h3>\n<pre><code class=\"java\">http.formLogin()\n    .usernameParameter(&quot;name&quot;) \/\/ \u8bbe\u7f6e\u8bf7\u6c42\u53c2\u6570\u4e2d\uff0c\u7528\u6237\u540d\u53c2\u6570\u540d\u79f0\u3002 \u9ed8\u8ba4username\n    .passwordParameter(&quot;pswd&quot;) \/\/ \u8bbe\u7f6e\u8bf7\u6c42\u53c2\u6570\u4e2d\uff0c\u5bc6\u7801\u53c2\u6570\u540d\u79f0\u3002 \u9ed8\u8ba4password\n    .loginPage(&quot;\/toLogin&quot;) \/\/ \u5f53\u7528\u6237\u672a\u767b\u5f55\u7684\u65f6\u5019\uff0c\u8df3\u8f6c\u7684\u767b\u5f55\u9875\u9762\u5730\u5740\u662f\u4ec0\u4e48\uff1f \u9ed8\u8ba4 \/login\n    .loginProcessingUrl(&quot;\/login&quot;) \/\/ \u7528\u6237\u767b\u5f55\u903b\u8f91\u8bf7\u6c42\u5730\u5740\u662f\u4ec0\u4e48\u3002 \u9ed8\u8ba4\u662f \/login\n    .failureForwardUrl(&quot;\/failure&quot;); \/\/ \u767b\u5f55\u5931\u8d25\u540e\uff0c\u8bf7\u6c42\u8f6c\u53d1\u7684\u4f4d\u7f6e\u3002Security\u8bf7\u6c42\u8f6c\u53d1\u4f7f\u7528Post\u8bf7\u6c42\u3002\u9ed8\u8ba4\u8f6c\u53d1\u5230\uff1a loginPage?error\n    .successForwardUrl(&quot;\/toMain&quot;); \/\/ \u7528\u6237\u767b\u5f55\u6210\u529f\u540e\uff0c\u8bf7\u6c42\u8f6c\u53d1\u5230\u7684\u4f4d\u7f6e\u3002Security\u8bf7\u6c42\u8f6c\u53d1\u4f7f\u7528POST\u8bf7\u6c42\u3002<\/code><\/pre>\n<h3>\u65b9\u5f0f\u4e8c \uff1a\u91cd\u5b9a\u5411<\/h3>\n<pre><code class=\"java\">http.formLogin()\n    .usernameParameter(&quot;name&quot;) \/\/ \u8bbe\u7f6e\u8bf7\u6c42\u53c2\u6570\u4e2d\uff0c\u7528\u6237\u540d\u53c2\u6570\u540d\u79f0\u3002 \u9ed8\u8ba4username\n    .passwordParameter(&quot;pswd&quot;) \/\/ \u8bbe\u7f6e\u8bf7\u6c42\u53c2\u6570\u4e2d\uff0c\u5bc6\u7801\u53c2\u6570\u540d\u79f0\u3002 \u9ed8\u8ba4password\n    .loginPage(&quot;\/toLogin&quot;) \/\/ \u5f53\u7528\u6237\u672a\u767b\u5f55\u7684\u65f6\u5019\uff0c\u8df3\u8f6c\u7684\u767b\u5f55\u9875\u9762\u5730\u5740\u662f\u4ec0\u4e48\uff1f \u9ed8\u8ba4 \/login\n    .loginProcessingUrl(&quot;\/login&quot;) \/\/ \u7528\u6237\u767b\u5f55\u903b\u8f91\u8bf7\u6c42\u5730\u5740\u662f\u4ec0\u4e48\u3002 \u9ed8\u8ba4\u662f \/login\n    .defaultSuccessUrl(&quot;\/toMain&quot;,true); \/\/\u7528\u6237\u767b\u5f55\u6210\u529f\u540e\uff0c\u54cd\u5e94\u91cd\u5b9a\u5411\u5230\u7684\u4f4d\u7f6e\u3002 GET\u8bf7\u6c42\u3002\u5fc5\u987b\u914d\u7f6e\u7edd\u5bf9\u5730\u5740\u3002\n     .failureUrl(&quot;\/failure&quot;); \/\/ \u767b\u5f55\u5931\u8d25\u540e\uff0c\u91cd\u5b9a\u5411\u7684\u4f4d\u7f6e\u3002<\/code><\/pre>\n<h3>\u65b9\u5f0f\u4e09\uff1a\u81ea\u5b9a\u4e49\u767b\u5f55\u5904\u7406\u5668<\/h3>\n<h4>\u81ea\u5b9a\u4e49\u767b\u5f55\u5931\u8d25\u903b\u8f91\u5904\u7406\u5668<\/h4>\n<pre><code class=\"java\">\/*\u81ea\u5b9a\u4e49\u767b\u5f55\u5931\u8d25\u5904\u7406\u5668*\/\npublic class MyAuthenticationFailureHandler implements AuthenticationFailureHandler {\n    private  String url;\n    private boolean isRedirect;\n\n\n    public MyAuthenticationFailureHandler(String url, boolean isRedirect) {\n        this.url = url;\n        this.isRedirect = isRedirect;\n    }\n\n    @Override\n    public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {\n        if (isRedirect){\n            httpServletResponse.sendRedirect(url);\n        }else {\n            httpServletRequest.getRequestDispatcher(url).forward(httpServletRequest,httpServletResponse);\n        }\n    }\n\n\/\/get set \u65b9\u6cd5 \u7701\u7565<\/code><\/pre>\n<h4>\u81ea\u5b9a\u4e49\u767b\u5f55\u6210\u529f\u903b\u8f91\u5904\u7406\u5668<\/h4>\n<pre><code class=\"java\">\/**\n * \u81ea\u5b9a\u4e49\u767b\u5f55\u6210\u529f\u540e\u5904\u7406\u5668\n * \u8f6c\u53d1\u91cd\u5b9a\u5411\uff0c\u6709\u4ee3\u7801\u903b\u8f91\u5b9e\u73b0\n * *\/\npublic class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {\n    private String url;\n    private boolean isRedirect;\n\n    public MyAuthenticationSuccessHandler(String url, boolean isRedirect) {\n        this.url = url;\n        this.isRedirect = isRedirect;\n    }\n\n    \/**\n     * @param request \u8bf7\u6c42\u5bf9\u8c61 request.getRequestDispatcher.forward()\n     * @param response \u54cd\u5e94\u5bf9\u8c61 response.sendRedirect()\n     * @param authentication \u7528\u6237\u8ba4\u8bc1\u6210\u529f\u540e\u7684\u5bf9\u8c61\u3002\u5176\u4e2d\u62a5\u6362\u7528\u6237\u540d\u6743\u9650\u7ed3\u5408\uff0c\u5185\u5bb9\u662f\n     *                       \u81ea\u5b9a\u4e49UserDetailsService\n     * *\/\n    @Override\n    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {\n        if (isRedirect){\n            response.sendRedirect(url);\n        }else {\n            request.getRequestDispatcher(url).forward(request,response);\n        }\n    }\n\n\/\/get set \u65b9\u6cd5 \u7701\u7565   \nhttp.formLogin()\n    .usernameParameter(&quot;name&quot;) \/\/ \u8bbe\u7f6e\u8bf7\u6c42\u53c2\u6570\u4e2d\uff0c\u7528\u6237\u540d\u53c2\u6570\u540d\u79f0\u3002 \u9ed8\u8ba4username\n    .passwordParameter(&quot;pswd&quot;) \/\/ \u8bbe\u7f6e\u8bf7\u6c42\u53c2\u6570\u4e2d\uff0c\u5bc6\u7801\u53c2\u6570\u540d\u79f0\u3002 \u9ed8\u8ba4password\n    .loginPage(&quot;\/toLogin&quot;) \/\/ \u5f53\u7528\u6237\u672a\u767b\u5f55\u7684\u65f6\u5019\uff0c\u8df3\u8f6c\u7684\u767b\u5f55\u9875\u9762\u5730\u5740\u662f\u4ec0\u4e48\uff1f \u9ed8\u8ba4 \/login\n    .loginProcessingUrl(&quot;\/login&quot;) \/\/ \u7528\u6237\u767b\u5f55\u903b\u8f91\u8bf7\u6c42\u5730\u5740\u662f\u4ec0\u4e48\u3002 \u9ed8\u8ba4\u662f \/login<\/code><\/pre>\n<h2>\u767b\u5f55\u76f8\u5173\u914d\u7f6e\u7c7b<\/h2>\n<pre><code class=\"java\">@Configuration\n@EnableWebSecurity\npublic class SecurityConfig extends WebSecurityConfigurerAdapter {\n\n    @Autowired\n    private  UserSecurity userSecurity;\n    @Autowired\n    private PersistentTokenRepository persistentTokenRepository;\n\n\n    \/**\n     * \u52a0\u5bc6\n     * @return \u52a0\u5bc6\u5bf9\u8c61\n     * \u5982\u9700\u4f7f\u7528\u81ea\u5b9a\u4e49\u52a0\u5bc6\u903b\u8f91 \u8fd4\u56de\u81ea\u5b9a\u4e49\u52a0\u5bc6\u5bf9\u8c61\n     * return new MD5PasswordEncoder(); return new SimplePasswordEncoder();\n     *\/\n    @Bean\n    public PasswordEncoder passwordEncoder() {\n        return new BCryptPasswordEncoder(); \/\/Spring Security \u81ea\u5e26\n    }\n\n    @Override\n    protected void configure(HttpSecurity http) throws Exception {\n        \/\/ \u914d\u7f6e\u767b\u5f55\u8bf7\u6c42\u76f8\u5173\u5185\u5bb9\u3002\n        http.formLogin()\n            .loginPage(&quot;\/toLogin&quot;) \/\/ \u5f53\u7528\u6237\u672a\u767b\u5f55\u7684\u65f6\u5019\uff0c\u8df3\u8f6c\u7684\u767b\u5f55\u9875\u9762\u5730\u5740\u662f\u4ec0\u4e48\uff1f \u9ed8\u8ba4 \/login\n            .usernameParameter(&quot;name&quot;) \/\/ \u8bbe\u7f6e\u8bf7\u6c42\u53c2\u6570\u4e2d\uff0c\u7528\u6237\u540d\u53c2\u6570\u540d\u79f0\u3002 \u9ed8\u8ba4username\n            .passwordParameter(&quot;pswd&quot;) \/\/ \u8bbe\u7f6e\u8bf7\u6c42\u53c2\u6570\u4e2d\uff0c\u5bc6\u7801\u53c2\u6570\u540d\u79f0\u3002 \u9ed8\u8ba4password\n            .loginProcessingUrl(&quot;\/login&quot;) \/\/\u8bbe\u7f6e\u767b\u5f55 \u63d0\u4ea4\u8868\u5355\u6570\u636e\u8bbf\u95ee\u8bf7\u6c42\u5730\u5740\n            .defaultSuccessUrl(&quot;\/toMain&quot;)   \n            .failureUrl(&quot;\/toLogin&quot;);\n            \/\/.successForwardUrl(&quot;\/toMain&quot;)\n               \/\/.failureForwardUrl(&quot;\/toLogin&quot;);\n            \/\/.successHandler(new LoginSuccessHandler(&quot;\/toMain&quot;, true)) \/\/\u81ea\u5b9a\u4e49\u767b\u5f55\u6210\u529f\u5904\u7406\u5668\n                \/\/.failureHandler(new LoginErrorHandler(&quot;\/toLogin&quot;, true));\n\n        http.authorizeRequests()\n            \/\/.antMatchers(&quot;\/toLogin&quot;).anonymous() \/\/\u53ea\u80fd\u533f\u540d\u7528\u6237\u8bbf\u95ee\n            .antMatchers(&quot;\/toLogin&quot;, &quot;\/register&quot;, &quot;\/login&quot;, &quot;\/favicon.ico&quot;).permitAll() \/\/ \/toLogin\u8bf7\u6c42\u5730\u5740\uff0c\u53ef\u4ee5\u968f\u4fbf\u8bbf\u95ee\u3002\n            .antMatchers(&quot;\/**\/*.js&quot;).permitAll() \/\/ \u6388\u4e88\u6240\u6709\u76ee\u5f55\u4e0b\u7684\u6240\u6709.js\u6587\u4ef6\u53ef\u8bbf\u95ee\u6743\u9650\n            .regexMatchers(&quot;.*[.]css&quot;).permitAll() \/\/ \u6388\u4e88\u6240\u6709\u76ee\u5f55\u4e0b\u7684\u6240\u6709.css\u6587\u4ef6\u53ef\u8bbf\u95ee\u6743\u9650\n            .anyRequest().authenticated(); \/\/ \u4efb\u610f\u7684\u8bf7\u6c42\uff0c\u90fd\u5fc5\u987b\u8ba4\u8bc1\u540e\u624d\u80fd\u8bbf\u95ee\u3002\n\n\n        \/\/ \u914d\u7f6e\u9000\u51fa\u767b\u5f55\n        http.logout()\n                .invalidateHttpSession(true) \/\/ \u56de\u6536HttpSession\u5bf9\u8c61\u3002\u9000\u51fa\u4e4b\u524d\u8c03\u7528HttpSession.invalidate() \u9ed8\u8ba4 true\n                .clearAuthentication(true) \/\/ \u9000\u51fa\u4e4b\u524d\uff0c\u6e05\u7a7aSecurity\u8bb0\u5f55\u7684\u7528\u6237\u767b\u5f55\u6807\u8bb0\u3002 \u9ed8\u8ba4 true\n                \/\/ .addLogoutHandler() \/\/ \u589e\u52a0\u9000\u51fa\u5904\u7406\u5668\u3002\n                .logoutSuccessUrl(&quot;\/&quot;) \/\/ \u914d\u7f6e\u9000\u51fa\u540e\uff0c\u8fdb\u5165\u7684\u8bf7\u6c42\u5730\u5740\u3002 \u9ed8\u8ba4\u662floginPage?logout\n                .logoutUrl(&quot;\/logout&quot;); \/\/ \u914d\u7f6e\u9000\u51fa\u767b\u5f55\u7684\u8def\u5f84\u5730\u5740\u3002\u548c\u9875\u9762\u8bf7\u6c42\u5730\u5740\u4e00\u81f4\u5373\u53ef\u3002\n\n        \/\/ \u5173\u95edCSRF\u5b89\u5168\u534f\u8bae\u3002\n        \/\/ \u5173\u95ed\u662f\u4e3a\u4e86\u4fdd\u8bc1\u5b8c\u6574\u6d41\u7a0b\u7684\u53ef\u7528\u3002\n        http.csrf().disable();\n    }\n\n\n   @Bean\n   public PersistentTokenRepository persistentTokenRepository(DataSource dataSource){\n        JdbcTokenRepositoryImpl jdbcTokenRepository = new JdbcTokenRepositoryImpl();\n        jdbcTokenRepository.setDataSource(dataSource);\n        \/\/jdbcTokenRepository.setCreateTableOnStartup(true);\n        return jdbcTokenRepository;\n    }\n\n}<\/code><\/pre>\n<h2>\u89d2\u8272\u6743\u9650<\/h2>\n<blockquote><p><strong>hasAuthority(String)<\/strong>   \u5224\u65ad\u89d2\u8272\u662f\u5426\u5177\u6709\u7279\u5b9a\u6743\u9650<\/p><\/blockquote>\n<pre><code class=\"java\">http.authorizeRequests().antMatchers(&quot;\/main1.html&quot;).hasAuthority(&quot;admin&quot;)<\/code><\/pre>\n<blockquote><p><strong>hasAnyAuthority(String &#8230;)<\/strong>  \u5982\u679c\u7528\u6237\u5177\u5907\u7ed9\u5b9a\u6743\u9650\u4e2d\u67d0\u4e00\u4e2a\uff0c\u5c31\u5141\u8bb8\u8bbf\u95ee<\/p><\/blockquote>\n<pre><code class=\"java\">http.authorizeRequests().antMatchers(&quot;\/admin\/read&quot;).hasAnyAuthority(&quot;xxx&quot;,&quot;xxx&quot;) <\/code><\/pre>\n<blockquote><p><strong>hasRole(String)<\/strong>  \u5982\u679c\u7528\u6237\u5177\u5907\u7ed9\u5b9a\u89d2\u8272\u5c31\u5141\u8bb8\u8bbf\u95ee\u3002\u5426\u5219\u51fa\u73b0403<\/p><\/blockquote>\n<pre><code class=\"java\">\/\/\u8bf7\u6c42\u5730\u5740\u4e3a\/admin\/read\u7684\u8bf7\u6c42\uff0c\u5fc5\u987b\u767b\u5f55\u7528\u6237\u62e5\u6709'\u7ba1\u7406\u5458'\u89d2\u8272\u624d\u53ef\u8bbf\u95ee\nhttp.authorizeRequests().antMatchers(&quot;\/admin\/read&quot;).hasRole(&quot;\u7ba1\u7406\u5458&quot;) <\/code><\/pre>\n<blockquote><p><strong>hasAnyRole(String &#8230;)<\/strong> \u5982\u679c\u7528\u6237\u5177\u5907\u7ed9\u5b9a\u89d2\u8272\u7684\u4efb\u610f\u4e00\u4e2a\uff0c\u5c31\u5141\u8bb8\u88ab\u8bbf\u95ee<\/p><\/blockquote>\n<pre><code class=\"java\">\/\/\u7528\u6237\u62e5\u6709\u89d2\u8272\u662f\u7ba1\u7406\u5458 \u6216 \u8bbf\u5ba2 \u53ef\u4ee5\u8bbf\u95ee \/guest\/read\nhttp.authorizeRequests().antMatchers(&quot;\/guest\/read&quot;).hasAnyRole(&quot;\u7ba1\u7406\u5458&quot;, &quot;\u8bbf\u5ba2&quot;)<\/code><\/pre>\n<blockquote><p><strong>hasIpAddress(String)<\/strong> \u8bf7\u6c42\u662f\u6307\u5b9a\u7684IP\u5c31\u8fd0\u884c\u8bbf\u95ee<\/p><\/blockquote>\n<pre><code class=\"java\">\/\/ip \u662f127.0.0.1 \u7684\u8bf7\u6c42 \u53ef\u4ee5\u8bbf\u95ee\/ip\nhttp.authorizeRequests().antMatchers(&quot;\/ip&quot;).hasIpAddress(&quot;127.0.0.1&quot;)<\/code><\/pre>\n<h2>403 \u6743\u9650\u4e0d\u8db3\u9875\u9762\u5904\u7406<\/h2>\n<p>1.\u7f16\u5199\u7c7b\u5b9e\u73b0\u63a5\u53e3<strong>AccessDeniedHandler<\/strong><\/p>\n<pre><code class=\"java\">\/**\n * @describe  403 \u6743\u9650\u4e0d\u8db3\n * @author: AnyWhere\n * @date 2021\/4\/18 20:57\n *\/\n@Component\npublic class MyAccessDeniedHandler implements AccessDeniedHandler {\n    @Override\n    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) \n            throws IOException, ServletException {\n\n        response.setStatus(HttpServletResponse.SC_OK);\n\n        response.setContentType(&quot;text\/html;charset=UTF-8&quot;);\n\n        response.getWriter().write(\n                &quot;&lt;html&gt;&quot; +\n                        &quot;&lt;body&gt;&quot; +\n                        &quot;&lt;div style='width:800px;text-align:center;margin:auto;font-size:24px'&gt;&quot; +\n                        &quot;\u6743\u9650\u4e0d\u8db3\uff0c\u8bf7\u8054\u7cfb\u7ba1\u7406\u5458&quot; +\n                        &quot;&lt;\/div&gt;&quot; +\n                        &quot;&lt;\/body&gt;&quot; +\n                        &quot;&lt;\/html&gt;&quot;\n\n        );\n\n        response.getWriter().flush();\/\/\u5237\u65b0\u7f13\u51b2\u533a\n    }\n}<\/code><\/pre>\n<p>2.\u914d\u7f6e\u7c7b\u4e2d\u914d\u7f6eexceptionHandling<\/p>\n<pre><code class=\"java\">\/\/ \u914d\u7f6e403\u8bbf\u95ee\u9519\u8bef\u5904\u7406\u5668\u3002\nhttp.exceptionHandling().accessDeniedHandler(myAccessDeniedHandler);\/<\/code><\/pre>\n<h2>RememberMe\uff08\u8bb0\u4f4f\u6211\uff09<\/h2>\n<pre><code class=\"java\">@Configuration\n@EnableWebSecurity\npublic class SecurityConfig extends WebSecurityConfigurerAdapter {\n  @Override\n  protected void configure(HttpSecurity http) throws Exception {\n    \/\/\u914d\u7f6e\u8bb0\u4f4f\u5bc6\u7801\n    http.rememberMe()\n        .rememberMeParameter(&quot;remember-me&quot;) \/\/ \u4fee\u6539\u8bf7\u6c42\u53c2\u6570\u540d\u3002 \u9ed8\u8ba4\u662fremember-me\n        .tokenValiditySeconds(14*24*60*60) \/\/ \u8bbe\u7f6e\u8bb0\u4f4f\u6211\u6709\u6548\u65f6\u95f4\u3002\u5355\u4f4d\u662f\u79d2\u3002\u9ed8\u8ba4\u662f14\u5929\n        .rememberMeCookieName(&quot;remember-me&quot;) \/\/ \u4fee\u6539remember me\u7684cookie\u540d\u79f0\u3002\u9ed8\u8ba4\u662fremember-me\n        .tokenRepository(persistentTokenRepository) \/\/ \u914d\u7f6e\u7528\u6237\u767b\u5f55\u6807\u8bb0\u7684\u6301\u4e45\u5316\u5de5\u5177\u5bf9\u8c61\u3002\n        .userDetailsService(userSecurity); \/\/ \u914d\u7f6e\u81ea\u5b9a\u4e49\u7684UserDetailsService\u63a5\u53e3\u5b9e\u73b0\u7c7b\u5bf9\u8c61\n\n  }\n  @Bean\n  public PersistentTokenRepository persistentTokenRepository(DataSource dataSource){\n     JdbcTokenRepositoryImpl jdbcTokenRepository = new JdbcTokenRepositoryImpl();\n     jdbcTokenRepository.setDataSource(dataSource);\n     \/\/jdbcTokenRepository.setCreateTableOnStartup(true);\n     return jdbcTokenRepository;\n  }\n}   <\/code><\/pre>\n<h2>Spring Security \u6ce8\u89e3<\/h2>\n<h3>@Secured<\/h3>\n<blockquote>\n<p>\u89d2\u8272\u6821\u9a8c ,\u8bf7\u6c42\u5230\u6765\u8bbf\u95ee\u63a7\u5236\u5355\u5143\u65b9\u6cd5\u65f6\u5fc5\u987b\u5305\u542bXX\u89d2\u8272\u624d\u80fd\u8bbf\u95ee<\/p>\n<p>\u89d2\u8272\u5fc5\u987b\u6dfb\u52a0ROLE_\u524d\u7f00<\/p>\n<\/blockquote>\n<pre><code class=\"java\">  @Secured({&quot;ROLE_\u7ba1\u7406\u5458&quot;,&quot;ROLE_\u8bbf\u5ba2&quot;})\n  @RequestMapping(&quot;\/toMain&quot;)\n  public String toMain(){\n      return &quot;main&quot;;\n  }<\/code><\/pre>\n<p>\u4f7f\u7528\u6ce8\u89e3@Secured\u9700\u8981\u5728\u914d\u7f6e\u7c7b\u4e2d\u6dfb\u52a0\u6ce8\u89e3 \u4f7f@Secured\u6ce8\u89e3\u751f\u6548<\/p>\n<pre><code class=\"java\">@EnableGlobalMethodSecurity(securedEnabled = true)<\/code><\/pre>\n<h3>@PreAuthorize<\/h3>\n<blockquote><p>\u6743\u9650\u68c0\u9a8c,\u8bf7\u6c42\u5230\u6765\u8bbf\u95ee\u63a7\u5236\u5355\u5143\u4e4b\u524d\u5fc5\u987b\u5305\u542bxx\u6743\u9650\u624d\u80fd\u8bbf\u95ee\uff0c\u63a7\u5236\u5355\u5143\u65b9\u6cd5\u6267\u884c\u524d\u8fdb\u884c\u89d2\u8272\u6821\u9a8c<\/p><\/blockquote>\n<pre><code class=\"java\">   \/**\n     * [ROLE_\u7ba1\u7406\u5458, admin:read, admin:write, all:login, all:logout, all:error, all:toMain]\n     * @PreAuthorize   \u89d2\u8272 \u3001\u6743\u9650 \u6821\u9a8c \u65b9\u6cd5\u6267\u884c\u524d\u8fdb\u884c\u89d2\u8272\u6821\u9a8c\n     *\n     *  hasAnyAuthority() \n     *  hasAuthority()\n     *\n     *  hasPermission()\n     *\n     *\n     *  hasRole()   \n     *  hasAnyRole()\n     * *\/\n\n    @PreAuthorize(&quot;hasAnyRole('ROLE_\u7ba1\u7406\u5458','ROLE_\u8bbf\u5ba2')&quot;)\n    @RequestMapping(&quot;\/toMain&quot;)\n    @PreAuthorize(&quot;hasAuthority('admin:write')&quot;)\n    public String toMain(){\n        return &quot;main&quot;;\n    }<\/code><\/pre>\n<p>\u4f7f\u7528<code>@PreAuthorize<\/code>\u548c<code>@PostAuthorize<\/code> \u9700\u8981\u5728\u914d\u7f6e\u7c7b\u4e2d\u914d\u7f6e\u6ce8\u89e3@EnableGlobalMethodSecurity \u624d\u80fd\u751f\u6548<\/p>\n<pre><code class=\"java\">@EnableGlobalMethodSecurity(prePostEnabled = true)<\/code><\/pre>\n<h3>@PostAuthorize<\/h3>\n<blockquote><p>\u6743\u9650\u68c0\u9a8c,\u8bf7\u6c42\u5230\u6765\u8bbf\u95ee\u63a7\u5236\u5355\u5143\u4e4b\u540e\u5fc5\u987b\u5305\u542bxx\u6743\u9650\u624d\u80fd\u8bbf\u95ee \uff0c\u63a7\u5236\u5355\u5143\u65b9\u6cd5\u6267\u884c\u5b8c\u540e\u8fdb\u884c\u89d2\u8272\u6821\u9a8c<\/p><\/blockquote>\n<pre><code class=\"java\">   \/**\n     * [ROLE_\u7ba1\u7406\u5458, admin:read, admin:write, all:login, all:logout, all:error, all:toMain]\n     * @PostAuthorize  \u89d2\u8272 \u3001\u6743\u9650 \u6821\u9a8c \u65b9\u6cd5\u6267\u884c\u540e\u8fdb\u884c\u89d2\u8272\u6821\u9a8c\n     *\n     *  hasAnyAuthority()\n     *  hasAuthority()\n     *  hasPermission()\n     *  hasRole()\n     *  hasAnyRole()\n     * *\/\n\n    @PostAuthorize(&quot;hasRole('ROLE_\u7ba1\u7406\u5458')&quot;)\n    @RequestMapping(&quot;\/toMain&quot;)\n    @PreAuthorize(&quot;hasAuthority('admin:write')&quot;)\n    public String toMain(){\n        return &quot;main&quot;;\n    }<\/code><\/pre>\n<h2>Spring Security \u6574\u5408Thymeleaf \u8fdb\u884c\u6743\u9650\u6821\u9a8c<\/h2>\n<pre><code class=\"xml\">&lt;dependency&gt;\n      &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n      &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;\/artifactId&gt;\n&lt;\/dependency&gt;\n\n&lt;dependency&gt;\n     &lt;groupId&gt;org.thymeleaf.extras&lt;\/groupId&gt;\n     &lt;artifactId&gt;thymeleaf-extras-springsecurity5&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n<h2>Spring Security\u4e2dCSRF<\/h2>\n<h3>\u4ec0\u4e48\u662fCSRF?<\/h3>\n<p>CSRF\uff08Cross-site request forgery\uff09\u8de8\u7ad9\u8bf7\u6c42\u4f2a\u9020\uff0c\u4e5f\u88ab\u79f0\u4e3a\u201cOne Click Attack\u201d \u6216\u8005Session Riding\u3002\u901a\u8fc7\u4f2a\u9020\u7528\u6237\u8bf7\u6c42\u8bbf\u95ee\u53d7\u4fe1\u4efb\u7ad9\u70b9\u7684\u975e\u6cd5\u8bf7\u6c42\u8bbf\u95ee\u3002<\/p>\n<p>\u8de8\u57df\uff1a\u53ea\u8981\u7f51\u7edc\u534f\u8bae\uff0cip\u5730\u5740\uff0c\u7aef\u53e3\u4e2d\u4efb\u4f55\u4e00\u4e2a\u4e0d\u76f8\u540c\u5c31\u662f\u8de8\u57df\u8bf7\u6c42\u3002<\/p>\n<p>\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u8fdb\u884c\u4ea4\u4e92\u65f6\uff0c\u7531\u4e8ehttp\u534f\u8bae\u672c\u8eab\u662f\u65e0\u72b6\u6001\u534f\u8bae\uff0c\u6240\u4ee5\u5f15\u5165\u4e86cookie\u8fdb\u884c\u8bb0\u5f55\u5ba2\u6237\u7aef\u8eab\u4efd\u3002\u5728cookie\u4e2d\u4f1a\u5b58\u653esession id\u7528\u6765\u8bc6\u522b\u5ba2\u6237\u7aef\u8eab\u4efd\u7684\u3002\u5728\u8de8\u57df\u7684\u60c5\u51b5\u4e0b\uff0csession id\u53ef\u80fd\u88ab\u7b2c\u4e09\u65b9\u6076\u610f\u52ab\u6301\uff0c\u901a\u8fc7\u8fd9\u4e2asession id\u5411\u670d\u52a1\u7aef\u53d1\u8d77\u8bf7\u6c42\u65f6\uff0c\u670d\u52a1\u7aef\u4f1a\u8ba4\u4e3a\u8fd9\u4e2a\u8bf7\u6c42\u662f\u5408\u6cd5\u7684\uff0c\u53ef\u80fd\u53d1\u751f\u5f88\u591a\u610f\u60f3\u4e0d\u5230\u7684\u4e8b\u60c5\u3002<\/p>\n<p>\u901a\u4fd7\u89e3\u91ca\uff1a<\/p>\n<p>CSRF\u5c31\u662f\u522b\u7684\u7f51\u7ad9\u975e\u6cd5\u83b7\u53d6\u6211\u4eec\u7f51\u7ad9Cookie\u503c\uff0c\u6211\u4eec\u9879\u76ee\u670d\u52a1\u5668\u662f\u65e0\u6cd5\u533a\u5206\u5230\u5e95\u662f\u4e0d\u662f\u6211\u4eec\u7684\u5ba2\u6237\u7aef\uff0c\u53ea\u6709\u8bf7\u6c42\u4e2d\u6709Cookie\uff0c\u8ba4\u4e3a\u662f\u81ea\u5df1\u7684\u5ba2\u6237\u7aef\uff0c\u6240\u4ee5\u8fd9\u4e2a\u65f6\u5019\u5c31\u51fa\u73b0\u4e86CSRF\u3002<\/p>\n<p><strong>\u8fd1\u671f\u70ed\u6587\u63a8\u8350\uff1a<\/strong><\/p>\n<p>1.<a href=\"https:\/\/link.segmentfault.com\/?enc=QEB2YAYLMCFfESY5fm4DVQ%3D%3D.rZO4uaKtakvW0FJ1rF7bkAGWct8V0HFCC4epwEjiqYU%3D\" rel=\"nofollow\">1,000+ \u9053 Java\u9762\u8bd5\u9898\u53ca\u7b54\u6848\u6574\u7406(2022\u6700\u65b0\u7248)<\/a><\/p>\n<p>2.<a href=\"https:\/\/link.segmentfault.com\/?enc=tIomrkkOcrpIXlvAJB%2BXIQ%3D%3D.Q3lEfvf6ysJ2t01J41rtCTlL%2BWMBi5Gnhc4p%2FzLcDfVuAOAToklHJCVVahaLIN592%2BjTOInfbbiYvSUJbCbpVHXl3KsMpgwQACCl8j%2FwbqY%3D\" rel=\"nofollow\">\u52b2\u7206\uff01Java \u534f\u7a0b\u8981\u6765\u4e86\u3002\u3002\u3002<\/a><\/p>\n<p>3.<a href=\"https:\/\/link.segmentfault.com\/?enc=2MXGb%2FPEjbyBdXw0SsZJPw%3D%3D.v3e2RnyCsL%2BHVpQqtJL2b1Ols%2FGZtqyL%2BqjZ0ZmLR0dcbAk6XIXecgfwCiP9MNqZ\" rel=\"nofollow\">Spring Boot 2.x \u6559\u7a0b\uff0c\u592a\u5168\u4e86\uff01<\/a><\/p>\n<p>4.<a href=\"https:\/\/link.segmentfault.com\/?enc=qRArl4fQzNDu8BTdHcnbgQ%3D%3D.3upWx%2BO7dF9AmW%2FRchET2a3lXqMg1LKe7Jh74sKsosS%2B8XHHtKmZF6a%2BFR2sqdar377E1UUYuHUo%2For4NcLa4JBrFP7JCku3IrvsWeJF5zs%3D\" rel=\"nofollow\">\u522b\u518d\u5199\u6ee1\u5c4f\u7684\u7206\u7206\u7206\u70b8\u7c7b\u4e86\uff0c\u8bd5\u8bd5\u88c5\u9970\u5668\u6a21\u5f0f\uff0c\u8fd9\u624d\u662f\u4f18\u96c5\u7684\u65b9\u5f0f\uff01\uff01<\/a><\/p>\n<p>5.<a href=\"https:\/\/link.segmentfault.com\/?enc=qyxS%2BJY8apNwXvMePaKwUA%3D%3D.ufVAfZsXKOEwJU1TGby5%2F3i5fmJ%2BPFuxw7IAhe2%2FbGCB1bZirgP6Ruq%2B%2Btts4IMVvNx0z3THeOuzkLTIKCAFB4mZz1o5EtehpKptEzxxnwJ%2B%2FrLkkqko1uWE0XJdIx9r\" rel=\"nofollow\">\u300aJava\u5f00\u53d1\u624b\u518c\uff08\u5d69\u5c71\u7248\uff09\u300b\u6700\u65b0\u53d1\u5e03\uff0c\u901f\u901f\u4e0b\u8f7d\uff01<\/a><\/p>\n<p>\u89c9\u5f97\u4e0d\u9519\uff0c\u522b\u5fd8\u4e86\u968f\u624b\u70b9\u8d5e+\u8f6c\u53d1\u54e6\uff01<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042290891\">https:\/\/segmentfault.com\/a\/1190000042290891<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1a\u6e05\u8336\u6de1\u7ca5\u9171\/\u94fe\u63a5\uff1ahttps:\/\/juejin.cn\/post\/702673&#8230; Spring [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-10006153","post","type-post","status-publish","format-standard","hentry"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006153"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006153\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}