04-03-2012 05:19 AM
04-03-2012 07:08 AM
04-03-2012 07:55 AM
package autoLogin;
import java.io.IOException;
import org.alfresco.webservice.util.AuthenticationDetails;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.WebServiceFactory;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
public class AutoLogin extends AbstractWebScript{
boolean logged = false;
private static Logger log = Logger.getLogger("AutoLogin");
public void execute(WebScriptRequest req, WebScriptResponse res)
throws IOException
{
JSONObject obj = new JSONObject();
WebServiceFactory.setEndpointAddress("http://localhost:8080/alfresco/api");
try
{
AuthenticationUtils.startSession("admin", "admin",10000);
// AuthenticationUtils.startSession("", "","" );
AuthenticationDetails authenticationDetails = AuthenticationUtils.getAuthenticationDetails();
if(AuthenticationUtils.isCurrentTicketTimedOut())
{
obj.put("Already Logged in", "");
obj.put("User:"+authenticationDetails.getUserName()+"Session ID:"+authenticationDetails.getSessionId()+"Ticket :"+authenticationDetails.getTicket()+"Time Out Interval:"+authenticationDetails.getTimeoutInterval(),"OK");
}
else{
obj.put("Not Logged in", "");
if (authenticationDetails != null) {
logged = true;
try {
obj.put("User:"+authenticationDetails.getUserName()+"Session ID:"+authenticationDetails.getSessionId()+"Ticket :"+authenticationDetails.getTicket()+"Time Out Interval:"+authenticationDetails.getTimeoutInterval(),"OK");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//log.info("isLoggedIn, logged in user : [" + userName + "]");
} else {
//log.info("isLoggedIn, Not logged in");
try {
obj.put("isLoggedIn, Not logged in","no");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// build a json object
// put some data on it
obj.put("field1", "data1");
// build a JSON string and send it back
String jsonString = obj.toString();
res.getWriter().write(jsonString);
}
catch(JSONException e)
{
throw new WebScriptException("Unable to serialize JSON");
}
}
}
04-03-2012 09:19 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.