Skip to content

Commit a1afe5b

Browse files
author
quarkusbot
committed
Sync web site with Quarkus documentation
1 parent cc59d42 commit a1afe5b

8 files changed

+52
-39
lines changed

_guides/_attributes.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Common attributes.
22
// --> No blank lines (it ends the document header)
33
:project-name: Quarkus
4-
:quarkus-version: 3.17.7
4+
:quarkus-version: 3.17.8
55
:quarkus-platform-groupid: io.quarkus.platform
66
// .
77
:maven-version: 3.9.9

_guides/cdi-reference.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ public class EagerAppBean {
333333

334334
NOTE: Quarkus users are encouraged to always prefer the `@Observes StartupEvent` to `@Initialized(ApplicationScoped.class)` as explained in the xref:lifecycle.adoc[Application Initialization and Termination] guide.
335335

336+
[[request-context-lifecycle]]
336337
=== Request Context Lifecycle
337338

338339
The request context is also active:

_guides/kotlin.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ group = '...' // set your group
221221
version = '1.0.0-SNAPSHOT'
222222
223223
java {
224-
sourceCompatibility = JavaVersion.VERSION_11
225-
targetCompatibility = JavaVersion.VERSION_11
224+
sourceCompatibility = JavaVersion.VERSION_21
225+
targetCompatibility = JavaVersion.VERSION_21
226226
}
227227
228228
allOpen { // <2>
@@ -233,12 +233,12 @@ allOpen { // <2>
233233
}
234234
235235
compileKotlin {
236-
kotlinOptions.jvmTarget = JavaVersion.VERSION_11
236+
kotlinOptions.jvmTarget = JavaVersion.VERSION_21
237237
kotlinOptions.javaParameters = true
238238
}
239239
240240
compileTestKotlin {
241-
kotlinOptions.jvmTarget = JavaVersion.VERSION_11
241+
kotlinOptions.jvmTarget = JavaVersion.VERSION_21
242242
}
243243
----
244244

@@ -290,8 +290,8 @@ group = '...' // set your group
290290
version = "1.0.0-SNAPSHOT"
291291
292292
java {
293-
sourceCompatibility = JavaVersion.VERSION_11
294-
targetCompatibility = JavaVersion.VERSION_11
293+
sourceCompatibility = JavaVersion.VERSION_21
294+
targetCompatibility = JavaVersion.VERSION_21
295295
}
296296
297297
allOpen { // <2>

_guides/security-authorize-web-endpoints-reference.adoc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ public class CustomNamedHttpSecPolicy implements HttpSecurityPolicy {
123123
public Uni<CheckResult> checkPermission(RoutingContext event, Uni<SecurityIdentity> identity,
124124
AuthorizationRequestContext requestContext) {
125125
if (customRequestAuthorization(event)) {
126-
return Uni.createFrom().item(CheckResult.PERMIT);
126+
return CheckResult.permit();
127127
}
128-
return Uni.createFrom().item(CheckResult.DENY);
128+
return CheckResult.deny();
129129
}
130130
131131
@Override
@@ -182,6 +182,17 @@ You can also create global `HttpSecurityPolicy` invoked on every request.
182182
Just do not implement the `io.quarkus.vertx.http.runtime.security.HttpSecurityPolicy.name` method and leave the policy nameless.
183183
====
184184

185+
[[policy-active-cdi-request-context]]
186+
=== Inject `@RequestScoped` beans into `HttpSecurityPolicy`
187+
188+
`@RequestScoped` beans can only be injected when the xref:cdi-reference.adoc#request-context-lifecycle[CDI request context] is active.
189+
The context can be activated by users, for example with the `@ActivateRequestContext`, however authorization happens before Quarkus prepares some `@RequestScoped` beans.
190+
We recommend to let Quarkus activate and prepare CDI request context for you.
191+
For example, consider a situation where you want to inject a bean from the Jakarta REST context, such as the `jakarta.ws.rs.core.UriInfo` bean.
192+
In this case, you must apply the `HttpSecurityPolicy` to Jakarta REST endpoints. This can be achieved in one of the following ways:
193+
* Use the `@AuthorizationPolicy` security annotation.
194+
* Set the `quarkus.http.auth.permission.custom1.applies-to=jaxrs` configuration property.
195+
185196
=== Matching on paths and methods
186197

187198
Permission sets can also specify paths and methods as a comma-separated list.
@@ -494,7 +505,7 @@ s| `@PermitAll` | Specifies that all security roles are allowed to invoke the sp
494505
s| `@RolesAllowed` | Specifies the list of security roles allowed to access methods in an application.
495506
s| `@Authenticated` | {project-name} provides the `io.quarkus.security.Authenticated` annotation that permits any authenticated user to access the resource. It's equivalent to `@RolesAllowed("**")`.
496507
s| `@PermissionsAllowed` | Specifies the list of permissions that are allowed to invoke the specified methods.
497-
s| `@AuthorizationPolicy` | Specifies named `io.quarkus.vertx.http.runtime.security.HttpSecurityPolicy` that should authorize access to the specified endpoints.HttpSecurityPolicy.
508+
s| `@AuthorizationPolicy` | Specifies named `io.quarkus.vertx.http.runtime.security.HttpSecurityPolicy` that should authorize access to the specified Jakarta REST endpoints.
498509
Named HttpSecurityPolicy can be used for general authorization checks as demonstrated by <<authorization-policy-example>>.
499510
|===
500511

_guides/security-customization.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ You can enforce the order by implementing a default `SecurityIdentityAugmentor#p
242242
By default, the request context is not activated when augmenting the security identity, this means that if you want to use for example Hibernate
243243
that mandates a request context, you will have a `jakarta.enterprise.context.ContextNotActiveException`.
244244

245+
IMPORTANT: Please also review the xref:security-proactive-authentication.adoc#cdi-request-context-activation[Activating the CDI request context] section of the "Proactive authentication" guide.
246+
245247
The solution is to activate the request context, the following example shows how to get the roles from an Hibernate with Panache `UserRoleEntity`.
246248

247249
[source,java]

_guides/security-getting-started-tutorial.adoc

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,16 @@ For example:
324324
----
325325
quarkus.http.auth.basic=true
326326
327-
quarkus.datasource.db-kind=postgresql
328-
quarkus.datasource.username=quarkus
329-
quarkus.datasource.password=quarkus
330-
quarkus.datasource.jdbc.url=jdbc:postgresql:security_jpa
327+
%prod.quarkus.datasource.db-kind=postgresql
328+
%prod.quarkus.datasource.username=quarkus
329+
%prod.quarkus.datasource.password=quarkus
330+
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql:security_jpa
331331
332332
quarkus.hibernate-orm.database.generation=drop-and-create
333333
----
334+
335+
By adding the `%prod.` profile prefix, you ensure that the data source properties are only observed by an application running in production mode.
336+
334337
====
335338
+
336339
. To initialize the database with users and roles, implement the `Startup` class, as outlined in the following code snippet:
@@ -384,7 +387,7 @@ In a production environment, do not store plain text passwords.
384387
As a result, the `quarkus-security-jpa` defaults to using bcrypt-hashed passwords.
385388
====
386389

387-
== Test your application by using Dev Services for PostgreSQL
390+
== Test your application in dev mode by using Dev Services for PostgreSQL
388391

389392
Complete the integration testing of your application in JVM and native modes by using xref:dev-services.adoc#databases[Dev Services for PostgreSQL] before you run your application in production mode.
390393

@@ -411,21 +414,8 @@ To run your application in dev mode:
411414
include::{includes}/devtools/dev.adoc[]
412415

413416

414-
The following properties configuration demonstrates how to enable PostgreSQL testing to run only in production (`prod`) mode.
415417
In this scenario, `Dev Services for PostgreSQL` launches and configures a `PostgreSQL` test container.
416418

417-
[source,properties]
418-
----
419-
%prod.quarkus.datasource.db-kind=postgresql
420-
%prod.quarkus.datasource.username=quarkus
421-
%prod.quarkus.datasource.password=quarkus
422-
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://localhost/quarkus
423-
424-
quarkus.hibernate-orm.database.generation=drop-and-create
425-
----
426-
427-
If you add the `%prod.` profile prefix, data source properties are not visible to `Dev Services for PostgreSQL` and are only observed by an application running in production mode.
428-
429419
To write the integration test, use the following code sample:
430420

431421
[source,java]
@@ -503,7 +493,7 @@ While developing your application, you can add and run tests individually by usi
503493
Dev Services for PostgreSQL supports testing while you develop by providing a separate PostgreSQL test container that does not conflict with the dev mode container.
504494
====
505495

506-
== Test your application using Curl or browser
496+
== Test your application in production mode by using Curl or browser
507497

508498
To test your application using Curl or the browser, you must first start a PostgreSQL server, then compile and run your application either in JVM or native mode.
509499

@@ -513,7 +503,7 @@ To test your application using Curl or the browser, you must first start a Postg
513503
----
514504
docker run --rm=true --name security-getting-started -e POSTGRES_USER=quarkus \
515505
-e POSTGRES_PASSWORD=quarkus -e POSTGRES_DB=quarkus \
516-
-p 5432:5432 postgres:14.1
506+
-p 5432:5432 postgres:17
517507
----
518508

519509
=== Compile and run the application
@@ -576,11 +566,7 @@ public
576566
$ curl -i -X GET http://localhost:8080/api/admin
577567
578568
HTTP/1.1 401 Unauthorized
579-
Content-Length: 14
580-
Content-Type: text/html;charset=UTF-8
581569
WWW-Authenticate: Basic
582-
583-
Not authorized
584570
----
585571
====
586572
* Connect to a protected endpoint as an authorized user:
@@ -616,10 +602,6 @@ If a resource is protected with `@RolesAllowed("user")`, the user `admin` is not
616602
$ curl -i -X GET -u admin:admin http://localhost:8080/api/users/me
617603
618604
HTTP/1.1 403 Forbidden
619-
Content-Length: 34
620-
Content-Type: text/html;charset=UTF-8
621-
622-
Forbidden
623605
----
624606

625607
Finally, the user named `user` is authorized, and the security context contains the principal details, for example, the username.

_guides/security-openid-connect-client-registration.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ include::_attributes.adoc[]
99
:categories: security
1010
:topics: security,oidc,client
1111
:extensions: io.quarkus:quarkus-oidc-client-registration
12+
:extension-status: experimental
13+
14+
include::{includes}/extension-status.adoc[]
1215

1316
Typically, you have to register an OIDC client (application) manually in your OIDC provider's dashboard.
1417
During this process, you specify the human readable application name, allowed redirect and post logout URLs, and other properties.

_guides/security-proactive-authentication.adoc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Gain practical insights and strategies for various application scenarios.
1818
Proactive authentication is enabled in Quarkus by default.
1919
It ensures that all incoming requests with credentials are authenticated, even if the target page does not require authentication.
2020
As a result, requests with invalid credentials are rejected, even if the target page is public.
21+
Requests without credentials are not rejected, because anonymous requests are allowed.
2122

2223
You can turn off this default behavior if you want to authenticate only when the target page requires it.
2324
To turn off proactive authentication so that authentication occurs only when the target page requires it, modify the `application.properties` configuration file as follows:
@@ -30,7 +31,7 @@ quarkus.http.auth.proactive=false
3031
If you turn off proactive authentication, the authentication process runs only when an identity is requested.
3132
An identity can be requested because of security rules that require the user to authenticate or because programmatic access to the current identity is required.
3233

33-
If proactive authentication is used, accessing `SecurityIdentity` is a blocking operation.
34+
If proactive authentication is not used, accessing `SecurityIdentity` is a blocking operation.
3435
This is because authentication might have yet to happen, and accessing `SecurityIdentity` might require calls to external systems, such as databases, that might block the operation.
3536
For blocking applications, this is not an issue.
3637
However, if you have disabled authentication in a reactive application, this fails because you cannot do blocking operations on the I/O thread.
@@ -96,6 +97,19 @@ public class HelloService {
9697
}
9798
----
9899

100+
[[cdi-request-context-activation]]
101+
== Activating the CDI request context
102+
103+
You may need to inject `@RequestScoped` beans during authentication and authorization.
104+
A good example of this is accessing a database during a `SecurityIdentity` augmentation,
105+
which is described in the xref:security-customization.adoc#security-identity-customization[Security Identity Customization] section of the "Security Tips and Tricks" guide.
106+
If authentication or authorization fails with the `jakarta.enterprise.context.ContextNotActiveException`, disabling proactive authentication is most often the best solution.
107+
Users can also activate xref:cdi-reference.adoc#request-context-lifecycle[CDI request context], for example, by using the `@ActivateRequestContext` annotation.
108+
However, some CDI beans may not be ready for use.
109+
110+
One exception to this solution is a situation when application endpoints are secured with the xref:security-authorize-web-endpoints-reference.adoc#authorization-using-configuration[Authorization using configuration].
111+
For more information, see the xref:security-authorize-web-endpoints-reference.adoc#policy-active-cdi-request-context[Inject RequestScoped beans into HttpSecurityPolicy] section of the "Authorization of Web endpoints" guide for more information.
112+
99113
[[customize-auth-exception-responses]]
100114
== Customize authentication exception responses
101115

0 commit comments

Comments
 (0)