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; }
private void internalSetAuthCredentials( ICredentials credentials, URI link, String realm, boolean persist) throws CredentialsException { /* Store Credentials in In-Memory Store */ if (!persist) { fInMemoryStore.put(toCacheKey(link, realm), credentials); } /* Store Credentials in secure Storage */ else { ISecurePreferences securePreferences = getSecurePreferences(); /* Check if Bundle is Stopped */ if (securePreferences == null) return; /* Store in Equinox Security Storage */ ISecurePreferences allFeedsPreferences = securePreferences.node(SECURE_FEED_NODE); ISecurePreferences feedPreferences = allFeedsPreferences.node(EncodingUtils.encodeSlashes(link.toString())); ISecurePreferences realmPreference = feedPreferences.node(EncodingUtils.encodeSlashes(realm != null ? realm : REALM)); IPreferenceScope globalScope = Owl.getPreferenceService().getGlobalScope(); /* OS Password is only supported on Windows and Mac */ boolean useOSPassword = globalScope.getBoolean(DefaultPreferences.USE_OS_PASSWORD); if (!Platform.OS_WIN32.equals(Platform.getOS()) && !Platform.OS_MACOSX.equals(Platform.getOS())) useOSPassword = false; boolean encryptPW = useOSPassword || globalScope.getBoolean(DefaultPreferences.USE_MASTER_PASSWORD); try { if (credentials.getUsername() != null) realmPreference.put(USERNAME, credentials.getUsername(), encryptPW); if (credentials.getPassword() != null) realmPreference.put(PASSWORD, credentials.getPassword(), encryptPW); if (credentials.getDomain() != null) realmPreference.put(DOMAIN, credentials.getDomain(), encryptPW); realmPreference.flush(); // Flush to disk early } catch (StorageException e) { throw new CredentialsException(Activator.getDefault().createErrorStatus(e.getMessage(), e)); } catch (IOException e) { throw new CredentialsException(Activator.getDefault().createErrorStatus(e.getMessage(), e)); } } /* Uncache */ removeUnprotected(link, realm); }
private static void saveServers(Collection<SonarServer> servers) { IEclipsePreferences rootNode = new InstanceScope().getNode(NODE); try { Preferences serversNode = rootNode.node(PREF_SERVERS); for (SonarServer server : servers) { String encodedUrl = EncodingUtils.encodeSlashes(server.getUrl()); serversNode.node(encodedUrl).putBoolean("auth", server.hasCredentials()); } serversNode.flush(); } catch (BackingStoreException e) { LoggerFactory.getLogger(SecurityManager.class).error(e.getMessage(), e); } }
/* * @see * org.rssowl.core.connection.ICredentialsProvider#deleteAuthCredentials(java * .net.URI, java.lang.String) */ public synchronized void deleteAuthCredentials(URI link, String realm) throws CredentialsException { /* Delete from In-Memory Store if present */ fInMemoryStore.remove(toCacheKey(link, realm)); /* Delete from Cache */ removeUnprotected(link, realm); /* Check if Bundle is Stopped */ ISecurePreferences securePreferences = getSecurePreferences(); if (securePreferences == null) return; /* Remove 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)); realmPreferences.clear(); realmPreferences.removeNode(); try { feedPreferences.flush(); } catch (IOException e) { throw new CredentialsException( Activator.getDefault().createErrorStatus(e.getMessage(), e)); } } } } }