Skip to content

Commit f8ee906

Browse files
vaadin-botfredpenapeholmst
authored
Add documentation for Custom Authorization Rules and Disabling Features in Vaadin Security (#4485) (#4519)
Summary This PR adds detailed for two key sections in Vaadin Security configuration: Custom Authorization Rules – explains what they are, their use cases, and how they complement Vaadin's annotation-based view access control. Disabling Features – explains the default behavior of CSRF configuration and Navigation Access Control in VaadinSecurityConfigurer, and when it is safe to disable them. Co-authored-by: Fred Peña <f.ant.pena@gmail.com> Co-authored-by: Petter Holmström <petter@vaadin.com>
1 parent 855b570 commit f8ee906

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

articles/flow/security/vaadin-security-configurer.adoc

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,19 @@ public class SecurityConfig {
298298

299299
===== Custom Authorization Rules
300300

301+
In Spring Security, *Custom Authorization Rules* are developer-defined rules that control who can access certain HTTP routes or resources. In Vaadin, they complement the access control already applied to views through annotations like `@PermitAll` or `@RolesAllowed`.
302+
303+
====== Use Cases
304+
305+
- Protect REST endpoints that are not part of Vaadin navigation.
306+
- Define public routes that don’t require authentication (`/public/**`).
307+
- Restrict specific areas based on roles (`/admin-only/**`).
308+
- Allow access to error pages without authentication (`/error`).
309+
310+
====== How It Works With Vaadin
311+
312+
Vaadin uses annotations to control access to views at the navigation level, while Spring Security applies these *Custom Authorization Rules* at the HTTP request level. Both layers work together to ensure a secure application.
313+
301314
[source,java]
302315
----
303316
@Configuration
@@ -327,6 +340,42 @@ public class SecurityConfig {
327340

328341
===== Disabling Features
329342

343+
The `VaadinSecurityConfigurer` provides some security features enabled by
344+
default to ensure smooth integration between Vaadin and Spring Security.
345+
In certain scenarios, you may disable these defaults to apply your own
346+
custom security configuration.
347+
348+
====== Features That Can Be Disabled
349+
350+
- **CSRF Configuration** (`enableCsrfConfiguration(false)`):
351+
By default, the configurer automatically sets up Spring Security’s CSRF
352+
filter so that Vaadin internal framework requests (such as UIDL, heartbeat,
353+
and push) are processed without issues.
354+
Disabling this means you will need to handle CSRF configuration yourself,
355+
ensuring that internal Vaadin requests are not blocked.
356+
357+
- **Navigation Access Control** (`enableNavigationAccessControl(false)`):
358+
Vaadin enables `NavigationAccessControl` by default to check access
359+
annotations (such as `@PermitAll` or `@RolesAllowed`) when navigating
360+
between views.
361+
Disabling this means Vaadin will no longer enforce annotation-based
362+
navigation security, and you will need to implement your own access control
363+
logic for view navigation.
364+
365+
====== When To Disable
366+
367+
You should only disable these features if:
368+
369+
- You have a clear, secure, and tested replacement for the default behavior.
370+
371+
- You understand the implications of removing these protections.
372+
373+
- Your application has special requirements that conflict with the defaults.
374+
375+
In most applications, keeping these features enabled is the recommended and
376+
safest option.
377+
378+
330379
[source,java]
331380
----
332381
@Configuration
@@ -343,4 +392,4 @@ public class SecurityConfig {
343392
}).build();
344393
}
345394
}
346-
----
395+
----

0 commit comments

Comments
 (0)