【发布时间】:2015-10-12 09:15:43
【问题描述】:
配置 Spring Security 似乎是一门黑暗的艺术!
我正在尝试实现方法级别的安全性。我已经尽一切努力让这个方法触发它的 preAuthorize。
谁能解释为什么第一种方法可以正常工作并评估任何反对它的表达式,但第二种方法不行。在日志中,我没有看到对该方法的安全框架的任何调用(我已经重新启动服务器可能 20 次,并且尝试了各种版本,在父方法上有和没有任何 preAuthorize)...
这很有挑战性,我没有任何信息可以参考,也没有 SPEL 表达式的调试功能...我似乎处于这个无处可去的试错循环中!
第二种方法肯定是输入的,因为我可以调试它,在日志中看到输出。
@PreAuthorize("hasAnyRole('ROLE_REGISTERED_CUSTOMER', 'ROLE_ADMIN')")
public void updateAddress(CustomerAddress customerAddress) {
logger.entry();
geocodingService.geoCodeAddress(customerAddress);
if (customerAddress.getId() != null)
{
CustomerAddress oldAddress = customerAddressRepository.findForReference(customerAddress.getId());
updateExistingAddress(customerAddress, oldAddress);
customerSearchService.reindexCustomer(oldAddress.getCustomer(), true);
}else
{
updateNewAddress(customerAddress);
customerSearchService.reindexCustomer(customerAddress.getCustomer(), true);
}
logger.exit();
}
/**
* A secured method for updating the existing address.
* @param newAddress the new address
* @param oldAddress the existing database address
*/
@PreAuthorize("denyAll")
public void updateExistingAddress(CustomerAddress newAddress, CustomerAddress oldAddress)
{
logger.entry();
logger.debug("Updating an existing address.");
oldAddress.mergeEdit(newAddress);
saveAddress(oldAddress);
logger.exit();
}
【问题讨论】:
-
为什么会失败?这是一个内部方法调用,因此绕过了您拥有的任何代理行为。如果从外部调用它将起作用...
-
denyAll 只是一个测试。我刚刚也想通了:代理...我将不得不重构这么多代码!哇,这将需要数周的工作才能解决:(
标签: spring-security