Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: How to get the connected userid?

  1. #1
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    6

    Default How to get the connected userid?

    I wrote a zimlet, which calls file1.js which opens a new window with file2.jsp.

    In file2.jsp I need to know the userID of the current user.

    There are two ways:
    1. a "magic" java command to write in file2.jsp
    2. obtain the userID in file1.js and call file2.jsp?uid=<uid_not_known>

    How can I do it? Thanks.

    Fede

  2. #2
    Join Date
    Mar 2008
    Location
    Stanford, CA
    Posts
    15
    Rep Power
    7

    Default

    Put something like this in your .jsp

    Code:
      String name = null;
      Provisioning prov = Provisioning.getInstance();
      javax.servlet.http.Cookie[] cookies = request.getCookies();
      String authTokenString = "";
      Account acct = null;
    
      for (javax.servlet.http.Cookie cookie : cookies) {
         if (cookie.getName().equals("ZM_AUTH_TOKEN")) {
            authTokenString = cookie.getValue();
         }
      }
    
      if (!authTokenString.equals("")) {
         AuthToken authToken = AuthToken.getAuthToken(authTokenString);
         acct = prov.get(Provisioning.AccountBy.id, authToken.getAccountId());
      }
    
       if (acct != null) {
          name = acct.getName();
       }

  3. #3
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    6

    Default

    Thanks for the reply.

    I wrote the code but when the JSP page is opened I get:
    Code:
    PWC6033: Unable to compile class for JSP
    
    PWC6197: An error occurred at line: 14 in the jsp file: /zimlet/_dev/org_munet_prova/test.jsp
    PWC6199: Generated servlet error:
    Provisioning cannot be resolved to a type
    
    PWC6197: An error occurred at line: 14 in the jsp file: /zimlet/_dev/org_munet_prova/test.jsp
    PWC6199: Generated servlet error:
    Provisioning cannot be resolved
    
    PWC6197: An error occurred at line: 14 in the jsp file: /zimlet/_dev/org_munet_prova/test.jsp
    PWC6199: Generated servlet error:
    Account cannot be resolved to a type
    
    PWC6197: An error occurred at line: 14 in the jsp file: /zimlet/_dev/org_munet_prova/test.jsp
    PWC6199: Generated servlet error:
    AuthToken cannot be resolved to a type
    
    PWC6197: An error occurred at line: 14 in the jsp file: /zimlet/_dev/org_munet_prova/test.jsp
    PWC6199: Generated servlet error:
    AuthToken cannot be resolved
    
    PWC6197: An error occurred at line: 14 in the jsp file: /zimlet/_dev/org_munet_prova/test.jsp
    PWC6199: Generated servlet error:
    Provisioning.AccountBy.id cannot be resolved to a type

  4. #4
    Join Date
    Mar 2008
    Location
    Stanford, CA
    Posts
    15
    Rep Power
    7

    Default

    Add this to the top of your .jsp:

    Code:
    <&#37;@ page import="com.zimbra.cs.account.*, com.zimbra.cs.zimlet.*" %>

  5. #5
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    6

    Default

    Quote Originally Posted by scotty View Post
    Add this to the top of your .jsp:

    Code:
    <%@ page import="com.zimbra.cs.account.*, com.zimbra.cs.zimlet.*" %>
    Now works perfectly!

    Before marking the issue solved I would like to read those class specification, one day I could need to access to something else other than the username. Can you, kindly, give me a web page adress to read from? thanks

  6. #6
    Join Date
    Mar 2008
    Location
    Stanford, CA
    Posts
    15
    Rep Power
    7

    Default

    Use the instructions at http://wiki.zimbra.com/index.php?tit...using_Perforce to download the source, then look in ZimbraServer/src/java/com/zimbra/cs.

  7. #7
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    6

    Default

    Quote Originally Posted by scotty View Post
    Use the instructions at Building Zimbra using Perforce - Zimbra :: Wiki to download the source, then look in ZimbraServer/src/java/com/zimbra/cs.
    Yesterday afternoon I had the same thought. "Isn't it an open source project? So, download the source files and dig trought them."

    But I waited for a reply as if web page lists alla the class' methods it would be easier to read.

    Thanks for reply and the link.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PS
    The function I was looking for was
    public String getId()
    in the package
    package com.zimbra.cs.account;
    Last edited by mune72; 10-07-2009 at 09:44 AM. Reason: wrong function

  8. #8
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    6

    Default

    I store the ID in a DB, sometime later I read that ID and I want to retrive the relative account properties: it seems to use
    Code:
    retAcct = <AccountCacheObject>.getById(my_uid);
    Am I right? And how to get that kind of object?

    thnaks

  9. #9
    Join Date
    Mar 2008
    Location
    Stanford, CA
    Posts
    15
    Rep Power
    7

    Default

    I don't think you can get the AccountCache singleton directly; it's used internally. However, it looks like you can use the Provisioning singleton and the get() method:

    Code:
    Provisioning prov = Provisioning.getInstance();
    Account retAcct = prov.get(AccountBy.id, my_uid);

  10. #10
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    6

    Default

    Quote Originally Posted by scotty View Post
    I don't think you can get the AccountCache singleton directly; it's used internally. However, it looks like you can use the Provisioning singleton and the get() method:

    Code:
    Provisioning prov = Provisioning.getInstance();
    Account retAcct = prov.get(AccountBy.id, my_uid);
    Unfortunally it doesn't work (I get a java compilation error)
    Code:
    <!-- test.jsp -->
    <html>
    	<head>
    		<title>Prova</title>
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1; Tue, 20 Aug 2996 14:25:27 GMT">
    	</head>
    
    <body>
    <%@ page import="com.zimbra.cs.account.*, com.zimbra.cs.zimlet.*" %>
    
    <% 
      out.println("JSP --> Ciao Mondo!");
      out.println("<BR>");
    
      String name = null;
      String my_uid = null;
      Provisioning prov = Provisioning.getInstance();
      javax.servlet.http.Cookie[] cookies = request.getCookies();
      String authTokenString = "";
      Account acct = null;
    
      for (javax.servlet.http.Cookie cookie : cookies) {
         if (cookie.getName().equals("ZM_AUTH_TOKEN")) {
            authTokenString = cookie.getValue();
         }
      }
    
      if (!authTokenString.equals("")) {
         AuthToken authToken = AuthToken.getAuthToken(authTokenString);
         acct = prov.get(Provisioning.AccountBy.id, authToken.getAccountId());
      }
    
       if (acct != null) {
    	name = acct.getName();
    	out.println(name);
       }
       if (acct != null) {
            my_uid = acct.getId();
            out.println(my_uid);
            out.println("<BR>"+"retAcct"+"<BR>");
            Provisioning prov1 = Provisioning.getInstance();
            Account retAcct = prov1.get(AccountBy.id, my_uid);
           /*
           if (retAcct != null) {
    	   name = retAcct.getName();
               out.println(name);
           }
           if (retAcct != null) {
    	   my_uid = retAcct.getId();
       	   out.println(my_uid);
           }
           */
       }
    %>
    </body>
    </html>

Similar Threads

  1. [SOLVED] Moving Zimbra to a new server
    By krolen in forum Administrators
    Replies: 109
    Last Post: 02-05-2009, 11:38 AM
  2. Replies: 20
    Last Post: 03-18-2008, 06:37 AM
  3. can't you help me
    By iwan siahaan in forum Administrators
    Replies: 6
    Last Post: 12-17-2007, 06:53 PM
  4. Cannot login as admin after install
    By elesouef in forum Installation
    Replies: 23
    Last Post: 02-13-2007, 09:06 AM
  5. Seeming variety of problems on suse-9.1
    By Crexis in forum Installation
    Replies: 52
    Last Post: 03-04-2006, 12:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •