Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Spring Security中使用类字段的注释中的表达式_Java_Spring_Spring Security_Spring El - Fatal编程技术网

Java 在Spring Security中使用类字段的注释中的表达式

Java 在Spring Security中使用类字段的注释中的表达式,java,spring,spring-security,spring-el,Java,Spring,Spring Security,Spring El,我使用方法级安全性。在我注释了一些方法的类中,表达式使用这个类的字段。但我看到SpEL例外,我无法引用它们。 下面是这个类的部分代码。在表达式中,我想使用字段repPrefix,但收到的异常是它是未知变量 @Component("c2rTableManager") @Scope("prototype") public class C2RTableManager implements TableManager { private final TableManager tableManag

我使用方法级安全性。在我注释了一些方法的类中,表达式使用这个类的字段。但我看到SpEL例外,我无法引用它们。 下面是这个类的部分代码。在表达式中,我想使用字段repPrefix,但收到的异常是它是未知变量

@Component("c2rTableManager")
@Scope("prototype")
public class C2RTableManager implements TableManager {
     private final TableManager tableManager;
     private final String repPrefix;

     @Autowired
     private SecurityInfoService securityInfoService;

     public C2RTableManager(TableManager tableManager, String repository) {
          this.tableManager = tableManager;
          this.repPrefix = repository + "__";
     }

     ...some methods

     @Override
     @PreAuthorize("hasRole('DBA') || hasPermission(repPrefix + #table, 'TABLE', 'DELETE_TABLE')")
     public void dropTable(String table) throws InterruptedException, IOException {
          tableManager.dropTable(table);
     }

     ...other methods
}
如果我用另一种方式写,表达式根本不会被计算。我不明白为什么

@Component("c2rTableManager")
@Scope("prototype")
public class C2RTableManager implements TableManager {
     private final TableManager tableManager;
     private final String repPrefix;

     @Autowired
     private SecurityInfoService securityInfoService;

     public C2RTableManager(TableManager tableManager, String repository) {
          this.tableManager = tableManager;
          this.repPrefix = repository + "__";
     }

     ...some methods

     @Override

     public void dropTable(String table) throws InterruptedException, IOException {
          dropTable(table, repPrefix);
     }

     @PreAuthorize("hasRole('DBA') || hasPermission(#repPrefix + #table, 'TABLE', 'DELETE_TABLE')")
     public void dropTable(String table, String repPrefix) throws InterruptedException, IOException {
          tableManager.dropTable(table);
     }

     ...other methods
}

如何使用此类字段的值为类的方法编写表达式?

我没有足够的声誉添加注释。 从Spring安全文档中,可在

这里我们实际上使用了一个方法参数作为表达式的一部分 要决定当前用户是否具有该应用程序的“管理员”权限,请执行以下操作: 给予联系。内置的hasPermission()表达式链接到 通过应用程序上下文访问Spring安全ACL模块,如下所示 我们将在下面看到。您可以按名称访问任何方法参数,如下所示: 表达式变量,前提是代码具有调试信息 编入

请强调最后一句。检查以下两点:

  • 您是否编译了启用调试标志的类
  • 您是否使用以下声明启用了方法级安全性:

我需要将bield声明为公共

private final String repPrefix;
并编写带有此链接的注释

@PreAuthorize("hasRole('DBA') || hasPermission(repPrefix + #table, 'TABLE', 'DELETE_TABLE')")

具体是什么:SPEL异常?类似于未知变量,无法计算它等等。如果使用接口AOP代理,来自同一实例的方法调用将不会计算任何注释。我对AOP一无所知。但是im是否可以使来自同一实例的方法调用评估注释?如果我克隆实例并调用所需的方法,可以吗<代码>this.clone().dropTable(table,repPrefix)我不知道如何使用debug编译,因为我使用Maven构建应用程序并在NetBeans中调试它们。当然,这个声明是启用的,其他表达式正常工作。但是为什么有些表达式是经过计算的(第一个示例),而有些表达式不是(第二个示例)?