@Service
public class MyVoter implements AccessDecisionVoter<Entity> {
@Override
public boolean supports(ConfigAttribute attribute) {
boolean myBool = false;
return myBool;
}
@Override
public boolean supports(Class<?> clazz) {
return clazz == Project.class;
}
@Override
public int vote(Authentication authentication, Entity someEntity,
Collection<ConfigAttribute> config) {
return ACCESS_GRANTED;
}
}
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.
Any ideas?
EDIT:
@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<String, AccessDecisionVoter> beans = context
.getBeansOfType(AccessDecisionVoter.class);
List<AccessDecisionVoter> decisionVoters = new ArrayList<>(
beans.values());
AffirmativeBased affirmativeBased = new AffirmativeBased(decisionVoters);
return affirmativeBased;
}
}
This is basically my only config.
This is how I used the AccessDecisionManager:
/* AUTHORIZATION */
Authentication authentication = SecurityContextHolder.getContext()
.getAuthentication();
Collection<ConfigAttribute> config = new HashSet<ConfigAttribute>();
config.add(new SecurityConfig("Something"));
try {
adm.decide(authentication, project, config);
} catch (Exception e) {
// .. Exception Handling
}