From 121f1d84c24ef0a0e125f8f03880405e511214a6 Mon Sep 17 00:00:00 2001 From: Carsten Hammer Date: Fri, 5 Jul 2019 20:43:21 +0200 Subject: Use jdk 5 for-each-loop (security) Replace most simple uses of Iterator with a corresponding for-each-loop. Also add missing braces on loops as necessary. Change-Id: Ia21206d22b14f3cf504678bd1554c60c7ac6b089 Signed-off-by: Carsten Hammer --- .../META-INF/MANIFEST.MF | 2 +- bundles/org.eclipse.equinox.security.tests/pom.xml | 4 +- .../security/tests/storage/ManualTest.java | 54 ++++++++++------------ .../tests/storage/SecurePreferencesTest.java | 6 +-- .../tests/storage/WaitingRegistryListener.java | 16 ++++--- .../security/tests/storage/WinPreferencesTest.java | 6 +-- .../META-INF/MANIFEST.MF | 2 +- bundles/org.eclipse.equinox.security.ui/pom.xml | 4 +- .../security/ui/X500PrincipalHelper.java | 6 +-- .../security/ui/SecurityConfigurationSection.java | 9 ++-- .../internal/security/ui/storage/TabContents.java | 10 ++-- .../internal/security/ui/storage/TabPassword.java | 14 +++--- .../security/ui/storage/view/NewValueDialog.java | 4 +- .../ui/wizard/CertificateImportCertSelectPage.java | 4 +- .../CertificateImportTrustEngineSelectPage.java | 9 ++-- .../META-INF/MANIFEST.MF | 2 +- bundles/org.eclipse.equinox.security/pom.xml | 4 +- .../security/auth/ConfigurationFactory.java | 8 ++-- .../security/auth/ConfigurationFederator.java | 13 +++--- .../auth/ext/loader/ExtCallbackHandlerLoader.java | 4 +- .../auth/ext/loader/ExtLoginModuleLoader.java | 6 +-- .../internal/security/storage/JavaEncryption.java | 5 +- .../security/storage/PasswordManagement.java | 4 +- .../security/storage/PasswordProviderSelector.java | 20 ++++---- .../security/storage/SecurePreferencesRoot.java | 3 +- .../security/storage/friends/ReEncrypter.java | 19 ++++---- 26 files changed, 112 insertions(+), 126 deletions(-) diff --git a/bundles/org.eclipse.equinox.security.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.security.tests/META-INF/MANIFEST.MF index 759bb863b..8a366f348 100644 --- a/bundles/org.eclipse.equinox.security.tests/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.security.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Equinox security tests Bundle-SymbolicName: org.eclipse.equinox.security.tests;singleton:=true -Bundle-Version: 1.1.100.qualifier +Bundle-Version: 1.1.200.qualifier Bundle-Activator: org.eclipse.equinox.internal.security.tests.SecurityTestsActivator Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-Vendor: Eclipse.org diff --git a/bundles/org.eclipse.equinox.security.tests/pom.xml b/bundles/org.eclipse.equinox.security.tests/pom.xml index 1cf2ada4e..0601685e0 100644 --- a/bundles/org.eclipse.equinox.security.tests/pom.xml +++ b/bundles/org.eclipse.equinox.security.tests/pom.xml @@ -5,7 +5,7 @@ are made available under the terms of the Eclipse Distribution License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/org/documents/edl-v10.php - + Contributors: Igor Fedorenko - initial implementation --> @@ -19,7 +19,7 @@ org.eclipse.equinox org.eclipse.equinox.security.tests - 1.1.100-SNAPSHOT + 1.1.200-SNAPSHOT eclipse-test-plugin true diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/ManualTest.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/ManualTest.java index 6cf050c14..78dc29111 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/ManualTest.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/ManualTest.java @@ -42,9 +42,8 @@ public class ManualTest { // few aliases are useful and it will be harder to separate human-redable // aliases from internal ones Provider[] providers = Security.getProviders(); - for (int i = 0; i < providers.length; i++) { - for (Iterator> j = providers[i].entrySet().iterator(); j.hasNext();) { - Map.Entry entry = j.next(); + for (Provider provider : providers) { + for (Map.Entry entry : provider.entrySet()) { String key = (String) entry.getKey(); if (key == null) continue; @@ -65,32 +64,29 @@ public class ManualTest { * algorithm should be really irrelevant. That said, Blowfish would not work with JavaCrypt * - so need to manually test all and exclude those that we know not supported * (or provide a roundtrip test - if it fails, exclude the value) - [keyFactory] PBKDF2WithHmacSHA1 - [keyFactory] DES - [keyFactory] DESede - [keyFactory] PBE - [keyFactory] PBEWithSHA1AndRC2_40 - [keyFactory] PBEWithSHA1AndDESede - [keyFactory] PBEWithMD5AndTripleDES - [keyFactory] PBEWithMD5AndDES - - - [cypher] DES - [cypher] Blowfish - [cypher] RC2 - [cypher] AES - [cypher] DESede - [cypher] PBEWithMD5AndDES - [cypher] PBEWithMD5AndTripleDES - [cypher] ARCFOUR - [cypher] RSA - [cypher] AESWrap - [cypher] PBEWithSHA1AndRC2_40 - [cypher] PBEWithSHA1AndDESede - [cypher] DESedeWrap - - http://java.sun.com/javase/6/docs/technotes/guides/security/StandardNames.html#SecretKeyFactory - http://java.sun.com/j2se/1.4.2/docs/guide/security/jce/JCERefGuide.html#AppA + [keyFactory] PBKDF2WithHmacSHA1 + [keyFactory] DES + [keyFactory] DESede + [keyFactory] PBE + [keyFactory] PBEWithSHA1AndRC2_40 + [keyFactory] PBEWithSHA1AndDESede + [keyFactory] PBEWithMD5AndTripleDES + [keyFactory] PBEWithMD5AndDES + [cypher] DES + [cypher] Blowfish + [cypher] RC2 + [cypher] AES + [cypher] DESede + [cypher] PBEWithMD5AndDES + [cypher] PBEWithMD5AndTripleDES + [cypher] ARCFOUR + [cypher] RSA + [cypher] AESWrap + [cypher] PBEWithSHA1AndRC2_40 + [cypher] PBEWithSHA1AndDESede + [cypher] DESedeWrap + http://java.sun.com/javase/6/docs/technotes/guides/security/StandardNames.html#SecretKeyFactory + http://java.sun.com/j2se/1.4.2/docs/guide/security/jce/JCERefGuide.html#AppA */ } } diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/SecurePreferencesTest.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/SecurePreferencesTest.java index 62374209a..dfb75fc2f 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/SecurePreferencesTest.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/SecurePreferencesTest.java @@ -553,10 +553,10 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { assertNotNull(array1); assertNotNull(array2); assertEquals(array1.length, array2.length); - for (int i = 0; i < array1.length; i++) { + for (String s : array1) { boolean found = false; - for (int j = 0; j < array2.length; j++) { - if (array1[i].equals(array2[j])) { + for (String s2 : array2) { + if (s.equals(s2)) { found = true; break; } diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WaitingRegistryListener.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WaitingRegistryListener.java index e64f369a9..ce52b8fd9 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WaitingRegistryListener.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WaitingRegistryListener.java @@ -149,8 +149,7 @@ public class WaitingRegistryListener extends org.junit.Assert implements IRegist private void extensionsToString(IExtension[] extensions) { extensionIDs = new ArrayList<>(extensions.length); - for (int i = 0; i < extensions.length; i++) { - IExtension extension = extensions[i]; + for (IExtension extension : extensions) { extensionIDs.add(extension.getUniqueIdentifier()); // test navigation: to extension point @@ -165,19 +164,22 @@ public class WaitingRegistryListener extends org.junit.Assert implements IRegist private boolean validContents(IConfigurationElement[] children) { if (children == null) return true; - for (int i = 0; i < children.length; i++) { - if (!children[i].isValid()) + for (IConfigurationElement child : children) { + if (!child.isValid()) { return false; - if (!validContents(children[i].getChildren())) + } + if (!validContents(child.getChildren())) { return false; + } } return true; } private void extPointsToString(IExtensionPoint[] extensionPoints) { extPointIDs = new ArrayList<>(extensionPoints.length); - for (int i = 0; i < extensionPoints.length; i++) - extPointIDs.add(extensionPoints[i].getUniqueIdentifier()); + for (IExtensionPoint extensionPoint : extensionPoints) { + extPointIDs.add(extensionPoint.getUniqueIdentifier()); + } } } diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WinPreferencesTest.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WinPreferencesTest.java index 8c396f75e..5aaebc70b 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WinPreferencesTest.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WinPreferencesTest.java @@ -53,11 +53,11 @@ public class WinPreferencesTest extends SecurePreferencesTest { static private boolean hasBundle(String symbolicID) { BundleContext context = SecurityTestsActivator.getDefault().getBundleContext(); Bundle[] bundles = context.getBundles(); - for (int i = 0; i < bundles.length; i++) { - String bundleName = bundles[i].getSymbolicName(); + for (Bundle bundle : bundles) { + String bundleName = bundle.getSymbolicName(); if (!symbolicID.equals(bundleName)) continue; - int bundleState = bundles[i].getState(); + int bundleState = bundle.getState(); return (bundleState != Bundle.INSTALLED) && (bundleState != Bundle.UNINSTALLED); } return false; diff --git a/bundles/org.eclipse.equinox.security.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.security.ui/META-INF/MANIFEST.MF index bdd1e0a85..7636e9a4f 100644 --- a/bundles/org.eclipse.equinox.security.ui/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.security.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.security.ui;singleton:=true -Bundle-Version: 1.2.300.qualifier +Bundle-Version: 1.2.400.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Import-Package: javax.crypto.spec, diff --git a/bundles/org.eclipse.equinox.security.ui/pom.xml b/bundles/org.eclipse.equinox.security.ui/pom.xml index aaebb2874..ba7d5ada3 100644 --- a/bundles/org.eclipse.equinox.security.ui/pom.xml +++ b/bundles/org.eclipse.equinox.security.ui/pom.xml @@ -5,7 +5,7 @@ are made available under the terms of the Eclipse Distribution License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/org/documents/edl-v10.php - + Contributors: Igor Fedorenko - initial implementation --> @@ -21,7 +21,7 @@ org.eclipse.equinox org.eclipse.equinox.security.ui - 1.2.300-SNAPSHOT + 1.2.400-SNAPSHOT eclipse-plugin diff --git a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/provisional/security/ui/X500PrincipalHelper.java b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/provisional/security/ui/X500PrincipalHelper.java index e560b4a51..6fd82dd25 100644 --- a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/provisional/security/ui/X500PrincipalHelper.java +++ b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/provisional/security/ui/X500PrincipalHelper.java @@ -237,8 +237,7 @@ public class X500PrincipalHelper { ArrayList retList = new ArrayList<>(); String searchPart = attributeID + attrTerminator; - for (Iterator> iter = rdnNameArray.iterator(); iter.hasNext();) { - List nameList = iter.next(); + for (List nameList : rdnNameArray) { String namePart = nameList.get(0); if (namePart.startsWith(searchPart)) { @@ -259,8 +258,7 @@ public class X500PrincipalHelper { String retNamePart = null; String searchPart = attributeID + attrTerminator; - for (Iterator> iter = rdnNameArray.iterator(); iter.hasNext();) { - List nameList = iter.next(); + for (List nameList : rdnNameArray) { String namePart = nameList.get(0); if (namePart.startsWith(searchPart)) { diff --git a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/SecurityConfigurationSection.java b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/SecurityConfigurationSection.java index 66a3b5a81..e2f175e68 100644 --- a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/SecurityConfigurationSection.java +++ b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/SecurityConfigurationSection.java @@ -63,8 +63,7 @@ public class SecurityConfigurationSection implements ISystemSummarySection { Map attributes = service.getAttributes(); if ((null != attributes) && (0 < attributes.size())) { writer.println(" Attributes:"); //$NON-NLS-1$ - for (Iterator> it = attributes.entrySet().iterator(); it.hasNext();) { - Entry entry = it.next(); + for (Entry entry : attributes.entrySet()) { String key = entry.getKey(); writer.print(" " + key + ": "); //$NON-NLS-1$//$NON-NLS-2$ writer.println(entry.getValue()); @@ -77,8 +76,7 @@ public class SecurityConfigurationSection implements ISystemSummarySection { Hashtable serviceList = new Hashtable<>(); Hashtable> attributeMap = new Hashtable<>(); // "type" => "Hashtable of (attribute,value) pairs" Hashtable> aliasMap = new Hashtable<>(); // "type" => "Arraylist of aliases" - for (Iterator> it = provider.entrySet().iterator(); it.hasNext();) { - Entry entry = it.next(); + for (Entry entry : provider.entrySet()) { String key = (String) entry.getKey(); // this is provider info, available off the Provider API @@ -126,8 +124,7 @@ public class SecurityConfigurationSection implements ISystemSummarySection { ProviderService[] serviceArray = new ProviderService[serviceList.size()]; int serviceCount = 0; - for (Iterator> it = serviceList.entrySet().iterator(); it.hasNext();) { - Entry entry = it.next(); + for (Entry entry : serviceList.entrySet()) { String key = entry.getKey(); String type = key.substring(0, key.indexOf('.')); String algo = key.substring(key.indexOf('.') + 1, key.length()); diff --git a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/storage/TabContents.java b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/storage/TabContents.java index a022cb3b4..d45a4ed6a 100644 --- a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/storage/TabContents.java +++ b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/storage/TabContents.java @@ -174,18 +174,18 @@ public class TabContents implements ISecurePreferencesSelection, IDeleteListener if (keys.length > 0) { String header = '[' + node.absolutePath() + ']'; stream.println(header); - for (int i = 0; i < keys.length; i++) { + for (String key : keys) { try { - String data = keys[i] + " := " + node.get(keys[i], ""); //$NON-NLS-1$ //$NON-NLS-2$ + String data = key + " := " + node.get(key, ""); //$NON-NLS-1$ //$NON-NLS-2$ stream.println(data); - } catch (StorageException e) { + }catch (StorageException e) { Activator.log(IStatus.ERROR, SecUIMessages.failedDecrypt, null, e); } } } String[] children = node.childrenNames(); - for (int i = 0; i < children.length; i++) { - export(node.node(children[i]), stream); + for (String child : children) { + export(node.node(child), stream); } } diff --git a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/storage/TabPassword.java b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/storage/TabPassword.java index cd7ba96b6..a3345a2b2 100644 --- a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/storage/TabPassword.java +++ b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/storage/TabPassword.java @@ -263,8 +263,7 @@ public class TabPassword { Set defaultDisabledModules = getDefaultDisabledModules(); TableItem[] items = providerTable.getItems(); - for (int i = 0; i < items.length; i++) { - TableItem item = items[i]; + for (TableItem item : items) { String moduleId = getModuleId(item); boolean enabled = defaultDisabledModules == null || moduleId == null || !defaultDisabledModules.contains(moduleId); if (item.getChecked() != enabled) { @@ -281,14 +280,15 @@ public class TabPassword { StringBuffer tmp = new StringBuffer(); boolean first = true; TableItem[] items = providerTable.getItems(); - for (int i = 0; i < items.length; i++) { - if (items[i].getChecked()) + for (TableItem item : items) { + if (item.getChecked()) { continue; + } if (!first) tmp.append(','); else first = false; - tmp.append(((PasswordProviderDescription) items[i].getData()).getId()); + tmp.append(((PasswordProviderDescription) item.getData()).getId()); } IEclipsePreferences node = ConfigurationScope.INSTANCE.getNode(PREFERENCES_PLUGIN); @@ -370,8 +370,8 @@ public class TabPassword { return null; HashSet modules = new HashSet<>(); String[] disabledProviders = joinedModuleIds.split(","); //$NON-NLS-1$ - for (int i = 0; i < disabledProviders.length; i++) { - modules.add(disabledProviders[i]); + for (String disabledProvider : disabledProviders) { + modules.add(disabledProvider); } return modules; } diff --git a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/storage/view/NewValueDialog.java b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/storage/view/NewValueDialog.java index 5647f070d..792ef4055 100644 --- a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/storage/view/NewValueDialog.java +++ b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/storage/view/NewValueDialog.java @@ -96,8 +96,8 @@ public class NewValueDialog extends TitleAreaDialog { valid = false; else { valid = true; - for (int i = 0; i < existingKeys.length; i++) { - if (existingKeys[i].equals(tmp)) { + for (String existingKey : existingKeys) { + if (existingKey.equals(tmp)) { valid = false; break; } diff --git a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/wizard/CertificateImportCertSelectPage.java b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/wizard/CertificateImportCertSelectPage.java index 2fe22f96a..795e08e31 100644 --- a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/wizard/CertificateImportCertSelectPage.java +++ b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/wizard/CertificateImportCertSelectPage.java @@ -112,8 +112,8 @@ public class CertificateImportCertSelectPage extends WizardPage implements Liste public void showCertificate(X509Certificate cert) { Control ctrls[] = certPreview.getChildren(); - for (int i = 0; i < ctrls.length; i++) { - ctrls[i].dispose(); + for (Control ctrl : ctrls) { + ctrl.dispose(); } CertificateViewer certViewer = new CertificateViewer(certPreview); certViewer.setCertificate(cert); diff --git a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/wizard/CertificateImportTrustEngineSelectPage.java b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/wizard/CertificateImportTrustEngineSelectPage.java index 5abccf884..d8d455d33 100644 --- a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/wizard/CertificateImportTrustEngineSelectPage.java +++ b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/wizard/CertificateImportTrustEngineSelectPage.java @@ -62,12 +62,11 @@ public class CertificateImportTrustEngineSelectPage extends WizardPage implement trustEngines.clear(); // get a list of trust engine and fill the combo - for (int i = 0; i < availableEngines.length; i++) { - if (!availableEngines[i].isReadOnly()) { - trustEngines.add(availableEngines[i]); - trustEngineCombo.add(availableEngines[i].getName()); + for (TrustEngine availableEngine : availableEngines) { + if (!availableEngine.isReadOnly()) { + trustEngines.add(availableEngine); + trustEngineCombo.add(availableEngine.getName()); } - } if (trustEngineCombo.getItemCount() == 0) setErrorMessage(SecurityUIMsg.WIZARD_ERROR_NO_WRITE_ENGINE); diff --git a/bundles/org.eclipse.equinox.security/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.security/META-INF/MANIFEST.MF index 6c57f9ea7..ceadfc967 100644 --- a/bundles/org.eclipse.equinox.security/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.security/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.security;singleton:=true -Bundle-Version: 1.3.200.qualifier +Bundle-Version: 1.3.300.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-Activator: org.eclipse.equinox.internal.security.auth.AuthPlugin diff --git a/bundles/org.eclipse.equinox.security/pom.xml b/bundles/org.eclipse.equinox.security/pom.xml index fcb746d7e..ea3b60b00 100644 --- a/bundles/org.eclipse.equinox.security/pom.xml +++ b/bundles/org.eclipse.equinox.security/pom.xml @@ -5,7 +5,7 @@ are made available under the terms of the Eclipse Distribution License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/org/documents/edl-v10.php - + Contributors: Igor Fedorenko - initial implementation --> @@ -19,7 +19,7 @@ org.eclipse.equinox org.eclipse.equinox.security - 1.3.200-SNAPSHOT + 1.3.300-SNAPSHOT eclipse-plugin diff --git a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ConfigurationFactory.java b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ConfigurationFactory.java index c57fcf5c5..b9cb6da56 100644 --- a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ConfigurationFactory.java +++ b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ConfigurationFactory.java @@ -44,10 +44,10 @@ public class ConfigurationFactory { IExtension[] extensions = point.getExtensions(); ArrayList returnValue = new ArrayList<>(extensions.length); - for (int i = 0; i < extensions.length; i++) { - IConfigurationElement[] elements = extensions[i].getConfigurationElements(); - for (int j = 0; j < elements.length; j++) { - Configuration provider = readProvider(elements[j]); + for (IExtension extension : extensions) { + IConfigurationElement[] elements = extension.getConfigurationElements(); + for (IConfigurationElement element : elements) { + Configuration provider = readProvider(element); if (provider != null) returnValue.add(provider); } diff --git a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ConfigurationFederator.java b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ConfigurationFederator.java index 1b649d8e6..e26937780 100644 --- a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ConfigurationFederator.java +++ b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ConfigurationFederator.java @@ -50,13 +50,13 @@ public class ConfigurationFederator extends Configuration { System.arraycopy(configs, 0, allConfigs, 0, configs.length); allConfigs[configs.length] = defaultConfiguration; } - for (int i = 0; i < allConfigs.length; i++) { + for (Configuration c : allConfigs) { boolean found = false; - AppConfigurationEntry[] config = allConfigs[i].getAppConfigurationEntry(name); + AppConfigurationEntry[] config = c.getAppConfigurationEntry(name); if (config == null) continue; String cachedProviderName = configToProviderMap.get(name); - if (cachedProviderName != null && !cachedProviderName.equals(allConfigs[i].getClass().getName())) { + if (cachedProviderName != null && !cachedProviderName.equals(c.getClass().getName())) { String message = NLS.bind(SecAuthMessages.duplicateJaasConfig1, name, cachedProviderName); AuthPlugin.getDefault().logError(message, null); } else { @@ -65,7 +65,7 @@ public class ConfigurationFederator extends Configuration { AuthPlugin.getDefault().logError(message, null); } else if ((config != null) && (config.length != 0)) { returnValue = config; - configToProviderMap.put(name, allConfigs[i].getClass().getName()); + configToProviderMap.put(name, c.getClass().getName()); configCache.put(name, returnValue); found = true; } @@ -81,8 +81,9 @@ public class ConfigurationFederator extends Configuration { @Override public synchronized void refresh() { - for (int i = 0; i < federatedConfigs.length; i++) - federatedConfigs[i].refresh(); + for (Configuration federatedConfig : federatedConfigs) { + federatedConfig.refresh(); + } if (defaultConfiguration != null) defaultConfiguration.refresh(); diff --git a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ext/loader/ExtCallbackHandlerLoader.java b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ext/loader/ExtCallbackHandlerLoader.java index 445cb42d7..530582088 100644 --- a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ext/loader/ExtCallbackHandlerLoader.java +++ b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ext/loader/ExtCallbackHandlerLoader.java @@ -38,8 +38,8 @@ public class ExtCallbackHandlerLoader { IExtensionPoint point = registry.getExtensionPoint(POINT_MAPPING); IExtension[] extenders = point.getExtensions(); String extensionId = null; - for (int i = 0; i < extenders.length; i++) { - IConfigurationElement[] confEelements = extenders[i].getConfigurationElements(); + for (IExtension extender : extenders) { + IConfigurationElement[] confEelements = extender.getConfigurationElements(); if (confEelements.length != 1) continue; // TBD error message? extensionId = loadMappingEntry(confEelements[0], configName); diff --git a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ext/loader/ExtLoginModuleLoader.java b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ext/loader/ExtLoginModuleLoader.java index 92cef92e1..2e5a4948d 100644 --- a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ext/loader/ExtLoginModuleLoader.java +++ b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/auth/ext/loader/ExtLoginModuleLoader.java @@ -40,12 +40,12 @@ public class ExtLoginModuleLoader { String targetPoint = (String) options.get(ExtensionLoginModule.OPTION_MODULE_POINT); LoginModule loginModule = null; - for (int i = 0; i < extensions.length; i++) { - String sourcePoint = extensions[i].getUniqueIdentifier(); + for (IExtension extension : extensions) { + String sourcePoint = extension.getUniqueIdentifier(); if (sourcePoint == null) // technically, IDs on extensions are optional continue; if (sourcePoint.equals(targetPoint)) { - IConfigurationElement[] elements = extensions[i].getConfigurationElements(); + IConfigurationElement[] elements = extension.getConfigurationElements(); int elementCount = elements.length; if (elementCount == 1) loginModule = readEntry(elements[0]); diff --git a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/JavaEncryption.java b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/JavaEncryption.java index 052d59326..2f34cfdc3 100644 --- a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/JavaEncryption.java +++ b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/JavaEncryption.java @@ -246,9 +246,8 @@ public class JavaEncryption { Provider[] providers = Security.getProviders(); Set algorithms = new HashSet<>(); int prefixLength = prefix.length(); - for (int i = 0; i < providers.length; i++) { - for (Iterator> j = providers[i].entrySet().iterator(); j.hasNext();) { - Entry entry = j.next(); + for (Provider provider : providers) { + for (Entry entry : provider.entrySet()) { Object key = entry.getKey(); if (key == null) continue; diff --git a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/PasswordManagement.java b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/PasswordManagement.java index bfed37322..dbe42fb91 100644 --- a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/PasswordManagement.java +++ b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/PasswordManagement.java @@ -153,8 +153,8 @@ public class PasswordManagement { static private String mashPassword(String[] answers) { // form a string composing answers StringBuffer tmp = new StringBuffer(); - for (int i = 0; i < answers.length; i++) { - tmp.append(answers[i].trim()); + for (String answer : answers) { + tmp.append(answer.trim()); } // mix it up StringBuffer mix = new StringBuffer(); diff --git a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/PasswordProviderSelector.java b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/PasswordProviderSelector.java index 0b6e9f97c..329e1b1f7 100644 --- a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/PasswordProviderSelector.java +++ b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/PasswordProviderSelector.java @@ -94,14 +94,14 @@ public class PasswordProviderSelector implements IRegistryEventListener { ArrayList allAvailableModules = new ArrayList<>(extensions.length); - for (int i = 0; i < extensions.length; i++) { - String moduleID = extensions[i].getUniqueIdentifier(); + for (IExtension extension : extensions) { + String moduleID = extension.getUniqueIdentifier(); if (moduleID == null) // IDs on those extensions are mandatory; if not specified, ignore the extension continue; moduleID = moduleID.toLowerCase(); if (expectedID != null && !expectedID.equals(moduleID)) continue; - IConfigurationElement[] elements = extensions[i].getConfigurationElements(); + IConfigurationElement[] elements = extension.getConfigurationElements(); if (elements.length == 0) continue; IConfigurationElement element = elements[0]; // only one module is allowed per extension @@ -118,21 +118,18 @@ public class PasswordProviderSelector implements IRegistryEventListener { if (priority > 10) priority = 10; } - String name = extensions[i].getLabel(); - + String name = extension.getLabel(); String description = element.getAttribute(MODULE_DESCRIPTION); - List suppliedHints = null; IConfigurationElement[] hints = element.getChildren(HINTS_NAME); if (hints.length != 0) { suppliedHints = new ArrayList<>(hints.length); - for (int j = 0; j < hints.length; j++) { - String hint = hints[j].getAttribute(HINT_VALUE); + for (IConfigurationElement h : hints) { + String hint = h.getAttribute(HINT_VALUE); if (hint != null) suppliedHints.add(hint); } } - Object clazz; try { clazz = element.createExecutableExtension(CLASS_NAME); @@ -143,7 +140,6 @@ public class PasswordProviderSelector implements IRegistryEventListener { } catch (CoreException e) { continue; } - allAvailableModules.add(new ExtStorageModule(moduleID, element, priority, name, description, suppliedHints)); } @@ -260,8 +256,8 @@ public class PasswordProviderSelector implements IRegistryEventListener { return null; HashSet disabledModules = new HashSet<>(); String[] disabledProviders = tmp.split(","); //$NON-NLS-1$ - for (int i = 0; i < disabledProviders.length; i++) { - disabledModules.add(disabledProviders[i]); + for (String disabledProvider : disabledProviders) { + disabledModules.add(disabledProvider); } return disabledModules; } diff --git a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/SecurePreferencesRoot.java b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/SecurePreferencesRoot.java index 3477e6dc4..a0ab7a76c 100644 --- a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/SecurePreferencesRoot.java +++ b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/SecurePreferencesRoot.java @@ -143,8 +143,7 @@ public class SecurePreferencesRoot extends SecurePreferences implements IStorage properties.remove(KEY_FACTORY_KEY); } - for (Iterator> it = properties.entrySet().iterator(); it.hasNext();) { - Entry entry = it.next(); + for (Entry entry : properties.entrySet()) { Object externalKey = entry.getKey(); Object value = entry.getValue(); if (!(externalKey instanceof String)) diff --git a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/friends/ReEncrypter.java b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/friends/ReEncrypter.java index 8648060b2..6fe0bc819 100644 --- a/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/friends/ReEncrypter.java +++ b/bundles/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/friends/ReEncrypter.java @@ -72,22 +72,22 @@ public class ReEncrypter { String[] keys = node.keys(); if (keys.length > 0) { Map map = new HashMap<>(keys.length); // could be less than that - for (int i = 0; i < keys.length; i++) { + for (String key : keys) { try { - if (!node.isEncrypted(keys[i])) + if (!node.isEncrypted(key)) { continue; + } if (!(node instanceof SecurePreferencesWrapper)) continue; - String encryptionModule = ((SecurePreferencesWrapper) node).getModule(keys[i]); + String encryptionModule = ((SecurePreferencesWrapper) node).getModule(key); if (encryptionModule == null) continue; if (!encryptionModule.equals(moduleID)) continue; - - map.put(keys[i], node.get(keys[i], null)); + map.put(key, node.get(key, null)); } catch (StorageException e) { // this value will not be re-coded - String msg = NLS.bind(SecAuthMessages.decryptingError, keys[i], node.absolutePath()); + String msg = NLS.bind(SecAuthMessages.decryptingError, key, node.absolutePath()); AuthPlugin.getDefault().logError(msg, e); processedOK = false; } @@ -96,8 +96,8 @@ public class ReEncrypter { elements.add(new TmpElement(node.absolutePath(), map)); } String[] childrenNames = node.childrenNames(); - for (int i = 0; i < childrenNames.length; i++) { - decrypt(node.node(childrenNames[i])); + for (String childrenName : childrenNames) { + decrypt(node.node(childrenName)); } } @@ -127,8 +127,7 @@ public class ReEncrypter { for (TmpElement element : elements) { ISecurePreferences node = root.node(element.getPath()); Map values = element.getValues(); - for (Iterator> it = values.entrySet().iterator(); it.hasNext();) { - Entry entry = it.next(); + for (Entry entry : values.entrySet()) { String key = entry.getKey(); try { node.put(key, entry.getValue(), true); -- cgit v1.2.3