2016-10-06 32 views
0

が発生し、私はそれを定義しています支払い "、すべてが実行されます。春のセキュリティhasIpAddressは私の構成でエラー

しかし、私はIP検証有効にしようとします

{"errorMessage":"Not Found","errorId":"6ae34aa3-9195-42d6-8906-996906988ce0","errorDetails":null} 

私が間違っているのは何:

http.exceptionHandling() 
      .authenticationEntryPoint(authEntryPoint) 
      .and() 
      .authorizeRequests() 
      //.antMatchers("/api/payment").permitAll() 
      .antMatchers("/api/payment").hasIpAddress("XXX.XXX.X.XX") 
... 

要求が与えられたIPアドレスからの送信を次の応答を受け取りますか?

EDIT

これは私が起動しています方法です:

@RequestMapping(value = "/payment", method = POST) 
public String saveOrder(@ModelAttribute PaymentDto paymentDto) { 
    paymentService.savePayment(paymentDto); 
    return "OK"; 
} 

を私は常に要求データを送信するので(例えば、ポストは、次のURLにある:api/payment?id=123&whatever

私は以下を追加しました:

.antMatchers("/api/payment?**").access("hasIpAddress('XXX.XXX.X.XX')") 

しかし、これはどちらもうまくいきませんでした。

UPDATEは2

私はこのように私のantMatcherの配置を変更しました:今、ちょうど私が与えられたからポストを作成しようとしているログインページに私をリダイレクトし

http.exceptionHandling() 
     .authenticationEntryPoint(authEntryPoint) 
     .and() 
     .authorizeRequests() 
     .antMatchers("/", "/app/**", "/assets/**", "/fonts/**", "/images/**").permitAll() 
     .antMatchers("/authentication/login", "/login.html").anonymous() 
     .antMatchers("/api/products/**").permitAll() 
     .antMatchers("/api/cities/**").permitAll() 
     .antMatchers("/api/order/**").permitAll() 
     .antMatchers("/api/payment").hasIpAddress("XXX.XXX.X.XX") 
     .anyRequest().authenticated() 
     .and() 
     .csrf().requireCsrfProtectionMatcher(new CsrfRequestMatcher()) 
     .and() 
     .formLogin() 
     .loginPage("/login.html") 
     .loginProcessingUrl("/authentication/login") 
     .successHandler(authSuccessHandler) 
     .failureHandler(authFailureHandler) 
     .and() 
     .logout() 
     .logoutUrl("/authentication/logout") 
     .logoutSuccessHandler(logoutSuccessHandler) 
     .deleteCookies(JSESSIONID_COOKIE, CSRF_COOKIE) 
     .invalidateHttpSession(true) 
     .permitAll(); 

IPアドレス

+0

は、おそらくあなたはNullPointerExceptionがに – reos

+0

@reosを取得しているが、何のNullPointerExceptionがありません。メソッドはまったく実行されません。 – uksz

+0

おそらくIPがnullで、春はnullpointerをスローします – reos

答えて

0

私が知ったように、リクエスタの元のIPアドレスを渡していなかったnginxからプロキシ経由でリクエストを受け取りました。私はいくつかの追加nginxの設定を追加する必要がありました、そして今、私はこのようなIPアドレスを確認することができます。

@RequestMapping(value = "/payment", method = POST) 
public String saveOrder(PaymentDto paymentDto, HttpServletRequest request) { 
    if (request.getHeader("X-Forwarded-For").equals("XXX.XXX.X.XX")){ 
     DO STUFF 
    } 
} 
関連する問題