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

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 Search this Thread Display Modes
  #1 (permalink)  
Old 08-31-2007, 10:59 AM
New Member
 
Posts: 3
Default intranet to single sign on to zimbra mail client using soap method. (ZClient)

I have an intranet site built with java which I wish to have single sign on with zimbra web mail.

I use ZClient to connect to the Zimbra's soap service.
I extract the ZM_AUTH_TOKEN & SessionId.

I then create a cookie using the ZM_AUTH_TOKEN and I add the cookie to
the response object.

The soap connection works and I can get info back from the server.
The cookie is created sucessfully.

But even with the cookie, I still keep getting the zimbra web mail login screen.

Here is the source code that I am using, can you tell me what I am doing wrong. No, I do not want to use preauth. So please do not recommend this to me, thanks.


<code>
import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import com.zimbra.common.service.ServiceException;
import com.zimbra.cs.service.mail.MailService;
import com.zimbra.cs.service.account.AccountService;
import com.zimbra.cs.servlet.ZimbraServlet;
import com.zimbra.cs.util.Zimbra;
import com.zimbra.soap.Element;
import com.zimbra.soap.SoapFaultException;
import com.zimbra.soap.SoapHttpTransport;
import com.zimbra.soap.ZimbraSoapContext;

/**
*
* @author
*/
public class ZimbraLogin {

/** Creates a new instance of ZimbraLogin */
public ZimbraLogin(HttpServletRequest request, HttpServletResponse response) {
SoapHttpTransport trans = null;
Element zresponse = null;
Element zrequest = null;
String authToken = null;
String sessionId = null;
try {
trans = new SoapHttpTransport("https://my.zimbrahost.com" + ZimbraServlet.USER_SERVICE_URI);

zrequest = Element.XMLElement.mFactory.createElement(AccountS ervice.AUTH_REQUEST);

zrequest.addAttribute(AccountService.E_ACCOUNT, (String) request.getSession().getAttribute("id") + "@my.zimbrahost.com" , Element.DISP_CONTENT);
zrequest.addAttribute(AccountService.E_PASSWORD, (String) request.getSession().getAttribute("password"), Element.DISP_CONTENT);
zresponse = trans.invoke(zrequest);

authToken = zresponse.getAttribute(AccountService.E_AUTH_TOKEN );
sessionId = zresponse.getAttribute(ZimbraSoapContext.E_SESSION _ID, null);


trans.setAuthToken(authToken);
if (sessionId != null)
trans.setSessionId(sessionId);


}
catch (Exception e){
e.printStackTrace();
}


Cookie authCookie = new Cookie("ZM_AUTH_TOKEN", authToken);
authCookie.setPath("/");
response.addCookie(authCookie);
}

}
</code>
Reply With Quote
  #2 (permalink)  
Old 09-03-2007, 09:18 AM
Zimlet Guru & Moderator
 
Posts: 467
Default

Quote:
Originally Posted by hebron View Post
I have an intranet site built with java which I wish to have single sign on with zimbra web mail.

I use ZClient to connect to the Zimbra's soap service.
I extract the ZM_AUTH_TOKEN & SessionId.

I then create a cookie using the ZM_AUTH_TOKEN and I add the cookie to
the response object.

The soap connection works and I can get info back from the server.
The cookie is created sucessfully.

But even with the cookie, I still keep getting the zimbra web mail login screen.

Here is the source code that I am using, can you tell me what I am doing wrong. No, I do not want to use preauth. So please do not recommend this to me, thanks.


<code>
import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import com.zimbra.common.service.ServiceException;
import com.zimbra.cs.service.mail.MailService;
import com.zimbra.cs.service.account.AccountService;
import com.zimbra.cs.servlet.ZimbraServlet;
import com.zimbra.cs.util.Zimbra;
import com.zimbra.soap.Element;
import com.zimbra.soap.SoapFaultException;
import com.zimbra.soap.SoapHttpTransport;
import com.zimbra.soap.ZimbraSoapContext;

/**
*
* @author
*/
public class ZimbraLogin {

/** Creates a new instance of ZimbraLogin */
public ZimbraLogin(HttpServletRequest request, HttpServletResponse response) {
SoapHttpTransport trans = null;
Element zresponse = null;
Element zrequest = null;
String authToken = null;
String sessionId = null;
try {
trans = new SoapHttpTransport("https://my.zimbrahost.com" + ZimbraServlet.USER_SERVICE_URI);

zrequest = Element.XMLElement.mFactory.createElement(AccountS ervice.AUTH_REQUEST);

zrequest.addAttribute(AccountService.E_ACCOUNT, (String) request.getSession().getAttribute("id") + "@my.zimbrahost.com" , Element.DISP_CONTENT);
zrequest.addAttribute(AccountService.E_PASSWORD, (String) request.getSession().getAttribute("password"), Element.DISP_CONTENT);
zresponse = trans.invoke(zrequest);

authToken = zresponse.getAttribute(AccountService.E_AUTH_TOKEN );
sessionId = zresponse.getAttribute(ZimbraSoapContext.E_SESSION _ID, null);


trans.setAuthToken(authToken);
if (sessionId != null)
trans.setSessionId(sessionId);


}
catch (Exception e){
e.printStackTrace();
}


Cookie authCookie = new Cookie("ZM_AUTH_TOKEN", authToken);
authCookie.setPath("/");
response.addCookie(authCookie);
}

}
</code>
I think you might want to look at the Pre-Auth stuff rather then using Z-client (someone at Zimbra can validate this for me). IIRC, The authorization token is stored both in the cookie, but also in a a JavaScript session variable. That variable protects against the kind of Ajax injection attacks we saw earlier.

There is also a 5.0 interface for custom authentication.
Reply With Quote
  #3 (permalink)  
Old 09-05-2007, 10:50 AM
New Member
 
Posts: 3
Arrow preauth

I see the benefits of preauth. But it does not lend it self well to a multi-server
environment spread across multiple timezones.
Reply With Quote
  #4 (permalink)  
Old 09-05-2007, 11:02 AM
New Member
 
Posts: 3
Arrow JavaScript session variable

Please tell me more about this JavaScript session variable.
Reply With Quote
  #5 (permalink)  
Old 09-05-2007, 02:33 PM
Zimlet Guru & Moderator
 
Posts: 467
Default

Quote:
Originally Posted by hebron View Post
Please tell me more about this JavaScript session variable.
It exists inside of the Zimbra instance itself. I am sure there is some way to force a relogin with cookies, but I don't know exactly how Zimbra manages that. I would look at the first JSP's that load to see how they look at the cookies.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.