Using security with .properties file

Quarkus は、開発およびテスト目的でプロパティーファイルベースの認証をサポートしています。現状では平文および MD5 ハッシュ化されたパスワードのみが使用され、プロパティーファイルは一般的に機能が限られているため、この認証を本番環境で使用することはお勧めしません。

以下をビルドファイルに追加します。

pom.xml
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-elytron-security-properties-file</artifactId>
</dependency>
build.gradle
implementation("io.quarkus:quarkus-elytron-security-properties-file")

設定

elytron-security-properties-file エクステンションは現在、認証および認可情報を保存するための 2 種類のレルムをサポートしています。どちらも、この情報をプロパティーファイルに保存することをサポートしています。

次のセクションでは、具体的な設定プロパティーについて詳しく説明します。

複数の認証メカニズムが使用される場合は、quarkus.http.auth.basic=true を使用して Basic 認証を明示的に有効にする必要があります。

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

タイプ

デフォルト

If the passwords are stored in the property file as plain text, e.g. quarkus.security.users.embedded.users.alice=AlicesSecretPassword. If this is false (the default) then it is expected that passwords are hashed as per the algorithm config property.

Environment variable: QUARKUS_SECURITY_USERS_EMBEDDED_PLAIN_TEXT

Show more

boolean

false

The algorithm with which user password is hashed. The library expects a password prepended with the username and the realm, in the form ALG( username ":" realm ":" password ) in hexadecimal format.

For example, on a Unix-like system we can produce the expected hash for Alice logging in to the Quarkus realm with password AlicesSecretPassword using echo -n "alice:Quarkus:AlicesSecretPassword" | sha512sum, and thus set quarkus.security.users.embedded.users.alice=c8131…​4546 (full hash output abbreviated here). This property is ignored if plainText is true.

Environment variable: QUARKUS_SECURITY_USERS_EMBEDDED_ALGORITHM

Show more

digest-md5, digest-sha, digest-sha-256, digest-sha-384, digest-sha-512, digest-sha-512-256

digest-sha-512

The realm users user1=password\nuser2=password2…​ mapping. See Embedded Users.

Environment variable: QUARKUS_SECURITY_USERS_EMBEDDED_USERS__USERS_

Show more

Map<String,String>

none

The realm roles user1=role1,role2,…​\nuser2=role1,role2,…​ mapping See Embedded Roles.

Environment variable: QUARKUS_SECURITY_USERS_EMBEDDED_ROLES__ROLES_

Show more

Map<String,String>

none

Property Files Realm Configuration

タイプ

デフォルト

The realm name. This is used when generating a hashed password

Environment variable: QUARKUS_SECURITY_USERS_FILE_REALM_NAME

Show more

string

Quarkus

Determine whether security via the file realm is enabled.

Environment variable: QUARKUS_SECURITY_USERS_FILE_ENABLED

Show more

boolean

false

If the properties are stored in plain text. If this is false (the default) then it is expected that the passwords are of the form HEX( MD5( username ":" realm ":" password ) )

Environment variable: QUARKUS_SECURITY_USERS_FILE_PLAIN_TEXT

Show more

boolean

false

Classpath resource name of properties file containing user to password mappings. See Users.properties.

Environment variable: QUARKUS_SECURITY_USERS_FILE_USERS

Show more

string

users.properties

Classpath resource name of properties file containing user to role mappings. See Roles.properties.

Environment variable: QUARKUS_SECURITY_USERS_FILE_ROLES

Show more

string

roles.properties

Embedded Realm Configuration

タイプ

デフォルト

The realm name. This is used when generating a hashed password

Environment variable: QUARKUS_SECURITY_USERS_EMBEDDED_REALM_NAME

Show more

string

Quarkus

Determine whether security via the embedded realm is enabled.

Environment variable: QUARKUS_SECURITY_USERS_EMBEDDED_ENABLED

Show more

boolean

false

プロパティーファイルレルムの設定

プロパティーファイルレルムは、プロパティーファイルの組み合わせにより、ユーザーをパスワードに、ユーザーをロールにマッピングすることをサポートしています。これらは、quarkus.security.users.file で始まるプロパティーで設定されます。

Example of the application.properties file section for property files realm
quarkus.security.users.file.enabled=true
quarkus.security.users.file.users=test-users.properties
quarkus.security.users.file.roles=test-roles.properties
quarkus.security.users.file.realm-name=MyRealm
quarkus.security.users.file.plain-text=true

