guides/security-basic-authentication-howto.adoc
Enable Basic authentication to require a username and password before users can access your Quarkus application. For more information, see Basic authentication.
前提条件
-
You have installed at least one extension that provides an
IdentityProviderto verify username and password credentials and map them to aSecurityIdentity. For example:
手順
-
application.propertiesファイルで、quarkus.http.auth.basicプロパティーをtrueに設定します。quarkus.http.auth.basic=true -
Configure an identity provider to verify the username and password against your user store. For a production application, configure one of the identity provider extensions listed in the Prerequisites, for example, by storing users in a database with the Jakarta Persistence extension. For more information, see the Identity providers guide.
-
For testing only: In a non-production environment, you can use the embedded realm provided by the
quarkus-elytron-security-properties-fileextension instead of a production identity provider.-
埋め込みレルムの認証を有効にするには、
quarkus.security.users.embedded.enabledプロパティーをtrueに設定します。quarkus.security.users.embedded.enabled=true -
You can also configure the required user credentials: user name, password, and roles. For example:
quarkus.http.auth.basic=true quarkus.security.users.embedded.enabled=true quarkus.security.users.embedded.plain-text=true quarkus.security.users.embedded.users.alice=alice quarkus.security.users.embedded.users.bob=bob quarkus.security.users.embedded.roles.alice=admin quarkus.security.users.embedded.roles.bob=userwhere:
-
ユーザー
aliceのパスワードはalice、ロールはadminです。 -
ユーザー
bobのパスワードはbob、ロールはuserです。
-
-
検証
-
Start your application.
-
Send a request to a secured endpoint without credentials and confirm that the application returns a
401 Unauthorizedresponse:$ curl -i -X GET http://localhost:8080/<your_secured_endpoint> HTTP/1.1 401 Unauthorized WWW-Authenticate: Basic -
Send the same request with a valid username and password and confirm that the application returns a
200 OKresponse:$ curl -i -X GET -u <username>:<password> http://localhost:8080/<your_secured_endpoint> HTTP/1.1 200 OK
次のステップ
ユーザー認証情報をデータベースに保存するために、Basic 認証と Jakarta Persistence を一緒に設定する方法に関する詳細なチュートリアルは、Basic 認証と Jakarta Persistence を使用したセキュリティーの開始 ガイドを参照してください。
リファレンス
-
また、「 application.propertiesでユーザー情報を設定する」も参照してください。