{"id":95961,"date":"2026-08-27T07:48:41","date_gmt":"2026-08-26T23:48:41","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/95961.html"},"modified":"2026-08-27T07:48:41","modified_gmt":"2026-08-26T23:48:41","slug":"spring-security-oauth2-%e8%b5%84%e6%ba%90%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%9a%e6%9e%84%e5%bb%ba%e5%ae%89%e5%85%a8%e7%9a%84%e5%be%ae%e6%9c%8d%e5%8a%a1%e6%9e%b6%e6%9e%84","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/95961.html","title":{"rendered":"Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\uff1a\u6784\u5efa\u5b89\u5168\u7684\u5fae\u670d\u52a1\u67b6\u6784"},"content":{"rendered":"<h2>Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668&#xff1a;\u6784\u5efa\u5b89\u5168\u7684\u5fae\u670d\u52a1\u67b6\u6784<\/h2>\n<p>\u522b\u53eb\u6211\u5927\u795e&#xff0c;\u53eb\u6211 Alex \u5c31\u597d\u3002<\/p>\n<h3>\u4e00\u3001\u5f15\u8a00<\/h3>\n<p>\u5927\u5bb6\u597d&#xff0c;\u6211\u662f Alex\u3002\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d&#xff0c;\u670d\u52a1\u95f4\u7684\u5b89\u5168\u901a\u4fe1\u662f\u4e00\u4e2a\u6838\u5fc3\u95ee\u9898\u3002Spring Security 6 \u5bf9 OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\u7684\u652f\u6301\u6709\u4e86\u91cd\u5927\u6539\u8fdb\u3002\u4eca\u5929&#xff0c;\u6211\u60f3\u548c\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b\u5982\u4f55\u4f7f\u7528 Spring Security OAuth2 \u6784\u5efa\u5b89\u5168\u7684\u8d44\u6e90\u670d\u52a1\u5668\u3002<\/p>\n<h3>\u4e8c\u3001OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\u57fa\u7840<\/h3>\n<h4>1. \u6838\u5fc3\u6982\u5ff5<\/h4>\n<ul>\n<li>\u8d44\u6e90\u670d\u52a1\u5668&#xff1a;\u6258\u7ba1\u53d7\u4fdd\u62a4\u8d44\u6e90\u7684\u670d\u52a1<\/li>\n<li>\u6388\u6743\u670d\u52a1\u5668&#xff1a;\u9881\u53d1\u548c\u7ba1\u7406\u8bbf\u95ee\u4ee4\u724c<\/li>\n<li>\u5ba2\u6237\u7aef&#xff1a;\u8bf7\u6c42\u8bbf\u95ee\u8d44\u6e90\u7684\u5e94\u7528\u7a0b\u5e8f<\/li>\n<li>\u8d44\u6e90\u6240\u6709\u8005&#xff1a;\u62e5\u6709\u8d44\u6e90\u7684\u7528\u6237<\/li>\n<\/ul>\n<h4>2. JWT \u4ee4\u724c\u7ed3\u6784<\/h4>\n<p>{<br \/>\n  &#034;header&#034;: {<br \/>\n    &#034;alg&#034;: &#034;RS256&#034;,<br \/>\n    &#034;typ&#034;: &#034;JWT&#034;<br \/>\n  },<br \/>\n  &#034;payload&#034;: {<br \/>\n    &#034;sub&#034;: &#034;user123&#034;,<br \/>\n    &#034;iss&#034;: &#034;https:\/\/auth.example.com&#034;,<br \/>\n    &#034;aud&#034;: &#034;resource-server&#034;,<br \/>\n    &#034;exp&#034;: 1699999999,<br \/>\n    &#034;scope&#034;: &#034;read write&#034;,<br \/>\n    &#034;roles&#034;: [&#034;USER&#034;, &#034;ADMIN&#034;]<br \/>\n  }<br \/>\n}<\/p>\n<h3>\u4e09\u3001\u8d44\u6e90\u670d\u52a1\u5668\u914d\u7f6e<\/h3>\n<h4>1. \u57fa\u7840\u914d\u7f6e<\/h4>\n<p>&#064;Configuration<br \/>\n&#064;EnableWebSecurity<br \/>\npublic class ResourceServerConfig {<\/p>\n<p>    &#064;Bean<br \/>\n    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {<br \/>\n        http<br \/>\n            .authorizeHttpRequests(authorize -&gt; authorize<br \/>\n                .requestMatchers(&#034;\/api\/public\/**&#034;).permitAll()<br \/>\n                .requestMatchers(&#034;\/api\/admin\/**&#034;).hasRole(&#034;ADMIN&#034;)<br \/>\n                .requestMatchers(&#034;\/api\/user\/**&#034;).hasAnyRole(&#034;USER&#034;, &#034;ADMIN&#034;)<br \/>\n                .anyRequest().authenticated()<br \/>\n            )<br \/>\n            .oauth2ResourceServer(oauth2 -&gt; oauth2<br \/>\n                .jwt(jwt -&gt; jwt<br \/>\n                    .jwtAuthenticationConverter(jwtAuthenticationConverter())<br \/>\n                )<br \/>\n            );<br \/>\n        return http.build();<br \/>\n    }<\/p>\n<p>    &#064;Bean<br \/>\n    public JwtAuthenticationConverter jwtAuthenticationConverter() {<br \/>\n        JwtGrantedAuthoritiesConverter authoritiesConverter &#061; new JwtGrantedAuthoritiesConverter();<br \/>\n        authoritiesConverter.setAuthorityPrefix(&#034;ROLE_&#034;);<br \/>\n        authoritiesConverter.setAuthoritiesClaimName(&#034;roles&#034;);<\/p>\n<p>        JwtAuthenticationConverter converter &#061; new JwtAuthenticationConverter();<br \/>\n        converter.setJwtGrantedAuthoritiesConverter(authoritiesConverter);<br \/>\n        converter.setPrincipalClaimName(&#034;sub&#034;);<br \/>\n        return converter;<br \/>\n    }<br \/>\n}<\/p>\n<h4>2. JWT \u89e3\u7801\u5668\u914d\u7f6e<\/h4>\n<p>&#064;Configuration<br \/>\npublic class JwtConfig {<\/p>\n<p>    &#064;Bean<br \/>\n    public JwtDecoder jwtDecoder() {<br \/>\n        \/\/ \u4f7f\u7528 JWKS \u7aef\u70b9<br \/>\n        NimbusJwtDecoder jwtDecoder &#061; NimbusJwtDecoder.withJwkSetUri(<br \/>\n            &#034;https:\/\/auth.example.com\/.well-known\/jwks.json&#034;<br \/>\n        ).build();<\/p>\n<p>        \/\/ \u914d\u7f6e\u9a8c\u8bc1\u5668<br \/>\n        OAuth2TokenValidator&lt;Jwt&gt; withIssuer &#061; JwtValidators.createDefaultWithIssuer(<br \/>\n            &#034;https:\/\/auth.example.com&#034;<br \/>\n        );<br \/>\n        OAuth2TokenValidator&lt;Jwt&gt; withAudience &#061; audienceValidator();<\/p>\n<p>        jwtDecoder.setJwtValidator(withIssuer.and(withAudience));<br \/>\n        return jwtDecoder;<br \/>\n    }<\/p>\n<p>    private OAuth2TokenValidator&lt;Jwt&gt; audienceValidator() {<br \/>\n        return jwt -&gt; {<br \/>\n            List&lt;String&gt; audience &#061; jwt.getAudience();<br \/>\n            if (audience !&#061; null &amp;&amp; audience.contains(&#034;resource-server&#034;)) {<br \/>\n                return OAuth2TokenValidatorResult.success();<br \/>\n            }<br \/>\n            return OAuth2TokenValidatorResult.failure(<br \/>\n                new OAuth2Error(&#034;invalid_token&#034;, &#034;Invalid audience&#034;, null)<br \/>\n            );<br \/>\n        };<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u56db\u3001\u9ad8\u7ea7\u5b89\u5168\u914d\u7f6e<\/h3>\n<h4>1. \u65b9\u6cd5\u7ea7\u5b89\u5168<\/h4>\n<p>&#064;Service<br \/>\npublic class OrderService {<\/p>\n<p>    &#064;PreAuthorize(&#034;hasRole(&#039;USER&#039;)&#034;)<br \/>\n    public Order getOrder(Long orderId) {<br \/>\n        \/\/ \u67e5\u8be2\u8ba2\u5355<br \/>\n        return orderRepository.findById(orderId).orElse(null);<br \/>\n    }<\/p>\n<p>    &#064;PreAuthorize(&#034;hasRole(&#039;ADMIN&#039;) or &#064;orderSecurity.isOwner(#orderId, authentication)&#034;)<br \/>\n    public void updateOrder(Long orderId, OrderUpdateRequest request) {<br \/>\n        \/\/ \u66f4\u65b0\u8ba2\u5355<br \/>\n    }<\/p>\n<p>    &#064;PostAuthorize(&#034;returnObject &#061;&#061; null or returnObject.customerId &#061;&#061; authentication.name&#034;)<br \/>\n    public Order getOrderDetail(Long orderId) {<br \/>\n        \/\/ \u67e5\u8be2\u8ba2\u5355\u8be6\u60c5<br \/>\n        return orderRepository.findById(orderId).orElse(null);<br \/>\n    }<br \/>\n}<\/p>\n<p>&#064;Component(&#034;orderSecurity&#034;)<br \/>\npublic class OrderSecurity {<\/p>\n<p>    &#064;Autowired<br \/>\n    private OrderRepository orderRepository;<\/p>\n<p>    public boolean isOwner(Long orderId, Authentication authentication) {<br \/>\n        Order order &#061; orderRepository.findById(orderId).orElse(null);<br \/>\n        return order !&#061; null &amp;&amp;<br \/>\n               order.getCustomerId().equals(authentication.getName());<br \/>\n    }<br \/>\n}<\/p>\n<h4>2. \u81ea\u5b9a\u4e49\u6743\u9650\u8bc4\u4f30<\/h4>\n<p>&#064;Component<br \/>\npublic class CustomPermissionEvaluator implements PermissionEvaluator {<\/p>\n<p>    &#064;Override<br \/>\n    public boolean hasPermission(Authentication authentication, Object targetDomain, Object permission) {<br \/>\n        if (authentication &#061;&#061; null || !authentication.isAuthenticated()) {<br \/>\n            return false;<br \/>\n        }<\/p>\n<p>        String targetType &#061; targetDomain.getClass().getSimpleName();<br \/>\n        return checkPermission(authentication, targetType, permission.toString());<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission) {<br \/>\n        \/\/ \u5b9e\u73b0\u903b\u8f91<br \/>\n        return false;<br \/>\n    }<\/p>\n<p>    private boolean checkPermission(Authentication authentication, String targetType, String permission) {<br \/>\n        \/\/ \u81ea\u5b9a\u4e49\u6743\u9650\u68c0\u67e5\u903b\u8f91<br \/>\n        return authentication.getAuthorities().stream()<br \/>\n            .anyMatch(auth -&gt; auth.getAuthority().equals(targetType &#043; &#034;:&#034; &#043; permission));<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u4e94\u3001\u591a\u79df\u6237\u652f\u6301<\/h3>\n<p>&#064;Component<br \/>\npublic class TenantContext {<\/p>\n<p>    private static final ThreadLocal&lt;String&gt; CURRENT_TENANT &#061; new ThreadLocal&lt;&gt;();<\/p>\n<p>    public static void setCurrentTenant(String tenant) {<br \/>\n        CURRENT_TENANT.set(tenant);<br \/>\n    }<\/p>\n<p>    public static String getCurrentTenant() {<br \/>\n        return CURRENT_TENANT.get();<br \/>\n    }<\/p>\n<p>    public static void clear() {<br \/>\n        CURRENT_TENANT.remove();<br \/>\n    }<br \/>\n}<\/p>\n<p>&#064;Component<br \/>\npublic class TenantJwtDecoder implements JwtDecoder {<\/p>\n<p>    &#064;Autowired<br \/>\n    private TenantRepository tenantRepository;<\/p>\n<p>    &#064;Override<br \/>\n    public Jwt decode(String token) throws JwtException {<br \/>\n        Jwt jwt &#061; JwtDecoders.fromIssuerLocation(&#034;https:\/\/auth.example.com&#034;).decode(token);<\/p>\n<p>        String tenantId &#061; jwt.getClaimAsString(&#034;tenant_id&#034;);<br \/>\n        TenantContext.setCurrentTenant(tenantId);<\/p>\n<p>        return jwt;<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u516d\u3001\u6d4b\u8bd5\u914d\u7f6e<\/h3>\n<p>&#064;SpringBootTest<br \/>\n&#064;AutoConfigureMockMvc<br \/>\npublic class ResourceServerTest {<\/p>\n<p>    &#064;Autowired<br \/>\n    private MockMvc mockMvc;<\/p>\n<p>    &#064;Test<br \/>\n    void testPublicEndpoint() throws Exception {<br \/>\n        mockMvc.perform(get(&#034;\/api\/public\/info&#034;))<br \/>\n            .andExpect(status().isOk());<br \/>\n    }<\/p>\n<p>    &#064;Test<br \/>\n    void testProtectedEndpointWithoutToken() throws Exception {<br \/>\n        mockMvc.perform(get(&#034;\/api\/user\/profile&#034;))<br \/>\n            .andExpect(status().isUnauthorized());<br \/>\n    }<\/p>\n<p>    &#064;Test<br \/>\n    &#064;WithMockJwt(roles &#061; &#034;USER&#034;, subject &#061; &#034;user123&#034;)<br \/>\n    void testProtectedEndpointWithToken() throws Exception {<br \/>\n        mockMvc.perform(get(&#034;\/api\/user\/profile&#034;))<br \/>\n            .andExpect(status().isOk());<br \/>\n    }<\/p>\n<p>    &#064;Test<br \/>\n    &#064;WithMockJwt(roles &#061; &#034;USER&#034;)<br \/>\n    void testAdminEndpointWithUserRole() throws Exception {<br \/>\n        mockMvc.perform(get(&#034;\/api\/admin\/users&#034;))<br \/>\n            .andExpect(status().isForbidden());<br \/>\n    }<br \/>\n}<\/p>\n<p>&#064;Retention(RetentionPolicy.RUNTIME)<br \/>\n&#064;WithSecurityContext(factory &#061; WithMockJwtSecurityContextFactory.class)<br \/>\npublic &#064;interface WithMockJwt {<br \/>\n    String[] roles() default {};<br \/>\n    String subject() default &#034;user&#034;;<br \/>\n    String[] scopes() default {};<br \/>\n}<\/p>\n<p>public class WithMockJwtSecurityContextFactory implements WithSecurityContextFactory&lt;WithMockJwt&gt; {<\/p>\n<p>    &#064;Override<br \/>\n    public SecurityContext createSecurityContext(WithMockJwt annotation) {<br \/>\n        SecurityContext context &#061; SecurityContextHolder.createEmptyContext();<\/p>\n<p>        List&lt;GrantedAuthority&gt; authorities &#061; new ArrayList&lt;&gt;();<br \/>\n        for (String role : annotation.roles()) {<br \/>\n            authorities.add(new SimpleGrantedAuthority(&#034;ROLE_&#034; &#043; role));<br \/>\n        }<br \/>\n        for (String scope : annotation.scopes()) {<br \/>\n            authorities.add(new SimpleGrantedAuthority(&#034;SCOPE_&#034; &#043; scope));<br \/>\n        }<\/p>\n<p>        Jwt jwt &#061; Jwt.withTokenValue(&#034;mock-token&#034;)<br \/>\n            .header(&#034;alg&#034;, &#034;none&#034;)<br \/>\n            .subject(annotation.subject())<br \/>\n            .claim(&#034;roles&#034;, Arrays.asList(annotation.roles()))<br \/>\n            .claim(&#034;scope&#034;, String.join(&#034; &#034;, annotation.scopes()))<br \/>\n            .build();<\/p>\n<p>        JwtAuthenticationToken authentication &#061; new JwtAuthenticationToken(jwt, authorities);<br \/>\n        context.setAuthentication(authentication);<\/p>\n<p>        return context;<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u4e03\u3001\u751f\u4ea7\u73af\u5883\u914d\u7f6e<\/h3>\n<h4>1. \u5b89\u5168\u914d\u7f6e<\/h4>\n<p>spring:<br \/>\n  security:<br \/>\n    oauth2:<br \/>\n      resourceserver:<br \/>\n        jwt:<br \/>\n          issuer-uri: https:\/\/auth.example.com<br \/>\n          jwk-set-uri: https:\/\/auth.example.com\/.well-known\/jwks.json<br \/>\n          audiences:<br \/>\n            &#8211; resource-server<\/p>\n<h4>2. \u5f02\u5e38\u5904\u7406<\/h4>\n<p>&#064;Component<br \/>\npublic class CustomJwtAuthenticationEntryPoint implements AuthenticationEntryPoint {<\/p>\n<p>    &#064;Override<br \/>\n    public void commence(HttpServletRequest request, HttpServletResponse response,<br \/>\n                        AuthenticationException authException) throws IOException {<\/p>\n<p>        response.setContentType(MediaType.APPLICATION_JSON_VALUE);<br \/>\n        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);<\/p>\n<p>        Map&lt;String, Object&gt; error &#061; new HashMap&lt;&gt;();<br \/>\n        error.put(&#034;error&#034;, &#034;Unauthorized&#034;);<br \/>\n        error.put(&#034;message&#034;, authException.getMessage());<br \/>\n        error.put(&#034;path&#034;, request.getRequestURI());<\/p>\n<p>        new ObjectMapper().writeValue(response.getOutputStream(), error);<br \/>\n    }<br \/>\n}<\/p>\n<p>&#064;Component<br \/>\npublic class CustomAccessDeniedHandler implements AccessDeniedHandler {<\/p>\n<p>    &#064;Override<br \/>\n    public void handle(HttpServletRequest request, HttpServletResponse response,<br \/>\n                      AccessDeniedException accessDeniedException) throws IOException {<\/p>\n<p>        response.setContentType(MediaType.APPLICATION_JSON_VALUE);<br \/>\n        response.setStatus(HttpServletResponse.SC_FORBIDDEN);<\/p>\n<p>        Map&lt;String, Object&gt; error &#061; new HashMap&lt;&gt;();<br \/>\n        error.put(&#034;error&#034;, &#034;Forbidden&#034;);<br \/>\n        error.put(&#034;message&#034;, &#034;You don&#039;t have permission to access this resource&#034;);<br \/>\n        error.put(&#034;path&#034;, request.getRequestURI());<\/p>\n<p>        new ObjectMapper().writeValue(response.getOutputStream(), error);<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<p>Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5b89\u5168\u4fdd\u62a4\u80fd\u529b\u3002\u901a\u8fc7\u5408\u7406\u914d\u7f6e&#xff0c;\u6211\u4eec\u53ef\u4ee5\u6784\u5efa\u51fa\u65e2\u5b89\u5168\u53c8\u7075\u6d3b\u7684\u5fae\u670d\u52a1\u67b6\u6784\u3002<\/p>\n<p>\u8fd9\u5176\u5b9e\u53ef\u4ee5\u66f4\u4f18\u96c5\u4e00\u70b9\u3002<\/p>\n<p>\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u5e2e\u52a9\u5927\u5bb6\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528 Spring Security OAuth2\u3002\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898&#xff0c;\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u7559\u8a00\u3002<\/p>\n<hr \/>\n<p>\u5173\u4e8e\u4f5c\u8005&#xff1a;\u6211\u662f Alex&#xff0c;\u4e00\u4e2a\u5728 CSDN \u5199 Java \u67b6\u6784\u601d\u8003\u7684\u6696\u7537\u3002\u559c\u6b22\u624b\u51b2\u5496\u5561&#xff0c;\u517b\u4e86\u4e00\u53ea\u53eb&#034;Java&#034;\u7684\u62c9\u5e03\u62c9\u591a\u3002\u5982\u679c\u6211\u7684\u6587\u7ae0\u5bf9\u4f60\u6709\u5e2e\u52a9&#xff0c;\u6b22\u8fce\u5173\u6ce8\u6211&#xff0c;\u4e00\u8d77\u63a2\u8ba8 Java \u6280\u672f\u7684\u4f18\u96c5\u4e4b\u9053\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668&#xff1a;\u6784\u5efa\u5b89\u5168\u7684\u5fae\u670d\u52a1\u67b6\u6784\u522b\u53eb\u6211\u5927\u795e&#xff0c;\u53eb\u6211 Alex \u5c31\u597d\u3002\u4e00\u3001\u5f15\u8a00<br \/>\n\u5927\u5bb6\u597d&#xff0c;\u6211\u662f Alex\u3002\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d&#xff0c;\u670d\u52a1\u95f4\u7684\u5b89\u5168\u901a\u4fe1\u662f\u4e00\u4e2a\u6838\u5fc3\u95ee\u9898\u3002Spring Security 6 \u5bf9 OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\u7684\u652f\u6301\u6709\u4e86\u91cd\u5927\u6539\u8fdb\u3002\u4eca\u5929&#xff0c;\u6211\u60f3\u548c\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b\u5982\u4f55\u4f7f\u7528 Spring Security OAuth2 \u6784\u5efa\u5b89\u5168\u7684\u8d44\u6e90\u670d\u52a1\u5668\u3002<br \/>\n\u4e8c\u3001OAuth2 \u8d44\u6e90\u670d\u52a1\u5668<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,101,1348],"topic":[],"class_list":["post-95961","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-spring","tag-1348"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\uff1a\u6784\u5efa\u5b89\u5168\u7684\u5fae\u670d\u52a1\u67b6\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/95961.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\uff1a\u6784\u5efa\u5b89\u5168\u7684\u5fae\u670d\u52a1\u67b6\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668&#xff1a;\u6784\u5efa\u5b89\u5168\u7684\u5fae\u670d\u52a1\u67b6\u6784\u522b\u53eb\u6211\u5927\u795e&#xff0c;\u53eb\u6211 Alex \u5c31\u597d\u3002\u4e00\u3001\u5f15\u8a00 \u5927\u5bb6\u597d&#xff0c;\u6211\u662f Alex\u3002\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d&#xff0c;\u670d\u52a1\u95f4\u7684\u5b89\u5168\u901a\u4fe1\u662f\u4e00\u4e2a\u6838\u5fc3\u95ee\u9898\u3002Spring Security 6 \u5bf9 OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\u7684\u652f\u6301\u6709\u4e86\u91cd\u5927\u6539\u8fdb\u3002\u4eca\u5929&#xff0c;\u6211\u60f3\u548c\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b\u5982\u4f55\u4f7f\u7528 Spring Security OAuth2 \u6784\u5efa\u5b89\u5168\u7684\u8d44\u6e90\u670d\u52a1\u5668\u3002 \u4e8c\u3001OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/95961.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-26T23:48:41+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/95961.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/95961.html\",\"name\":\"Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\uff1a\u6784\u5efa\u5b89\u5168\u7684\u5fae\u670d\u52a1\u67b6\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-26T23:48:41+00:00\",\"dateModified\":\"2026-08-26T23:48:41+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/95961.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/95961.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/95961.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\uff1a\u6784\u5efa\u5b89\u5168\u7684\u5fae\u670d\u52a1\u67b6\u6784\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\uff1a\u6784\u5efa\u5b89\u5168\u7684\u5fae\u670d\u52a1\u67b6\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/95961.html","og_locale":"zh_CN","og_type":"article","og_title":"Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\uff1a\u6784\u5efa\u5b89\u5168\u7684\u5fae\u670d\u52a1\u67b6\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668&#xff1a;\u6784\u5efa\u5b89\u5168\u7684\u5fae\u670d\u52a1\u67b6\u6784\u522b\u53eb\u6211\u5927\u795e&#xff0c;\u53eb\u6211 Alex \u5c31\u597d\u3002\u4e00\u3001\u5f15\u8a00 \u5927\u5bb6\u597d&#xff0c;\u6211\u662f Alex\u3002\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d&#xff0c;\u670d\u52a1\u95f4\u7684\u5b89\u5168\u901a\u4fe1\u662f\u4e00\u4e2a\u6838\u5fc3\u95ee\u9898\u3002Spring Security 6 \u5bf9 OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\u7684\u652f\u6301\u6709\u4e86\u91cd\u5927\u6539\u8fdb\u3002\u4eca\u5929&#xff0c;\u6211\u60f3\u548c\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b\u5982\u4f55\u4f7f\u7528 Spring Security OAuth2 \u6784\u5efa\u5b89\u5168\u7684\u8d44\u6e90\u670d\u52a1\u5668\u3002 \u4e8c\u3001OAuth2 \u8d44\u6e90\u670d\u52a1\u5668","og_url":"https:\/\/www.wsisp.com\/helps\/95961.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-26T23:48:41+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/95961.html","url":"https:\/\/www.wsisp.com\/helps\/95961.html","name":"Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\uff1a\u6784\u5efa\u5b89\u5168\u7684\u5fae\u670d\u52a1\u67b6\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-26T23:48:41+00:00","dateModified":"2026-08-26T23:48:41+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/95961.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/95961.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/95961.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Spring Security OAuth2 \u8d44\u6e90\u670d\u52a1\u5668\uff1a\u6784\u5efa\u5b89\u5168\u7684\u5fae\u670d\u52a1\u67b6\u6784"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/95961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=95961"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/95961\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=95961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=95961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=95961"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=95961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}