spring-security 在jsp中的标签库
2016-06-21 08:44
381 查看
spring-security 在jsp中的标签库
1.在jsp中声明
[html] view
plain copy
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
2.标签
目前共有三个标签
[html] view
plain copy
<sec:authorize></sec:authorize>
<sec:authentication property=""></sec:authentication>
<sec:accesscontrollist hasPermission="" domainObject=""></sec:accesscontrollist>
2.1、authorize标签
这个标签用来决定它的内容是否会被执行.
[html] view
plain copy
<sec:authorize access="hasRole('supervisor')">
This content will only be visible to users who have
the "supervisor" authority in their list of GrantedAuthoritys.
</sec:authorize>
显示一个特定的链接,如果用户允许点击它.
[html] view
plain copy
<sec:authorize url="/admin">
This content will only be visible to users who are authorized to send requests to the "/admin" URL.
</sec:authorize>
2.2、authentication标签
这个标签允许访问当前的Authentication 对象, 保存在安全上下文中。
比如,如果Authentication 的principal 属性是Spring Security 的UserDetails 对象的一个实例,
就要使用
[html] view
plain copy
<sec:authentication property="principal.username" />
来渲染当前用户的名称。
当然,它不必使用JSP 标签来实现这些功能,一些人更愿意在视图中保持逻辑越少越好。你可以在你的MVC 控制器中访问Authentication 对象( 通过调用
SecurityContextHolder.getContext().getAuthentication()) 然后直接在模型中添加数据,来渲染视图。
2.3、accesscontrollist标签
这个标签纸在使用Spring Security ACL 模块时才可以使用。它检测一个用逗号分隔的特
定领域对象的需要权限列表。如果当前用户拥有这些权限的任何一个,标签内容就会被执行。
否则,就会被略过。
[html] view
plain copy
<sec:accesscontrollist hasPermission="1,2" domainObject="${someObject}">
This will be shown if the user has either of the permissions
represented by the values "1" or "2" on the given object.
</sec:accesscontrollist>
参考:Spring_Security-3.0.1_中文官方文档(翻译版).pdf
1.在jsp中声明
[html] view
plain copy
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
2.标签
目前共有三个标签
[html] view
plain copy
<sec:authorize></sec:authorize>
<sec:authentication property=""></sec:authentication>
<sec:accesscontrollist hasPermission="" domainObject=""></sec:accesscontrollist>
2.1、authorize标签
这个标签用来决定它的内容是否会被执行.
[html] view
plain copy
<sec:authorize access="hasRole('supervisor')">
This content will only be visible to users who have
the "supervisor" authority in their list of GrantedAuthoritys.
</sec:authorize>
显示一个特定的链接,如果用户允许点击它.
[html] view
plain copy
<sec:authorize url="/admin">
This content will only be visible to users who are authorized to send requests to the "/admin" URL.
</sec:authorize>
2.2、authentication标签
这个标签允许访问当前的Authentication 对象, 保存在安全上下文中。
比如,如果Authentication 的principal 属性是Spring Security 的UserDetails 对象的一个实例,
就要使用
[html] view
plain copy
<sec:authentication property="principal.username" />
来渲染当前用户的名称。
当然,它不必使用JSP 标签来实现这些功能,一些人更愿意在视图中保持逻辑越少越好。你可以在你的MVC 控制器中访问Authentication 对象( 通过调用
SecurityContextHolder.getContext().getAuthentication()) 然后直接在模型中添加数据,来渲染视图。
2.3、accesscontrollist标签
这个标签纸在使用Spring Security ACL 模块时才可以使用。它检测一个用逗号分隔的特
定领域对象的需要权限列表。如果当前用户拥有这些权限的任何一个,标签内容就会被执行。
否则,就会被略过。
[html] view
plain copy
<sec:accesscontrollist hasPermission="1,2" domainObject="${someObject}">
This will be shown if the user has either of the permissions
represented by the values "1" or "2" on the given object.
</sec:accesscontrollist>
参考:Spring_Security-3.0.1_中文官方文档(翻译版).pdf
相关文章推荐
- 一个jar包里的网站
- 一个jar包里的网站之文件上传
- 一个jar包里的网站之返回对媒体类型
- Spring和ThreadLocal
- Spring Boot 开发微服务
- Spring AOP动态代理-切面
- Spring整合Quartz(JobDetailBean方式)
- Spring整合Quartz(JobDetailBean方式)
- 模拟Spring的简单实现
- Spring整合WebSocket应用示例(上)
- spring+html5实现安全传输随机数字密码键盘
- Spring中属性注入详解
- 监听器获取Spring配置文件的方法
- springmvc 发送ajax出现中文乱码的解决方法汇总
- SpringMVC框架下JQuery传递并解析Json格式的数据是如何实现的
- 详解Java的MyBatis框架和Spring框架的整合运用
- struts2 spring整合fieldError问题
- spring的jdbctemplate的crud的基类dao
- 读取spring配置文件的方法(spring读取资源文件)