<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
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.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd
">
<!--对登录和失败页面放行-->
<security:http pattern="/login.jsp" security="none"></security:http>
<security:http pattern="/error.jsp" security="none"></security:http>
<security:http pattern="/favicon.ico" security="none"></security:http>
<security:http pattern="/css/**" security="none"></security:http>
<security:http pattern="/img/**" security="none"></security:http>
<security:http pattern="/plugins/**" security="none"></security:http>
<!--
配置拦截的规则
auto-config="使用自带的页面"
use-expressions="是否使用spel表达式",如果使用表达式:hasRole('ROLE_USER')
-->
<security:http auto-config="true" use-expressions="false">
<!-- 配置拦截的请求地址,任何请求地址都必须有ROLE_USER的权限 -->
<security:intercept-url pattern="/**" access="ROLE_USER"/>
<!--指定安全框架使用的页面-->
<!--login-page: 指定登录页面
login-processing-url: 登录请求路径-登录时必须使用该路径
default-target-url:登录成功后进入的页面
authentication-failure-url;认证失败之后要进入的页面
-->
<security:form-login login-page="/login.jsp"
login-processing-url="/login"
default-target-url="/index.jsp"
authentication-failure-url="/login.jsp"
></security:form-login>
<!--关闭跨站请求伪造-->
<security:csrf disabled="true"></security:csrf>
<!-- 退出 -->
<security:logout invalidate-session="true" logout-url="/logout" logout-success-url="/login.jsp"/>
</security:http>
<!-- 配置认证(登录)信息: 认证管理器 -->
<security:authentication-manager>
<!--认证信息的提供者: 关联用户服务对象-提供账号和密码-->
<!--
解析标签security:authentication-provider,判断该标签中是否存在子标签security:password-encoder‘
如果有此子标签,则使用指定密码加密工具类
如果没有此子标签,则从spring容器中查询名称为passwordEncoder,的加密工具类,使用从容器中获取的工具类
-->
<security:authentication-provider user-service-ref="userService">
<!--指定登录加密工具类-->
<security:password-encoder ref="passwordEncoder"></security:password-encoder>
<!--用户的服务对象-->
<!--<security:user-service>-->
<!--用户信息:是临时账号和密码-->
<!--{noop}: 不使用加密-->
<!--authorities: 指定用户的认证角色-->
<!--<security:user name="admin" password="{noop}admin" authorities="ROLE_USER"/>-->
<!--</security:user-service>-->
</security:authentication-provider>
</security:authentication-manager>
<!--创建一个加密工具类-->
<bean id="passwordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"></bean>
</beans>
spring-security.xml配置文件 登陆加密
最新推荐文章于 2024-09-24 22:34:10 发布