Exemplo n.º 1
0
 /**
  * Checks for all the permissions that need to be present to open a list
  *
  * @param pimListType CONTACT_LIST, EVENT_LIST or TODO_LIST
  * @param mode READ_ONLY, WRITE_ONLY or READ_WRITE
  * @throws IllegalArgumentException if one of the parameters is out of bounds
  * @throws SecurityException if the application does not have the required permissions
  */
 private void checkPermissions(int pimListType, int mode) {
   int[] permissions = getPermissions(pimListType, mode);
   MIDletSuite suite = Scheduler.getScheduler().getMIDletSuite();
   /*
    * Do a first pass on the permissions to make sure that none is
    * automatically denied. This is for the case when both read permission
    * and write permission are required. It is possible that, for example,
    * read permission is granted only after asking the user, but write
    * permission is automatically denied. In this case, the user should
    * not be asked a question at all.
    */
   for (int i = 0; i < permissions.length; i++) {
     String name = Permissions.getName(permissions[i]);
     int status = suite.checkPermission(name);
     if (status == 0) {
       // throw an exception
       suite.checkIfPermissionAllowed(permissions[i]);
     } else if (status == 1) {
       // don't check this permission again
       permissions[i] = -1;
     }
   }
   for (int i = 0; i < permissions.length; i++) {
     if (permissions[i] != -1) {
       try {
         suite.checkForPermission(permissions[i], null);
       } catch (InterruptedException e) {
         throw new SecurityException("Security check interrupted: " + e.getMessage());
       }
     }
   }
 }
Exemplo n.º 2
0
  /** Reads the suite settings from storage. */
  private void readSettings() {
    byte[] maximums = Permissions.getEmptySet();
    byte[] currentLevels = Permissions.getEmptySet();
    RandomAccessStream storage = new RandomAccessStream(classSecurityToken);
    DataInputStream storageStream;
    int version;
    int count;

    permissions = new byte[2][];
    permissions[Permissions.MAX_LEVELS] = maximums;
    permissions[Permissions.CUR_LEVELS] = currentLevels;

    try {
      storage.connect(getStorageRoot() + Installer.SETTINGS_FILENAME, Connector.READ);
      try {
        storageStream = storage.openDataInputStream();

        version = storageStream.readByte();
        /*
         * only version 1 are handled by the method
         * 0 means that this is a beta version that are not handled
         * by the method. Note that version number only has to
         * increase if data has been removed, not if new data has been
         * added to the end of the file.
         */
        if (version != 1) {
          System.out.println("Corrupt application settings file.");
          return;
        }

        trusted = storageStream.readBoolean();

        pushInterruptSetting = storageStream.readByte();

        count = storageStream.readByte();
        storageStream.readFully(currentLevels, 0, count);

        count = storageStream.readByte();
        storageStream.readFully(maximums, 0, count);
      } finally {
        storage.disconnect();
      }
    } catch (IOException e) {
      // ignore, old settings files are shorter
    }
  }
Exemplo n.º 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);
  }