×

Discussion Board

Results 1 to 2 of 2

Hybrid View

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    4

    J2ME authentication

    Hi,


    I have J2ME app that send and receive information from a server (servlets with Tomcat 6.0).

    In first step the user have to be authenticated. The client app send authentication data and the servlet ejecute a stored procedure (MySQL) to validate the user and return a id user. While the app is open user is sending his id evry request to perform some operations.

    The app work fine in sigle cell phone but if I try to login with other device immediatly after that with wrong authentication data I receive always the user id on the first device thah was successfull signed. Probably this has to do with cache, if this this is the case how can I solve this?What is the better way to implement simple authentication?


    This is snippet of client side code:


    httpCon =(HttpConnection)Connector.open(url, Connector.READ_WRITE, true);
    httpCon.setRequestMethod(HttpConnection.POST);
    httpCon.setRequestProperty("Content-Language", "en-US");
    httpCon.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.1");
    httpCon.setRequestProperty("Accept", "application/octet-stream");
    httpCon.setRequestProperty("Pragma","no-cache");
    httpCon.setRequestProperty("Cache-Control","max-age=0, no-cache, no-store, must-revalidate, no-transform");
    httpCon.setRequestProperty("Connection", "close");




    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    dos.writeUTF(imei);
    dos.writeUTF(password);
    dos.writeUTF(clave);
    //dos.writeInt(driver_status);
    byte[] datos = baos.toByteArray();
    httpCon.setRequestProperty("Content-Length", "" + datos.length);


    try {
    os = httpCon.openOutputStream();
    os.write(datos);
    os.close();
    dos.flush();
    dos.close();



    And this is snippet of server side code:


    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    dos.writeInt(status);
    if(status == 99) {
    dos.writeInt(id);
    }
    dos.close();

    byte[] datos = baos.toByteArray();
    sendedBytes = datos.length;
    response.setContentType("application/octet-stream" );
    response.setContentLength(sendedBytes);

    response.setHeader("Pragma","no-cache");
    response.setHeader("Cache-Control","max-age=0, no-cache, no-store, must-revalidate, no-transform");




    OutputStream os = response.getOutputStream();
    os.write(datos);
    os.close();

    if (cstmt !=null)try { cstmt.close(); }catch(Exception e) {}
    if (con !=null)try { con.close(); }catch(Exception e) {}



    The imei, password and clave have the same length every request. Having thi is mind and the fact that I'm using binary stream to send an receive the information, it sounds like there is some cache. ???

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: J2ME authentication

    Requests are not cached, neither are responses to two different devices. I really don't think caching is your problem. I suspect there is a bug in your code, and information from a previous request is being used later.

    Cheers,
    Graham.

Similar Threads

  1. J2ME or C++ for VoIP on Mobile
    By sandeepkumar03 in forum VoIP
    Replies: 4
    Last Post: 2009-02-02, 10:28
  2. Calling a native c or c++ application from J2ME
    By satyarajasekhar in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2009-01-02, 12:10
  3. J2ME or C++ for VoIP on Mobile Phone
    By sandeepkumar03 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2008-11-13, 20:14
  4. Acessing voice channel using J2ME
    By diegomello in forum VoIP
    Replies: 1
    Last Post: 2008-10-21, 15:57
  5. Can J2ME be used for sending MMS Message ?
    By seno_ap in forum Mobile Java General
    Replies: 1
    Last Post: 2006-11-24, 14:36

Posting Permissions

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