use of org.springframework.security.access.ConfigAttribute in project dhis2-core by dhis2.
the class ActionAccessVoter method anyAuthority.
private int anyAuthority(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
int supported = 0;
boolean found = false;
for (ConfigAttribute attribute : attributes) {
if (supports(attribute)) {
++supported;
for (GrantedAuthority authority : authentication.getAuthorities()) {
if (authority.getAuthority().equals(attribute.getAttribute())) {
found = true;
break;
}
}
}
}
if (!found && supported > 0) {
LOG.debug("ACCESS_DENIED [" + object.toString() + "]");
return ACCESS_DENIED;
}
if (supported > 0) {
LOG.debug("ACCESS_GRANTED [" + object.toString() + "]");
return ACCESS_GRANTED;
}
LOG.debug("ACCESS_ABSTAIN [" + object.toString() + "]: No supported attributes.");
return ACCESS_ABSTAIN;
}
use of org.springframework.security.access.ConfigAttribute in project dhis2-core by dhis2.
the class AllRequiredRoleVoter method vote.
@Override
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
int supported = 0;
for (ConfigAttribute attribute : attributes) {
if (this.supports(attribute)) {
++supported;
boolean found = false;
for (GrantedAuthority authority : authentication.getAuthorities()) {
if (attribute.getAttribute().equals(authority.getAuthority())) {
found = true;
break;
}
}
if (!found) {
return ACCESS_DENIED;
}
}
}
if (supported > 0) {
return ACCESS_GRANTED;
}
return ACCESS_ABSTAIN;
}
use of org.springframework.security.access.ConfigAttribute in project spring-security by spring-projects.
the class ChannelDecisionManagerImplTests method testDecideIsOperational.
@Test
public void testDecideIsOperational() throws Exception {
ChannelDecisionManagerImpl cdm = new ChannelDecisionManagerImpl();
MockChannelProcessor cpXyz = new MockChannelProcessor("xyz", false);
MockChannelProcessor cpAbc = new MockChannelProcessor("abc", true);
List list = new Vector();
list.add(cpXyz);
list.add(cpAbc);
cdm.setChannelProcessors(list);
cdm.afterPropertiesSet();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
FilterInvocation fi = new FilterInvocation(request, response, mock(FilterChain.class));
List<ConfigAttribute> cad = SecurityConfig.createList("xyz");
cdm.decide(fi, cad);
assertThat(fi.getResponse().isCommitted()).isTrue();
}
use of org.springframework.security.access.ConfigAttribute in project spring-security-oauth by spring-projects.
the class ClientScopeVoterTests method testAccessDenied.
@Test(expected = AccessDeniedException.class)
public void testAccessDenied() {
client.setScope(Arrays.asList("none"));
assertEquals(AccessDecisionVoter.ACCESS_DENIED, voter.vote(authentication, null, Arrays.<ConfigAttribute>asList(new SecurityConfig("CLIENT_HAS_SCOPE"))));
}
use of org.springframework.security.access.ConfigAttribute in project spring-security-oauth by spring-projects.
the class ScopeVoterTests method testAbstainIfNotOAuth2.
@Test
public void testAbstainIfNotOAuth2() throws Exception {
Authentication clientAuthentication = new UsernamePasswordAuthenticationToken("foo", "bar");
assertEquals(AccessDecisionVoter.ACCESS_ABSTAIN, voter.vote(clientAuthentication, null, Collections.<ConfigAttribute>singleton(new SecurityConfig("SCOPE_READ"))));
}
Aggregations