{"id":554943,"date":"2022-02-16T06:44:55","date_gmt":"2022-02-15T22:44:55","guid":{"rendered":"http:\/\/4563.org\/?p=554943"},"modified":"2022-02-16T06:44:55","modified_gmt":"2022-02-15T22:44:55","slug":"%e6%b1%82%e5%8a%a9%e5%b8%96%ef%bc%9a-spring-security-%e5%a6%82%e4%bd%95%e5%b0%86-token-%e8%bd%ac%e6%8d%a2%e6%88%90-authentication-%e7%b1%bb%ef%bc%9f-2","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=554943","title":{"rendered":"\u6c42\u52a9\u5e16\uff1a Spring Security \u5982\u4f55\u5c06 token \u8f6c\u6362\u6210 Authentication \u7c7b\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1> \u6c42\u52a9\u5e16\uff1a Spring Security \u5982\u4f55\u5c06 token \u8f6c\u6362\u6210 Authentication \u7c7b\uff1f <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : winRain <\/span>  <span><i><\/i> 18<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5f66\u7956\u4eec\uff0c\u6211\u6700\u8fd1\u5728\u7528 keycloak \u505a\u8ba4\u8bc1\uff0c\u540e\u7aef\u4f7f\u7528 spring security \u548c keycloak spring security adapter \u8fdb\u884c\u5b89\u5168\u4fdd\u62a4\u3002<\/p>\n<p>\u5f53\u6211\u4f7f\u7528 client \u4ece keycloak \u83b7\u53d6\u5230\u4e86 token \uff0c\u7528 token \u53bb\u8c03\u7528\u540e\u7aef api \u7684\u65f6\u5019\uff0c\u5728 <code>KeycloakAuthenticationProcessingFilter<\/code> 180 \u884c\u4e2d\uff0c\u662f\u76f4\u63a5\u53bb <code>SecurityContext<\/code>\u4e2d\u62ff\u5230\u4e86\u672a\u8ba4\u8bc1\u7684 Authentication \u3002<\/p>\n<p>\u6211\u60f3\u77e5\u9053 token \u662f\u4ec0\u4e48\u65f6\u5019\u8f6c\u6362\u6210\u4e86 Authentication \u5e76\u653e\u8fdb SecurityContext \u4e2d\u53bb\u7684\uff1f\u6211\u80fd\u4e0d\u80fd\u901a\u8fc7\u5b9e\u73b0\u5b50\u7c7b\u4fee\u6539\u903b\u8f91\uff1f<\/p>\n<p>\u5404\u4f4d\u5927\u4f6c\u5e2e\u5e2e\u5fd9\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>) <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"7125940\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Oktfolio <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> \u591a\u770b\u770b\u6e90\u7801\u5427\uff0c\u80fd\u627e\u5230\u7684\u3002<br \/>class extends AbstractAuthenticationToken<br \/>AuthenticationFilter#attemptAuthentication(HttpServletRequest request, HttpServletResponse response)<br \/>AuthenticationFilter#successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authentication) <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7125941\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : damai0419 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> keycloak \u6ca1\u7528\u8fc7\u3002<br \/>\u4f46 spring cloud gateway \u548c security \u7ed3\u5408\u7684\u65f6\u5019\uff0c\u662f\u5728 ServerSecurityContextRepository \u7684\u5b50\u7c7b\u4e2d\u8fdb\u884c\u8f6c\u6362\u64cd\u4f5c\u7684\u3002 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7125942\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : winRain <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> \u8c22\u8c22\u4e24\u4f4d\u8001\u54e5\uff0c\u6211\u4ed4\u7ec6\u770b\u4e86\u4e0b\u6e90\u7801\uff0c\u5df2\u7ecf\u627e\u5230\u539f\u56e0\u4e86 <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6c42\u52a9\u5e16\uff1a Spring Secur&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/554943"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=554943"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/554943\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=554943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=554943"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=554943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}