In my Angular App, users are required to login and authenticate. However, upon logging in, they are redirected to a separate URL and service that is not integrated within the Angular template. This setup is beyond my control and I am unable to make any changes to it.
The app's main URL is located at
Upon login, users are directed to the following login URL (which further redirects to a Spring CAS URL)
This URL eventually redirects to
.
After successful authentication, users are redirected back to the original app page. However, I am in need of extracting the cookie containing the username of the logged-in user.
This particular cookie is linked to the response from
and not the primary app URL. How can I retrieve this specific cookie, ideally using ngCookie?
Here is the relevant backend code for handling this process:
@RequestMapping(method = RequestMethod.GET, value = "/login", headers = "Accept=application/json")
public @ResponseBody HttpServletResponse login(HttpServletRequest request, HttpServletResponse response) {
// toLog(Level.INFO, "Logging user in.");
String referingURL = request.getHeader("referer");
_LOG.debug("Referer: " + referingURL);
try {
String user = "123456789";
user = SecurityUtils.getCurrentUsername();
Cookie userCookie = new Cookie("USERNAME", user);
userCookie.setSecure(true);
response.addCookie(userCookie);
response.sendRedirect(referingURL);
return response;
} catch (Exception e) {
// toLog(Level.ERROR, "Error logging user in", e);
throw new ResourceNotFoundException(e);
}
}
I specifically want to access the 'userCookie' mentioned in the above code snippet.
In simpler terms,
The URL
contains a response cookie with the key 'USERNAME' holding the desired username value.
Since the app resides on , I aim to extract the aforementioned cookie.