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: docs/modules/ROOT/pages/servlet/integrations/data.adoc
+27-7Lines changed: 27 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -2,22 +2,31 @@
2
2
= Spring Data Integration
3
3
4
4
Spring Security provides Spring Data integration that allows referring to the current user within your queries.
5
-
It is not only useful but necessary to include the user in the queries to support paged results, since filtering the results afterwards would not scale.
5
+
It is not only useful but necessary to include the user in the queries to support paged results since filtering the results afterwards would not scale.
6
6
7
7
[[data-configuration]]
8
8
== Spring Data & Spring Security Configuration
9
9
10
-
To use this support, add the `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`:
12
11
13
12
====
14
-
[source,java]
13
+
.Java
14
+
[source,java,role="primary"]
15
15
----
16
16
@Bean
17
17
public SecurityEvaluationContextExtension securityEvaluationContextExtension() {
18
18
return new SecurityEvaluationContextExtension();
19
19
}
20
20
----
21
+
22
+
.Kotlin
23
+
[source,kotlin,role="secondary"]
24
+
----
25
+
@Bean
26
+
fun securityEvaluationContextExtension(): SecurityEvaluationContextExtension {
27
+
return SecurityEvaluationContextExtension()
28
+
}
29
+
----
21
30
====
22
31
23
32
In XML Configuration, this would look like:
@@ -35,16 +44,27 @@ In XML Configuration, this would look like:
35
44
Now you can use Spring Security within your queries:
36
45
37
46
====
38
-
[source,java]
47
+
.Java
48
+
[source,java,role="primary"]
39
49
----
40
50
@Repository
41
51
public interface MessageRepository extends PagingAndSortingRepository<Message,Long> {
42
52
@Query("select m from Message m where m.to.id = ?#{ principal?.id }")
@Query("select m from Message m where m.to.id = ?#{ principal?.id }")
63
+
fun findInbox(pageable: Pageable): Page<Message>
64
+
}
65
+
----
46
66
====
47
67
48
68
This checks to see if the `Authentication.getPrincipal().getId()` is equal to the recipient of the `Message`.
49
-
Note that this example assumes you have customized the principal to be an `Object` that has an `id` property.
50
-
By exposing the `SecurityEvaluationContextExtension` bean, all of the xref:servlet/authorization/expression-based.adoc#common-expressions[Common Security Expressions] are available within the query.
69
+
Note that this example assumes you have customized the principal to be an Object that has an id property.
70
+
By exposing the `SecurityEvaluationContextExtension` bean, all of the xref:servlet/authorization/expression-based.adoc#common-expressions[Common Security Expressions] are available within the Query.
0 commit comments