org.springframework.security.access.vote.RoleVoter.vote()方法的使用及代码示例

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

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

RoleVoter.vote介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-security

@Test
  public void nullAuthenticationDenies() {
    RoleVoter voter = new RoleVoter();
    voter.setRolePrefix("");
    Authentication notAuthenitcated = null;
    assertThat(voter.vote(notAuthenitcated, this, SecurityConfig.createList("A"))).isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
  }
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void oneMatchingAttributeGrantsAccess() {
  RoleVoter voter = new RoleVoter();
  voter.setRolePrefix("");
  Authentication userAB = new TestingAuthenticationToken("user", "pass", "A", "B");
  // Vote on attribute list that has two attributes A and C (i.e. only one matching)
  assertThat(voter.vote(userAB, this, SecurityConfig.createList("A", "C"))).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
}

代码示例来源:origin: org.springframework.boot/spring-boot-actuator

@Override
public boolean isUserInRole(String role) {
  if (!role.startsWith(this.roleVoter.getRolePrefix())) {
    role = this.roleVoter.getRolePrefix() + role;
  }
  return this.roleVoter.vote(this.authentication, null,
      Collections.singletonList(new SecurityConfig(
          role))) == AccessDecisionVoter.ACCESS_GRANTED;
}

代码示例来源:origin: codeabovelab/haven-platform

public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
    for (GrantedAuthority authority : authentication.getAuthorities()) {
      if (authority.getAuthority().equals(Authorities.ADMIN_ROLE)) {
        return ACCESS_GRANTED;
      }
    }
    return super.vote(authentication, object, attributes);
  }
}

代码示例来源:origin: org.duracloud/security

/**
 * This method is a pass-through for Spring-RoleVoter.
 *
 * @param authentication principal seeking AuthZ
 * @param resource       that is under protection
 * @param config         access-attributes defined on resource
 * @return vote (AccessDecisionVoter.ACCESS_GRANTED, ACCESS_DENIED, ACCESS_ABSTAIN)
 */
@Override
public int vote(Authentication authentication,
        Object resource,
        Collection<ConfigAttribute> config) {
  int decision = super.vote(authentication, resource, config);
  log.debug(VoterUtil.debugText("RoleVoterImpl",
                 authentication,
                 config,
                 resource,
                 decision));
  return decision;
}

相关文章