4 Replies Latest reply on Nov 15, 2007 8:20 AM by 807600

    Returning a variable after converting it into hexadecimal

      I am trying to work on getting a username out of a cookie to pass into a JAAS login module but I'm sure that I have awry.

      My code is:
      import java.io.IOException;
      import javax.servlet.*;
       import javax.servlet.http.*;
      import javax.security.auth.login.LoginContext;
      import javax.security.auth.login.LoginException;
      import javax.security.auth.callback.CallbackHandler;
      public class LoginServlet extends HttpServlet {
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
      int i;
      String name=null;
      Cookie[] cookie = request.getCookies();
      Cookie dough = null;
      for (i=0; i<cookie.length; i++){
           if (cookie.getName().equals("WALOGIN")){
                     dough = cookie[i];
      //Does it have any data in it?
      String s=dough.getValue();
      if(s != null) {
           String[] values = s.split("-");
           name = values[0];
           } else {
      System.out.println ("Cookie not present");
      }//end else
      }//end if

      //Define the email part of the string in hex
      for(int n=0; n<name.length(); n++){
           int ch=(int)name.charAt( n );
           String hexemail=Integer.toHexString( ch ); // String to Hex
           name = hexemail;
           }//email for

      WebCallbackHandler webcall = new WebCallbackHandler();
      I'm trying to find the cookie WALOGIN and then split it along the -. Once that is done, I'm attempting to transform the variable name into hexadecimal and pass it out so that the callback handler can find it and use it. However I think I've locked into the for loop.
      I'd be grateful for any pointers as to how to get this to work properly. Thanks.