當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleAuthorizationInfo.addStringPermission方法代碼示例

本文整理匯總了Java中org.apache.shiro.authz.SimpleAuthorizationInfo.addStringPermission方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleAuthorizationInfo.addStringPermission方法的具體用法?Java SimpleAuthorizationInfo.addStringPermission怎麽用?Java SimpleAuthorizationInfo.addStringPermission使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.shiro.authz.SimpleAuthorizationInfo的用法示例。


在下文中一共展示了SimpleAuthorizationInfo.addStringPermission方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
	SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
	Long userId = (Long) WebUtil.getCurrentUser();
	Parameter parameter = new Parameter("sysAuthorizeService", "queryPermissionByUserId").setId(userId);
	logger.info("{} execute queryPermissionByUserId start...", parameter.getNo());
	List<?> list = provider.execute(parameter).getList();
	logger.info("{} execute queryPermissionByUserId end.", parameter.getNo());
	for (Object permission : list) {
		if (StringUtils.isNotBlank((String) permission)) {
			// 添加基於Permission的權限信息
			info.addStringPermission((String) permission);
		}
	}
	// 添加用戶權限
	info.addStringPermission("user");
	return info;
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:18,代碼來源:Realm.java

示例2: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(
		PrincipalCollection principals) {
	String userName = (String) principals.fromRealm(getName()).iterator()
			.next();
	List<WizardRoleInfo> roleInfos = securityService.getRoleInfo(userName);
	List<WizardOrgInfo> permissionInfos = null;
	if (null == roleInfos || 0 == roleInfos.size()) {
		return null;
	} else {
		SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
		for (WizardRoleInfo roleInfo : roleInfos) {
			info.addRole(roleInfo.getRoleName());
			permissionInfos = securityService.getPermissionInfo(roleInfo
					.getRoleName());
			for (WizardOrgInfo permissionInfo : permissionInfos) {
				info.addStringPermission(permissionInfo.getOrgName());
			}
		}
		return info;
	}

}
 
開發者ID:joaquinaimar,項目名稱:wizard,代碼行數:24,代碼來源:WizardWebRealm.java

示例3: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {

    final String username = getUsername(principals);

    List<Roles> roles = usersRepository.findRolesByUsername(username);
    LOG.debug("Load Roles[{}] by username: {}", roles, username);

    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();

    for (Roles role : roles) {
        info.addRole(role.roleName());
        for (RolesPermissions permissions : role.permissions()) {
            info.addStringPermission(permissions.permission());
        }
    }

    return info;
}
 
開發者ID:monkeyk,項目名稱:oauth2-shiro-redis,代碼行數:20,代碼來源:RedisRealm.java

示例4: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
 * 獲取當前用戶的角色集合,權限集合
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
	SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
	//獲取保存在session中的用戶信息
	SysUser user = (SysUser) SecurityUtils.getSubject().getSession().getAttribute(SysUser.SYS_USER);
	if (user == null) {
		throw new IllegalArgumentException();
	}
	//獲取當前用戶擁有的所有角色
	List<SysRole> roles = roleService.getSysRoleByUserId(user.getUserId().toString(), PublicEnum.NORMAL.value());
	for (SysRole sysRole : roles) {
		authorizationInfo.addRole(sysRole.getRoleCode());
	}
	//獲取當前用戶擁有的所有權限
	List<SysPermission> permissions = permissionService.getSysPermissionByUserId(user.getUserId(), PublicEnum.NORMAL.value());
	for (SysPermission sysPermission : permissions) {
		authorizationInfo.addStringPermission(sysPermission.getPermission());
	}
	System.out.println("用戶權限:"+ JSON.toJSONString(authorizationInfo));
	return authorizationInfo;
}
 
開發者ID:babymm,項目名稱:mumu,代碼行數:25,代碼來源:UserRealm.java

示例5: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
//@org.springframework.transaction.annotation.Transactional
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
    //獲取當前用戶
    //UserDto user = convertToDto(userDao.findUserByUsername((String)principalCollection.getPrimaryPrincipal()));
    //User currentUser = userDao.findUserByUsername((String)principalCollection.getPrimaryPrincipal());
    UserDto user = (UserDto) SecurityUtils.getSubject().getSession().getAttribute("user");

    //把principals放session中,key=userId value=principals
    SecurityUtils.getSubject().getSession().setAttribute(String.valueOf(user.getId()),SecurityUtils.getSubject().getPrincipals());

    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    //賦予角色
    for(RoleDto role:user.getRoles()){
        info.addRole(role.getName());
    }
    //賦予權限
    for(PermissionDto permission:user.getPermissions()){
        //System.out.println(permission.getName());
        info.addStringPermission(permission.getName());
    }
    return info;
}
 
