# Spring Data Integration Spring Security provides Spring Data integration that allows referring to the current user within your queries. 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. ## Spring Data & Spring Security Configuration To use this support, add `org.springframework.security:spring-security-data` dependency and provide a bean of type `SecurityEvaluationContextExtension`. In Java Configuration, this would look like: Java ``` @Bean public SecurityEvaluationContextExtension securityEvaluationContextExtension() { return new SecurityEvaluationContextExtension(); } ``` Kotlin ``` @Bean fun securityEvaluationContextExtension(): SecurityEvaluationContextExtension { return SecurityEvaluationContextExtension() } ``` In XML Configuration, this would look like: ``` ``` ## Security Expressions within @Query Now Spring Security can be used within your queries. For example: Java ``` @Repository public interface MessageRepository extends PagingAndSortingRepository { @Query("select m from Message m where m.to.id = ?#{ principal?.id }") Page findInbox(Pageable pageable); } ``` Kotlin ``` @Repository interface MessageRepository : PagingAndSortingRepository { @Query("select m from Message m where m.to.id = ?#{ principal?.id }") fun findInbox(pageable: Pageable?): Page? } ``` This checks to see if the `Authentication.getPrincipal().getId()` is equal to the recipient of the `Message`. Note that this example assumes you have customized the principal to be an Object that has an id property. By exposing the `SecurityEvaluationContextExtension` bean, all of the [Common Security Expressions](../../servlet/authorization/expression-based.html#common-expressions) are available within the Query.