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>