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

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

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

RoleVoter.<init>介绍

暂无

代码示例

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

/**
 * Creates the default {@link AccessDecisionVoter} instances used if an
 * {@link AccessDecisionManager} was not specified.
 *
 * @param http the builder to use
 */
@Override
@SuppressWarnings("rawtypes")
final List<AccessDecisionVoter<? extends Object>> getDecisionVoters(H http) {
  List<AccessDecisionVoter<? extends Object>> decisionVoters = new ArrayList<AccessDecisionVoter<? extends Object>>();
  decisionVoters.add(new RoleVoter());
  decisionVoters.add(new AuthenticatedVoter());
  return decisionVoters;
}

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

@Test
public void testRoleVoterAlwaysReturnsTrueToSupports() {
  RoleVoter rv = new RoleVoter();
  assertThat(rv.supports(String.class)).isTrue();
}

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

private ConsensusBased makeDecisionManager() {
  RoleVoter roleVoter = new RoleVoter();
  DenyVoter denyForSureVoter = new DenyVoter();
  DenyAgainVoter denyAgainForSureVoter = new DenyAgainVoter();
  List<AccessDecisionVoter<? extends Object>> voters = new Vector<AccessDecisionVoter<? extends Object>>();
  voters.add(roleVoter);
  voters.add(denyForSureVoter);
  voters.add(denyAgainForSureVoter);
  return new ConsensusBased(voters);
}

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

private UnanimousBased makeDecisionManager() {
  RoleVoter roleVoter = new RoleVoter();
  DenyVoter denyForSureVoter = new DenyVoter();
  DenyAgainVoter denyAgainForSureVoter = new DenyAgainVoter();
  List<AccessDecisionVoter<? extends Object>> voters = new Vector<AccessDecisionVoter<? extends Object>>();
  voters.add(roleVoter);
  voters.add(denyForSureVoter);
  voters.add(denyAgainForSureVoter);
  return new UnanimousBased(voters);
}

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

private UnanimousBased makeDecisionManagerWithFooBarPrefix() {
  RoleVoter roleVoter = new RoleVoter();
  roleVoter.setRolePrefix("FOOBAR_");
  DenyVoter denyForSureVoter = new DenyVoter();
  DenyAgainVoter denyAgainForSureVoter = new DenyAgainVoter();
  List<AccessDecisionVoter<? extends Object>> voters = new Vector<AccessDecisionVoter<? extends Object>>();
  voters.add(roleVoter);
  voters.add(denyForSureVoter);
  voters.add(denyAgainForSureVoter);
  return new UnanimousBased(voters);
}

代码示例来源: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: spring-projects/spring-security

decisionVoters.add(new Jsr250Voter());
RoleVoter roleVoter = new RoleVoter();
GrantedAuthorityDefaults grantedAuthorityDefaults =
    getSingleBeanOrNull(GrantedAuthorityDefaults.class);

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

RoleVoter roleVoter = new RoleVoter();
roleVoter.setRolePrefix("");
voters.add(roleVoter);

代码示例来源:origin: psi-probe/psi-probe

/**
 * Gets the role voter.
 *
 * @return the role voter
 */
@Bean(name = "roleVoter")
public RoleVoter getRoleVoter() {
 return new RoleVoter();
}

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

@Before
public final void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);
  interceptor = new AspectJMethodSecurityInterceptor();
  AccessDecisionVoter[] voters = new AccessDecisionVoter[] {
      new RoleVoter(),
      new PreInvocationAuthorizationAdviceVoter(
          new ExpressionBasedPreInvocationAdvice()) };
  adm = new AffirmativeBased(
      Arrays.<AccessDecisionVoter<? extends Object>> asList(voters));
  interceptor.setAccessDecisionManager(adm);
  interceptor.setAuthenticationManager(authman);
  interceptor
      .setSecurityMetadataSource(new SecuredAnnotationSecurityMetadataSource());
  AnnotationSecurityAspect secAspect = AnnotationSecurityAspect.aspectOf();
  secAspect.setSecurityInterceptor(interceptor);
}

代码示例来源:origin: org.springframework.security/spring-security-config

/**
 * Creates the default {@link AccessDecisionVoter} instances used if an
 * {@link AccessDecisionManager} was not specified.
 *
 * @param http the builder to use
 */
@Override
@SuppressWarnings("rawtypes")
final List<AccessDecisionVoter<? extends Object>> getDecisionVoters(H http) {
  List<AccessDecisionVoter<? extends Object>> decisionVoters = new ArrayList<AccessDecisionVoter<? extends Object>>();
  decisionVoters.add(new RoleVoter());
  decisionVoters.add(new AuthenticatedVoter());
  return decisionVoters;
}

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

