具有多个登录页面的 Spring 安全性

标签 spring security spring-security

我正在使用 Spring 安全性来保护使用用户名和密码登录到应用程序管理部分。但是现在我的客户需要为应用程序客户端部分提供另一个登录屏幕,他们将在其中拥有自己的用户名/密码来登录客户端部分。到目前为止,我已经使用以下 spring-security.xml 设置成功实现了管理部分登录:

<security:http auto-config="true" use-expressions="true">
    <security:form-login login-page="/login"
        default-target-url="/admin/dashboard" always-use-default-target="true"
        authentication-failure-url="/login/admin?error_msg=wrong username or password" />
    <security:intercept-url pattern="/admin/*" access="hasRole('ROLE_ADMIN')" />        
    <security:logout logout-success-url="/login"/>
</security:http>

<security:authentication-manager>
    <security:authentication-provider
        user-service-ref="adminServiceImpl">
    </security:authentication-provider>
</security:authentication-manager>

我在网上搜索了很多,试图找到如何添加客户端部分登录屏幕、拦截 URL、安全身份验证提供程序,但找不到任何信息,所以有人可以帮我解决任何问题链接到任何教程/示例,指导如何做到这一点?

谢谢

最佳答案

根据Spring Security docs :

From Spring Security 3.1 it is now possible to use multiple http elements to define separate security filter chain configurations for different request patterns. If the pattern attribute is omitted from an http element, it matches all requests.

每个元素在内部 FilterChainProxy 和应该映射到它的 URL 模式中创建一个过滤器链。元素将按照声明的顺序添加,因此必须再次首先声明最具体的模式。

所以,基本上你需要两个 <http> 每个元素都有不同的 pattern属性。

这里有详细教程:https://blog.codecentric.de/en/2012/07/spring-security-two-security-realms-in-one-application/

关于具有多个登录页面的 Spring 安全性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21209962/

相关文章:

php - 生成一个 N 位随机数

spring-security - BadCredentialsException 预期,但得到 AccountExpiredException

spring-security - Grails 从 Spring Security 登录页面重定向 :not working

java - Spring 安全 OAuth2 样本中的缺陷 : same OAuth2ClientContext used for several providers

java - ExceptionHandler,得到 java.lang.IllegalStateException : Could not resolve method parameter at index 0?

security - GPG 与 SSH key

node.js - 使用 NodeJS,如何使用 Spring Security OAuth2 制作的 JWT 检索存储在 PostgreSQL 中的 session 信息?

java - Spring Batch 划分一个步骤

java - Spring集成Kafka ClassNotFoundException : KafkaHeaderMapper

security - "invalid %-encoding"和 "invalid byte sequence in UTF-8"错误正在急剧增加