示例#1
0
  /**
   * Constructor for development subclass.
   *
   * @param callerSecurityToken security token for the calling class
   * @param suitePermissions security token of the suite
   * @param pushSetting can this MIDlet suite interrupt other suites
   * @param trustedFlag true if the suite is to considered trusted (not to be confused with a domain
   *     named "trusted", this only shown to the user and not used for permissions)
   * @param theStorageName name to separate this suite's storage from others
   */
  protected MIDletSuiteImpl(
      SecurityToken callerSecurityToken,
      byte[][] suitePermissions,
      int pushSetting,
      boolean trustedFlag,
      String theStorageName) {

    callerSecurityToken.checkIfPermissionAllowed(Permissions.MIDP);

    permissions = suitePermissions;
    securityToken = new SecurityToken(classSecurityToken, permissions);
    pushInterruptSetting = pushSetting;
    trusted = trustedFlag;
    storageName = theStorageName;
  }
示例#2
0
  /**
   * get an available connection and set the boolean flag to true (unavailable) in the connection
   * pool. Also removes any stale connections, since this method gets called more than add or
   * remove.
   *
   * @param callerSecurityToken The security token of the caller
   * @param p_protocol The protocol for the connection
   * @param p_host The Hostname for the connection
   * @param p_port The port number for the connection
   * @return A stream connection element or null if not found
   */
  public synchronized StreamConnectionElement get(
      SecurityToken callerSecurityToken, String p_protocol, String p_host, int p_port) {

    StreamConnectionElement result = null;
    long c_time = System.currentTimeMillis();
    Enumeration cons = m_connections.elements();

    callerSecurityToken.checkIfPermissionAllowed(Permissions.MIDP);

    while (cons.hasMoreElements()) {
      StreamConnectionElement sce = (StreamConnectionElement) cons.nextElement();

      if ((c_time - sce.m_time) > m_connectionLingerTime) {
        if (!sce.m_in_use) {
          sce.close();
        } else {
          // signal returnToUse() to close
          sce.m_removed = true;
        }

        m_connections.removeElement(sce);
        continue;
      }

      if (p_host.equals(sce.m_host)
          && p_port == sce.m_port
          && p_protocol.equals(sce.m_protocol)
          && !sce.m_in_use) {
        result = sce;

        // do not break out so old connections can be removed
        continue;
      }
    }

    if (result != null) {
      result.m_in_use = true;
    }

    return result;
  }
示例#3
0
  /**
   * Checks for permission and throw an exception if not allowed. May block to ask the user a
   * question.
   *
   * @param permission ID of the permission to check for, the ID must be from {@link Permissions}
   * @param name name of the suite
   * @param resource string to insert into the question, can be null
   * @exception SecurityException if the permission is not allowed by this token
   * @exception InterruptedException if another thread interrupts the calling thread while this
   *     method is waiting to preempt the display.
   */
  protected void checkForPermission(int permission, String name, String resource)
      throws InterruptedException {
    String protocolName = null;

    try {
      int colon = resource.indexOf(':');

      if (colon != -1) {
        protocolName = resource.substring(0, colon);
      }
    } catch (Exception e) {
      // ignore
    }

    securityToken.checkForPermission(
        permission,
        Permissions.getTitle(permission),
        Permissions.getQuestion(permission),
        name,
        resource,
        protocolName);
  }
示例#4
0
  /**
   * Constructs MIDletSuiteImpl from an installed MIDlet Suite.
   *
   * @param callerSecurityToken security token for the calling class
   * @param theStorageRoot root path of any files for this suite
   * @param theStorageName unique vendor and suite name identifying this suite
   * @param theCA name of CA that authorized this suite
   * @param midletToRun the name of the initial MIDlet in this suite to run, can be null
   */
  MIDletSuiteImpl(
      SecurityToken callerSecurityToken,
      String theStorageRoot,
      String theStorageName,
      String theCA,
      String midletToRun) {
    callerSecurityToken.checkIfPermissionAllowed(Permissions.MIDP);

    storageRoot = theStorageRoot;

    storageName = theStorageName;

    ca = theCA;

    readSettings();

    securityToken = new SecurityToken(classSecurityToken, permissions);

    if (midletToRun != null) {
      initialMIDletClassName = getMIDletClassName(midletToRun);
    }
  }
