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

gavinc
Champ in-the-making
Champ in-the-making
Unfotunately JSF does not support GET requests which is why you are finding the approach you are trying is not working.

All form posting in JSF is done with POST so to get the automatic login you will have to mimic a form being POSTed in the JSF environment!

Alternatively, you could write a servlet that takes your security credentials and sets up the necessary context and then redirect to the browse.jsp. An example of how security is handled this way (but only for tickets right now) you could take a look at org.alfresco.web.app.servlet.DownloadContentServlet.

leon
Champ in-the-making
Champ in-the-making
thanks for your help, having followed your instructions and read other code files , I wrote a jsp file  to carry out the auto-login. Furthermore, I need to transfer a id to make the user enter the relevant store space, But unfortunately, the jsf view's cache is so good that two different id will display only the id which requests at the first.
for example, there are 2 ids
id=1, user  will navigate to the space "alfresco demo"
id=2 , …"glossary"
when I use id=1 to login, the space successfully navigate to "alfresco demo", then logout, use id=2 to login ,but the space  navigate to "alfresco demo" too.

   following is my code, I don't know how to restore the new view



String username = "guest";
      String password = "guest";

      /** AuthenticationService bean reference */
      AuthenticationService authenticationService = null;

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

      //ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
      
      //ApplicationContext ctx=FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
      
      WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(application);


      ServiceRegistry serviceRegistry = (ServiceRegistry) ctx
            .getBean(ServiceRegistry.SERVICE_REGISTRY);
      // get individual, required services
      nodeService = (NodeService)serviceRegistry.getNodeService();
      authenticationService=(AuthenticationService)ctx.getBean("authenticationService");
      try {

         String fromsysid = (String) request.getParameter("fromsysid");

         System.out.println("fromsysid=" + fromsysid);
         authenticationService
               .authenticate(username, password.toCharArray());

         // setup User object and Home space ID
         User user = new User(username, authenticationService
               .getCurrentTicket(), authenticationService
               .getPersonNodeRef(Repository.getStoreRef(), username));
         String homeSpaceId = null;
         if (fromsysid == null || fromsysid.trim().equals("")) {
            homeSpaceId = (String) nodeService.getProperty(
                  authenticationService.getPersonNodeRef(Repository
                        .getStoreRef(), username),
                  ContentModel.PROP_HOMEFOLDER);

            NodeRef homeSpaceRef = new NodeRef(Repository.getStoreRef(),
                  homeSpaceId);
            // check that the home space node exists - else user cannot login
            if (nodeService.exists(homeSpaceRef) == false) {
               throw new InvalidNodeRefException(homeSpaceRef);
            }
         } else { //get homespaceid from config-file
            homeSpaceId = "";
            Properties pro = new Properties();
            //InputStream in = new BufferedInputStream(new FileInputStream(file));
            InputStream in = getClass().getResourceAsStream(
                  "/subsysid.properties");
            try {
               pro.load(in);
               homeSpaceId = pro.getProperty(fromsysid.trim()).trim();
               if (homeSpaceId == null || homeSpaceId.trim().equals("")) {
                  homeSpaceId = pro.getProperty("default").trim();
               }

            } catch (IOException ex) {
            }
         }
         System.out.println(homeSpaceId);
         user.setHomeSpaceId(homeSpaceId);

         // put the User object in the Session - the authentication servlet will then allow
         // the app to continue without redirecting to the login page

         session.putValue(AuthenticationFilter.AUTHENTICATION_USER, user);
         
         response.sendRedirect(request.getContextPath() + "/faces/jsp/browse/browse.jsp");
      } catch (Exception ex) {
         out.println("something is  error.");
         out.println(ex);
      }


thanks for your help

gavinc
Champ in-the-making
Champ in-the-making
Hi,

Presuming you have used the logout link in the client the session should get destroyed, so when you login again you will have an empty session meaning that JSF won't have a cached view and none of the managed beans would exist.

Therefore, it appears that the code you have should work. You may want to check that you have indeed got a new session when you login after a logout.

Let us know if this is the case.

peter
Champ in-the-making
Champ in-the-making
Hello,

Thanks for your post.

Can you please send me the full servlet or jsp file used for auto login page and give me the necessary basic steps to implement that.I need that very urgently.

My email id is mpeterjohn@hotmail.com

Thanks,

John Peter.

toni
Champ in-the-making
Champ in-the-making
Can you send me on an example too.

jellobui at yahoo.ca

leon
Champ in-the-making
Champ in-the-making
It is a long time for me after last visiting.Now,I find a lot of amazing things.

   I also hope my file will help us.

tulum
Champ in-the-making
Champ in-the-making
me too, i'd like to have the full servlet or jsp & basic steps to implement that, if possible

TULUM_@YAHOO.COM

thank you!!!

tulum
Champ in-the-making
Champ in-the-making
hi Leon,

i tryied to use your code, but it throws a compilation error:

getPersonNodeRef(StoreRef, String) is undefined for the type AuthenticationService

i have the alfresco's v1.2.1
may be the method is a new one of 1.3?

sarag
Champ in-the-making
Champ in-the-making
hi!

Could somebody send me the code?
twinsara@gmail.com

thanks