有没有办法在@Preauthorize块中创建更具表现力的语句?这是我发现自己重复的一个例子,因为@Preauthorize不是非常聪明的开箱即用.
@RequestMapping(value = "{id}", method = RequestMethod.DELETE)
public void deleteGame(@PathVariable int id, @ModelAttribute User authenticatingUser) {
Game currentGame = gameService.findById(id);
if(authenticatingUser.isAdmin() || currentGame.getOwner().equals(authenticatingUser)) {
gameService.delete(gameService.findById(id));
} else {
throw new SecurityException("Only an admin, or an owner can delete a game.");
}
}
Run Code Online (Sandbox Code Playgroud)
我更喜欢的是类似的东西.
@RequestMapping(value = "{id}", method = RequestMethod.DELETE)
@Preauthorize(isAdmin(authenicatingUser) OR isOwner(authenicatingUser, id)
public void deleteGame(@PathVariable int id, @ModelAttribute User authenticatingUser, @ModelAttribute currentGame ) { //I'm not sure how to add this either :(
gameService.delete(gameService.findById(id));
}
Run Code Online (Sandbox Code Playgroud)
部分问题是我需要对数据库进行查询以获取一些这些东西以验证权限,例如查询数据库以获取游戏副本,然后将游戏所有者与制作人员进行比较请求.我不确定所有这些是如何在@Preauthorize注释处理器的上下文中运行的,或者我如何将事物添加到@Preauthorize("")值属性中可用的对象集合中.
我是 Spring AOP(以及一般的 AOP)的新手,需要实现以下内容:
@HasPermission(operation=SecurityOperation.ACTIVITY_EDIT, object="#act")
public Activity updateActivity(Activity act)
{
...
}
Run Code Online (Sandbox Code Playgroud)
@HasPermission 是我自定义的注解,用来标记所有需要预授权的方法。我正在使用基于 Apache Shiro 的自定义安全检查实现。一般来说,我想我需要定义切入点来匹配所有带注释的方法,并提供方面的实现(之前或周围)。
我的问题是重新。方面的实施。