2017-05-04 6 views
0

/login要求の認証をスキップします。 春の起動時に/ loginの認証をスキップする

@Configuration 
    @EnableResourceServer 
    protected class ResourceServer extends ResourceServerConfigurerAdapter { 

     @Override 
     public void configure(HttpSecurity http) throws Exception { 
      http.authorizeRequests().antMatchers("/login").permitAll(); 
     } 
    } 

しかし、 /ログインエンドポイントをヒットしようとしたときに、私がどんな引数/ヘッダ、(今、この応答を取得していないよ:私のサーバアプリケーションで

、私はそれを達成するために、この方法を書きました私が)合格:

{ 
    "timestamp": 1493881871867, 
    "status": 415, 
    "error": "Unsupported Media Type", 
    "exception": "org.springframework.web.HttpMediaTypeNotSupportedException", 
    "message": "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported", 
    "path": "/login" 
} 

consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,、いくつかの他の同様のソリューションをしようとしましたが、それでも同じ応答を得ます。

も/ログインのためのエンドポイントを作成し、それはヒットを取得していない:

@RequestMapping(value = "/login", 
      method = RequestMethod.POST, 
      produces = "application/json") 
    public ResponseEntity login(@RequestBody Map<String, String> requestBody) { 
     System.out.println("DO I EVEN REACH HERE?"); 
     return null; 
    } 

私は春に非常に新しいですし、私はここでやっているのミスを把握することはできません。どんな助け?

+0

'.antMatchers("/login * ")。anonymous()'? btw JSONを本当に送信しますか?コンテンツタイプが間違っている可能性があります。 – StanislavL

+0

did not worked .. :( –

+0

あなたの呼び出しに '.anyRequest();'を追加してみてください。 – Kai

答えて

0

エラーメッセージは次のとおりです。

Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported 

これは、/loginにhtml形式で投稿したことを意味します。 loginエンドポイントはフォームパラメータを受け入れません。 loginエンドポイントを次のように変更します。

@RequestMapping(value = "/login", 
     method = RequestMethod.POST, 
     produces = "application/json") 
public ResponseEntity login(@RequestParam("username") String username, @RequestParam("password") String password) { 
    System.out.println("DO I EVEN REACH HERE?"); 
    return null; 
} 
関連する問題