小编jay*_*jay的帖子

具有索引问题的弹簧安全数据

尝试使用具有 Spring 数据安全性的方法级安全性。

我创建了一个示例 repo https://github.com/jayasai470/spring-data-security-sample/

当@Indexed 被评论时一切正常,我可以在 mongo 调试日志中看到,对于 spel 查询 @Query("{tenantId: ?#{principal.tenantId}}") tenantId 被正确注入

但是当我尝试包含 @Indexed 注释服务器时无法启动。Mongo 模板抛出异常,身份验证对象为空

 // my entity class
@Data
@Document(collection = "userprofiles")
public class UserProfile {

@Id
@Field("_id")
private String id;

@Email(message = "not a valid email")
@Indexed(unique = true, name = "email_1", background = true)
private String email;

private String tenantId;
}

 //repository
@Repository
public interface UserProfileRepository extends 
  PagingAndSortingRepository<UserProfile, String> {

UserProfile findOneByEmail(String email);

@Query("{tenantId: ?#{principal.tenantId}}")
List<UserProfile> findAllByTenantId();
}

// registered a bean …
Run Code Online (Sandbox Code Playgroud)

spring-security spring-data spring-data-mongodb spring-boot

5
推荐指数
0
解决办法
541
查看次数