118.5. 处理身份验证和授权错误
如果 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>