可以說我有一個User
實體,ManyToMany
映射到UserGroup
實體。如果我創建兩個實體庫,並獲得URI /users/1
,我得到的迴應是這樣的:彈簧數據保持安全HATEOAS鏈接
{
"enabled" : true,
"password" : "xxxxxx",
"username" : "xxxxxx",
"credentialsNonExpired" : true,
"accountNonLocked" : true,
"accountNonExpired" : true,
"_links" : {
"self" : {
"href" : "http://127.0.0.1:45950/users/1"
},
"user" : {
"href" : "http://127.0.0.1:45950/users/1"
},
"userGroups" : {
"href" : "http://127.0.0.1:45950/users/1/userGroups"
}
}
}
這裏的羣組鏈接是非常有用的。
我可以使用/userGroups
端點列出所有UserGroup
。 我想保護/userGroups
端點和/users/1/userGroups
端點使用不同的spring-security
表達式。
使用參考這裏:http://docs.spring.io/spring-data/rest/docs/current/reference/html/#security我知道如何確保第一個端點:
public interface UserGroupRepository extends PagingAndSortingRepository<UserGroup, Long> {
@PreAuthorize("hasRole('ROLE_ADMIN')")
@Override
Iterable<T> findAll();
}
但是我怎麼保證第二端點?目前甚至有可能嗎?有沒有一些工作計劃在這個功能上。我很樂意貢獻。