private AbstractAccessDecisionManager createManager(SecurityRule rule) {
  List<AccessDecisionVoter<? extends Object>> voters = new ArrayList<AccessDecisionVoter<? extends Object>>();
  voters.add(new RoleVoter());
  if (rule.getComparisonType() == SecurityRule.COMPARISON_ANY) {
    return new AffirmativeBased(voters);
  } else if (rule.getComparisonType() == SecurityRule.COMPARISON_ALL) {
    return new UnanimousBased(voters);
  } else {
    throw new IllegalStateException("Unknown SecurityRule match type: " + rule.getComparisonType());
  }
}

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

@Bean
public AccessDecisionManager accessDecisionManager() {
  return new AffirmativeBased(Collections.singletonList(new RoleVoter()));
}

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

@Bean
public AccessDecisionManager accessDecisionManager() {
  return new AffirmativeBased(Collections.singletonList(new RoleVoter()));
}

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

private AbstractAccessDecisionManager createManagerWithSpringSecurity3(SecurityRule rule) {
  List<AccessDecisionVoter> voters = new ArrayList<>();
  voters.add(new RoleVoter());
  Class<?> managerType;
  if (rule.getComparisonType() == SecurityRule.COMPARISON_ANY) {
    managerType = AffirmativeBased.class;
  } else if (rule.getComparisonType() == SecurityRule.COMPARISON_ALL) {
    managerType = UnanimousBased.class;
  } else {
    throw new IllegalStateException("Unknown SecurityRule match type: " + rule.getComparisonType());
  }
  try {
    Constructor<?> constructor = managerType.getConstructor();
    AbstractAccessDecisionManager manager = (AbstractAccessDecisionManager) constructor.newInstance();
    new DirectFieldAccessor(manager).setPropertyValue("decisionVoters", voters);
    return manager;
  }
  catch (Throwable ex) {
    throw new IllegalStateException("Failed to initialize AccessDecisionManager", ex);
  }
}

代码示例来源:origin: org.springframework.security/spring-security-config

/**
 * Allows subclasses to provide a custom {@link AccessDecisionManager}. The default is
 * a {@link AffirmativeBased} with the following voters:
 *
 * <ul>
 * <li>{@link PreInvocationAuthorizationAdviceVoter}</li>
 * <li>{@link RoleVoter}</li>
 * <li>{@link AuthenticatedVoter}</li>
 * </ul>
 *
 * @return the {@link AccessDecisionManager} to use
 */
protected AccessDecisionManager accessDecisionManager() {
  List<AccessDecisionVoter<? extends Object>> decisionVoters = new ArrayList<AccessDecisionVoter<? extends Object>>();
  ExpressionBasedPreInvocationAdvice expressionAdvice = new ExpressionBasedPreInvocationAdvice();
  expressionAdvice.setExpressionHandler(getExpressionHandler());
  if (prePostEnabled()) {
    decisionVoters
        .add(new PreInvocationAuthorizationAdviceVoter(expressionAdvice));
  }
  if (jsr250Enabled()) {
    decisionVoters.add(new Jsr250Voter());
  }
  decisionVoters.add(new RoleVoter());
  decisionVoters.add(new AuthenticatedVoter());
  return new AffirmativeBased(decisionVoters);
}

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

@SuppressWarnings("rawtypes")
private static ChannelSecurityInterceptor createInterceptor(String role) throws Exception {
  ChannelSecurityMetadataSource securityMetadataSource = new ChannelSecurityMetadataSource();
  securityMetadataSource.addPatternMapping(Pattern.compile("secured.*"), new DefaultChannelAccessPolicy(role, null));
  ChannelSecurityInterceptor interceptor = new ChannelSecurityInterceptor(securityMetadataSource);
  AffirmativeBased accessDecisionManager = AffirmativeBased.class.getConstructor(List.class)
      .newInstance(Collections.singletonList(new RoleVoter()));
  accessDecisionManager.afterPropertiesSet();
  interceptor.setAccessDecisionManager(accessDecisionManager);
  interceptor.setAuthenticationManager(new MockAuthenticationManager(true));
  interceptor.afterPropertiesSet();
  return interceptor;
}

代码示例来源:origin: io.macgyver/macgyver-core

@SuppressWarnings("rawtypes")
@Bean
List<AccessDecisionVoter<? extends Object>> macAccessDecisionVoterList() {
  List<AccessDecisionVoter<? extends Object>> x = Lists.newCopyOnWriteArrayList();
  x.add(new LogOnlyAccessDecisionVoter());
  x.add(new RoleVoter());
  x.add(new WebExpressionVoter());
  x.add(new Jsr250Voter());
  return x;
}

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

private AbstractAccessDecisionManager createManager(SecurityRule rule) {
  List<AccessDecisionVoter<? extends Object>> voters = new ArrayList<AccessDecisionVoter<? extends Object>>();
  voters.add(new RoleVoter());
  if (rule.getComparisonType() == SecurityRule.COMPARISON_ANY) {
    return new AffirmativeBased(voters);
  } else if (rule.getComparisonType() == SecurityRule.COMPARISON_ALL) {
    return new UnanimousBased(voters);
  } else {
    throw new IllegalStateException("Unknown SecurityRule match type: " + rule.getComparisonType());
  }
}

相关文章