gpt4 book ai didi

spring-security - 将每个 http block 映射到特定的身份验证提供程序

转载 作者:行者123 更新时间:2023-12-01 00:31:02 25 4
gpt4 key购买 nike

我想根据用户的上下文路径来构建我的 Spring Security 配置。如果用户反对带有 http://path1/resource1 的网址我想将它们定向到特定的身份验证提供程序。如果他们进来 http://path2/resource2我想将它们定向到不同的身份验证提供程序。这些 url 路径是基于 REST 的 Web 服务调用,因此它们是无状态的并且不是来自表单的原因。目前,所有身份验证提供程序都已执行。这种情况的最佳方法是什么?我正在使用 spring-security 3.1.0.M1。

<http pattern="/path1/**" create-session="stateless">
<intercept-url pattern="/**" access="ROLE_USER,ROLE_VAR,ROLE_ADMIN" />
<http-basic />
</http>
<http pattern="/path2/**" create-session="stateless">
<intercept-url pattern="/**" access="ROLE_USER,ROLE_VAR,ROLE_ADMIN" />
<http-basic />
</http>

最佳答案

您可以在每个 http block 中定义一个身份验证管理器引用:

<http pattern="/api/**" authentication-manager-ref="apiAccess">
...
</http>

<http auto-config = "true" authentication-manager-ref="webAccess">
...
</http>

<!-- Web authentication manager -->
<authentication-manager id="webAccess">
<authentication-provider
user-service-ref="userService">
</authentication-provider>
</authentication-manager>

<!-- API authentication manager -->
<authentication-manager id="apiAccess">
<authentication-provider
user-service-ref="developerService">
</authentication-provider>
</authentication-manager>

此功能已在 Spring Security 3.1 中添加。

关于spring-security - 将每个 http block 映射到特定的身份验证提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5807863/

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