How to login to a spring security login form using cURL?

后端 未结 6 1811
谎友^
谎友^ 2020-12-14 08:14

I am working on a springMVC project in which the user authentication is based on spring security.

the idea is to have a mobile (android) application to be able to se

6条回答
  •  伪装坚强ぢ
    2020-12-14 08:58

    If CSRF is enabled, you need to capture the token value from the output of every request, in order to use it in the next one.

    BASEURL="http://localhost:8080/hac"
    csrf=$(curl --silent --cookie-jar cookies.txt -L "$BASEURL/login.jsp" | egrep -o -m1 "[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}")
    csrf=$(curl --silent --cookie cookies.txt --cookie-jar cookies.txt -L "$BASEURL/j_spring_security_check" --data "j_username=$USERNAME&j_password=$PASSWORD&_csrf=$csrf" | egrep -o -m1 "[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}" ) 
    

    You can chain more commands in this manner, updating the value of $csrf every time.

    This worked on Spring security 3.

提交回复
热议问题