shiro学习28-shiro提供的filter-PermissionAuthyorizationFilter

上一节说的是基于角色的权限验证,这一节介绍基于权限的角色验证类——PermissionAuthorizationFilter

这个类和前面的基于角色的判定一样,不过使用的权限而已,在配置shiroFilterFactoryBean的时候每一个filter后面的[permission1permission2]表示的是权限,而且是或的关系,只要一个满足即可。

public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws IOException {

    Subject subject = getSubject(request, response);
    String[] perms = (String[]) mappedValue;
    boolean isPermitted = true;
    if (perms != null && perms.length > 0) {
        if (perms.length == 1) {
            if (!subject.isPermitted(perms[0])) {
                isPermitted = false;
            }
        } else {
            if (!subject.isPermittedAll(perms)) {
                isPermitted = false;
            }
        }
    }
    return isPermitted;
}

 

 

同样这个类只适用于每个权限定死的情况,不是很灵活,无法满足后期的权限更改。

猜你喜欢

转载自suichangkele.iteye.com/blog/2277100