Pergunta

Today I tried to figure out how to use the R package RCurl to log onto my grails application, which uses the spring security plugin and not base authentication. I wanted to figure out how to log on to the website to download some data. On the console this seems to work easily like this:

curl -d j_username=user -d j_password=password -L http://localhost:8080/appName/j_spring_security_check

However, an RCurl equivalent like this fails:

require(RCurl)
authenticateUrl = paste(baseUrl, "j_spring_security_check", sep="")

cat(paste("trying to authenticate user", user))
agent="Mozilla/5.0"

#Set RCurl pars
curl = getCurlHandle()
curlSetOpt(ssl.verifypeer=FALSE, timeout=60, cookiefile="cookies.txt",   
cookiejar="cookies.txt", useragent = agent, 
followlocation = TRUE, curl=curl, verbose=verbose)

#Post login form
postForm(authenticateUrl, .params= list(j_username="user", j_password="password"),    
curl=curl, style="POST")

Instead of successfully logging in, I'm being redirected to the auth_fail page.

Foi útil?

Solução

It turns out that one has to call the login page first. I'm guessing this has something to do with the JSESSIONID that is stored in the cookie. If I add this step before calling postForm everything works fine:

loginUrl = paste(baseUrl, "login/auth", sep="")
getURL(loginUrl, curl=curl)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top