2016-07-06 1 views
0

Я пытаюсь подключиться Hawtio (1.4.64) к агенту Jolokia (1.3.3) работает в Спринг приложение в Tomcat 7.Spring Security 4.x JavaConfig для обычной проверки подлинности с Hawtio

После Недавнее обновление до Spring Security (4.0.3) hawtio прекратило проверку подлинности (используя базовый auth), и мы получаем ногами на страницу входа, аналогичную issue #1975. В отличие от этой проблемы, мы используем агент Jolokia, а не включаем hawtio в наше приложение (и мы не используем Spring Boot).

После изучения журналов отладки Spring, похоже, что AnonymousAuthenticationFilter настраивает пользователя на «анонимность» до применения BasicAuthenticationFilter. Таким образом, я настроил конфигурацию безопасности и отключены все параметры по умолчанию, в результате чего следующее:

@Configuration 
@Order(2) 
public static class JolokiaSecurityConfig extends WebSecurityConfigurerAdapter { 

    public JolokiaSecurityConfig() { 
     super(true); // disable defaults 
    } 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
      .requestMatchers().antMatchers("/jolokia/**") 
      .and().authorizeRequests().antMatchers("/jolokia/**").hasAuthority(BaseRoles.DEVELOPER).and().httpBasic(); 
    } 
} 

Теперь, когда я войти в Hawtio я получаю сообщение об ошибке в консоли Hawtio которая включает в себя некоторый вывод из моего Tomcat7 сервера: HTTP Status 500 - объект проверки подлинности не был найден в SecurityContext

StackTrace:

Jul 06, 2016 12:43:14 AM org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [jolokia-agent] in context with path [/foobar] threw exception 
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext 
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:378) 
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:222) 
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:123) 
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90) 
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:158) 
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 

...

Любые идеи, почему основной аутентификация больше не работает? Спасибо за любую помощь!

ответ

0

Мы получили вокруг проблемы путем переопределения обработки исключений для вызова BasicAuthenticationEntryPoint снова:

@Configuration 
@Order(2) 
public static class JolokiaSecurityConfig extends WebSecurityConfigurerAdapter { 

    private static final String REALM = "our admin services"; 
    private static final String JOLOKIA_URL_PATTERN = "/jolokia/**"; 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     BasicAuthenticationEntryPoint authenticationEntryPoint = new BasicAuthenticationEntryPoint(); 
     authenticationEntryPoint.setRealmName(REALM); 
     http 
      .csrf().disable() 
      .requestMatchers().antMatchers(JOLOKIA_URL_PATTERN) 
      .and().authorizeRequests().antMatchers(JOLOKIA_URL_PATTERN).hasAuthority(BaseRoles.DEVELOPER) 
      .and().httpBasic().realmName(REALM) 
      .and().exceptionHandling().authenticationEntryPoint(authenticationEntryPoint); 
    } 
}