{"id":1423,"date":"2023-03-20T21:50:45","date_gmt":"2023-03-20T13:50:45","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1423"},"modified":"2023-04-28T21:04:20","modified_gmt":"2023-04-28T13:04:20","slug":"detailed-explanation-of-loading-priority-for-authentication-services-resource-services-and-web-security-configuration-services-in-spring-security-oauth2","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/20\/detailed-explanation-of-loading-priority-for-authentication-services-resource-services-and-web-security-configuration-services-in-spring-security-oauth2\/","title":{"rendered":"Spring Security OAuth2\u4e4b\u8ba4\u8bc1\u670d\u52a1\u3001\u8d44\u6e90\u670d\u52a1\u3001web\u5b89\u5168\u914d\u7f6e\u670d\u52a1\u52a0\u8f7d\u4f18\u5148\u7ea7\u8be6\u89e3"},"content":{"rendered":"<p>\u642d\u5efaSpring Security OAuth2\u8ba4\u8bc1\u670d\u52a1\uff0c\u7ecf\u5e38\u4f1a\u9047\u5230\u5728\u8d44\u6e90\u670d\u52a1\u5668\u4e2d\u914d\u7f6e\u751f\u6548\uff0c\u4f46\u662f\u5728web\u5b89\u5168\u914d\u7f6e\u7c7b\u4e2d\u914d\u7f6e\u5c31\u4e0d\u751f\u6548\u7b49\u7b49\u7c7b\u4f3c\u7684\u95ee\u9898\uff0c\u6df1\u5165\u7814\u7a76\u4e86\u4e0b\u539f\u6765\u662f\u4e09\u4e2a\u7c7b\u5728IOC\u5bb9\u5668\u4e4b\u4e2d\u52a0\u8f7d\u7684\u4f18\u5148\u7ea7\u95ee\u9898\u6240\u9020\u6210\u7684\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u4e00\u6b65\u4e00\u6b65\u6765\u5206\u6790\u4e0b\u4e09\u4e2a\u7c7b\u7684\u4f18\u5148\u7ea7\u95ee\u9898\uff1b<\/p>\n<h4>@EnableAuthorizationServer\u6ce8\u89e3\u7684\u7c7b\u7ee7\u627fAuthorizationServerConfigurerAdapter\u7c7b\u914d\u7f6e\u8ba4\u8bc1\u670d\u52a1<\/h4>\n<p><!-- more --><\/p>\n<p>\u9996\u5148\u67e5\u770b<code>@EnableAuthorizationServer<\/code>\u7684\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-java\">@Target({ElementType.TYPE})\n@Retention(RetentionPolicy.RUNTIME)\n@Documented\n@Import({AuthorizationServerEndpointsConfiguration.class, AuthorizationServerSecurityConfiguration.class})\npublic @interface EnableAuthorizationServer {\n}<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u6ce8\u89e3\u5f15\u5165\u4e86\u4e24\u4e2a\u7c7b\uff0c\u6211\u4eec\u70b9\u51fb\u8fdb\u5165<code>AuthorizationServerEndpointsConfiguration<\/code>\u7c7b\u4e2d<\/p>\n<pre><code class=\"language-java\">@Configuration\n@Order(0)\n@Import({ClientDetailsServiceConfiguration.class, AuthorizationServerEndpointsConfiguration.class})\npublic class AuthorizationServerSecurityConfiguration extends WebSecurityConfigurerAdapter {\n    ...<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u6ce8\u89e3<code>@Order(0)<\/code>\uff0c\u4e5f\u5c31\u662f\u8ba4\u8bc1\u670d\u52a1\u5668\u914d\u7f6e\u7684\u4f18\u5148\u7ea7\u4e3a0<\/p>\n<h4>@EnableResourceServer\u6ce8\u89e3\u7684\u7c7b\u7ee7\u627fResourceServerConfigurerAdapter\u7c7b\u914d\u7f6e\u8d44\u6e90\u670d\u52a1\u5668<\/h4>\n<p>\u70b9\u51fb\u6ce8\u89e3<code>@EnableResourceServer<\/code>\u67e5\u770b\u6e90\u7801<\/p>\n<pre><code class=\"language-java\">@Target({ElementType.TYPE})\n@Retention(RetentionPolicy.RUNTIME)\n@Documented\n@Import({ResourceServerConfiguration.class})\npublic @interface EnableResourceServer {\n}<\/code><\/pre>\n<p>\u6ce8\u89e3\u4e2d\u5f15\u5165\u4e86<code>ResourceServerConfiguration<\/code>\u7c7b\uff0c\u70b9\u51fb\u8fdb\u5165<\/p>\n<pre><code class=\"language-java\">@Configuration\npublic class ResourceServerConfiguration extends WebSecurityConfigurerAdapter implements Ordered {\n    private int order = 3;<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u7c7b\u5b9e\u73b0\u4e86<code>Ordered<\/code>\u63a5\u53e3\uff0c\u4f18\u5148\u7ea7\u4e3a3<\/p>\n<h4>@EnableWebSecurity\u6ce8\u89e3\u4fee\u9970\u7684\u7c7b\u7ee7\u627fWebSecurityConfigurerAdapter\u7c7b\u914d\u7f6eweb\u5b89\u5168\u914d\u7f6e<\/h4>\n<p>\u67e5\u770b<code>WebSecurityConfigurerAdapter<\/code>\u7684\u6e90\u7801<\/p>\n<pre><code class=\"language-java\">@Order(100)\npublic abstract class WebSecurityConfigurerAdapter implements WebSecurityConfigurer&lt;WebSecurity&gt; {<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u7c7b\u4f7f\u7528\u6ce8\u89e3<code>@Order<\/code>\uff0c\u4f18\u5148\u7ea7\u4e3a100<\/p>\n<h4>\u5206\u6790\u8bf4\u660e<\/h4>\n<ul>\n<li>order\u7684\u503c\u8d8a\u5c0f\uff0c\u7c7b\u7684\u4f18\u5148\u7ea7\u8d8a\u9ad8\uff0cIOC\u5bb9\u5668\u5c31\u4f1a\u4f18\u5148\u52a0\u8f7d\uff0c\u4e0a\u9762\u7684\u4f18\u5148\u7ea7\u662f\uff1a\u8ba4\u8bc1\u670d\u52a1\u5668\u914d\u7f6e\uff080\uff09&gt; \u8d44\u6e90\u670d\u52a1\u5668\u914d\u7f6e\uff083\uff09&gt; web\u5b89\u5168\u670d\u52a1\u914d\u7f6e\uff08100\uff09<\/li>\n<li>\u5728\u505a\u8d44\u6e90\u6743\u9650\u914d\u7f6e\u7684\u65f6\u5019\u5e94\u6309\u7167\u4f18\u5148\u7ea7\u9ad8\u7684\u6765\u914d\u7f6e\uff0c\u5426\u5219\u4e0d\u4f1a\u751f\u6548<\/li>\n<\/ul>\n<p>\u672c\u6587\u8f6c\u8f7d\u53c2\u8003 <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/blog.csdn.net\/yaomingyang\/column\/info\/41645\" title=\"\u539f\u6587\">\u539f\u6587<\/a> \u5e76\u52a0\u4ee5\u8c03\u8bd5<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u642d\u5efaSpring Security OAuth2\u8ba4\u8bc1\u670d\u52a1\uff0c\u7ecf\u5e38\u4f1a\u9047\u5230\u5728\u8d44\u6e90\u670d\u52a1\u5668\u4e2d\u914d\u7f6e\u751f\u6548\uff0c\u4f46\u662f\u5728web\u5b89\u5168\u914d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[354],"tags":[353],"class_list":["post-1423","post","type-post","status-publish","format-standard","hentry","category-spring-security","tag-oauth2"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1423"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1423\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}