Spring Security 02
权限管理
配置不过滤的资源
方法1
<http pattern="/login.jsp" security="none"></http>方法2
<sec:http auto-config="true">
<intercept-url pattern="/login.jsp" access="IS_AUTHENTICATED_ANONYMOUSLY" />配置表示允许匿名用户访问
</sec:http>
配置需要赋予权限才能访问的资源
<http auto-config="true">
<!-- 表示访问app.jsp时,需要ROLE_ADMIN权限 -->
<intercept-url pattern="/adminpage.jsp" access="hasRole('ROLE_ADMIN')"></intercept-url>
<!--表示访问任何资源都需要ROLE_USER权限。 -->
<intercept-url pattern="/**" access="hasRole('ROLE_USER')"></intercept-url>
</http>
自定义登陆登出页面
applicationContext-security.xml配置
<http auto-config="false" use-expressions="true">
<!-- 具有ROLE_ADMIN权限的用户才能访问全部路径 -->
<intercept-url pattern="/adminpage.jsp" access="hasRole('ROLE_ADMIN')"/>
<!-- 具有ROLE_USER权限的用户才能访问全部路径 -->
<intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
<form-login
login-page="/login.jsp"
login-processing-url="/j_spring_security_check"
authentication-failure-url="/login.jsp"
default-target-url="/index.jsp" />
<csrf disabled="true" />
<logout invalidate-session="true"
logout-success-url="/login.jsp"
logout-url="/j_spring_security_logout" />
</http>
- auto-config="true"时使用默认的配置,会配置十个默认过滤器:SecurityContextPersistenceFilter、LogoutFilter、
UsernamePasswordAuthenticationFilter、BasicAuthenticationFilter、RequestCacheAwareFilter、SecurityContextHolderAwareRequestFilter、
AnonymousAuthenticationFilter、SessionManagementFilter、ExceptionTranslationFilter、FilterSecurityInterceptor
- login-page="/login.jsp" 表示使用login.jsp代替默认登陆界面。
- login-processing-url="/j_spring_security_check" 使用spring-security 4.x版本必须添加该属性,表示登录表单提交路径。
- authentication-failure-url="/login.jsp" 表示授权失败之后跳转到login.jsp界面。
- default-target-url="/index.jsp" 表示授权成功之后默认跳转到index.jsp界面。
- logout-url="/j_spring_security_logout" 表示退出操作要提交到的url。
- logout-success-url="/login.jsp" 表示退出操作成功后跳转到的界面。
页面
- login.jsp
<html>
<body>
<form action="j_spring_security_check" method="POST">
<input type="text" name="username" /> </br>
<input type="password" name="password" /> </br>
<input type="submit" value="submit" />
</form>
</body>
</html>
- index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="en">
<html>
<body>
<h2>this is a user page </h2>
<a href="${pageContext.request.contextPath}/j_spring_security_logout">退出登陆</a>
</body>
</html>
Spring Security 02的更多相关文章
- Spring Security(02)——关于登录
目录 1.1 form-login元素介绍 1.1.1 使用自定义登录页面 1.1.2 指定登录后的页面 1.1.3 指定登录失败后的页面 1.2 http-basi ...
- 02 spring security 自定义用户认证流程
1. 自定义登录页面 (1)首先在static目录下面创建login.html 注意: springboot项目默认可以访问resources/resources, resources/s ...
- 使用 Spring Security 保护 Web 应用的安全
安全一直是 Web 应用开发中非常重要的一个方面.从安全的角度来说,需要考虑用户认证和授权两个方面.为 Web 应用增加安全方面的能力并非一件简单的事情,需要考虑不同的认证和授权机制.Spring S ...
- 权限开发 spring security 3.0.7 序列1 数据库脚本
spring security 3 细粒度权限控制第一篇,关于权限的初始化测试数据库脚本. 空间脚本: drop user FrameworkTest cascade; drop tablespa ...
- spring security oauth2 client_credentials模
spring security oauth2 client_credentials模 https://www.jianshu.com/p/1c3eea71410e 序 本文主要简单介绍一下spring ...
- Spring Security原理与应用
Spring Security是什么 Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架.它提供了一组可以在Spring应用上下文中配置 ...
- 使用spring security 2.0 和extjs 3.0实现web登录
使用spring security 2.0 和extjs 3.0实现web登录 1开发环境说明 本例使用MyEclipse 6.5作为开发工具,jdk1.5作为编译工具,tomcat6.0作为web运 ...
- Spring Security认证提供程序
1.简介 本教程将介绍如何在Spring Security中设置身份验证提供程序,与使用简单UserDetailsService的标准方案相比,提供了额外的灵活性. 2. The Authentica ...
- 转 Spring Security 简介
https://blog.csdn.net/xlecho/article/details/80026527 Spring Security 简介 2018年04月21日 09:53:02 阅读数:13 ...
随机推荐
- TP中如何去掉index.php
使用过TP的同学都知道,在URL始终会有index .php 我们如何才能够去掉呢? 1. 确认httpd.conf配置文件中加载了mod_rewrite.so模块 2. AllowOverride ...
- git常用相关操作
// 账号密码克隆远程项目 git clone http://账号:密码@项目地址 // 查看当前状态 git status // 查看修改内容 git diff // 添加并提交 git add . ...
- Redis的客户端Jedis
1. Redis支持消息的订阅与发布 Redis的消息订阅支持:先订阅后发布 订阅:subscribe c1 c2 发布:publish c2 hello-redis 支持通配符的订阅:psubscr ...
- 21eval 函数
eval() 函数十分强大 ---- 将字符串 当成 有效的表达式 来求职 并 返回计算结果 # 基本的数学计算 # 字符串重复 print(eval("'*' * 5")) # ...
- join 按两个文件的相同字段合并
1.命令功能 join对每一对具相同内容的输入行,合并为一行输出.默认情况是把输入的第一个字段作为连接字段,字段间用空格隔开. 2.语法格式 join option file1 file2 jo ...
- Fabric的使用总结
环境说明 建议python版本:2.7 fabric版本:最新版(当前为1.10.2) fabric安装 通过pip.py的方式安装(详细可以在fabric官网了解) fabric执行py文件的方法, ...
- size_t为什么重要
参考:https://www.zhihu.com/question/24773728/answer/66535663 前言:使用size_t可能会提高代码的可移植性.有效性或者可读性,或许同时提高这三 ...
- 2017ICPC沈阳网络赛 HDU 6205 -- card card card(最大子段和)
card card card Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- ORACLE错误:ORA-28001: the password has expired解决方法
Oracle提示错误消息ORA-28001: the password has expired,是由于Oracle11G的新特性所致, Oracle11G创建用户时缺省密码过期限制是180天(即6个月 ...
- jstl学习资料
jstl印象中叫标准标签库,是apache的一个项目,网址为: Apache Taglibs - Apache Standard Taglib: JSP[tm] Standard Tag Librar ...