開發者ID:ZhuXS,項目名稱:Spring-Shiro-Spark,代碼行數:24,代碼來源:ShiroRealm.java

示例6: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(
        PrincipalCollection principals) {
    //XXX 在這裏獲取到用戶,並獲取到相關角色和權限,在這裏定義一個基礎用戶
    SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
    String username = String.valueOf(principals.getPrimaryPrincipal());//取查詢獲取用戶名
    //獲取當前用戶
    //final IUserModel user =mscUsersPersonService.findByUserName(username);// userService.selectByUsername(username);
    //權限列表
    final List<IRoleDomain> roleInfoList =CurrentUserUtil.getPermissionList();//mscAuthRoleService.findByUser(user.getUserId());
    if(roleInfoList!=null && !roleInfoList.isEmpty()){
        for (IRoleDomain role : roleInfoList) {
            // 添加權限角色
            String authRole= AuthConstant.getRole(role.getType());
            authorizationInfo.addRole(authRole);
            authorizationInfo.addStringPermission(authRole);//將擁有的角色權限直接添加到權限中
            final List<IAuthDomain> mscAuthInfoList =role.getAuthList();// permissionService.selectPermissionsByRoleId(role.getId());
            for (IAuthDomain authInfo : mscAuthInfoList) {
                // 添加權限
                authorizationInfo.addStringPermission(authInfo.getAuthKey());//(permission.getPermissionSign());
            }
        }
    }
    return authorizationInfo;

}
 
開發者ID:haizicq,項目名稱:osframe,代碼行數:27,代碼來源:MscLoginRealm.java

示例7: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
 * 授權查詢回調函數, 進行鑒權但緩存中無用戶的授權信息時調用
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
	Principal principal = (Principal) getAvailablePrincipal(principals);

	User user = getSystemService().getUserByLoginName(principal.getLoginName());
	if (user != null) {
		SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();

		info.addStringPermission("sys:test:add");
		info.addStringPermission("sys:test:edit");
		// 添加用戶權限
		info.addStringPermission("user");
		info.addRole("role1");
		info.addRole("role2");
		return info;
	} else {
		return null;
	}
}
 
開發者ID:whatlookingfor,項目名稱:spring-boot-sample,代碼行數:23,代碼來源:SystemAuthorizingRealm.java

示例8: getSimpleAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
private SimpleAuthorizationInfo getSimpleAuthorizationInfo(String username) throws Exception {
	Map<String, Object> params = new HashMap<String, Object>();
	params.put("account", username);
	List<TbUserRole> roleList = userRoleService.findListByParams(params);
	if (roleList==null) {
		return null;
	}
	SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
	for (TbUserRole userRole : roleList) {
		info.addRole(userRole.getRole());
		params.clear();
		params.put("role", userRole.getRole());
		List<TbRolePermission> rolePermissionList = rolePermissionService.findListByParams(params);
		if (rolePermissionList==null) {
			continue;
		}
		for (TbRolePermission rolePermission : rolePermissionList) {
			info.addStringPermission(rolePermission.getPermission());
		}
	}
	return info;		
}
 
開發者ID:billchen198318,項目名稱:bamboobsc,代碼行數:23,代碼來源:GreenStepBaseAuthorizingLdapRealm.java

示例9: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
  // make sure the user is jcool, (its just for testing)

  if (principals.asList().get(0).toString().equals("jcool")) {
    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();

    info.addRole("test-role1");
    info.addRole("test-role2");

    info.addStringPermission("test:*");

    return info;
  }

  return null;
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:18,代碼來源:MockRealmB.java

示例10: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 * <p>This default implementation handles built-in groups (all, anonymous, registered, etc.), delegating
 * to loadAuthorizationInfo method the actual loading of application-specific groups.</p>
 *
 * @return
 */
public AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    Object principal = principals.getPrimaryPrincipal();
    Set<String> groups = new HashSet<String>();
    groups.add(SecurityLogic.getAllGroup(portofinoConfiguration));
    if (principal == null) {
        groups.add(SecurityLogic.getAnonymousGroup(portofinoConfiguration));
    } else if (principal instanceof Serializable) {
        groups.add(SecurityLogic.getRegisteredGroup(portofinoConfiguration));
        groups.addAll(loadAuthorizationInfo((Serializable) principal));
    } else {
        throw new AuthorizationException("Invalid principal: " + principal);
    }

    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(groups);
    if(groups.contains(SecurityLogic.getAdministratorsGroup(portofinoConfiguration))) {
        info.addStringPermission("*");
    }
    Permission permission = new GroupPermission(groups);
    info.setObjectPermissions(Collections.singleton(permission));
    return info;
}
 
