jueves, 5 de septiembre de 2019

Spring Boot: RedirectStrategy sendRedirect method always redirects to http. How do I make it stay on https?

I have a pretty simple handler method in my code:

@Service
public class AuthenticationSuccessHandler implements org.springframework.security.web.authentication.AuthenticationSuccessHandler {

    private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();

   
    @Override

    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication a) throws IOException, ServletException {

        redirectStrategy.sendRedirect(request, response, PATH_CURRENT_USER);

    }

}


The problem is, if I browse to https://my.domain.com/, I end up at http://my.domain.com/ after the redirect. In actuality my load-balancer redirects all http requests to https, but this just causes multiple browser errors and incorrect behavior: "Mixed Content: The page at was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint".

So the question is: how does one get spring to redirect to https when that's what the original request used?

What worked for me is adding this to application.properties server.tomcat.use-relative-redirects=true

Without the server.tomcat.use-relative-redirects it will add a Location header like: http://my.domain.com/. With the server.tomcat.use-relative-redirects it will look like: /. So it will be relative to the current page from browser perspective.

Allow access to the Docker Engine without admin rights on Windows

If you have been working with Docker on Windows, the following message is probably familiar:

error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/containers/json: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.

As the message says, there are two likely reasons for this error: 1) Your Docker engine is not running and you need to start it. 2) You are not in an administrator / elevated session and therefore don’t have access to the engine. The reason for requiring an admin session is that the Docker client in the default configuration uses a named pipe to connect to the Docker engine and that named pipe can only be accessed by administrators.

If you are not an administrator, you can manage to run docker without being one just only adding your current user to the docker-users group in Windows.

Steps:

  1. Hit Windows+R, type “lusrmgr.msc” into the Run box, and then hit Enter.
  2. Double clic docker-users group:
  3. Clic on Add:
  4. Add your current user to the group:
  5. Finally restart your computer. After your computer is restarted you will be able to run docker without admin rights.