org.opencastproject.security.api.User.hasRole()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(2.3k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中org.opencastproject.security.api.User.hasRole()方法的一些代码示例,展示了User.hasRole()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。User.hasRole()方法的具体详情如下:
包路径:org.opencastproject.security.api.User
类名称:User
方法名:hasRole

User.hasRole介绍

[英]Returns whether the user is in a specific role.
[中]返回用户是否处于特定角色。

代码示例

代码示例来源:origin: opencast/opencast

/**
 * Check if the current user has access to the capture agent with the given id.
 * @param agentId
 *           The agent id to check.
 * @throws UnauthorizedException
 *           If the user doesn't have access.
 */
public static void checkAgentAccess(final SecurityService securityService, final String agentId)
  throws UnauthorizedException {
 if (isBlank(agentId)) {
  return;
 }
 final User user = securityService.getUser();
 if (user.hasRole(SecurityConstants.GLOBAL_ADMIN_ROLE) || user.hasRole(user.getOrganization().getAdminRole())) {
  return;
 }
 if (!user.hasRole(SecurityUtil.getCaptureAgentRole(agentId))) {
  throw new UnauthorizedException(user, "schedule");
 }
}

代码示例来源:origin: opencast/opencast

if (user.hasRole(GLOBAL_ADMIN_ROLE) || user.hasRole(org.getAdminRole()))
 return true;

代码示例来源:origin: opencast/opencast

if (!originalUser.hasRole(GLOBAL_ADMIN_ROLE)) {
 logger.warn("An unauthorized request is trying to switch from organization '{}' to '{}'",
     originalOrganization.getId(), organizationHeader);
if (!originalUser.hasRole(GLOBAL_SUDO_ROLE)) {
 logger.warn("An unauthorized request is trying to switch from user '{}' to '{}'", originalUser.getUsername(),
     userHeader);
 if (!originalUser.hasRole(GLOBAL_ADMIN_ROLE)) {
   if (requestedUser.hasRole(systemRole)) {
    logger.warn("An unauthorized request is trying to switch to an admin user, from '{}' to '{}'",
        originalUser.getUsername(), userHeader);
  if (!originalUser.hasRole(organizationAdminRole) && requestedUser.hasRole(organizationAdminRole)) {
   logger.warn("An unauthorized request is trying to switch to an admin user, from '{}' to '{}'",
       originalUser.getUsername(), userHeader);
if (!originalUser.hasRole(GLOBAL_SUDO_ROLE)) {
 logger.warn("An unauthorized request is trying to switch roles from '{}' to '{}'", requestedUser.getRoles(),
     rolesHeader);
if (!originalUser.hasRole(GLOBAL_ADMIN_ROLE)) {
 if (!originalUser.hasRole(organizationAdminRole) && requestedRoles.contains(organizationAdminRole)) {
  logger.warn("An unauthorized request by user '{}' is trying to gain admin role '{}'",
      originalUser.getUsername(), organizationAdminRole);

相关文章