AnsweredAssumed Answered

servlet auto-login

Question asked by nyronian on Jul 13, 2007
Latest reply on Jul 17, 2007 by nyronian
I have created a new servlet (within alfresco) that is designed to "auto-login" the user under a specific name (not guest).  I have not figured out how to do this.  The problem I am trying to solve is there are nodes that I need to be able to access when the servlet is called that is NOT accessable by Guest.  So I am going to "auto-login" a user in order to access these nodes.  How do I do this?

Right now I have the following code that doesn't work: :)

NOTE:  The servlet extends Alfresco's BaseServlet.

   protected void service(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException
      String ticket = login(request);
      logger.debug("login ticket = "+ticket);
      AuthenticationStatus status =  AuthenticationHelper.authenticate(getServletContext(), request, response, ticket);
      if (status == AuthenticationStatus.Failure)
      processRequest(request, response, false);

   public String login(HttpServletRequest httpRequest)
      String ticket = null;
        HttpSession session = httpRequest.getSession();
        ticket = (String)session.getAttribute(SESSION_USER_TICKET);
      FacesContext fc = FacesContext.getCurrentInstance();
      ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
      AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();

         authenticationService.authenticate("admin", "admin".toCharArray());
         ticket = authenticationService.getCurrentTicket();
         session.setAttribute(SESSION_USER_TICKET, ticket);

      catch (AuthenticationException aerr)
         Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_UNKNOWN_USER));
      catch (InvalidNodeRefException refErr)
               Repository.ERROR_NOHOME), refErr.getNodeRef().getId()));

      return ticket;

I get the following Exception when I try to access a Node:

        at org.springframework.web.jsf.FacesContextUtils.getWebApplicationContex
        at org.springframework.web.jsf.FacesContextUtils.getRequiredWebApplicati
        at org.alfresco.web.bean.repository.Repository.getServiceRegistry(Reposi
        at org.alfresco.web.bean.repository.Node.getServiceRegistry(
        at org.alfresco.web.bean.repository.Node.<init>(
        at com.tlhc.wc.servlet.PageProcessor.processTemplateRequest(PageProcesso
        at com.tlhc.wc.servlet.PageProcessor.service(
        at javax.servlet.http.HttpServlet.service(

If I log into alfresco and then access the servlet (under the same session) everything works perfectly :)

Thanks in advance.