java-memidpksoap

J2ME: Set security permission programmatically


I have created a J2ME app and added it as jar in another app. The original app runs with maximum permission and works fine, but when I add it as jar in the 2nd app, I get security exception while making a web service call, and I noticed the app is running in minimum security.

I have added the midlet permissions for http and https in the JAD as well.

javax.microedition.io.Connector.http, javax.microedition.io.Connector.https

Any idea on how to fix this? The error I get is as below:

java.lang.SecurityException: Application not authorized to access the restricted API
  at com.sun.midp.security.SecurityToken.checkForPermission(+459)
  at com.sun.midp.security.SecurityToken.checkForPermission(+15)
  at com.sun.midp.midletsuite.MIDletSuiteImpl.checkForPermission(+20)
  at com.sun.midp.dev.DevMIDletSuiteImpl.checkForPermission(+28)
  at com.sun.midp.dev.DevMIDletSuiteImpl.checkForPermission(+7)
  at com.sun.midp.io.ConnectionBaseAdapter.checkForPermission(+67)
  at com.sun.midp.io.j2me.http.Protocol.checkForPermission(+17)
  at com.sun.midp.io.ConnectionBaseAdapter.openPrim(+6)
  at javax.microedition.io.Connector.openPrim(+299)
  at javax.microedition.io.Connector.open(+15)
  at org.ksoap2.transport.ServiceConnectionMidp.<init>(+11)
  at org.ksoap2.transport.HttpTransport.getServiceConnection(+11)
  at org.ksoap2.transport.HttpTransport.call(+51)
  at com.vxceed.xnappexpresssync.comm.WebserviceCall.call(+28)
  at com.vxceed.xnappexpresssync.comm.WebserviceCall.callServiceMethod(+112)
  at com.vxceed.xnappexpresssync.utility.Generic.sendRequest(+22)
  at com.vxceed.xnappexpresssync.main.Authentication.authenticateUser(+77)
  at app.ui.ServerSync.sendServerRequest(+127)
  at app.ui.LoginScreen.authenticateUser(+9)
  at app.ui.LoginScreen.isLoginValidate(+76)
  at app.ui.LoginScreen.keyPressed(+48)
  at app.ui.MainAppScreen$Clean.run(+33)
  at java.util.TimerThread.mainLoop(+237)
  at java.util.TimerThread.run(+4)

Solution

  • Posting the solution in case it helps someone.

    The problem was with the emulator. When I used J2ME SDK 3.0, with the DefaultCldcPhone1 it worked fine.