liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
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
/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.common.security.shiro;
 
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.tags.PermissionTag;
 
/**
 * Shiro HasAnyPermissions Tag.
 * 
 * @author calvin
 */
public class HasAnyPermissionsTag extends PermissionTag {
 
    private static final long serialVersionUID = 1L;
    private static final String PERMISSION_NAMES_DELIMETER = ",";
 
    @Override
    protected boolean showTagBody(String permissionNames) {
        boolean hasAnyPermission = false;
 
        Subject subject = getSubject();
 
        if (subject != null) {
            // Iterate through permissions and check to see if the user has one of the permissions
            for (String permission : permissionNames.split(PERMISSION_NAMES_DELIMETER)) {
 
                if (subject.isPermitted(permission.trim())) {
                    hasAnyPermission = true;
                    break;
                }
 
            }
        }
 
        return hasAnyPermission;
    }
 
}