private ICredentials getAuthorizationInfo(URI link, String realm) throws CredentialsException {
    ISecurePreferences securePreferences = getSecurePreferences();

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

    /* Return from Equinox Security Storage */
    if (securePreferences.nodeExists(SECURE_FEED_NODE)) { // Global Feed Node
      ISecurePreferences allFeedsPreferences = securePreferences.node(SECURE_FEED_NODE);
      if (allFeedsPreferences.nodeExists(
          EncodingUtils.encodeSlashes(link.toString()))) { // Feed Node
        ISecurePreferences feedPreferences =
            allFeedsPreferences.node(EncodingUtils.encodeSlashes(link.toString()));
        if (feedPreferences.nodeExists(
            EncodingUtils.encodeSlashes(realm != null ? realm : REALM))) { // Realm Node
          ISecurePreferences realmPreferences =
              feedPreferences.node(EncodingUtils.encodeSlashes(realm != null ? realm : REALM));

          try {
            String username = realmPreferences.get(USERNAME, null);
            String password = realmPreferences.get(PASSWORD, null);
            String domain = realmPreferences.get(DOMAIN, null);

            if (username != null && password != null)
              return new Credentials(username, password, domain);
          } catch (StorageException e) {
            throw new CredentialsException(
                Activator.getDefault().createErrorStatus(e.getMessage(), e));
          }
        }
      }
    }

    return null;
  }
    public synchronized Authorization authorize(URI uri) {
      String host = getHost(uri);
      if (host != null) {
        Authorization cachedAuthorization = authorizations.get(host);
        if (cachedAuthorization == Authorization.UNAUTHORIZEABLE) {
          return cachedAuthorization;
        }

        if (securePreferences != null) {
          try {
            ISecurePreferences node = securePreferences.node(host);
            String user = node.get("user", "");
            String password = node.get("password", "");

            Authorization authorization = new Authorization(user, password);
            if (authorization.isAuthorized()) {
              authorizations.put(host, authorization);
              return authorization;
            }
          } catch (StorageException ex) {
            SetupCorePlugin.INSTANCE.log(ex);
          }
        }

        if (cachedAuthorization != null) {
          return cachedAuthorization;
        }
      }

      return Authorization.UNAUTHORIZED;
    }
Пример #3
0
 private String getString(ISecurePreferences settings, String key) {
   try {
     return settings.get(key, ""); // $NON-NLS-1$
   } catch (StorageException e) {
     return ""; //$NON-NLS-1$
   }
 }
 private String loadSecurePassword(String login) {
   ISecurePreferences node = getPasswordNode(login);
   if (node != null)
     try {
       return node.get("password", null);
     } catch (StorageException e) {
     }
   return null;
 }
  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";
    }
  }
Пример #6
0
 private byte[] getEncryptedPassword(IPreferencesContainer container) {
   ISecurePreferences node = container.getPreferences().node(WIN_PROVIDER_NODE);
   String passwordHint;
   try {
     passwordHint = node.get(PASSWORD_KEY, null);
   } catch (StorageException e) { // should never happen in this scenario
     AuthPlugin.getDefault().logError(WinCryptoMessages.decryptPasswordFailed, e);
     return null;
   }
   if (passwordHint == null) return null;
   return Base64.decode(passwordHint);
 }