cancel
Showing results for 
Search instead for 
Did you mean: 

How to make auto login be available

leon
Champ in-the-making
Champ in-the-making
hi, I want users can login the alfresco system by a url like "http://localhost:8080/alfresco/faces/jsp/login.jsp?user-name=***&user-password=***".
When I use hard code to set the username and password in  login.jsp ,then make the form submit by itself ,this does not  work.

  How can I do it? plz help me

thx.

Leon
22 REPLIES 22

michaelvuong
Champ in-the-making
Champ in-the-making
could you also post the full servlet to me…

michaelvuong168@yahoo.com

thanks

mastanar
Champ in-the-making
Champ in-the-making
Could some one send me full servlet.iam using alfresco 1.3.
My id is mastanar@gmail.com

crouchm
Champ in-the-making
Champ in-the-making
Could someone please send me the necessary files to enable the auto-login?  My email is melanie.crouch@gmail.com.  I would really appreciate it!  Thanks!

kevinr
Star Contributor
Star Contributor
Maybe the author of this work could add the code to the Alfresco Forge to make it publically available?

Thanks,

Kevin

mastanar
Champ in-the-making
Champ in-the-making
Iam using following code  in jsp for auto login.
I use http://usoakapp06:8082/alfresco/auto.jsp?username=username&password=password&id=e67af88f-27ee-11db-a... for auto login.
It works well for first time.
when i tried to login second time it is giving this excpetion
javax.faces.FacesException: Error calling action method of component with id loginForm:submit

caused by:
javax.faces.el.EvaluationException: Exception while invoking expression #{LoginBean.login}

caused by:
org.springframework.transaction.UnexpectedRollbackException: Transaction has been rolled back because it has been marked as rollback-only.

When i get this excpetion i can no longer login to alfresco with any user name and i have to restart the server to login again.
Can some one help to tell whats the problem in my jsp code.

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="org.alfresco.service.cmr.security.AuthenticationService"%>
<%@ page import="org.alfresco.web.bean.repository.*"%>
<%@ page import="org.alfresco.service.cmr.repository.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="org.alfresco.web.bean.*"%>
<%@ page import="org.springframework.context.ApplicationContext"%>
<%@ page import="org.alfresco.util.ApplicationContextHelper"%>
<%@ page import="org.alfresco.service.ServiceRegistry"%>
<%@ page import="org.alfresco.web.app.servlet.AuthenticationHelper"%>
<%@ page import="org.alfresco.web.app.servlet.AuthenticationFilter"%>
<%@ page import="org.alfresco.model.ContentModel"%>
<%@ page import="org.springframework.web.jsf.FacesContextUtils"%>
<%@ page import="javax.faces.context.FacesContext"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ page import="org.springframework.web.context.WebApplicationContext"%>
<%@ page import="org.alfresco.service.cmr.security.PersonService"%>
<%@ page import="org.alfresco.web.bean.*"%>
<%@ page import="javax.transaction.UserTransaction"%>

<%


                String username ="admin";
                String password ="admin";

username = request.getParameter("username");
password = request.getParameter("password");


UserTransaction tx ;

                        AuthenticationService authenticationService = null;

                /** NodeService bean reference */
                NodeService nodeService = null;


                WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(application);
                ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);

tx = serviceRegistry.getTransactionService().getUserTransaction();
tx.begin();

                // get individual, required services

   nodeService = (NodeService)serviceRegistry.getNodeService();
authenticationService=(AuthenticationService)ctx.getBean("authenticationService");
PersonService personService = (PersonService)ctx.getBean("personService");


                try {

                        //logout first
                    
                              // invalidate User ticket
                              User user = (User)session.getValue(AuthenticationHelper.AUTHENTICATION_USER);
                             if (user != null)
                              {
                                 authenticationService.invalidateTicket(user.getTicket());

                                 Enumeration em= session.getAttributeNames();
                                         while(em.hasMoreElements()) {
                                          String name=(String)em.nextElement();
                                          session.removeAttribute(name);
                                        }

                              }



                        authenticationService.authenticate(username, password.toCharArray());




                        // setup User object and Home space ID
        user = new User(authenticationService.getCurrentUserName(), authenticationService.getCurrentTicket(),personService.getPerson(username));
//user = (User)session.getAttribute(AUTHENTICATION_USER);

                        String homeSpaceId = null;


                        //nothing but workspace guid ,person or

                         //GUID for workspace from node_properties   from the database
                        homeSpaceId = (String) request.getParameter("id");

                        // set the current user workspace

                        user.setHomeSpaceId(homeSpaceId);
tx.commit();
tx = null;
  //inintialize the authentication session

                      session.putValue(AuthenticationHelper.AUTHENTICATION_USER, user);

out.println("user");
                         //get the noderep object form  Noderef bean

                         NodeRef homeSpaceRef = new NodeRef(Repository.getStoreRef(), homeSpaceId);
out.println("Homespace ref" + homeSpaceRef);

out.println("user");
                         String homeSpaceName = Repository.getNameForNode((NodeService)serviceRegistry.getNodeService(), homeSpaceRef);



                        // move to actuale working service area
                        response.sendRedirect(request.getContextPath() + "/faces/jsp/browse/browse.jsp");
                } catch (Exception ex) {

                        out.println("something is  error." + ex.getMessage());


                                      }

        %>

