Skip to content

Commit 8895a66

Browse files
committed
Add hasIpAddress Migration Steps
Closes gh-13474
1 parent 80a5028 commit 8895a66

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

docs/modules/ROOT/pages/migration/servlet/authorization.adoc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,59 @@ Xml::
10901090
----
10911091
======
10921092

1093+
=== Migrate `hasIpAddress` to `access(AuthorizationManager)`
1094+
1095+
`hasIpAddress` has no DSL equivalent in `authorizeHttpRequests`.
1096+
1097+
As such, you need to change any called to `hasIpAddress` to using an `AuthorizationManager`.
1098+
1099+
First, construct an `IpAddressMatcher` like so:
1100+
1101+
====
1102+
.Java
1103+
[source,java,role="primary"]
1104+
----
1105+
IpAddressMatcher hasIpAddress = new IpAddressMatcher("127.0.0.1");
1106+
----
1107+
====
1108+
1109+
And then change from this:
1110+
1111+
====
1112+
.Java
1113+
[source,java,role="primary"]
1114+
----
1115+
http
1116+
.authorizeRequests((authorize) -> authorize
1117+
.mvcMatchers("/app/**").hasIpAddress("127.0.0.1")
1118+
// ...
1119+
.anyRequest().denyAll()
1120+
)
1121+
// ...
1122+
----
1123+
====
1124+
1125+
to this:
1126+
1127+
====
1128+
.Java
1129+
[source,java,role="primary"]
1130+
----
1131+
http
1132+
.authorizeHttpRequests((authorize) -> authorize
1133+
.requestMatchers("/app/**").access((authentication, context) ->
1134+
new AuthorizationDecision(hasIpAddress.matches(context.getRequest()))
1135+
// ...
1136+
.anyRequest().denyAll()
1137+
)
1138+
// ...
1139+
----
1140+
====
1141+
1142+
[NOTE]
1143+
Securing by IP Address is quite fragile to begin with.
1144+
For that reason, there are no plans to port this support over to `authorizeHttpRequests`.
1145+
10931146
=== Migrate SpEL expressions to `AuthorizationManager`
10941147

10951148
For authorization rules, Java tends to be easier to test and maintain than SpEL.

0 commit comments

Comments
 (0)