[ 
https://issues.apache.org/jira/browse/SHIRO-450?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13877421#comment-13877421
 ] 

Devendra Mani commented on SHIRO-450:
-------------------------------------

Following works. You have to create a class and then map it to tld.
 I used HasAnyPermissionTag class in my  package and then binded this to 
shiro.tld 


public class HasAnyPermissionTag extends PermissionTag {
    public HasAnyPermissionTag() {
    }

    protected boolean showTagBody(String permissions) {
            boolean hasAnyPermissions = false;
            Subject subject = getSubject();
            if (subject != null) {             
                    for (String role : permissions.split(",")) {
                            if (subject.isPermitted(role.trim())) {
                                    hasAnyPermissions = true;
                                    break;
                            }
                    }
            }
            return hasAnyPermissions;
    }
}

<tag>
    <name>hasAnyPermission</name>
    <tag-class>in.org.cris.oaew.rshl.shiro.HasAnyPermissionTag</tag-class>
    <body-content>JSP</body-content>
    <description>Displays body content only if the current Subject (user)
      'has' (implies) the specified permission (i.e the user has the specified 
ability).
    </description>
    <attribute>
      <name>name</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>
  </tag>

Now you can use  like <shiro:hasAnyPermission 
name="printer:register,pc:register">

> Why there is NO <hasAnyPermission> tag in the shiro-web project?
> ----------------------------------------------------------------
>
>                 Key: SHIRO-450
>                 URL: https://issues.apache.org/jira/browse/SHIRO-450
>             Project: Shiro
>          Issue Type: Question
>          Components: Authorization (access control) , Web
>    Affects Versions: 1.2.1
>            Reporter: Harry Chan
>            Priority: Minor
>
> In the Shiro web page: 
> http://shiro.apache.org/web.html#Web-JSP%2FGSPTagLibrary
> I found that there is a <hasAnyRole> tag but NO <hasAnyPermission> tag.
> I am wondering if there is a plan to implement the <hasAnyPermission> tag.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to