The English version of quarkus.io is the official project site. Translated sites are community supported on a best-effort basis.

Usando a segurança com o arquivo .properties

Quarkus provides support for properties file based authentication that is intended for development and testing purposes. It is not recommended that this be used in production as at present only plaintext and MD5 hashed passwords are used, and properties files are generally too limited to use in production.

Adicione o seguinte ao seu arquivo de compilação:

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")

Configuração

The elytron-security-properties-file extension currently supports two different realms for the storage of authentication and authorization information. Both support storage of this information in properties files. The following sections detail the specific configuration properties.

Propriedade de Configuração Fixa no Momento da Compilação - Todas as outras propriedades de configuração podem ser sobrepostas em tempo de execução.

Configuration property

Tipo

Padrão

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_EMBEDDED_PLAIN_TEXT

Show more

booleano

false

Determine which algorithm to use. 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-md5

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

Environment variable: QUARKUS_SECURITY_USERS_EMBEDDED_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

Show more

Map<String,String>

none

Property Files Realm Configuration

Tipo

Padrão

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

booleano

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

booleano

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

Tipo

Padrão

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

booleano

false

Arquivos de propriedades Realm Configuration

The properties files realm supports mapping of users to password and users to roles with a combination of properties files. They are configured with properties starting with quarkus.security.users.file.

example 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

Usuários.propriedades

The quarkus.security.users.file.users configuration property specifies a classpath resource which is a properties file with a user to password mapping, one per line. The following example test-users.properties file illustrates the format:

example test-users.properties file
scott=jb0ss (1)
jdoe=p4ssw0rd (2)
stuart=test
noadmin=n0Adm1n
1 O usuário scott tem uma senha definida como jb0ss
2 O usuário jdoe tem uma senha definida como p4ssw0rd

This file has the usernames and passwords stored in plain text, which is not recommended. If plain-text is set to false (or omitted) in the config then passwords must be stored in the form MD5 ( username : realm : password ). This can be generated for the first example above by running the command echo -n scott:MyRealm:jb0ss | md5 from the command line.

Roles.properties

example test-roles.properties file
scott=Admin,admin,Tester,user (1)
jdoe=NoRolesUser (2)
stuart=admin,user (3)
noadmin=user
1 O usuário scott recebeu as funções Admin , admin , Tester e user
2 O usuário jdoe recebeu a atribuição da função NoRolesUser
3 O usuário stuart recebeu as funções admin e user .

Configuração do Embedded Realm

The embedded realm also supports mapping of users to password and users to roles. It uses the main application.properties Quarkus configuration file to embed this information. They are configured with properties starting with quarkus.security.users.embedded.

A seguir, um exemplo de seção do arquivo application.properties que ilustra a configuração do realm incorporado:

example 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

As with the first example this file has the usernames and passwords stored in plain text, which is not recommended. If plain-text is set to false (or omitted) in the config then passwords must be stored in the form MD5 ( username : realm : password ). This can be generated for the first example above by running the command echo -n scott:MyRealm:jb0ss | md5 from the command line.

Usuários incorporados

The user to password mappings are specified in the application.properties file by properties keys of the form quarkus.security.users.embedded.users.<user>=<password>. The following Example Passwords illustrates the syntax with 4 user to password mappings:

Example 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 O usuário scott tem senha jb0ss
2 O usuário stuart tem senha test

Funções incorporadas

The user to role mappings are specified in the application.properties file by properties keys of the form quarkus.security.users.embedded.roles.<user>=role1[,role2[,role3[,…​]]]. The following Example Roles illustrates the syntax with 4 user to role mappings:

Example 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 O usuário scott tem funções Admin , admin , Tester , e user
2 O usuário stuart tem funções admin e user