极客学院Spring Security

例子

<?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="/*.html" security="none"></http>
<http pattern="/css/**" security="none"></http>
<http pattern="/img/**" security="none"></http>
<http pattern="/js/**" security="none"></http>
<http pattern="/plugins/**" security="none"></http> <!-- 页面的拦截规则 use-expressions:是否启动SPEL表达式 默认是true -->
<http use-expressions="false">
<!-- 当前用户必须有ROLE_USER的角色 才可以访问根目录及所属子目录的资源 -->
<intercept-url pattern="/**" access="ROLE_ADMIN"/>
<!-- 开启表单登陆功能 -->
<form-login login-page="/login.html" default-target-url="/admin/index.html" authentication-failure-url="/login.html" always-use-default-target="true"/>
<csrf disabled="true"/>
<headers>
<!-- 里面iframe不拦截 -->
<frame-options policy="SAMEORIGIN"/>
</headers>
<logout/>
</http> <!-- 认证管理器 -->
<authentication-manager>
<authentication-provider>
<user-service>
<user name="admin" password="123456" authorities="ROLE_ADMIN"/>
<user name="sunwukong" password="dasheng" authorities="ROLE_ADMIN"/>
</user-service>
</authentication-provider>
</authentication-manager> </beans:beans>

使用

SecurityContextHolder.getContext().getAuthentication().getName();

spring-security使用的更多相关文章

  1. Spring Security OAuth2 开发指南

    官方原文:http://projects.spring.io/spring-security-oauth/docs/oauth2.html 翻译及修改补充:Alex Liao. 转载请注明来源:htt ...

  2. spring mvc 和spring security配置 web.xml设置

    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmln ...

  3. SPRING SECURITY JAVA配置:Web Security

    在前一篇,我已经介绍了Spring Security Java配置,也概括的介绍了一下这个项目方方面面.在这篇文章中,我们来看一看一个简单的基于web security配置的例子.之后我们再来作更多的 ...

  4. 【OAuth2.0】Spring Security OAuth2.0篇之初识

    不吐不快 因为项目需求开始接触OAuth2.0授权协议.断断续续接触了有两周左右的时间.不得不吐槽的,依然是自己的学习习惯问题,总是着急想了解一切,习惯性地钻牛角尖去理解小的细节,而不是从宏观上去掌握 ...

  5. spring security oauth2.0 实现

    oauth应该属于security的一部分.关于oauth的的相关知识可以查看阮一峰的文章:http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html ...

  6. Spring Security(08)——intercept-url配置

    http://elim.iteye.com/blog/2161056 Spring Security(08)--intercept-url配置 博客分类: spring Security Spring ...

  7. Spring Security控制权限

    Spring Security控制权限 1,配置过滤器 为了在项目中使用Spring Security控制权限,首先要在web.xml中配置过滤器,这样我们就可以控制对这个项目的每个请求了. < ...

  8. Spring Security笔记:Hello World

    本文演示了Spring Security的最最基本用法,二个页面(或理解成二个url),一个需要登录认证后才能访问(比如:../admin/),一个可匿名访问(比如:../welcome) 注:以下内 ...

  9. Spring Security笔记:自定义Login/Logout Filter、AuthenticationProvider、AuthenticationToken

    在前面的学习中,配置文件中的<http>...</http>都是采用的auto-config="true"这种自动配置模式,根据Spring Securit ...

  10. spring session 和 spring security整合

    背景: 我要做的系统前面放置zuul. 使用自己公司提供的单点登录服务.后面的业务应用也是spring boot支撑的rest服务. 目标: 使用spring security管理权限包括权限.用户请 ...

随机推荐

  1. 基于Verilog的按键检测实验

    一.模块框图及基本思路 detect_module:检测按键输入脚的电平边沿变化 delay_10ms_module:延时消抖,输出按键有效信号 debounce_module:前两个模块的组合模块 ...

  2. leetcode题解2. Add Two Numbers

    题目: You are given two non-empty linked lists representing two non-negative integers. The digits are ...

  3. 自动化测试-1.selenium简介

    1. selenium一个自动化测试工具,适用于测试web系统2. selenium支持多种编程语言:python .java .c#.ruby3.selenium支持多浏览器,selenium脚本可 ...

  4. spark on yarn运行产生jar包冲突问题

    1.1 问题描述 Spark Streaming程序解析protobuf序列化的数据时,--jars 来添加依赖的protobuf-java-3.0.0.jar包,使用local模式程序正常,使用ya ...

  5. ubuntu下安装mysql和配置远程访问

    ubuntu下安装mysql和配置远程访问   下载安装mysql sudo apt-get install mysql-client mysql-server 安装的时候会提示要设置root密码,如 ...

  6. R语言中的字符串处理函数

    内容概览   尽管R是一门以数值向量和矩阵为核心的统计语言,但字符串有时候也会在数据分析中占到相当大的份量.   R语言是一个擅长处理数据的语言,但是也不可避免的需要处理一些字符串(文本数据).如何高 ...

  7. 我发起了一个 网格计算 协议 开源项目 GridP

    GridP  是   Grid Protocol   的 全称  . 我在 <关于软件产业的两个契机>  https://www.cnblogs.com/KSongKing/p/95319 ...

  8. js 函数问题

    replace() is not a function 1,情景描述:做项目的时候想把内容的某些字符给替换成另外一些字符 2,replace用法:replace() 方法用于在字符串中用一些字符替换另 ...

  9. 1.1.18 Word里将“字体加红”自定义为快捷方式

    1.单击[文件]>[选项]: 2.选择[自定义功能区],单击[键盘快捷方式]旁的[自定义]: 3.在[类别]菜单中选择[开始选项卡]:在[命令]菜单中选择[FontColorPicker] (或 ...

  10. shell 生成MAC地址

    # cat /dev/urandom |od -x |awk '{print $2,$3,$4}' |head -n 1 |sed -e 's/[[:space:]]//g' -e 's/\(..\) ...