相关疑难解决方法(0)

如何在Spring Security @ PreAuthorize/@ PostAuthorize注释中使用自定义表达式

有没有办法在@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("")值属性中可用的对象集合中.

security spring spring-security

28
推荐指数
3
解决办法
3万
查看次数

如何使用 Spring AOP 实现基于注解的安全性?

我是 Spring AOP(以及一般的 AOP)的新手,需要实现以下内容:

@HasPermission(operation=SecurityOperation.ACTIVITY_EDIT, object="#act")
public Activity updateActivity(Activity act)
{
   ...
}
Run Code Online (Sandbox Code Playgroud)

@HasPermission 是我自定义的注解,用来标记所有需要预授权的方法。我正在使用基于 Apache Shiro 的自定义安全检查实现。一般来说,我想我需要定义切入点来匹配所有带注释的方法,并提供方面的实现(之前或周围)。

我的问题是重新。方面的实施。

  • 如何从注释中提取操作对象参数?
  • 如何解析对象定义中的 SpEL 表达式并将对象作为“act”参数传递?

java aop spring aspectj spring-el

5
推荐指数
1
解决办法
4913
查看次数

标签 统计

spring ×2

aop ×1

aspectj ×1

java ×1

security ×1

spring-el ×1

spring-security ×1