'How to secure my redirected link from Spring Boot?

I am using Spring Boot Security for authorization and authentication in my REST service. It uses database user data and sessionID cookie. In a Spring web controller I have a redirection to my Angular project site localhost:4200.

@GetMapping("/admin")

public void admin(HttpServletResponse httpServletResponse) throws IOException, MessagingException {

    httpServletResponse.setHeader("Location", "http://localhost:4200/");
    httpServletResponse.setStatus(302);
}

Can I secure that site (http://localhost:4200/) , so that only with sessionID you can access it, so you can not go directly there, only through spring's url localhost:8080 and login form? Would saving sessionid in localstorage in Java, sending it with redirection and then in Angular read it from local storage and compare it with one from request work?



Solution 1:[1]

Would saving sessionid in localstorage in Java, sending it with redirection and then in Angular read it from local storage and compare it with one from request work?

YES

As far as you are working on local, that is the only option you have, either to save mappings to a file or code (Although both ways not recommended). To still add a bit of complication on receiving side, you can use base64Encoding and decoding so that the data being passed is not so easily guessable (But still decodable)

One way you can also do is store in a Key-value form

Key -> localhost:4200

Password -> anyPassword (Base64Encoded)

In real time, SSL certifications are used to secure your data over network by using certificates and Transport layer security!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Harsh