當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。