spring Security 31的配置.docx
- 文档编号:30766137
- 上传时间:2023-08-23
- 格式:DOCX
- 页数:24
- 大小:25.02KB
spring Security 31的配置.docx
《spring Security 31的配置.docx》由会员分享,可在线阅读,更多相关《spring Security 31的配置.docx(24页珍藏版)》请在冰豆网上搜索。
springSecurity31的配置
springSecurity3.1的配置
一.springSecurity3.1最基本的配置
1.lib里的jar包,就用3.1中的示例内的包即可。
2.web.xml
xmlversion="1.0"encoding="UTF-8"?
>
xsi="http: //www.w3.org/2001/XMLSchema-instance"xmlns="xmlns: web="xsi: schemaLocation="version="2.5"> --加载spring配置文件classpath*为扫描classpath目录下,applicationContext-*.xml为以applicationContext-开头的所有xml文件--> classpath*: applicationContext-*.xml --加载springSecurity过滤器--> --拦截所有请求。 --> --为spring添加监听器--> 3.applicationContext-security.xml xmlversion="1.0"encoding="UTF-8"? > beansxmlns="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-3.1.xsd"> --自动配置模式,拦截所有请求,有ROLE_USER才可以通过--> --认证管理器。 用户名密码都集成在配置文件中--> beans> 4.发布,测试。 当打开首页时,因权限不足会自动跳转到默认登录页面。 登录成功后,便可访问默认首页。 二.自定义登录页。 1.只需要修改一个文件 applicationContext-security.xml xmlversion="1.0"encoding="UTF-8"? > beansxmlns="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-3.1.xsd"> --开启测试模式--> --自动配置模式,拦截所有请求进行匹配,有ROLE_USER才可以通过--> --指定不拦截登录页,*表示可以带参数。 从3.10开始,不再支持filters="none"配置--> --指定登录页面及登录失败跳转页--> login_error=1"/> --认证管理器--> --指定中文资源。 默认命名空间是security,所以要加前缀beans: --> beanid="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> propertyname="basename"value="classpath: org/springframework/security/messages_zh_CN"/> bean> beans> 2.增加一个登录页。 可以从示例代码中拷贝过来。 (以下为对源代码做了简单的修改) login.jsp <%@taglibprefix="c"uri="%> <%@pagepageEncoding="UTF-8"%>请登录
地区代码:
<%=request.getLocale()%>
<%--thisform-login-pageformisalsousedasthe
form-error-pagetoaskforaloginagain.
--%>
iftest="${notemptyparam.login_error}"> 登录失败,请重试. 原因: outvalue="${SPRING_SECURITY_LAST_EXCEPTION.message}"/>. if> urlvalue='j_spring_security_check'/>"method="POST"> iftest="${notemptyparam.login_error}"> outvalue="${SPRING_SECURITY_LAST_USERNAME}"/> if>'/>用户名: 密码: Don'taskformypasswordfortwoweeks