Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
 
Go Back   Zimbra - Forums > Zimbra Collaboration Suite > Zimlets

Welcome to the Zimbra - Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-04-2009, 03:12 AM
Intermediate Member
 
Posts: 22
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
Reply With Quote
  #2 (permalink)  
Old 10-05-2009, 07:27 AM
Member
 
Posts: 11
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();
   }
Reply With Quote
  #3 (permalink)  
Old 10-05-2009, 08:12 AM
Intermediate Member
 
Posts: 22
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
Reply With Quote
  #4 (permalink)  
Old 10-05-2009, 08:41 AM
Member
 
Posts: 11
Default

Add this to the top of your .jsp:

Code:
<%@ page import="com.zimbra.cs.account.*, com.zimbra.cs.zimlet.*" %>
Reply With Quote
  #5 (permalink)  
Old 10-05-2009, 09:12 AM
Intermediate Member
 
Posts: 22
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
Reply With Quote
  #6 (permalink)  
Old 10-06-2009, 06:42 AM
Member
 
Posts: 11
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.
Reply With Quote
  #7 (permalink)  
Old 10-07-2009, 06:38 AM
Intermediate Member
 
Posts: 22
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
Reply With Quote
  #8 (permalink)  
Old 10-07-2009, 10:12 AM
Intermediate Member
 
Posts: 22
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
Reply With Quote
  #9 (permalink)  
Old 10-07-2009, 10:25 AM
Member
 
Posts: 11
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);
Reply With Quote
  #10 (permalink)  
Old 10-07-2009, 11:12 AM
Intermediate Member
 
Posts: 22
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>
Reply With Quote
Reply


Thread Tools
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

Zimbrablog.com




 

Search Engine Optimization by vBSEO 3.1.0