示例#5
0
 /**
  * Secure method to send VM hint about end of a MIDlet startup phase within specified isolate
  *
  * @param token security token with the AMS permission allowed
  * @param midletIsolateId ID of the started MIDlet isolate
  */
 public static void vmEndStartUp(SecurityToken token, int midletIsolateId) {
   token.checkIfPermissionAllowed(Permissions.AMS);
   vmEndStartUp(midletIsolateId);
 }
示例#6
0
 /**
  * Default constructor.
  *
  * @param token security token for initilaization
  * @param isolateId id of the Isolate this instance is created in
  */
 public DisplayContainer(SecurityToken token, int isolateId) {
   token.checkIfPermissionAllowed(Permissions.MIDP);
   this.isolateId = isolateId;
 }
示例#7
0
  /**
   * Asks the user want to interrupt the current MIDlet with a new MIDlet that has received network
   * data.
   *
   * @param connection connection to place in the permission question or null for alarm
   * @return true if the use wants interrupt the current MIDlet, else false
   */
  public boolean permissionToInterrupt(String connection) {
    String name;
    MIDletSuite current;
    String question;
    String currentName;

    if (pushInterruptSetting == Permissions.USER_DENIED
        || pushInterruptSetting == Permissions.NEVER) {
      return false;
    }

    // treat SESSION level the same as ONE_SHOT

    switch (pushInterruptSetting) {
      case Permissions.ALLOW:
      case Permissions.BLANKET_GRANTED:
        return true;
    }

    name = getSuiteNameForInterrupt();

    // The currently running suite controls what question to ask.
    current = Scheduler.getScheduler().getMIDletSuite();
    if (current instanceof MIDletSuiteImpl) {
      MIDletSuiteImpl temp = (MIDletSuiteImpl) current;
      if (connection == null) {
        question = temp.getAlarmInterruptQuestion();
      } else {
        question = temp.getPushInterruptQuestion();
      }

      currentName = temp.getSuiteNameForInterrupt();
    } else {
      // use the questions of this suite
      if (connection == null) {
        question = getAlarmInterruptQuestion();
      } else {
        question = getPushInterruptQuestion();
      }

      currentName = Resource.getString("The current application");
    }

    try {
      switch (SecurityToken.askUserForPermission(
          classSecurityToken,
          "Can %1 Interrupt?",
          question,
          name,
          currentName,
          null,
          Permissions.BLANKET,
          pushInterruptSetting)) {
        case Permissions.BLANKET:
          pushInterruptSetting = Permissions.BLANKET_GRANTED;
          return true;

        case Permissions.SESSION:
        case Permissions.ONE_SHOT:
          // treat one shot as session
          pushInterruptSetting = Permissions.SESSION;
          return true;

        case Permissions.DENY:
          pushInterruptSetting = Permissions.USER_DENIED;
          return false;
      }
    } catch (InterruptedException ie) {
      return false;
    }

    // default, is cancel, ask again next time
    pushInterruptSetting = Permissions.DENY_SESSION;
    return false;
  }
示例#8
0
 /**
  * Gets the status of the specified permission. If no API on the device defines the specific
  * permission requested then it must be reported as denied. If the status of the permission is not
  * known because it might require a user interaction then it should be reported as unknown.
  *
  * @param permission to check if denied, allowed, or unknown
  * @return 0 if the permission is denied; 1 if the permission is allowed; -1 if the status is
  *     unknown
  */
 public int checkPermission(String permission) {
   return securityToken.checkPermission(permission);
 }
示例#9
0
 /**
  * Checks to see the suite has the ALLOW level for specific permission. This is used for by
  * internal APIs that only provide access to trusted system applications.
  *
  * @param permission permission ID from com.sun.midp.security.Permissions
  * @exception SecurityException if the suite is not ALLOWed the permission
  */
 public void checkIfPermissionAllowed(int permission) {
   securityToken.checkIfPermissionAllowed(permission);
 }