@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;
}
}
첫 번째 지원 방법이 어떻게 작동 할 것이라고 설명 할 수 있습니까? myBool을 어떻게 변경하든 관계없이 항상 vote 메소드가 호출됩니다. 그것은 단지 지원 (클래스 clazz)이 invokation에 영향을 미친 것처럼 보입니다.스프링 보안 : AccessDecisionVoter
아이디어가 있으십니까?
편집 :
@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;
}
}
이것은 기본적으로 내 유일한 설정입니다.
이 내가 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
}
안녕하세요. Java 구성 만 사용하고 있으며 Spring에 대해 상당히 익숙하므로 답변을 이해하지 못합니다. 나는 스프링 부트를 사용하고 액세스 결정 관리자 만 구성했습니다. 액세스 결정 관리자가 내 컨트롤러에서 사용자가 개체에 액세스 할 권한이 있는지 여부를 결정하는 방법을 사용하고 있습니다. void 결정 (인증 인증, Object 객체, Collection configAttributes) configAttributes가 유권자에게 어떤 영향을 미쳤다 고 생각합니다 ....? –
Java 구성보기 및 컨트롤러에서 AccessDecisionManager를 사용하는 방법에 대해서는 더 자세히 대답하기가 어렵습니다. – shazin
내 질문을 편집했습니다. 희망이 당신이 나를 도울 수 있습니다 :) –