Skip to content

Commit bb72206

Browse files
committed
Add Kotlin samples to docs
Issue: gh-5558
1 parent 87ca714 commit bb72206

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

docs/manual/src/docs/asciidoc/_includes/servlet/authorization/authorize-requests.adoc

+31
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ protected void configure(HttpSecurity http) throws Exception {
4747
<intercept-url pattern="/**" access="authenticated"/>
4848
</http>
4949
----
50+
51+
.Kotlin
52+
[source,kotlin,role="secondary"]
53+
----
54+
fun configure(http: HttpSecurity) {
55+
http {
56+
// ...
57+
authorizeRequests {
58+
authorize(anyRequest, authenticated)
59+
}
60+
}
61+
}
62+
----
5063
====
5164

5265
We can configure Spring Security to have different rules by adding more rules in order of precedence.
@@ -83,6 +96,24 @@ protected void configure(HttpSecurity http) throws Exception {
8396
<intercept-url pattern="/**" access="denyAll"/> <!--5-->
8497
</http>
8598
----
99+
100+
.Kotlin
101+
[source,kotlin,role="secondary"]
102+
----
103+
fun configure(http: HttpSecurity) {
104+
http {
105+
authorizeRequests { // <1>
106+
authorize("/resources/**", permitAll) // <2>
107+
authorize("/signup", permitAll)
108+
authorize("/about", permitAll)
109+
110+
authorize("/admin/**", hasRole("ADMIN")) // <3>
111+
authorize("/db/**", "hasRole('ADMIN') and hasRole('DBA')") // <4>
112+
authorize(anyRequest, denyAll) // <5>
113+
}
114+
}
115+
}
116+
----
86117
====
87118
<1> There are multiple authorization rules specified.
88119
Each rule is considered in the order they were declared.

docs/manual/src/docs/asciidoc/_includes/servlet/exploits/firewall.adoc

+22
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ public StrictHttpFirewall httpFirewall() {
6767
6868
<http-firewall ref="httpFirewall"/>
6969
----
70+
71+
.Kotlin
72+
[source,kotlin,role="secondary"]
73+
----
74+
@Bean
75+
fun httpFirewall(): StrictHttpFirewall {
76+
val firewall = StrictHttpFirewall()
77+
firewall.setAllowSemicolon(true)
78+
return firewall
79+
}
80+
----
7081
====
7182

7283
The `StrictHttpFirewall` provides an allowed list of valid HTTP methods that are allowed to protect against https://www.owasp.org/index.php/Cross_Site_Tracing[Cross Site Tracing (XST)] and https://www.owasp.org/index.php/Test_HTTP_Methods_(OTG-CONFIG-006)[HTTP Verb Tampering].
@@ -97,6 +108,17 @@ public StrictHttpFirewall httpFirewall() {
97108
98109
<http-firewall ref="httpFirewall"/>
99110
----
111+
112+
.Kotlin
113+
[source,kotlin,role="secondary"]
114+
----
115+
@Bean
116+
fun httpFirewall(): StrictHttpFirewall {
117+
val firewall = StrictHttpFirewall()
118+
firewall.setAllowedHttpMethods(listOf("GET", "POST"))
119+
return firewall
120+
}
121+
----
100122
====
101123

102124
[TIP]

0 commit comments

Comments
 (0)