Users.properties

quarkus.security.users.file.users 設定プロパティーは、ユーザーとパスワードのマッピングを 1 行に 1 つずつ記述したプロパティーファイルであるクラスパスリソースを指定します。

次の Example of test-users.properties はそのフォーマットを示しています。

Example of test-users.properties
scott=jb0ss (1)
jdoe=p4ssw0rd (2)
stuart=test
noadmin=n0Adm1n
1 ユーザー scott のパスワードは jb0ss として定義されています。
2 ユーザー jdoe のパスワードは p4ssw0rd として定義されています。

このファイルでは、ユーザー名とパスワードがプレーンテキストで保存されていますが、これは推奨されません。設定でプレーンテキストをfalseに設定(または省略)した場合、パスワードは MD5 ( username : realm : password ) という形式で保存する必要があります。これは、コマンドラインから echo -n scott:MyRealm:jb0ss | md5 というコマンドを実行することで、上記の最初の例で生成することができます。

Roles.properties

Example of test-roles.properties
scott=Admin,admin,Tester,user (1)
jdoe=NoRolesUser (2)
stuart=admin,user (3)
noadmin=user
1 ユーザー scott には Admin、admin、Tester、user のロールが割り当てられています。
2 ユーザー jdoe には NoRolesUser ロールが割り当てられています。
3 ユーザー stuart には admin と user のロールが割り当てられています。

組込レルムの設定

組込レルムは、ユーザーとパスワード、ユーザーとロールのマッピングもサポートします。この情報を埋め込むには、メインの application.properties Quarkus設定ファイルを使用します。これらは、 quarkus.security.users.embedded で始まるプロパティで設定されます。

以下は、組込レルムの設定を示す application.properties ファイルセクションの例です。

Example of the application.properties file section for embedded realm
quarkus.security.users.embedded.enabled=true
quarkus.security.users.embedded.plain-text=true
quarkus.security.users.embedded.users.scott=jb0ss
quarkus.security.users.embedded.users.stuart=test
quarkus.security.users.embedded.users.jdoe=p4ssw0rd
quarkus.security.users.embedded.users.noadmin=n0Adm1n
quarkus.security.users.embedded.roles.scott=Admin,admin,Tester,user
quarkus.security.users.embedded.roles.stuart=admin,user
quarkus.security.users.embedded.roles.jdoe=NoRolesUser
quarkus.security.users.embedded.roles.noadmin=user

最初の例と同様に、このファイルではユーザー名とパスワードがプレーンテキストで保存されていますが、これは推奨されません。コンフィグでプレーンテキストをfalseに設定(または省略)した場合、パスワードは MD5 ( username : realm : password ) という形式で保存する必要があります。これは、コマンドラインから echo -n scott:MyRealm:jb0ss | md5 というコマンドを実行することで、上記の最初の例に対して生成することができます。

組込ユーザー

ユーザーとパスワードのマッピングは、application.properties ファイルで、quarkus.security.users.embedded.users.<user>=<password> の形式のプロパティーキーによって指定されます。次の Example of passwords は、4 つのユーザーとパスワードのマッピングを持つ構文を示しています。

Example of passwords
quarkus.security.users.embedded.users.scott=jb0ss (1)
quarkus.security.users.embedded.users.stuart=test (2)
quarkus.security.users.embedded.users.jdoe=p4ssw0rd
quarkus.security.users.embedded.users.noadmin=n0Adm1n
1 ユーザー scott のパスワードは jb0ss です。
2 ユーザー stuart のパスワードは test です。

組込ロール

ユーザーとロールのマッピングは、application.properties ファイルで、quarkus.security.users.embedded.roles.<user>=role1[,role2[,role3[,…​]]] の形式のプロパティーキーによって指定されます。次の Example of roles は、4 つのユーザーとロールのマッピングを持つ構文を示しています。

Example of roles
quarkus.security.users.embedded.roles.scott=Admin,admin,Tester,user (1)
quarkus.security.users.embedded.roles.stuart=admin,user (2)
quarkus.security.users.embedded.roles.jdoe=NoRolesUser
quarkus.security.users.embedded.roles.noadmin=user
1 ユーザー scott には Admin、admin、Tester、user のロールがあります。
2 ユーザー stuart には admin と user のロールがあります。

リファレンス