cancel
Showing results for 
Search instead for 
Did you mean: 

Basic Authentication to OWA

Former Member
0 Kudos

Hi guys, I've a problem, I'm trying to access to OWA, I'm using org.apache.commons.httpclient.HttpClient to get a cookie to authenticate the user to OWA and get the content of the browser in a console mode, when I get the cookie and the HTML content I'm only set the cookie and the HTML content on the object response like this:

public class OWAMail extends HttpServlet {

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

try {
   HttpClient client = new HttpClient();
   ArrayList authPrefs = new ArrayList(1);
   authPrefs.add(AuthPolicy.BASIC);
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,authPrefs);
   client.getState().setCredentials(new    AuthScope("10.210.64.230",80,AuthScope.ANY_REALM), new    UsernamePasswordCredentials("mxm\" + userid , mailpassword ) );
   GetMethod get = new    GetMethod("http://server/exchange");
   get.setDoAuthentication(true);

   int status = client.executeMethod(get);
   respuesta = get.getResponseBodyAsString();
   Cookie[] cookies = client.getState().getCookies();
   response.addCokie(cookies[1]);
   PrintWriter out = response.getWriter();
   out.println(respuesta);
   out.flush();
   out.close();
} catch(Exception e){
   e.printStackTrace();
} finally {
   get.releaseConnection();
}

.....

}

The problem appears when I print the response on the browser because a basic authentication asking for the user credentials appears again, I think the cookie is ignored.....

Any ideas would be greatly appreciated

Regards

Lalo.....

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Lalo!

Let me paraphrase what you are trying with this code-snippet:

1. Use HttpClient to establish a connection to OWA of a given Exchange server.

2. Get the cookie from the Exchange server's response.

3. Pass that cookie to the response that is sent back to the client (browser).

There are two problems that I see with this approach:

1. The cookie you get out of the HttpClient with client.getState().getCookies(); are typed as org.apache.commons.httpclient.cookie.Cookie. The addCookie method of the HttpServletResponse is expecting an object of type javax.servlet.http.Cookie. In my eyes this should not even compile.

2. I don't think that it is possible to add a cookie of server A to the response of server B and pretend being the cookie of server B.

If you want to pass the contents of the Exchange server's cookie to the HTTP-repsonse of your AppServer I would consider to somehow copy the values of the org.apache.commons.httpclient.cookie.Cookie object to a new object of javax.servlet.http.Cookie and then add it to the response-object.

By the way.. Is this code part of an existing application or are you just playing around with it?

I hope I could help you out in some way..

Former Member
0 Kudos

Thanks Nicolai and thanks robin...

Well as you said Robin "The addCookie method of the HttpServletResponse is expecting an object of type javax.servlet.http.Cookie. In my eyes this should not even compile", you're right I get the cookie in this way:


   javax.servlet.http.Cookie c = new javax.servlet.http.Cookie
                            (cookies[1].getName(), cookies[1].getValue());
                    c.setPath(cookies[1].getCookiePath());
                    response.addCookie(c);

But I omitted this in the code-snippet (Sorry).

I think the problem is as you said trying to pass the cookie from Server A to server B, and I don't know how to solved it. This is the problem...

Thanks....

NikiD
Employee
Employee
0 Kudos

Hi Lalo

are you sure the correct cookie is set on the response?

Regards

Nikolai