0

I have the following problem: I want to access a picutre (Motion Stream on Raspberry Pi) which is secured by http authentication.

To don't show the password in plain html code, I use this in html:

<img src="/image"/>

And process the request on my Spring Boot server, so this function in my WebController class redirects the request to the real location of the image:

    @RequestMapping("/image")
    public RedirectView image() {
        RedirectView redirectView = new RedirectView();
        redirectView.setUrl("http://user:password@server:port/");
        return redirectView;
    }

This method works fine in Firefox, but I can't access the image in Chromium unless I enter the login data in a new tab by accessing the server myself. How can I create a working and even safer method for all browsers, on backend with Java & Spring or frontend with html & Javascript?

Thanks for your help!

  • Are you using basic authentication and Spring Security? That would be really easy with Security. – Diego Victor de Jesus Jul 09 '20 at 20:42
  • I'm using the Spring Security LDAP Module for basic authentication. Its just a private single-user web application, so it might be ok. The image is loaded from another server (on same device) running by motion with http authentication. – Marcel21 Jul 10 '20 at 10:15
  • You can fetch the image in the back end and return a byte array from your endpoint. Your img src would be the url of the endpoint. Take a look here: https://stackoverflow.com/questions/32080207/how-to-download-image-using-rest-template – Diego Victor de Jesus Jul 10 '20 at 16:16

0 Answers0