Handling authentication and authorization errors - 6.3

Talend ESB Mediation Developer Guide

EnrichVersion
6.3
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Design and Development
EnrichPlatform
Talend ESB

If authentication or authorization fails in the SpringSecurityAuthorizationPolicy, a CamelAuthorizationException will be thrown. This can be handled using Camel's standard exception handling methods, like the Exception clause. The CamelAuthorizationException will have a reference to the ID of the policy which threw the exception so you can handle errors based on the policy as well as the type of exception:

<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>