Anand
I see multiple issues here.
Firstly, the federation journey does not look right to me.
When request arrives into /affwebservices/public/saml2sso with a SMSESSION which is invalid (because of UD2 latched to partnerships); I'd expect affwebservices to trigger the Authentication URL defined within the partnership and redirect the user to Authentication URL. Authentication URL is a protected page e.g. /affwebservices/redirectjsp/redirect.jsp and thus user would get a login page to login again.
Secondly, Why would you kill a valid SMSESSION. SMSession attached to UD1 is still a valid SMSESSION for that part of the journey. Why would you want the user to login again on the UD1 part of the journey.
I think we need to start planning user experience design more carefully rather than built solutions like this.
I am kind of lost in the above design. But I'll try to answer the core request of how you may try to get the TARGET. But these are options which are available after the WebAgent processes the request. On SPS WebAgent runs as Java code within Tomcat.
OPTION-1:
Check for a SiteMinder Header SM_LOCATION, this is normally populated with the TARGET URI.
However ---> 00338955: SM_USER and SM_LOCATION not working in configured Responses
OPTION-2:
In the Policy Server we have Variable Responses.
Variables Overview - CA Single Sign-On - 12.52 SP2 - CA Technologies Documentation
However ---> 00300147: Variables Request Context