The English version of quarkus.io is the official project site. Translated sites are community supported on a best-effort basis.
このページを編集

Basic 認証を有効にする

Enable Basic authentication to require a username and password before users can access your Quarkus application. For more information, see Basic authentication.

手順

  1. application.properties ファイルで、quarkus.http.auth.basic プロパティーを true に設定します。

    quarkus.http.auth.basic=true
  2. 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.

  3. For testing only: In a non-production environment, you can use the embedded realm provided by the quarkus-elytron-security-properties-file extension instead of a production identity provider.

    1. 埋め込みレルムの認証を有効にするには、quarkus.security.users.embedded.enabled プロパティーを true に設定します。

      quarkus.security.users.embedded.enabled=true
    2. 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=user

      where:

      • ユーザー alice は、パスワードが alice で、ロールが admin です。

      • ユーザー bob は、パスワードが bob で、ロールが user です。

検証

  1. Start your application.

  2. Send a request to a secured endpoint without credentials and confirm that the application returns a 401 Unauthorized response:

    $ curl -i -X GET http://localhost:8080/<your_secured_endpoint>
    
    HTTP/1.1 401 Unauthorized
    WWW-Authenticate: Basic
  3. Send the same request with a valid username and password and confirm that the application returns a 200 OK response:

    $ curl -i -X GET -u <username>:<password> http://localhost:8080/<your_secured_endpoint>
    
    HTTP/1.1 200 OK

次のステップ

ユーザー認証情報をデータベースに保存するために Basic 認証と Jakarta Persistence を組み合わせて設定する方法を示す、より詳細なチュートリアルについては、Basic 認証と Jakarta Persistence を使用した Security の開始 ガイドを参照してください。

関連コンテンツ