1
使用弹簧安全性登录对多个用户正常工作。 现在我必须使用密码登录到应用程序,该密码应在数据库中加密。弹簧安全性_密码加密
首页控制器:在这里,我正在从FORM检索用户名,密码。
spring-security.xml:在这里我从数据库检索用户名,密码。
现在我要比较这些密码进行匹配,然后我要让这个人登录。
请给我一个想法,我们如何使用弹簧安全来做到这一点。 ??
使用弹簧安全性登录对多个用户正常工作。 现在我必须使用密码登录到应用程序,该密码应在数据库中加密。弹簧安全性_密码加密
首页控制器:在这里,我正在从FORM检索用户名,密码。
spring-security.xml:在这里我从数据库检索用户名,密码。
现在我要比较这些密码进行匹配,然后我要让这个人登录。
请给我一个想法,我们如何使用弹簧安全来做到这一点。 ??
我相信你在使用Spring Security时不会自己做凭证匹配。这是您配置的AuthenticationManager的责任。
可以指定编码器,同时匹配凭证喜欢用: -
<!-- This is the authentication manager -->
<authentication-manager>
<authentication-provider user-service-ref="yourUserService">
<password-encoder hash="sha"/>
</authentication-provider>
</authentication-manager>
所有你需要关心你的用户信息表中存储编码的密码。
看看docs
扰流
如果你正在使用Spring Security的,你不需要有一个控制器,以收集用户凭据。 Spring Security过滤器负责照顾。
例如: -
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<security:global-method-security secured-annotations="enabled" />
<security:http auto-config="true">
<!-- Restrict URLs based on role -->
<security:intercept-url pattern="/login*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<security:intercept-url pattern="/logoutSuccess*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<security:intercept-url pattern="/css/main.css" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<security:intercept-url pattern="/resources/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<security:intercept-url pattern="/**" access="ROLE_USER" />
<!-- Override default login and logout pages -->
<security:form-login login-page="/login.html" // this is where your custome login page lives.
login-processing-url="/loginProcess" //this is where you POST your login form
default-target-url="/index.jsp"
authentication-failure-url="/login.html?login_error=1" />
<security:logout logout-url="/logout" logout-success-url="/logoutSuccess.html" />
</security:http>
<security:authentication-manager>
<security:authentication-provider >
<security:jdbc-user-service data-source-ref="dataSource" />
</security:authentication-provider>
</security:authentication-manager>
</beans>
我建议你去通过一个参考文档和简单的博客/教程(有很多)。
更多的是,给Spring Boot Security一枪。