Java 创建简单的自定义标记以显示或隐藏主体
我正在尝试创建自己的自定义标记,以便根据属性集显示或隐藏标记之间的内容Java 创建简单的自定义标记以显示或隐藏主体,java,jsp,jsp-tags,Java,Jsp,Jsp Tags,我正在尝试创建自己的自定义标记,以便根据属性集显示或隐藏标记之间的内容 <mytag:isUserInRole role="admin">Show admin specific text</mytag:isUserInRole>` 下面是我的AuthorizationTag doStartTag方法: public int doStartTag() throws JspException{ System.out.println("Role"+role);
<mytag:isUserInRole role="admin">Show admin specific text</mytag:isUserInRole>`
下面是我的AuthorizationTag doStartTag方法:
public int doStartTag() throws JspException{
System.out.println("Role"+role);
//Check that role is given and securitycontext is not null
if(role==null|| SecurityContextHolder.getContext()==null || SecurityContextHolder.getContext().getAuthentication()==null){
return Tag.SKIP_BODY;
}
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if(hasPermission(auth)){
return Tag.EVAL_BODY_INCLUDE;
} else {
return Tag.SKIP_BODY;
}
}
试试这个:
jsp
,还要注意
和
之间的区别,因为我知道有一个标记库uri=”http://www.springframework.org/security/tags“
哪一个正是您想要实现的目标-它有谢谢!工作起来很有魅力:)请注意,Facelets与JSP不同,因此标记处理程序可能不完全相同。是的,我正在调查这个问题,但我找不到任何关于如何根据需要使用它的文档,所以我决定实现我自己的解决方案。。。
public int doStartTag() throws JspException{
System.out.println("Role"+role);
//Check that role is given and securitycontext is not null
if(role==null|| SecurityContextHolder.getContext()==null || SecurityContextHolder.getContext().getAuthentication()==null){
return Tag.SKIP_BODY;
}
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if(hasPermission(auth)){
return Tag.EVAL_BODY_INCLUDE;
} else {
return Tag.SKIP_BODY;
}
}