当前位置: 首页>>代码示例>>Java>>正文


Java Subject.isPermitted方法代码示例

本文整理汇总了Java中org.apache.shiro.subject.Subject.isPermitted方法的典型用法代码示例。如果您正苦于以下问题:Java Subject.isPermitted方法的具体用法?Java Subject.isPermitted怎么用?Java Subject.isPermitted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.shiro.subject.Subject的用法示例。


在下文中一共展示了Subject.isPermitted方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkSubjectRolesAndPermissions

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/**
 * Check subject roles and permissions.
 *
 * @param currentUser the current user
 * @throws FailedLoginException the failed login exception in case roles or permissions are absent
 */
protected void checkSubjectRolesAndPermissions(final Subject currentUser) throws FailedLoginException {
    if (this.requiredRoles != null) {
        for (final String role : this.requiredRoles) {
            if (!currentUser.hasRole(role)) {
                throw new FailedLoginException("Required role " + role + " does not exist");
            }
        }
    }

    if (this.requiredPermissions != null) {
        for (final String perm : this.requiredPermissions) {
            if (!currentUser.isPermitted(perm)) {
                throw new FailedLoginException("Required permission " + perm + " does not exist");
            }
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:24,代码来源:ShiroAuthenticationHandler.java

示例2: showTagBody

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@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;
}
 
开发者ID:funtl,项目名称:framework,代码行数:21,代码来源:HasAnyPermissionsTag.java

示例3: checkSubjectRolesAndPermissions

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/**
 * Check subject roles and permissions.
 *
 * @param currentUser the current user
 * @throws FailedLoginException the failed login exception in case roles or permissions are absent
 */
protected void checkSubjectRolesAndPermissions(final Subject currentUser) throws FailedLoginException {
    if (this.requiredRoles != null) {
        for (final String role : this.requiredRoles) {
            if (!currentUser.hasRole(role)) {
                throw new FailedLoginException("Required role " + role + " does not exist");
            }
        }
    }

    if (this.requiredPermissions != null) {
        for (final String perm : this.requiredPermissions) {
            if (!currentUser.isPermitted(perm)) {
                throw new FailedLoginException("Required permission " + perm + " cannot be located");
            }
        }
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:24,代码来源:ShiroAuthenticationHandler.java

示例4: hasAnyPermissions

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/**
 * 验证用户是否具有以下任意一个权限。
 * @param permissions 以 delimeter 为分隔符的权限列表
 * @param delimeter 权限列表分隔符
 * @return 用户是否具有以下任意一个权限
 */
public boolean hasAnyPermissions(String permissions, String delimeter) {
	Subject subject = SecurityUtils.getSubject();

	if (subject != null) {
		if (delimeter == null || delimeter.length() == 0) {
			delimeter = PERMISSION_NAMES_DELIMETER;
		}

		for (String permission : permissions.split(delimeter)) {
			if (permission != null && subject.isPermitted(permission.trim()) == true) {
				return true;
			}
		}
	}

	return false;
}
 
开发者ID:babymm,项目名称:mumu,代码行数:24,代码来源:ShiroPermissingTag.java

示例5: authorize

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@Override
public AuthorizeResult authorize() {
    try {
        String[] perms = requiresPermissions.value();
        Subject subject = SecurityUtils.getSubject();

        if (perms.length == 1) {
            subject.checkPermission(perms[0]);
            return AuthorizeResult.ok();
        }
        if (Logical.AND.equals(requiresPermissions.logical())) {
            subject.checkPermissions(perms);
            return AuthorizeResult.ok();
        }
        if (Logical.OR.equals(requiresPermissions.logical())) {
            // Avoid processing exceptions unnecessarily - "delay" throwing the
            // exception by calling hasRole first
            boolean hasAtLeastOnePermission = false;
            for (String permission : perms)
                if (subject.isPermitted(permission))
                    hasAtLeastOnePermission = true;
            // Cause the exception if none of the role match, note that the
            // exception message will be a bit misleading
            if (!hasAtLeastOnePermission)
                subject.checkPermission(perms[0]);

        }

        return AuthorizeResult.ok();

    } catch (AuthorizationException e) {
        return AuthorizeResult.fail(AuthorizeResult.ERROR_CODE_UNAUTHORIZATION);
    }
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:35,代码来源:ShiroRequiresPermissionsProcesser.java

示例6: isAccessAllowed

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@Override
protected boolean isAccessAllowed(ServletRequest request,
		ServletResponse response, Object mappedValue) throws Exception {
	
	//先判断带参数的权限判断
	Subject subject = getSubject(request, response);
	if(null != mappedValue){
		String[] arra = (String[])mappedValue;
		for (String permission : arra) {
			if(subject.isPermitted(permission)){
				return Boolean.TRUE;
			}
		}
	}
	//取到请求的uri ,进行权限判断
	HttpServletRequest httpRequest = (HttpServletRequest)request;
	
	String uri = httpRequest.getRequestURI();
	String contextPath = httpRequest.getContextPath();
	if(uri != null && uri.startsWith(contextPath))
	{
		uri = uri.replace(contextPath, "");
	}
	if("/".equals(uri)) //http://localhost:8070/webside/  处理这样的url
		return Boolean.TRUE;
	if(subject.isPermitted(uri))
		return Boolean.TRUE;
	return Boolean.FALSE;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:30,代码来源:PermissionFilter.java

示例7: test

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@Test
public void test(){

    log.info("My First Apache Shiro Application");

    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);

    // get the currently executing user:
    Subject currentUser = SecurityUtils.getSubject();

    // Do some stuff with a Session (no need for a web or EJB container!!!)
    Session session = currentUser.getSession();
    session.setAttribute("someKey", "aValue");
    String value = (String) session.getAttribute("someKey");
    if (value.equals("aValue")) {
        log.info("Retrieved the correct value! [" + value + "]");
    }

    // let's login the current user so we can check against roles and permissions:
    if (!currentUser.isAuthenticated()) {
        UsernamePasswordToken token = new UsernamePasswordToken("lonestarr", "vespa");
        token.setRememberMe(true);
        try {
            currentUser.login(token);
        } catch (UnknownAccountException uae) {
            log.info("There is no user with username of " + token.getPrincipal());
        } catch (IncorrectCredentialsException ice) {
            log.info("Password for account " + token.getPrincipal() + " was incorrect!");
        } catch (LockedAccountException lae) {
            log.info("The account for username " + token.getPrincipal() + " is locked.  " +
                    "Please contact your administrator to unlock it.");
        }
        // ... catch more exceptions here (maybe custom ones specific to your application?
        catch (AuthenticationException ae) {
            //unexpected condition?  error?
        }
    }

    //say who they are:
    //print their identifying principal (in this case, a username):
    log.info("User [" + currentUser.getPrincipal() + "] logged in successfully.");

    //test a role:
    if (currentUser.hasRole("schwartz")) {
        log.info("May the Schwartz be with you!");
    } else {
        log.info("Hello, mere mortal.");
    }

    //test a typed permission (not instance-level)
    if (currentUser.isPermitted("lightsaber:weild")) {
        log.info("You may use a lightsaber ring.  Use it wisely.");
    } else {
        log.info("Sorry, lightsaber rings are for schwartz masters only.");
    }

    //a (very powerful) Instance Level permission:
    if (currentUser.isPermitted("winnebago:drive:eagle5")) {
        log.info("You are permitted to 'drive' the winnebago with license plate (id) 'eagle5'.  " +
                "Here are the keys - have fun!");
    } else {
        log.info("Sorry, you aren't allowed to drive the 'eagle5' winnebago!");
    }
    //all done - log out!
    currentUser.logout();
}
 
开发者ID:followwwind,项目名称:apache,代码行数:69,代码来源:ShiroTest.java

示例8: hasPermission

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/**
 * 验证用户是否具备某权限。
 * @param permission 权限名称
 * @return 用户是否具备某权限
 */
public boolean hasPermission(String permission) {
	Subject subject = SecurityUtils.getSubject();
	return subject != null && subject.isPermitted(permission);
}
 
开发者ID:babymm,项目名称:mumu,代码行数:10,代码来源:ShiroPermissingTag.java

示例9: hasPermission

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/**
 * 是否拥有该权限
 * @param permission  权限标识
 * @return   true:是     false:否
 */
public boolean hasPermission(String permission) {
	Subject subject = SecurityUtils.getSubject();
	return subject != null && subject.isPermitted(permission);
}
 
开发者ID:gyp220203,项目名称:renren-msg,代码行数:10,代码来源:VelocityShiro.java


注:本文中的org.apache.shiro.subject.Subject.isPermitted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。