crouchm
Champ in-the-making
Champ in-the-making
Hi!  Thanks for posting your code, I was able to tweak it a bit and got it to work for me.  Hope it'll help you. 

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="org.alfresco.service.cmr.security.AuthenticationService"%>
<%@ page import="org.alfresco.web.bean.repository.*"%>
<%@ page import="org.alfresco.service.cmr.repository.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="org.alfresco.web.bean.*"%>
<%@ page import="org.springframework.context.ApplicationContext"%>
<%@ page import="org.alfresco.util.ApplicationContextHelper"%>
<%@ page import="org.alfresco.service.ServiceRegistry"%>
<%@ page import="org.alfresco.web.app.servlet.AuthenticationHelper"%>
<%@ page import="org.alfresco.web.app.servlet.AuthenticationFilter"%>
<%@ page import="org.alfresco.model.ContentModel"%>
<%@ page import="org.springframework.web.jsf.FacesContextUtils"%>
<%@ page import="javax.faces.context.FacesContext"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ page import="org.springframework.web.context.WebApplicationContext"%>
<%@ page import="org.alfresco.service.cmr.security.PersonService"%>
<%@ page import="org.alfresco.web.bean.*"%>
<%@ page import="javax.transaction.UserTransaction"%>

<%

User user = null;
String username ="joeb";
String password ="joeb";


UserTransaction tx ;

AuthenticationService authenticationService = null;

/** NodeService bean reference */
NodeService nodeService = null;


WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(application);
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
tx = serviceRegistry.getTransactionService().getUserTransaction();
tx.begin();

// get individual, required services

nodeService = (NodeService)serviceRegistry.getNodeService();
authenticationService=(AuthenticationService)ctx.getBean("authenticationService");
PersonService personService = (PersonService)ctx.getBean("personService");
//logout first

// invalidate User ticket
try
{
   try
   {
      user = (User)session.getValue(AuthenticationHelper.AUTHENTICATION_USER);
      out.println("User is : " + user.toString());
      if (user != null)
      {
         out.println("user was not null");
         authenticationService.invalidateTicket(user.getTicket());
         Enumeration em= session.getAttributeNames();

         while(em.hasMoreElements())
         {
            String name=(String)em.nextElement();
            session.removeAttribute(name);
         }

      }
   
   }
   catch (NullPointerException e)
   {
      out.println("User was null!");
      authenticationService.authenticate(username, password.toCharArray());

      // setup User object and Home space ID
      user = new User(authenticationService.getCurrentUserName(), authenticationService.getCurrentTicket(),personService.getPerson(username));
      out.println("New user is " + user);

      

           NodeRef homeSpaceRef = (NodeRef) nodeService.getProperty(personService.getPerson(username), ContentModel.PROP_HOMEFOLDER);
       
         // check that the home space node exists - else user cannot login
         if (nodeService.exists(homeSpaceRef) == false)
         {
            throw new InvalidNodeRefException(homeSpaceRef);
         }
     
      user.setHomeSpaceId(homeSpaceRef.getId());
      
      tx.commit();
      tx = null;
      //inintialize the authentication session

      session.putValue(AuthenticationHelper.AUTHENTICATION_USER, user);

      String homeSpaceName = Repository.getNameForNode((NodeService)serviceRegistry.getNodeService(), homeSpaceRef);

      // move to actuale working service area
      response.sendRedirect(request.getContextPath() + "/faces/jsp/browse/browse.jsp");

   }

}
catch (Exception ex)
{
   out.println("something is wrong." + ex.getMessage());
   
}

%>

crouchm
Champ in-the-making
Champ in-the-making
Oh - one more thing - if you are pulling variables off the session for username / password - might try editing the faces-config-navigation.xml.  I have further tweaked my code to put username and password on session in index.jsp - then pull them off in login.jsp.  I fixed the "Logout" in the above-mentioned xml file to take me back to index.jsp - that way, it'll pull the user variables off session again.  Hope this helps.  Smiley Happy

why1525
Champ in-the-making
Champ in-the-making
Hi,

Have anyone upload the auto login servlet or jsp into the source forge?

If not can anyone send one copy to me?

why1525@gmail.com

Thanks you.

robertoroberto
Champ in-the-making
Champ in-the-making
Could someone please send me the necessary files to enable the auto-login? My email is robplay82@yahoo.it. I would really appreciate it! Thanks!

robertoroberto
Champ in-the-making
Champ in-the-making
I have the same problem of mastanar