gpt4 book ai didi

spring-security - 分离资源服务器和授权服务器的正确方法是什么?

转载 作者:行者123 更新时间:2023-12-04 04:26:57 25 4
gpt4 key购买 nike

使用spring-security-oauth2可以充当授权服务器的SSO端点保护我的资源。当文档说明时,我有点困惑:

The provider role in OAuth 2.0 is actually split between Authorization Service and Resource Service, and while these sometimes reside in the same application, with Spring Security OAuth you have the option to split them across two applications, and also to have multiple Resource Services that share an Authorization Service.



但是我认为我没有找到发生这种情况的例子。在sparklr/tonr中,授权服务器和资源服务器位于同一应用程序中。我从搜索中看到的唯一示例是 this spring-servlet.xml,它需要 thisResourceServerTokenServices自定义实现才能起作用。

如果可能的话,我想避免编写 ResourceServerTokenServices的自定义实现。还有另一种方法可以在资源服务器中支持外部授权服务器吗?类似于以下内容:
<bean class="com.example.ExternalAuthorizationServerTokenServices" 
p:remote-url="https://my-oauth-compatible-sso.com"
p:token-endpoint="/oauth/access_token"
p:authorize-endpoint="/oauth/authorize" />

这可能吗?

*编辑:我将其添加为一种解决方法(或者这可能是预期的解决方案),我正在使用jdbc token 存储,并依赖于两个服务器碰巧都可以访问该数据库的事实。

最佳答案

您可以在spring-security.xml中分离开放资源和 protected 资源

模式/api/**将受到保护,其他资源将被打开。

<!-- Protected resources -->
<http pattern="/api/**" create-session="never" use-expressions="true"
entry-point-ref="oauthAuthenticationEntryPoint"
access-decision-manager-ref="accessDecisionManager"
xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="false" />
<intercept-url pattern="/api/**"
access="hasAnyRole('ROLE_USER','ROLE_ADMIN')" />
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
<!-- <access-denied-handler ref="oauthAccessDeniedHandler"/> -->
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>

关于spring-security - 分离资源服务器和授权服务器的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16613301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com