I want to be able to login a user programmatically on my CQ website. I have created users wih a user id from a genenered UUID, and I store the user's email address as normal as a profile property.
Example:
User ID/Username/Login ID: 3b60ef68-881c-4ad7-b5b4-ffc0c7ebcca6
Email: test@test.com
When the user wants to login they will supply their email address and password. I have used a form with a custom action, and using forward.jsp to intercept the form post. I will lookup the user id (UUID) based on the email adress and the programatically post this information to the j_security_check servlet. However, when I post to j_security_check it just displays a blank screen. I get a 302 status code back from the form post, which I guess means the login was successful as invalid user details produces a status code 403.
import org.apache.commons.httpclient.HttpClient,
import org.apache.commons.httpclient.HttpException,
import org.apache.commons.httpclient.HttpStatus,
import org.apache.commons.httpclient.methods.PostMethod
HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod( "http://localhost:4502/content/test-site/en/login/j_security_check" );
postMethod.addParameter( "resource","http://localhost:4502/content/test-site/en/login.html");
postMethod.addParameter( "_charset_","UTF-8");
postMethod.addParameter( "j_username", "test@test.com" );
postMethod.addParameter( "j_password", "test" );
status = httpClient.executeMethod( postMethod );
contents = postMethod.getResponseBodyAsString();
postMethod.releaseConnection();