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/manual/src/docs/asciidoc/_includes/servlet/integrations/data.adoc
+28-4Lines changed: 28 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,17 +7,28 @@ It is not only useful but necessary to include the user in the queries to suppor
7
7
[[data-configuration]]
8
8
=== Spring Data & Spring Security Configuration
9
9
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`:
12
11
13
-
[source,java]
12
+
====
13
+
.Java
14
+
[source,java,role="primary"]
14
15
----
15
16
@Bean
16
17
public SecurityEvaluationContextExtension securityEvaluationContextExtension() {
17
18
return new SecurityEvaluationContextExtension();
18
19
}
19
20
----
20
21
22
+
.Kotlin
23
+
[source,kotlin,role="secondary"]
24
+
----
25
+
@Bean
26
+
fun securityEvaluationContextExtension(): SecurityEvaluationContextExtension {
27
+
return SecurityEvaluationContextExtension()
28
+
}
29
+
----
30
+
====
31
+
21
32
In XML Configuration, this would look like:
22
33
23
34
[source,xml]
@@ -31,7 +42,9 @@ In XML Configuration, this would look like:
31
42
Now Spring Security can be used within your queries.
32
43
For example:
33
44
34
-
[source,java]
45
+
====
46
+
.Java
47
+
[source,java,role="primary"]
35
48
----
36
49
@Repository
37
50
public interface MessageRepository extends PagingAndSortingRepository<Message,Long> {
@@ -40,6 +53,17 @@ public interface MessageRepository extends PagingAndSortingRepository<Message,Lo
@Query("select m from Message m where m.to.id = ?#{ principal?.id }")
62
+
fun findInbox(pageable: Pageable): Page<Message>
63
+
}
64
+
----
65
+
====
66
+
43
67
This checks to see if the `Authentication.getPrincipal().getId()` is equal to the recipient of the `Message`.
44
68
Note that this example assumes you have customized the principal to be an Object that has an id property.
45
69
By exposing the `SecurityEvaluationContextExtension` bean, all of the <<common-expressions,Common Security Expressions>> are available within the Query.
0 commit comments