他の Web サービスで使用される安らかな Web サービスを作成しようとしています。理想的には、クライアントがサービスにアクセスし、認証されていない場合、401 を取得する必要があります。リクエストに認証ヘッダーを追加して、ユーザーを認証できるようにしたいと考えています。ユーザーがログインフォームに記入して投稿したくありません。また、ログイン資格情報をCookieに保存したくない(つまり、状態を保持する)必要はありません。すべてのログイン資格情報は、各リクエストで送信される認証ヘッダーに含まれている必要があります。spring roo を使用して Web サービスを作成しました。
私が現在持っているもの (Spring Security 3.1 チュートリアルの 1 つから取得) では、ユーザーが 401 を取得すると、ログイン ページが表示され、ページを投稿して、リクエストごとに送信される Cookie を取得します。
これが私の春のセキュリティxmlです。
<http use-expressions="true">
<intercept-url pattern="/customers/**" access="isAuthenticated()" />
<intercept-url pattern="/**" access="denyAll" />
<form-login />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="alice" password="other" authorities="user" />
<user name="custome1" password="other" authorities="user" />
</user-service>
</authentication-provider>
</authentication-manager>
curl からリクエストを送信すると、次のようになります。
$ curl -i -H "Accept: application/json" -H "Authorization: Basic Y3VzdG9tZXIxOm90aGVy" http://localhost:8080/Secured/customers
HTTP/1.1 302 Found
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=B4F983464F68199FA0160DBE6279F440; Path=/Secured/; HttpOnly
Location: http://localhost:8080/Secured/spring_security_login;jsessionid=B4F983464F68199FA0160DBE6279F440
Content-Length: 0
Date: Thu, 25 Apr 2013 17:18:48 GMT
私の基本的なヘッダートークンは base64(customer1:other) です
Web サービスが認証ヘッダーを受け入れ、ログイン ページにリダイレクトしないようにするにはどうすればよいですか?
security.xml から を削除すると、次のようになります。
excpetion:org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: No AuthenticationEntryPoint could be established.
Please make sure you have a login mechanism configured through the namespace
(such as form-login) or specify a custom AuthenticationEntryPoint with the
'entry-point-ref' attribute