Skip to content

Commit 070b67a

Browse files
talerngpongmarcusdacoregio
authored andcommitted
add Kotlin examples for Spring Data Integration of servlet application
1 parent 304ef23 commit 070b67a

File tree

1 file changed

+28
-4
lines changed
  • docs/manual/src/docs/asciidoc/_includes/servlet/integrations

1 file changed

+28
-4
lines changed

docs/manual/src/docs/asciidoc/_includes/servlet/integrations/data.adoc

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,28 @@ It is not only useful but necessary to include the user in the queries to suppor
77
[[data-configuration]]
88
=== Spring Data & Spring Security Configuration
99

10-
To use this support, add `org.springframework.security:spring-security-data` dependency and provide a bean of type `SecurityEvaluationContextExtension`.
11-
In Java Configuration, this would look like:
10+
To use this support, add `org.springframework.security:spring-security-data` dependency and provide a bean of type `SecurityEvaluationContextExtension`:
1211

13-
[source,java]
12+
====
13+
.Java
14+
[source,java,role="primary"]
1415
----
1516
@Bean
1617
public SecurityEvaluationContextExtension securityEvaluationContextExtension() {
1718
return new SecurityEvaluationContextExtension();
1819
}
1920
----
2021
22+
.Kotlin
23+
[source,kotlin,role="secondary"]
24+
----
25+
@Bean
26+
fun securityEvaluationContextExtension(): SecurityEvaluationContextExtension {
27+
return SecurityEvaluationContextExtension()
28+
}
29+
----
30+
====
31+
2132
In XML Configuration, this would look like:
2233

2334
[source,xml]
@@ -31,7 +42,9 @@ In XML Configuration, this would look like:
3142
Now Spring Security can be used within your queries.
3243
For example:
3344

34-
[source,java]
45+
====
46+
.Java
47+
[source,java,role="primary"]
3548
----
3649
@Repository
3750
public interface MessageRepository extends PagingAndSortingRepository<Message,Long> {
@@ -40,6 +53,17 @@ public interface MessageRepository extends PagingAndSortingRepository<Message,Lo
4053
}
4154
----
4255
56+
.Kotlin
57+
[source,kotlin,role="secondary"]
58+
----
59+
@Repository
60+
interface MessageRepository : PagingAndSortingRepository<Message,Long> {
61+
@Query("select m from Message m where m.to.id = ?#{ principal?.id }")
62+
fun findInbox(pageable: Pageable): Page<Message>
63+
}
64+
----
65+
====
66+
4367
This checks to see if the `Authentication.getPrincipal().getId()` is equal to the recipient of the `Message`.
4468
Note that this example assumes you have customized the principal to be an Object that has an id property.
4569
By exposing the `SecurityEvaluationContextExtension` bean, all of the <<common-expressions,Common Security Expressions>> are available within the Query.

0 commit comments

Comments
 (0)