Bonzour

Java EE Authentication with Curl

If you’ve always wondered how to authenticate to a standard Java EE authentication form using the curl command, this page is for you!

  • First we’ll obtain a session id from the server.

    curl -v -c cookies.txt http://localhost/login/index.jsp
    

    The session id will be stored as a cookie in the file cookies.txt.

  • Next we’ll use the session id to authenticate the user.

    curl -L -v -b cookies.txt \
         -d 'j_username=<username>&j_password=<password>' \
         http://localhost/login/j_security_check
    
  • Finally once the session id is authenticated, we can use it to do secured operations.

    curl -v -b cookies.txt http://localhost/list
    

Hope that was useful :)