- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章springboot 自定义权限标签(tld),在freemarker引用操作由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
第一步:引入jar包 。
1
2
3
4
5
|
<
dependency
>
<
groupId
>javax.servlet.jsp</
groupId
>
<
artifactId
>jsp-api</
artifactId
>
<
version
>2.2.1-b03</
version
>
</
dependency
>
|
第二步:自定义标签类 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
import
java.util.Map;
import
java.util.Set;
import
javax.servlet.http.HttpServletRequest;
import
org.jasig.cas.client.authentication.AttributePrincipal;
import
org.springframework.web.servlet.tags.RequestContextAwareTag;
import
com.goodidea.sso.dto.PrivilegesDto;
import
com.goodidea.sso.dto.ResourcesDto;
import
com.goodidea.sso.service.PrivilegesService;
/**
*
* @ClassName: PrivilegeTag
* @Description: 权限标签类
* @author lsg
* @date 2017年9月12日 下午5:36:01
*
*/
public
class
PrivilegeTag
extends
RequestContextAwareTag{
private
static
final
long
serialVersionUID = 534416848523276042L;
private
String menuAlias;
private
String priAlias;
public
String getMenuAlias() {
return
menuAlias;
}
public
void
setMenuAlias(String menuAlias) {
this
.menuAlias = menuAlias;
}
public
String getPriAlias() {
return
priAlias;
}
public
void
setPriAlias(String priAlias) {
this
.priAlias = priAlias;
}
@Override
protected
int
doStartTagInternal() {
// TODO Auto-generated method stub
boolean
result =
false
;
try
{
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
AttributePrincipal principal = (AttributePrincipal)request.getUserPrincipal();
Map<String, Object> attributes = principal.getAttributes();
String username=(String) attributes.get(
"username"
);
PrivilegesService privilegesService= (PrivilegesService)
this
.getRequestContext().getWebApplicationContext().getBean(
"privilegesServiceImpl"
);
Set<ResourcesDto> dto = privilegesService.findResourcesByUsername(username);
for
(ResourcesDto resourcesDto : dto) {
if
(
this
.menuAlias.equals(resourcesDto.getAlias())){
for
(PrivilegesDto pdto : resourcesDto.getPrivileges()) {
if
(
this
.priAlias.equals(pdto.getAlias())){
result =
true
;
}
}
}
}
}
catch
(Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
result =
false
;
}
return
result? EVAL_BODY_INCLUDE : SKIP_BODY;
}
}
|
第三步:创建tld标签,放入在web-inf下 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<
taglib
>
<
tlibversion
>1.0</
tlibversion
>
<
jspversion
>1.1</
jspversion
>
<
shortname
>privilege</
shortname
>
<
tag
>
<
name
>privilege</
name
>
<
tagclass
>com.goodidea.sso.core.PrivilegeTag</
tagclass
>
<
bodycontent
>empty</
bodycontent
>
<!--这里如果设为empty,则无body-->
<
attribute
>
<
name
>menuAlias</
name
>
<
required
>true</
required
>
<
rtexprvalue
>true</
rtexprvalue
>
</
attribute
>
<
attribute
>
<
name
>priAlias</
name
>
<
required
>true</
required
>
<
rtexprvalue
>true</
rtexprvalue
>
</
attribute
>
</
tag
>
</
taglib
>
|
第四:页面引用 。
<#assign p=JspTaglibs["/WEB-INF/tld/privilege.tld"] /> 。
注意tld,如果不在web.xml上进行引入的话,就放在web-inf下,要不然会报找不到tld资源异常 。
补充知识:Springboot项目 freemarker 引入shiro 标签 。
springboot集成shiro权限过程略过 。
1、添加maven 依赖 。
1
2
3
4
5
|
<
dependency
>
<
groupId
>net.mingsoft</
groupId
>
<
artifactId
>shiro-freemarker-tags</
artifactId
>
<
version
>0.1</
version
>
</
dependency
>
|
2、注入FreeMarkerConfigurer,未指定templateLoaderPath时遇到过跳转到页面404问题 。
1
2
3
4
5
6
7
8
9
10
11
|
@Bean
public
FreeMarkerConfigurer freeMarkerConfigurer()
throws
IOException, TemplateException {
FreeMarkerConfigurer freeMarkerConfigurer =
new
FreeMarkerConfigurer();
freeMarkerConfigurer.setTemplateLoaderPath(
"classpath:templates/"
);
freemarker.template.Configuration configuration = freeMarkerConfigurer.createConfiguration();
configuration.setDefaultEncoding(
"UTF-8"
);
//这里可以添加其他共享变量 比如sso登录地址
configuration.setSharedVariable(
"shiro"
,
new
ShiroTags());
freeMarkerConfigurer.setConfiguration(configuration);
return
freeMarkerConfigurer;
}
|
3、shiro标签 。
1、session中读取登录人信息 。
<@shiro.principal/> 。
2、带有loginName属性的对象转换为Prinipal后保存在session 。
<shiro:principal property="loginName" /> 。
3、带有loginName属性的Json(个人使用的是FashJson对象)转换为Prinipal后保存在session,使用freemarker标签处理Json 。
<#assign loginInfo><@shiro.principal/></#assign> 。
<#assign data=loginInfo?eval> 。
用户:${data.loginName!""} 。
4、其他shiro标签使用 。
<@shiro.hasPermission name="权限编码"> ... </@shiro.hasPermission> 。
以上这篇springboot 自定义权限标签(tld),在freemarker引用操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我.
原文链接:https://blog.csdn.net/cutterwolf/article/details/78085808 。
最后此篇关于springboot 自定义权限标签(tld),在freemarker引用操作的文章就讲到这里了,如果你想了解更多关于springboot 自定义权限标签(tld),在freemarker引用操作的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我似乎明白 TLD 后的点无关紧要,例如: http://example.com/somepage/ == http://example.com./somepage/ (注意 TLD 后面的点) 我的
我正在尝试运行一个简单的自定义 jsp 程序,但它不起作用,我使用的是 tomcat 8.5 和 ubuntu 14.04,我还将 custom.tld 放在 WEB-INF older这是我的代码
我正在尝试将应用程序发布到门户服务器上,由于无法在 WEB-INF 目录中找到 .tld 文件,因此 pu8blication 失败。 tld is 文件实际上不在 WEB-INF 目录中,我们将 t
这些文件应该提交给版本控制,还是重新生成: web-app/WEB-INF/tld/c.tld web-app/WEB-INF/tld/fmt.tld grails integrate-with --
我一直在 tomcat 7.30 (eclipse juno) 上得到这个 At least one JAR was scanned for TLDs yet contained no TLDs. E
TL;DR 我应该从 www.domain.tld 重定向到 domain.tld 还是相反? 我正在运行一个处理多个域的 CMS。到目前为止,CMS 负责将 www.domain.tld 重定向到
过去几天我一直在纠结这个 JSTL 问题。任何帮助表示赞赏。 Tomcat 6.0.28 eclipse :太阳神 pom.xml: javax.servlet jstl 1.1
我在使用 JSP 编写的新项目中遇到了问题。一些细节:- 使用 tomcat6。- 使用 Java 甲骨文 6。- 开发智能。 当通过 Inteliji 解聚和运行应用程序时,我总是遇到这个错误:
在将我们的 Web 应用程序主要升级到 ivy 以进行构建管理之后,我遇到了一些不寻常的错误,其中还包括更新所有涉及的主要库。当我们设法通过单元测试时,当我们将 Web 应用程序部署到 Tomcat
我使用 STS 插件从 Spring 模板创建一个 Spring MVC 项目。但是,当我运行该应用程序时出现错误: org.apache.jasper.JasperException: /WEB-I
是否可以使用 .htaccess 重写规则将子子域重定向到子域,并将子子域作为新文件夹? 例如...当我访问 2013.archive.example.com 时,我希望最终到达 archive.ex
我创建了一个自定义标签并包含以下 Maven 依赖项,以便获取所需的 java 类(标签支持等) javax.servlet jsp-api
我在 tomcat 8 上遇到问题,在 Tomcat 7 中运行 Web 应用程序时不会出现此问题。错误的详细信息 org.apache.jasper.JasperException: Mandato
感谢专家的帮助。 我被要求将客户的 WordPress 主页放在一个 TLD(即 domain.eu)上,并将所有其他页面/目录 301 到不同的 TLD 扩展名(即 domain.com/every
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Internal subdomain to folder redirect 我希望它是自动的,因为我正在为
我安装了 Magento,想知道如何将 domain.tld/index.php 重定向到 domain.tld? 我想删除 index.php 然后 301 回到 root。我有很多旧链接,这些链接
我正在尝试将 nginx 配置为: http://www.domain.tld --> https://domain.tld http://domain.tld --> https://domain.
我需要匹配主机名 - 但不需要 tld: example.com =~/regex/=> 示例 sub.example.com =~/regex/=> sub.example sub.sub.exam
我想将此函数导出到我的 custom-functions.tld 文件: package com.site.vo; public class Utils { public static Str
我已经创建了一个自定义 tld 文件。并包含在我的jsp中。 myJsp ... pageContext.setAttribute("pageBean", myPageBean); pageCont
我是一名优秀的程序员,十分优秀!