Spring Security学习笔记自定义登录页面(二)
来源:互联网 发布:程序员赚钱吗 编辑:程序博客网 时间:2024/04/30 20:02
在入门(一)是有问题的:
- 在做项目的时候,登录页面都是需要自己写的,并且登录页面是不需要验证直接可以访问的。
- 用户名和密码直接写在配置文件中,而实际项目中我们是放在数据库中的。
在之前 Spring Security 框架生成的登录页面中直接输入用户名和密码提交后,Spring Security框架替我们进行验证的
由于验证过程是 Spring Security 框架自动完成的,所以在我们的登录页面中表单元素的 name都是固定的
现在自己新建一个登录页面login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>登录页面</title></head> <body> <form name='f' action='/springSecurity/j_spring_security_check' method='POST'> <table> <tr> <td>用户名:</td> <td><input type='text' name='j_username' value='user'></td> </tr> <tr> <td>密码:</td> <td><input type='password' name='j_password' /></td> </tr> <tr> <td ><input name="submit" type="submit" value="登录"/></td> <td ><input name="reset" type="reset" value="重置"/></td> </tr> </table> </form> </body></html>
写完登录页面后,需要指定spring Security跳转到我们写的登录页面
springSecurity.xml配置
<?xml version="1.0" encoding="UTF-8"?><b:beans xmlns="http://www.springframework.org/schema/security" xmlns:b="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.0.xsd"> <!-- 这表示,我们要保护应用程序中的所有 URL,只有拥有 ROLE_USER 角色的用户才能访问 --> <http auto-config="true"> <intercept-url pattern="/*" access="ROLE_USER"/> <!-- login-page指定登录页面 /login.jsp* 加个*号是防止请求时后面带了参数 filters="none" 表示不拦截 --> <form-login login-page="/login.jsp"/> <intercept-url pattern="/login.jsp*" filters="none"/> </http> <!-- 配置认证管理器 --> <authentication-manager> <authentication-provider> <user-service> <user name="user" password="user" authorities="ROLE_USER"/> </user-service> </authentication-provider> </authentication-manager></b:beans>
访问我们的项目,发现已经可以跳转到我们自己写的登录页面了
阅读全文
0 0
- Spring Security学习笔记自定义登录页面(二)
- spring security起步二:自定义登录页
- spring security起步二:自定义登录页
- Spring security学习笔记二
- spring security 二中使用通过自定义过滤器实现多登录页面
- Spring Security学习二 - 自定义Login方法
- Spring Security教程(3)---- 自定义登录页面
- Spring Security教程(3)---- 自定义登录页面
- Spring Security教程(3)---- 自定义登录页面
- Spring Security教程(3)---- 自定义登录页面
- Spring Security教程第四部分-自定义登录页面
- spring security2学习笔记二(自定义数据结构及登陆页面)
- Spring Security 3.1自定义登录
- spring security 自定义认证登录
- Spring Security学习(二)Spring Security Guides 定制登录界面
- spring security 3 自定义(二)
- spring security学习笔记
- Spring Security学习笔记
- 基于opencv车牌识别项目完整代码
- ubuntu环境下安装php的yac扩展
- oracle的一些没注意到的细节
- Qt图形视图框架二--图元创建
- 源--StringBuilder
- Spring Security学习笔记自定义登录页面(二)
- 模拟退火算法
- Android组件化开发
- qduoj 树结构重逢 (两遍深搜)
- 喷水装置(二)
- spring cloud ribbon配置
- 2003 navicat mac (61)localhost解决方法
- 文献学习-Factoring Polynomials with Rational Coefficients
- tp5框架中的hook机制