权限管理

配置不过滤的资源

  • 方法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
  1. login-page="/login.jsp" 表示使用login.jsp代替默认登陆界面。
  2. login-processing-url="/j_spring_security_check" 使用spring-security 4.x版本必须添加该属性,表示登录表单提交路径。
  3. authentication-failure-url="/login.jsp" 表示授权失败之后跳转到login.jsp界面。
  4. default-target-url="/index.jsp" 表示授权成功之后默认跳转到index.jsp界面。
  5. logout-url="/j_spring_security_logout" 表示退出操作要提交到的url。
  6. 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的更多相关文章

  1. Spring Security(02)——关于登录

    目录 1.1     form-login元素介绍 1.1.1    使用自定义登录页面 1.1.2    指定登录后的页面 1.1.3    指定登录失败后的页面 1.2     http-basi ...

  2. 02 spring security 自定义用户认证流程

    1. 自定义登录页面 (1)首先在static目录下面创建login.html       注意: springboot项目默认可以访问resources/resources, resources/s ...

  3. 使用 Spring Security 保护 Web 应用的安全

    安全一直是 Web 应用开发中非常重要的一个方面.从安全的角度来说,需要考虑用户认证和授权两个方面.为 Web 应用增加安全方面的能力并非一件简单的事情,需要考虑不同的认证和授权机制.Spring S ...

  4. 权限开发 spring security 3.0.7 序列1 数据库脚本

    spring  security  3 细粒度权限控制第一篇,关于权限的初始化测试数据库脚本. 空间脚本: drop user FrameworkTest cascade; drop tablespa ...

  5. spring security oauth2 client_credentials模

    spring security oauth2 client_credentials模 https://www.jianshu.com/p/1c3eea71410e 序 本文主要简单介绍一下spring ...

  6. Spring Security原理与应用

    Spring Security是什么 Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架.它提供了一组可以在Spring应用上下文中配置 ...

  7. 使用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运 ...

  8. Spring Security认证提供程序

    1.简介 本教程将介绍如何在Spring Security中设置身份验证提供程序,与使用简单UserDetailsService的标准方案相比,提供了额外的灵活性. 2. The Authentica ...

  9. 转 Spring Security 简介

    https://blog.csdn.net/xlecho/article/details/80026527 Spring Security 简介 2018年04月21日 09:53:02 阅读数:13 ...

随机推荐

  1. org.hibernate.hql.ast.QuerySyntaxException: tb_voteoption is not mapped [from tb_voteoption where voteID=?]

    转自:https://www.cnblogs.com/albert1017/archive/2012/08/25/2656873.html org.hibernate.hql.ast.QuerySyn ...

  2. [CF] E. Camels

    CF 2000 的dp题目还是有点难qwq 题意: 一行有\(n\)个空位,每个空位可以填\([1,4]\)的整数,要求: 1.有\(t\)个位置满足 \(ai−1<ai>ai+1(1&l ...

  3. [php代码审计] Window api函数 FindFirstFile 在php中的问题

    include文件夹中文件: 内容: <?php echo __FILE__; ?> index.php: 演示如下: “<<”替换多个任意字符: “>”替换单个字符:

  4. css 伪类选择器:checked实例讲解

    css :checked伪类选择器介绍 css :checked伪类选择器用于选择匹配所有被选中的单选按钮(radio)或复选框(checkbox),你可以结合:checked伪类选择器和:not选择 ...

  5. 【leetcode】1094. Car Pooling

    题目如下: You are driving a vehicle that has capacity empty seats initially available for passengers.  T ...

  6. python学习笔记(十一)处理json

    json串就是字符串,json串里必须是双引号 d={'car':{'color':'red','price':100,'count':50}, '爱分叉':{'color':'red','price ...

  7. php md5()函数 语法

    php md5()函数 语法 作用:字符串md5编码.dd马达价格 语法:md5(string,raw) 参数: 参数 描述 string     必需.规定要计算的字符串. raw     可选.规 ...

  8. Cluster基础(三):配置HAProxy负载平衡集群、Keepalived高可用服务器、Keepalived+LVS服务器

    一.配置HAProxy负载平衡集群 目标: 准备三台Linux服务器,两台做Web服务器,一台安装HAProxy,实现如下功能: 客户端访问HAProxy,HAProxy分发请求到后端Real Ser ...

  9. Windows无法启动MapGIS DataStorage Service服务

    但是启动又启动不了,查看属性 发现计算机服务器确实少了该文件目录.. 可能是不小心删除了? 之前确实有删过一些文件 下次直接把.net禁止就可以了,不用删除,不然不小心删除了其它服务.. 参考文献:h ...

  10. CF1137F Matches Are Not a Child's Play

    我们定义一棵树的删除序列为:每一次将树中编号最小的叶子删掉,将该节点编号加入到当前序列的最末端,最后只剩下一个节点时将该节点的编号加入到结尾.现在给出一棵n个节点的树,有m次操作: up v:将v号节 ...