gpt4 book ai didi

java - Spring Security @PreAuthorize 使用 SpEL 语言访问 Autowiring bean

转载 作者:行者123 更新时间:2023-12-02 01:50:31 25 4
gpt4 key购买 nike

我想使用 SpEL 语言访问 Spring Security @PreAuthorize 下的 Autowiring 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);
}
}

关于java - Spring Security @PreAuthorize 使用 SpEL 语言访问 Autowiring bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53045918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com