java - Spring Security @PreAuthorize 使用 SpEL 语言访问自动装配的 bean
问题描述
我想使用 SpEL 语言在 Spring Security @PreAuthorize 下访问我的自动装配 bean。
@Component
@Transactional
public class TodoDao implements ITodoDao {
@Autowired
private SessionFactory sessionFactory;
@Autowired
private AuthenticationFacade authenticationFacade;
@Override
@PreAuthorize("...") // I want to access to one of my autowired bean here
public void changeTodoStatus(Todo todo) {
Object user = authenticationFacade.getAuthentication().getPrincipal();
todo.setDone(!todo.isDone());
sessionFactory.getCurrentSession().update(todo);
}
}
解决方案
在您的 bean 名称前使用“@”:
@Component
@Transactional
public class TodoDao implements ITodoDao {
@Autowired
private SessionFactory sessionFactory;
@Autowired
private AuthenticationFacade authenticationFacade;
@Override
@PreAuthorize("@authenticationFacade.(#toDo)") // I want to access to one of my autowired bean here
public void changeTodoStatus(Todo todo) {
Object user = authenticationFacade.getAuthentication().getPrincipal();
todo.setDone(!todo.isDone());
sessionFactory.getCurrentSession().update(todo);
}
}
推荐阅读
- c++ - 有没有办法从项目的主程序文件中设置对象成员数组大小,该文件#includes 用于声明/定义对象的.h 文件?
- mobile - 从移动浏览器获取 GPS 数据是否已知有些不稳定?
- python - 不带括号的列表或元组不用于打印
- windows - Windows 10 中缺少 IPP 驱动程序(需要连接到 CUPS)
- google-analytics - 未检测到 HTTP 响应 - Wix 上的 Google Analytics(分析)
- jahia - DigitalExperienceManager-CommunityDistribution-7.3.1.0 以错误“无法将 maven 可执行文件设置为 mvn,请检查您的配置”开始
- ios - 如何在导航 SWIFT Xcode 中使用 segue?
- python - 如何防止python将重复项插入mongodb?
- excel - 从 Excel 函数 NETWORKDAYS 获取“start_date”
- javascript - 您是否正确注册了组件?对于递归组件,请确保提供“名称”选项。(在发现
) VUE