324.4. 处理身份验证和授权错误
如果在 SpringSecurityAuthorizationPolicy
中进行身份验证或授权失败,则会抛出 CamelAuthorizationException
。这可以通过使用 Camel 的标准异常处理方法(如 Exception Clause )进行处理。CamelAuthorizationException
将具有对策略 ID 的引用,该策略重写异常,以便您可以根据策略以及异常类型处理错误:
<onException> <exception>org.springframework.security.authentication.AccessDeniedException</exception> <choice> <when> <simple>${exception.policyId} == 'user'</simple> <transform> <constant>You do not have ROLE_USER access!</constant> </transform> </when> <when> <simple>${exception.policyId} == 'admin'</simple> <transform> <constant>You do not have ROLE_ADMIN access!</constant> </transform> </when> </choice> </onException>