@Test public void shouldVoteAffirmativeIfUserHasAccess() { List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>(); attributes.add(new SecurityConfig("access_testuser")); attributes.add(new SecurityConfig("access_motechUser")); MotechUserProfile userProfile = new MotechUserProfile(new MotechUser("TestUser", "p@ssw0rd", "", "", null, "", Locale.ENGLISH)); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("TestUser", "p@ssw0rd"); authentication.setDetails(userProfile); MotechAccessVoter voter = new MotechAccessVoter(); assertEquals(1, voter.vote(authentication, null, attributes)); }
@Override public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) { int result = ACCESS_ABSTAIN; LOGGER.debug("Voting on the access to the {} for user {} with permissions {}", object, authentication.getPrincipal(), authentication.getAuthorities()); for (ConfigAttribute attribute : attributes) { if (this.supports(attribute)) { LOGGER.debug("Verifying supported attribute: " + attribute.getAttribute()); result = ACCESS_DENIED; if (StringUtils.equalsIgnoreCase(SecurityConfigConstants.USER_ACCESS_PREFIX + authentication.getName(), attribute.getAttribute())) { result = ACCESS_GRANTED; break; } } } logAccessResult(result, object); return result; }
MotechAccessVoter implements AccessDecisionVoter<Object> { @Override public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) { int result = ACCESS_ABSTAIN; LOGGER.debug("Voting on the access to the {} for user {} with permissions {}", object, authentication.getPrincipal(), authentication.getAuthorities()); for (ConfigAttribute attribute : attributes) { if (this.supports(attribute)) { LOGGER.debug("Verifying supported attribute: " + attribute.getAttribute()); result = ACCESS_DENIED; if (StringUtils.equalsIgnoreCase(SecurityConfigConstants.USER_ACCESS_PREFIX + authentication.getName(), attribute.getAttribute())) { result = ACCESS_GRANTED; break; } } } logAccessResult(result, object); return result; } }
MotechAccessVoter implements AccessDecisionVoter<Object> { @Override public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) { int result = ACCESS_ABSTAIN; LOGGER.debug("Voting on the access to the {} for user {} with permissions {}", object, authentication.getPrincipal(), authentication.getAuthorities()); for (ConfigAttribute attribute : attributes) { if (this.supports(attribute)) { LOGGER.debug("Verifying supported attribute: " + attribute.getAttribute()); result = ACCESS_DENIED; if (StringUtils.equalsIgnoreCase(SecurityConfigConstants.USER_ACCESS_PREFIX + authentication.getName(), attribute.getAttribute())) { result = ACCESS_GRANTED; break; } } } logAccessResult(result, object); return result; }  }
MotechAccessVoter implements AccessDecisionVoter<Object> { @Override public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) { int result = ACCESS_ABSTAIN; LOGGER.debug("Voting on the access to the {} for user {} with permissions {}", object, authentication.getPrincipal(), authentication.getAuthorities()); for (ConfigAttribute attribute : attributes) { if (this.supports(attribute)) { LOGGER.debug("Verifying supported attribute: " + attribute.getAttribute()); result = ACCESS_DENIED; if (StringUtils.equalsIgnoreCase(SecurityConfigConstants.USER_ACCESS_PREFIX + authentication.getName(), attribute.getAttribute())) { result = ACCESS_GRANTED; break; } } } logAccessResult(result, object); return result; }  @Override boolean supports(ConfigAttribute attribute); @Override boolean supports(Class<?> clazz); @Override int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes); }
MotechAccessVoter implements AccessDecisionVoter<Object> { @Override public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) { int result = ACCESS_ABSTAIN; LOGGER.debug("Voting on the access to the {} for user {} with permissions {}", object, authentication.getPrincipal(), authentication.getAuthorities()); for (ConfigAttribute attribute : attributes) { if (this.supports(attribute)) { LOGGER.debug("Verifying supported attribute: " + attribute.getAttribute()); result = ACCESS_DENIED; if (StringUtils.equalsIgnoreCase(SecurityConfigConstants.USER_ACCESS_PREFIX + authentication.getName(), attribute.getAttribute())) { result = ACCESS_GRANTED; break; } } } logAccessResult(result, object); return result; }  @Override boolean supports(ConfigAttribute attribute); @Override boolean supports(Class<?> clazz); @Override int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes);  }