Interacting with a spring-security app from the command line using Curl
daniel Fri, 02/17/2012 - 12:33pm
If you want to use Curl to interact with a spring-security protected application (like Grails or Spring-Web), the following will do the trick.
$ curl --data "j_username=myusername&j_password=mypassword" http://localhost:8080/springSecurityApp/j_spring_security_check --cookie-jar cookies.txt
Explanation:
This line logs into the app with a username of "myusername" and a password of "mypassword".
The Context of the spring-security protected application is http://localhost:8080/springSecurityApp.
Spring security listens at a controller named j_spring_security_check for those credentials.
Curl will store the cookie from that response in a "cookie-jar", which is just a file named cookies.txt.
$ curl http://localhost:8080/springSecurityApp/api/thing1 --cookie cookies.txt
This second line is our actual api call to the spring-security protected application.
Curl submits the cookie received from the first call.
If you want more output from curl, just append this argument to any call:
--verbose
If you want curl to follow redirects, append this argument:
--location
- Log in to post comments