2016-08-15 7 views
2

Springブート1.4のリリース以降、次の問題が発生しています。 Spring Security用のJWTトークンの解析を管理するカスタム認証プロバイダがあります。基本的には、トークンが無効または期限切れのときにBadCredentialsExceptionをスローします。また、私はここでJSONSpringブート1.4:プリンシパルがnull例外ではない

@Override 
public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException 
{ 
    httpServletResponse.setContentType("application/json"); 
    httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 
    httpServletResponse.getOutputStream().println("{ \"error\": \"" + e.getMessage() + "\" }"); 

} 

で無許可のHttpServletレスポンス認証プロバイダの例外を管理フィルタはこの春ブーツ1.3で正常に動作して

@Override 
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException 

{ 

    String authToken = httpServletRequest.getHeader("Authorization"); 



    JwtToken token = new JwtToken(authToken); 
    try 
    { 
     Authentication auth = authenticationManager.authenticate(token); 
     SecurityContextHolder.getContext().setAuthentication(auth); 
     filterChain.doFilter(httpServletRequest, httpServletResponse); 

    } 
    catch(AuthenticationException ae) 
    { 
     SecurityContextHolder.clearContext(); 
     unauthorizedHandler.commence(httpServletRequest, httpServletResponse, ae); 
    } 

であるとのメッセージを再フォーマットAutenticationEntryPointを持っています0.6 は今、私は次のエラーを取得しています

java.lang.IllegalArgumentExceptionが:

:校長はヌル スタックトレースであってはなりません
java.lang.IllegalArgumentException: Principal must not be null 
at org.springframework.util.Assert.notNull(Assert.java:115) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
at org.springframework.boot.actuate.audit.AuditEvent.<init>(AuditEvent.java:83) ~[spring-boot-actuator-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
at org.springframework.boot.actuate.audit.AuditEvent.<init>(AuditEvent.java:59) ~[spring-boot-actuator-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
at org.springframework.boot.actuate.security.AuthenticationAuditListener.onAuthenticationFailureEvent(AuthenticationAuditListener.java:67) ~[spring-boot-actuator-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
at org.springframework.boot.actuate.security.AuthenticationAuditListener.onApplicationEvent(AuthenticationAuditListener.java:50) ~[spring-boot-actuator-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
at org.springframework.boot.actuate.security.AuthenticationAuditListener.onApplicationEvent(AuthenticationAuditListener.java:34) ~[spring-boot-actuator-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:382) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:336) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
at org.springframework.security.authentication.DefaultAuthenticationEventPublisher.publishAuthenticationFailure(DefaultAuthenticationEventPublisher.java:124) ~[spring-security-core-4.1.1.RELEASE.jar:4.1.1.RELEASE] 
at org.springframework.security.authentication.ProviderManager.prepareException(ProviderManager.java:240) ~[spring-security-core-4.1.1.RELEASE.jar:4.1.1.RELEASE] 
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:233) ~[spring-security-core-4.1.1.RELEASE.jar:4.1.1.RELEASE] 
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:199) ~[spring-security-core-4.1.1.RELEASE.jar:4.1.1.RELEASE] 
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$AuthenticationManagerDelegator.authenticate(WebSecurityConfigurerAdapter.java:454) ~[spring-security-config-4.1.1.RELEASE.jar:4.1.1.RELEASE] 
at com.icentia.tracking.security.JwtFilter.doFilterInternal(JwtFilter.java:49) ~[classes/:na] 

これはSpring Boot Actuatorからのものです。私がそれを取り除くと、以前と同じように働いていますか?

そこには、ここに記載されているバグ、ではないが、同じように見える: https://github.com/spring-projects/spring-boot/issues/6447

私は、生産に私はこのために使用できる任意の回避策をアクチュエータを持つようにしたいですか?

+0

こんにちは - これを投稿してからしばらくお待ちください、この問題を解決しましたか? –

+1

問題は、AcutatorがSpring Bootに一度追加されたログイン(監査)の失敗を追跡するということです。私はBadCredential例外をNonce例外に投げないようにJWTチェックを変更しました。これはトリックでした。おそらく、getNameフォームをプリンシパルでチェックしていないからです(でも、私はこれを検証しませんでした)。 –

+0

おかげさまで、ありがとう!エステバンも同様の答えを出しました。 –

答えて

5

PrincipalインタフェースからgetName()方法は、あなたのJwtTokenクラス内の非NULL値を返すことを確認していただきありがとうございます。

+0

Ali、ちょっと指摘しておきます - あなたは有効な認証チェーンを持っているので、この問題は参照されているオープンスプリングブートバグに関係していない可能性があります。 Springブートの問題は、@ WebSecurityConfigurationを手動で登録しても、デフォルトのBeanがまだインストールされていることです。 –

関連する問題