Я хочу получить доступ к моему автоинтегрированному компоненту в Spring Security @PreAuthorize, используя язык SpEL.
@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);
}
}