Spring Security Authentication Using cURL

Posted By : Ashish Sharma | 30-Jan-2014

cURL Spring

To Install cURL in your Ubuntu System
, run the following command in your terminal:

  1. sudo sed -i -e 's/us.archive.ubuntu.com/archive.ubuntu.com/g' /etc/apt/sources.list
  2. sudo apt-get update
  3. sudo apt-get install curl

 

Now its time to run some cURL command to login

  • curl -i -H "Content-type: application/x-www-form-urlencoded" -c cookies.txt -X POST http://localhost:8080/myGrailsApp/j_spring_security_check -d "[email protected]&j_password=oodles"
  • If you get successfully logged in response will be
    HTTP/1.1 302 Found
    Server: Apache-Coyote/1.1
    Set-Cookie: JSESSIONID=F7A7D768C65E601A44649C2BECC6B879; Path=/; HttpOnly
    Location: http://localhost:8080/myGrailsApp
    Content-Length: 0
    Date: Wed, 29 Jan 2014 10:51:41 GMT
  • If your authentication fails then response will be
    HTTP/1.1 302 Found
    Server: Apache-Coyote/1.1
    Set-Cookie: Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
    Set-Cookie: JSESSIONID=D143DFD97A0E0C0155F8DB3F7E50065D; Path=/; HttpOnly
    Location: http://localhost:8080/myGrailsApp/login/authfail?login_error=1
    Content-Length: 0
    Date: Wed, 29 Jan 2014 11:05:20 GMT

 

After this we can call all the Spring security secured controllers and actions like this-

  • curl -i -b cookies.txt -X GET http://localhost:8080/myGrailsApp/controllerName/actionName

 

About Author

Author Image
Ashish Sharma

Ashish is a bright Groovy and Grails developer and have worked on development of various SaaS applications using Grails technologies. Ashish likes PC games and works out at Gym in his free time.

Request for Proposal

Name is required

Comment is required

Sending message..