private ISecurePreferences getSecurePreferences() {
    if (!InternalOwl.IS_ECLIPSE) {
      IPreferenceScope prefs = Owl.getPreferenceService().getGlobalScope();
      boolean useOSPasswordProvider = prefs.getBoolean(DefaultPreferences.USE_OS_PASSWORD);

      /* Disable OS Password if Master Password shall be used */
      if (prefs.getBoolean(DefaultPreferences.USE_MASTER_PASSWORD)) useOSPasswordProvider = false;

      /* Try storing credentials in profile folder */
      try {
        Activator activator = Activator.getDefault();

        /* Check if Bundle is Stopped */
        if (activator == null) return null;

        IPath stateLocation = activator.getStateLocation();
        stateLocation = stateLocation.append(SECURE_STORAGE_FILE);
        URL location = stateLocation.toFile().toURL();
        Map<String, String> options = null;

        /* Use OS dependent password provider if available */
        if (useOSPasswordProvider) {
          if (Platform.OS_WIN32.equals(Platform.getOS())) {
            options = new HashMap<String, String>();
            options.put(IProviderHints.REQUIRED_MODULE_ID, WIN_PW_PROVIDER_ID);
          } else if (Platform.OS_MACOSX.equals(Platform.getOS())) {
            options = new HashMap<String, String>();
            options.put(IProviderHints.REQUIRED_MODULE_ID, MACOS_PW_PROVIDER_ID);
          }
        }

        /* Use RSSOwl password provider */
        else {
          options = new HashMap<String, String>();
          options.put(IProviderHints.REQUIRED_MODULE_ID, RSSOWL_PW_PROVIDER_ID);
        }

        return SecurePreferencesFactory.open(location, options);
      } catch (MalformedURLException e) {
        Activator.safeLogError(e.getMessage(), e);
      } catch (IllegalStateException e1) {
        Activator.safeLogError(e1.getMessage(), e1);
      } catch (IOException e2) {
        Activator.safeLogError(e2.getMessage(), e2);
      }
    }

    /* Fallback to default location */
    return SecurePreferencesFactory.getDefault();
  }
Ejemplo n.º 2
0
 /**
  * Answer secured preferences which can be used for storing sensitive information of this tab
  *
  * @return default instance of secure preferences for this tab, <code>null</code> if application
  *     was unable to create secure preferences using default location
  */
 private ISecurePreferences getPreferences(String sectionName) {
   ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
   if (preferences == null) {
     return null;
   }
   return preferences.node(IPDEUIConstants.PLUGIN_ID).node(sectionName);
 }
  @Override
  public void saveRepositories() {
    if (storage != null) {
      try {
        OutputStream output = storage.createOutputStream();
        try {
          repositoryRegistry.eResource().save(output, null);
        } finally {
          if (output != null) {
            IOUtil.closeSilent(output);
          }
        }
      } catch (IOException e) {
        Activator.log.error(
            "Failed to save model repositories to custom storage.", e); // $NON-NLS-1$
      }
    } else {
      try {
        repositoryRegistry.eResource().save(null);
      } catch (IOException e) {
        Activator.log.error("Failed to save model repositories.", e); // $NON-NLS-1$
      }
    }

    // save passwords, if any
    try {
      SecurePreferencesFactory.getDefault().flush();
    } catch (IOException e) {
      Activator.log.error(
          "Failed to save repository passwords to secure storage.", e); // $NON-NLS-1$
    }
  }
  private ISecurePreferences getPasswordNode(String login) {
    if (login == null) return null;

    ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
    if (preferences == null) return null;

    String host = Strings.trimToNull(preferenceHelper.getForgeURI());
    if (host == null) return null;

    StringBuilder bld = new StringBuilder();
    bld.append("/Puppetforge Credentials/"); // $NON-NLS-1$
    bld.append(login);
    bld.append('/');
    Checksums.appendSHA1(bld, host);
    return preferences.node(bld.toString());
  }
  public ProxyPreferencesHandler() {
    try {
      ISecurePreferences securePref = SecurePreferencesFactory.getDefault();
      node = securePref.node("proxy");
      staticMethod = node.get("method", "No proxy");
      staticAuthRequired = false;

      staticHost = node.get("host", "");
      staticPort = node.get("port", "");
      staticAuthRequired = node.getBoolean("authRequired", false);
      if (staticAuthRequired) {
        staticUser = node.get("user", "");
        staticPass = node.get("password", "");
      }
    } catch (StorageException e1) {
      e1.printStackTrace();
      staticMethod = "No proxy";
    }
  }