Security实现登录安全控制
1:在pom.xml中添加依赖
<!-- 身份验证 -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.1..RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.1..RELEASE</version>
</dependency>
2:在web.xml中添加配置
注意:
classpath:spring/spring-security.xml写的是自己配置sping-security的路径
<!--登录校验-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-security.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3:在配置文件中配置spring-security.xml
我配置在resources下的spring文件夹下
<?xml version="1.0" encoding="UTF-8"?>
<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.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<!-- 不拦截页面 -->
<http pattern="/login.html" security="none"/>
<http pattern="/css/**" security="none"/>
<http pattern="/img/**" security="none"/>
<http pattern="/js/**" security="none"/>
<http pattern="/plugins/**" security="none"/> <!-- use-expressions:设置是否启动SpEL表达式,默认值是true。 -->
<http use-expressions="false">
<!--
配置SpringSecurity的拦截路径(拦截规则)
* pattern:配置拦截规则。 /* 代表的是根路径下的所有资源(不包含子路径) /**代表的是根路径下所有的资源(包含子路径)
* access:设置角色 角色命名 ROLE_角色名称 如: ROLE_USER
-->
<intercept-url pattern="/**" access="ROLE_ADMIN"/> <!--
开启表单验证
username-parameter="username"
password-parameter="password"
login-page :登录页面名称 以 / 开始
default-target-url :登录成功后跳转的页面
login-processing-url:提交的路径的设置 默认值"/login" 可以修改
-->
<form-login login-page="/login.html" default-target-url="/admin/index.html" always-use-default-target="true" authentication-failure-url="/login.html"/>
<!-- 不使用csrf的校验 -->
<csrf disabled="true"/>
<!-- 配置框架页面不拦截 -->
<headers>
<frame-options policy="SAMEORIGIN"/>
</headers>
<!-- 注销的配置,这里登录可以先不写 -->
<logout logout-url="/logout" logout-success-url="/login.html" />
</http>
<!-- 配置认证管理器 -->
<authentication-manager>
<!-- 认证的提供者 -->
<authentication-provider>
<user-service>
<!-- 可以用来登录的用户名和密码 -->
<user name="admin" password="123456" authorities="ROLE_ADMIN"/>
<user name="wc" password="123456" authorities="ROLE_ADMIN"/>
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
4:登录页面设置及注意事项
注意:表单的action必须为/login 请求方式必须为post请求
用户名和密码输入框的name值必须分别设置为username和password
点击超链接提交表单onclick="document:loginform.submit()"
<form id="loginform" action="/login" method="post">
<input name="username" type="text" placeholder="邮箱/用户名/手机号">
<input name="password" type="password" placeholder="请输入密码">
<a onclick="document:loginform.submit()" target="_blank">登 录</a>
</form>
Security实现登录安全控制的更多相关文章
- Spring Security 自定义登录认证(二)
一.前言 本篇文章将讲述Spring Security自定义登录认证校验用户名.密码,自定义密码加密方式,以及在前后端分离的情况下认证失败或成功处理返回json格式数据 温馨小提示:Spring Se ...
- Spring Security 基础登录实例
1 新建Java Web项目 导入Jar: 2 修改web.xml <?xml version="1.0" encoding="UTF-8"?> & ...
- spring boot 下 spring security 自定义登录配置与form-login属性详解
package zhet.sprintBoot; import org.springframework.beans.factory.annotation.Autowired;import org.sp ...
- (二)spring Security 自定义登录页面与校验用户
文章目录 配置 security 配置下 MVC 自定义登录页面 自定义一个登陆成功欢迎页面 效果图 小结: 使用 Spring Boot 的快速创建项目功能,勾选上本篇博客需要的功能:web,sec ...
- Spring Boot整合Spring Security自定义登录实战
本文主要介绍在Spring Boot中整合Spring Security,对于Spring Boot配置及使用不做过多介绍,还不了解的同学可以先学习下Spring Boot. 本demo所用Sprin ...
- springboot中使用spring security,登录url就出现403错误
参考链接:https://segmentfault.com/q/1010000012743613 有两个controller,一个是所有用户可以访问的@RequestMapping("use ...
- Spring Security在登录验证中增加额外数据(如验证码)
在使用Spring Security框架过程中,经常会有这样的需求,即在登录验证时,附带增加额外的数据,如验证码.用户类型等.下面将介绍如何实现. 注:我的工程是在Spring Boot框架基础上的, ...
- Spring Security 自定义登录页面
SpringMVC + Spring Security,自定义登录页面登录验证 学习参考:http://www.mkyong.com/spring-security/spring-security-f ...
- spring security简单登录的认证
一.思路 1.先导入相关配置(使用spring security校验之后,登录拦截的配置) 2.创建一个 WebSecurityConfig 继承 WebSecurityConfigurerAdapt ...
随机推荐
- 【maven】测试
针对spring-boot项目 通过命令行执行mvn命令来启动测试模块. 1.引入plugin 并自定义参数ignore.test 2.命令行传递参数启动test mvn clean package ...
- ubuntu玩坏之后
昨天,安装openssh-server的时候,与openssh-client冲突,故卸载openssh-client然后重装openssh-server解决问题. 今天,想装emacs,发现跟perl ...
- PHP 日历函数手册
PHP日历函数安装>>> 函数名称 描述 cal_days_in_month 返回某个历法中某年中某月的天数 cal_from_jd 转换Julian Day计数到一个支持的历法. ...
- 怎么进入bios设置界面,电脑如何进入BIOS进行设置,怎么进入BIOS的方法集合
怎么进入bios设置界面,电脑如何进入BIOS进行设置,怎么进入BIOS的方法集合 开机出现电脑商家图标时,按住F10键进入BIOS界面.进入BIOS界面一般都是开机后按<del,Esc,F1, ...
- 微信小程序 自定义顶部状态栏
1>项目的结构如下: 2>组件的index.wxml代码如下: <!--没有按钮的情况--> <view class="custom flex_center&q ...
- [git] your branch is ahead of ... 解决办法
出现该问题表示在次之前已经有X个commite了,执行命令git reset --hard HEAD~X解决其中X表示有多少次提交,此命令的意思是回退到x个commit之前.git reset --h ...
- 第七篇Scrum冲刺博客
第七篇Scrum冲刺博客 一.站立式会议 提供当天站立式会议照片一张 二.每个人的工作 成员 已完成工作 明天计划完成的工作 遇到的困难 林剑峰 加入搜索页面 无 陆君健 校园卡匹配功能的实现 无 石 ...
- Arthas实践--抽丝剥茧排查线上应用日志打满问题
现象 在应用的 service_stdout.log里一直输出下面的日志,直接把磁盘打满了: 23:07:34.441 [TAIRCLIENT-1-thread-1] DEBUG io.netty.c ...
- LeetCode——Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- Visual Studio 2019尝鲜----新建空项目体验
等待一个中午的时间终于下载安装完成,vs版本Enterprise 2019 16.0.4 官方可直接下载安装引导程序: https://visualstudio.microsoft.com/zh- ...