You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: config/src/main/java/org/springframework/security/config/annotation/authorization/AuthorizationManagerFactoryConfiguration.java
Copy file name to clipboardExpand all lines: config/src/main/java/org/springframework/security/config/annotation/authorization/EnableMultiFactorAuthentication.java
Copy file name to clipboardExpand all lines: config/src/main/java/org/springframework/security/config/annotation/authorization/MultiFactorAuthenticationSelector.java
Copy file name to clipboardExpand all lines: config/src/test/java/org/springframework/security/config/annotation/authorization/EnableMultiFactorAuthenticationFiltersSetTests.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -53,14 +53,14 @@
53
53
importstaticorg.mockito.Mockito.mock;
54
54
55
55
/**
56
-
* Tests for {@link EnableGlobalMultiFactorAuthentication}.
56
+
* Tests for {@link EnableMultiFactorAuthentication}.
Copy file name to clipboardExpand all lines: config/src/test/java/org/springframework/security/config/annotation/authorization/EnableMultiFactorAuthenticationTests.java
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/servlet/authentication/mfa.adoc
+16-9Lines changed: 16 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,17 +18,17 @@ In order to require MFA with Spring Security you must:
18
18
- Specify an authorization rule that requires multiple factors
19
19
- Setup authentication for each of those factors
20
20
21
-
[[egmfa]]
22
-
== @EnableGlobalMultiFactorAuthentication
21
+
[[emfa]]
22
+
== @EnableMultiFactorAuthentication
23
23
24
-
javadoc:org.springframework.security.config.annotation.authorization.EnableGlobalMultiFactorAuthentication[format=annotation] simplifies Global MFA (the entire application requires MFA).
24
+
javadoc:org.springframework.security.config.annotation.authorization.EnableMultiFactorAuthentication[format=annotation] makes it easy to enable multifactor authentication.
25
25
Below you can find a configuration that adds the requirement for both passwords and OTT to every authorization rule.
<1> URLs that begin with `/admin/**` require the authorities `FACTOR_OTT`, `FACTOR_PASSWORD`, `ROLE_ADMIN`.
33
33
<2> Every other URL requires the authorities `FACTOR_OTT`, `FACTOR_PASSWORD`
34
34
<3> Set up the authentication mechanisms that can provide the required factors.
@@ -40,18 +40,18 @@ If the user logged in initially with a token, then Spring Security redirects to
40
40
[[authorization-manager-factory]]
41
41
== AuthorizationManagerFactory
42
42
43
-
The `@EnableGlobalMultiFactorAuthentication` annotation is just a shortcut for publishing an javadoc:org.springframework.security.authorization.AuthorizationManagerFactory[] Bean.
43
+
The `@EnableMultiFactorAuthentication` `authorities` property is just a shortcut for publishing an javadoc:org.springframework.security.authorization.AuthorizationManagerFactory[] Bean.
44
44
When an `AuthorizationManagerFactory` Bean is available, it is used by Spring Security to create authorization rules, like `hasAnyRole(String)`, that are defined on the `AuthorizationManagerFactory` Bean interface.
45
-
The implementation published by `@EnableGlobalMultiFactorAuthentication` will ensure that each authorization is combined with the requirement of having the specified factors.
45
+
The implementation published by `@EnableMultiFactorAuthentication` will ensure that each authorization is combined with the requirement of having the specified factors.
46
46
47
-
The `AuthorizationManagerFactory` Bean below is what is published in the previously discussed xref:./mfa.adoc#using-egmfa[`@EnableGlobalMultiFactorAuthentication` example].
47
+
The `AuthorizationManagerFactory` Bean below is what is published in the previously discussed xref:./mfa.adoc#emfa[`@EnableMultiFactorAuthentication` example].
We have demonstrated how to configure an entire application to require MFA (Global MFA) by using xref:./mfa.adoc#egmfa[`@EnableGlobalMultiFactorAuthentication`].
54
+
We have demonstrated how to configure an entire application to require MFA by using xref:./mfa.adoc#emfa[`@EnableMultiFactorAuthentication`]s `authorities` property.
55
55
However, there are times that an application only wants parts of the application to require MFA.
56
56
Consider the following requirements:
57
57
@@ -63,6 +63,13 @@ In this case, some URLs require MFA while others do not.
63
63
This means that the global approach that we saw before does not work.
64
64
Fortunately, we can use what we learned in xref:./mfa.adoc#authorization-manager-factory[] to solve this in a concise manner.
65
65
66
+
Start by specifying `@EnableMultiFactorAuthentication` without any authorities.
67
+
By doing so we enable MFA support, but no `AuthorizationManagerFactory` Bean is published.
Copy file name to clipboardExpand all lines: docs/src/test/java/org/springframework/security/docs/servlet/authentication/emfa/EnableMultiFactorAuthenticationConfiguration.java
Copy file name to clipboardExpand all lines: docs/src/test/java/org/springframework/security/docs/servlet/authentication/emfa/EnableMultiFactorAuthenticationTests.java
Copy file name to clipboardExpand all lines: docs/src/test/java/org/springframework/security/docs/servlet/authentication/selectivemfa/SelectiveMfaConfiguration.java
Copy file name to clipboardExpand all lines: docs/src/test/kotlin/org/springframework/security/kt/docs/servlet/authentication/emfa/EnableMultiFactorAuthenticationConfiguration.kt
0 commit comments