開發者ID:ManyDesigns,項目名稱:Portofino,代碼行數:29,代碼來源:AbstractPortofinoRealm.java

示例11: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    // null usernames are invalid
    if (principals == null) {
        throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
    }
    Integer userId = (Integer) getAvailablePrincipal(principals);

    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    Set<Role> roles = userRepository.getRoles(userId);
    for (Role role : roles) {
        info.addRole(role.getName());
    }
    List<PostPermission> permissions = userRepository.getPermissions(userId);

    for (PostPermission permission : permissions) {
        if (permission.getMask() > 0) {
            info.addStringPermission(permission.getLiteral());
        }
    }
    return info;
}
 
開發者ID:antoniomaria,項目名稱:shiro-jpa,代碼行數:23,代碼來源:JPARealm.java

示例12: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    Subject pricipalSubject = SecurityUtils.getSubject();
    User principalUser = (User) pricipalSubject.getPrincipal();// 獲取通過認證用戶
    List<Authority> authorityList = authorityMapper.selectByUserId(principalUser.getUserId());// 獲取用戶的權限集合(用戶和用戶組的角色權限)
    if (null != authorityList && authorityList.size() > 0) {
        SimpleAuthorizationInfo authInfo = new SimpleAuthorizationInfo();// 創建返回權限對象
        for (Authority authority : authorityList) {
            if (null != authority && StringUtils.isNotBlank(authority.getActions())) {
                String[] actionString = authority.getActions().split(",");
                for (String action : actionString) {
                    // shiro權限字符串為:“當前資源英文名稱:操作名英文名稱”
                    // 對action進行分割,避免權限範圍對其造成的影響 
                    String[] authStr = action.split(":");
                    authInfo.addStringPermission(authority.getMenuEnName() + ":" + authStr[0]);// 設置權限操作(設置Permission)
                }
            }
        }
        return authInfo;
    }
    return null;
}
 
開發者ID:GlacierSoft,項目名稱:netloan-project,代碼行數:23,代碼來源:CustomPermissionsRealm.java

示例13: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(final PrincipalCollection principals) {
    try {
        String principal = (String) principals.getPrimaryPrincipal();
        SimpleAuthorizationInfo sai = new SimpleAuthorizationInfo();
        Set<String> perms = getPerms(principal);
        if (perms != null) {
            for (String perm : perms) {
                sai.addStringPermission(perm);
            }
        }
        Set<String> roles = getRoles(principal);
        if (roles != null) {
            for (String role : roles) {
                sai.addRole(role);
            }
        }
        return sai;
    } catch (GwtUtilException e) {
        log.warn("Exception getting authorization info: {}", e);
    }
    return null;
}
 
開發者ID:rkfg,項目名稱:gwtutil,代碼行數:24,代碼來源:GwtUtilRealm.java

示例14: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    // null usernames are invalid
    if (principals == null) {
        throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
    }
    User user = (User) getAvailablePrincipal(principals);

    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    Set<Role> roles = userService.getRoles(user.getId());
    for (Role role : roles) {
        info.addRole(role.getName());
    }
    Set<Permission<?>> permissions = userService.getPermissions(user.getId());

    for (Permission<?> permission : permissions) {
        info.addStringPermission(permission.getLiteral());
    }
    return info;
}
 
開發者ID:antoniomaria,項目名稱:gazpachoquest,代碼行數:21,代碼來源:JPARealm.java

示例15: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(
		PrincipalCollection principals) {
	Authentication authentication = (Authentication) principals
			.fromRealm(getName()).iterator().next();
	Role[] roles = securityService.getRoles(authentication);
	Permission[] permissionos = null;
	if (!CommonUtil.isEmpty(roles)) {
		SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
		for (Role role : roles) {
			info.addRole(role.getName());
			permissionos = securityService.getPermissions(role);
			for (Permission permission : permissionos)
				info.addStringPermission(permission.getName());
		}
		return info;
	}
	return null;
}
 
開發者ID:joaquinaimar,項目名稱:wizard,代碼行數:20,代碼來源:WebAuthorizingRealm.java


注:本文中的org.apache.shiro.authz.SimpleAuthorizationInfo.addStringPermission方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。