title: Spring Security: AccessDecisionVoter
body: <pre><code>@Service
  public class MyVoter implements AccessDecisionVoter&lt;Entity&gt; {
  
      @Override
      public boolean supports(ConfigAttribute attribute) {        
          boolean myBool = false;
          return myBool;
      }
  
      @Override
      public boolean supports(Class&lt;?&gt; clazz) {
          return clazz == Project.class;
      }
  
      @Override
      public int vote(Authentication authentication, Entity someEntity,
              Collection&lt;ConfigAttribute&gt; config) {
          return ACCESS_GRANTED;
      }
  }
  </code></pre>
  
  <p>Can you explain me, how the first supports method is supposed to work? No matter how i change myBool, the vote-method is always invoked. It seems like only supports(Class clazz) has effect on the invokation.</p>
  
  <p>Any ideas?</p>
  
  <p>EDIT:</p>
  
  <pre><code>@Configuration
  @EnableWebMvcSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
  @Autowired
  ApplicationContext context;
  
  @Override
  protected void configure(HttpSecurity http) throws Exception {
      http.csrf().disable();
      http
          .authorizeRequests()
              .antMatchers("/").permitAll()
              .anyRequest().authenticated();
      http
          .formLogin()
              .loginPage("/login")
              .permitAll()               
              .and()
          .logout()
              .permitAll();
  }
  
  @Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth
          .inMemoryAuthentication()
              .withUser("user").password("password").roles("USER");
  }
  
  @Bean
  public AffirmativeBased accessDecisionManager() {
      Map&lt;String, AccessDecisionVoter&gt; beans = context
              .getBeansOfType(AccessDecisionVoter.class);
  
      List&lt;AccessDecisionVoter&gt; decisionVoters = new ArrayList&lt;&gt;(
              beans.values());
  
      AffirmativeBased affirmativeBased = new AffirmativeBased(decisionVoters);
      return affirmativeBased;
  }
  }
  </code></pre>
  
  <p>This is basically my only config.</p>
  
  <p>This is how I used the AccessDecisionManager:</p>
  
  <pre><code>    /* AUTHORIZATION */
      Authentication authentication = SecurityContextHolder.getContext()
              .getAuthentication();
  
      Collection&lt;ConfigAttribute&gt; config = new HashSet&lt;ConfigAttribute&gt;();
      config.add(new SecurityConfig("Something"));
  
      try {
          adm.decide(authentication, project, config);
      } catch (Exception e) {
          // .. Exception Handling
      }
  </code></pre>