java role_Java Role.isAllowed方法代码示例

import org.sakaiproject.authz.api.Role; //导入方法依赖的package包/类

public boolean setPermissionsForSite(String siteId, Map params) {

String userId = getCurrentUserId();

if (userId == null)

throw new SecurityException("This action (setPerms) is not accessible to anon and there is no current user.");

Site site = null;

try {

site = siteService.getSite(siteId);

} catch (IdUnusedException ide) {

log.warn(userId + " attempted to update COMMONS permissions for unknown site " + siteId);

return false;

}

boolean admin = securityService.isSuperUser(userId);

try {

AuthzGroup authzGroup = authzGroupService.getAuthzGroup(site.getReference());

// admin can update permissions. check for anyone else

if (!securityService.isSuperUser()) {

Role siteRole = getCurrentUserRoleForSite(site);

AuthzGroup siteHelperAuthzGroup = authzGroupService.getAuthzGroup("!site.helper");

Role siteHelperRole = siteHelperAuthzGroup.getRole(siteRole.getId());

if (!siteRole.isAllowed(SiteService.SECURE_UPDATE_SITE)) {

log.warn(userId + " attempted to update COMMONS permissions for site " + site.getTitle());

return false;

}

}

boolean changed = false;

for (String name : params.keySet()) {

if (!name.contains(":")) {

continue;

}

String value = (String) params.get(name);

String roleId = name.substring(0, name.indexOf(":"));

Role role = authzGroup.getRole(roleId);

if (role == null) {

throw new IllegalArgumentException("Invalid role id '" + roleId + "' provided in POST parameters.");

}

String function = name.substring(name.indexOf(":") + 1);

if ("true".equals(value)) {

role.allowFunction(function);

} else {

role.disallowFunction(function);

}

changed = true;

}

if (changed) {

try {

authzGroupService.save(authzGroup);

} catch (AuthzPermissionException ape) {

throw new SecurityException("The permissions for this site (" + siteId + ") cannot be updated by the current user.");

}

}

return true;

} catch (GroupNotDefinedException gnde) {

log.error("No realm defined for site (" + siteId + ").", gnde);

}

return false;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值