具有多个登录页面的Spring安全性
我正在使用SpringSecurity来确保使用用户名和密码登录到应用程序管理部分。但是现在,我的客户机需要为应用程序客户机部分设置另一个登录屏幕,在这里,他们将拥有自己的用户名/密码来登录到客户机部分。到目前为止,我已经使用以下spring-security.xml设置成功实现了管理部分登录:具有多个登录页面的Spring安全性,spring,security,spring-security,Spring,Security,Spring Security,我正在使用SpringSecurity来确保使用用户名和密码登录到应用程序管理部分。但是现在,我的客户机需要为应用程序客户机部分设置另一个登录屏幕,在这里,他们将拥有自己的用户名/密码来登录到客户机部分。到目前为止,我已经使用以下spring-security.xml设置成功实现了管理部分登录: <security:http auto-config="true" use-expressions="true"> <security:form-login login-pag
<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、安全身份验证提供商,但找不到任何信息,所以有人能帮我找到任何教程/示例的链接,以及如何这样做的指南吗
谢谢根据:
从SpringSecurity3.1开始,现在可以使用多个http
元素定义单独的安全筛选器链配置
不同的请求模式。如果从中省略模式属性
一个http元素,它匹配所有请求
每个元素在内部FilterChainProxy和应映射到它的URL模式中创建一个过滤器链。元素将按照声明的顺序添加,因此必须首先再次声明最特定的模式
因此,本质上您需要两个元素,每个元素具有不同的模式属性
这里有一个详细的教程:我只使用一个安全性:http
,但注册两个用户名密码登录过滤器
如果两个登录页面属于同一个安全领域,则此解决方案是合适的。(如果用户登录到哪个登录页面并不重要的话)。当然,您仍然可以使用角色来限制不同类型用户对应用程序不同部分的访问
这个解决方案应该非常简单,因为您不需要处理两个安全性:http
部分
这样做的主要缺点是:如果一个未登录的用户试图访问一个需要登录的页面,您必须决定在两个登录页面中的哪一个页面被重定向。具有多个登录表单的Spring MVC应用程序示例项目
三种类型的页面:普通/会员/管理员。
若你们试图进入会员页面,你们将进入会员登录表单。
如果您试图访问管理员页面,请转到管理员登录表单
在seucrityxml配置文件中使用ant regex请求匹配器完成
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<global-method-security secured-annotations="enabled" />
<http name="member" pattern="/member/*" request-matcher="ant" auto-config="true" use-expressions="false">
<csrf disabled="true"/>
<intercept-url pattern="/member/home" access="ROLE_MEMBER" />
<intercept-url pattern="/member/account" access="ROLE_MEMBER" />
<intercept-url pattern="/member/orders" access="ROLE_MEMBER" />
<form-login login-page="/member-login" always-use-default-target="false"/>
<logout logout-url="/logout" logout-success-url="/home"/>
</http>
<http name="admin" request-matcher="regex" auto-config="true" use-expressions="false">
<csrf disabled="true"/>
<intercept-url pattern="/admin/home" access="ROLE_ADMIN" />
<intercept-url pattern="/admin/users" access="ROLE_ADMIN" />
<form-login login-page="/admin-login" always-use-default-target="false"/>
<logout logout-url="/logout" logout-success-url="/home"/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="admin" password="password" authorities="ROLE_ADMIN" />
<user name="member" password="password" authorities="ROLE_MEMBER" />
<user name="super" password="password" authorities="ROLE_ADMIN,ROLE_MEMBER" />
</user-service>
</authentication-provider>
</authentication-manager>
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
“>
这里我需要两个对所有用户都通用的登录表单。我在spring-security.xml中配置了上面提到的标记元素。但是它不起作用。请给我建议一个解决方案非常感谢您的回复。不幸的是,我想要的是有两个登录页面,每个页面在DB中都有自己单独的用户表,所以我想我必须遵循两种安全性:http方法。
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/" access="permitAll" />
<intercept-url pattern="/login" access="permitAll" />
<!-- <intercept-url pattern="/welcome/**" access="permitAll" /> <intercept-url
pattern="/admin*" access="hasRole('ROLE_ADMIN')" /> -->
<intercept-url access="hasRole('ROLE_USER')" pattern="/main*" />
<intercept-url pattern="/main*" access="hasRole('ROLE_USER')" />
<form-login login-page="/login" default-target-url="/login-success"
authentication-failure-url="/loginError" />
<!-- <session-management invalid-session-url="/login" session-fixation-protection="newSession">
<concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />
</session-management> -->
<logout logout-success-url="/login" delete-cookies="JSESSIONID" />
<csrf disabled="true" />
<headers>
<frame-options policy="SAMEORIGIN" />
</headers>
</http>
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/mobile/" access="permitAll" />
<intercept-url pattern="/mobile/login" access="permitAll" />
<!-- <intercept-url pattern="/welcome/**" access="permitAll" /> <intercept-url
pattern="/admin*" access="hasRole('ROLE_ADMIN')" /> -->
<intercept-url access="hasRole('ROLE_USER')" pattern="/main*" />
<intercept-url pattern="/main*" access="hasRole('ROLE_USER')" />
<form-login login-page="/mobile/login" default-target-url="/mobile/login-success"
always-use-default-target="true" authentication-failure-url="/mobile/login?error"
username-parameter="username" password-parameter="password" />
<logout delete-cookies="JSESSIONID" logout-success-url="/mobile/login" />
<csrf disabled="true" />
<headers>
<frame-options policy="SAMEORIGIN" />
</headers>