@PreAuthorize注释可以抛出异常吗?

时间:2014-11-13 10:42:10

标签: java spring-security

我编写了自己的安全服务,以使用@PreAuthorize批注验证对方法的访问。它使用返回true或false的方法正常工作,但在某些方法中我想返回true或抛出特定异常。它看起来像这样:

public boolean validateAccess(String code) throws MyException{
    if (contidions){
        return true;
    }
    throw new MyException(code);
}

我用这种方式:

@PreAuthorize("@securityService.validateAccess('aaa')")
public void methodName(){
    //stuff to do
}

不幸的是,如果不满足条件,则不会抛出异常,但会出现表达式评估错误。

有没有办法从@PreAuthorize注释中抛出特定的异常?

0 个答案:

没有答案