1
나는 나의 컨트롤러/서비스에봄 부트 보안 익명 인증
SecurityContextHolder.getContext().getAuthentication()
방법을 사용해야합니다.
이전에 비슷한 방법으로 접근 한 XML 구성 Spring MVC 애플리케이션 (현재는 Java 구성 만 가능)에서 Spring 1.4.1로 마이그레이션했습니다. 항상 null
반환
@RestController
@Secured("IS_AUTHENTICATED_ANONYMOUSLY")
@RequestMapping("utils")
public class UtilsController {
@RequestMapping(value = "/check_auth", method = RequestMethod.GET)
public Boolean getAuthState() throws SQLException {
if (SecurityContextHolder.getContext().getAuthentication() == null){
logger.info("Auth obj null");
}
if (SecurityContextHolder.getContext().getAuthentication().getName() != null && SecurityContextHolder.getContext().getAuthentication().getName() != "anonymousUser") {
return true;
} else return false;
}
}
:
나는이 컨트롤러 예를 들면 SecurityContextHolder.getContext().getAuthentication()
을 요구하는 문제를 가지고있다. 익명 인증이 작동하지 않는 이유를 알아낼 수 없습니다.
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint).and()
.formLogin()
.successHandler(ajaxSuccessHandler)
.failureHandler(ajaxFailureHandler)
.loginProcessingUrl("/authentication")
.passwordParameter("password")
.usernameParameter("username")
.and()
.logout()
.deleteCookies("JSESSIONID")
.invalidateHttpSession(true)
.logoutUrl("/logout")
.logoutSuccessUrl("/")
.and()
.csrf().disable()
// .anonymous().disable()
.authorizeRequests()
// .anyRequest().anonymous()
.antMatchers("/utils").permitAll()
.antMatchers("/oauth/token").permitAll()
.antMatchers("/admin/*").access("hasRole('ROLE_ADMIN')")
.antMatchers("/user/*").access("hasRole('ROLE_USER')");
}
내가 함께 컨트롤러에 @Secured
주석없이 시도 않은 : 여기
.authorizeRequests()
// .anyRequest().anonymous()
.antMatchers("/utils").permitAll()
이 설정과 다른 변형입니다. 당신은 보안 구성을 내 인증되지 않기 때문에
SecurityContextHolder.getContext().getAuthentication()
: