残りのアプリケーションにセキュリティを追加しようとしています。
このチュートリアルに従いました: http://www.codesandnotes.be/2014/10/31/restful-authentication-using-spring-security-on-spring-boot-and-jquery-as-a-web-client/
WebSecurityConfigurerAdapter を拡張するクラスを構成しました。
http.authorizeRequests().antMatchers("/rest/**").authenticated();
http.csrf().disable();
http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint);
http.formLogin().successHandler(authenticationSuccessHandler);
http.formLogin().failureHandler(authenticationFailureHandler);
index.htmlに他のhtmlファイルを(jquery経由で)ロードするlogin.html、index.htmlがあります。
curl でサービスにアクセスしようとしています
curl -i -X POST -d username=test -d password=test http://localhost:8080/rest/cities
私は得る
HTTP/1.1 401 Unauthorized
残りのすべての URL は保護されていますが、ユーザー名とパスワードを提供する必要があります。
デバッグすると、メソッド loadUserByUsername を持つ UserDetailsService を実装するクラスが呼び出されないことがわかります。
リンクを正しく行っていない人がいます。