Replace keySet with entrySet

Closes #40064

Signed-off-by: akbarhusainpatel <apatel@intermiles.com>
Co-authored-by: akbarhusainpatel <apatel@intermiles.com>
This commit is contained in:
Akbar Husain 2025-08-14 21:01:15 +05:30 committed by GitHub
parent 0c33217729
commit 06f80416fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 97 additions and 89 deletions

View File

@ -489,8 +489,9 @@ public class Profile {
}
private static void verifyConfig(Map<Feature, Boolean> features) {
for (Feature f : features.keySet()) {
if (features.get(f) && f.getDependencies() != null) {
for (Map.Entry<Feature, Boolean> entry : features.entrySet()) {
Feature f = entry.getKey();
if (entry.getValue() && f.getDependencies() != null) {
for (Feature d : f.getDependencies()) {
if (!features.get(d)) {
throw new ProfileException("Feature " + f.getKey() + " depends on disabled feature " + d.getKey());

View File

@ -72,10 +72,10 @@ public class StringPropertyReplacerTest {
public void testEnvironmentVariables() throws NoSuchAlgorithmException {
Map<String, String> env = System.getenv();
for (String key : env.keySet()) {
String value = env.get(key);
for (Map.Entry<String, String> entry : env.entrySet()) {
String value = entry.getValue();
if ( !(value == null || "".equals(value)) ) {
Assert.assertEquals("foo-" + value, replaceProperties("foo-${env." + key + "}"));
Assert.assertEquals("foo-" + value, replaceProperties("foo-${env." + entry.getKey() + "}"));
break;
}
}

View File

@ -179,8 +179,9 @@ public class RealmConfigData {
if (clients == null) {
clients = source.clients;
} else {
for (String key: source.clients.keySet()) {
String val = source.clients.get(key);
for (var entry : source.clients.entrySet()) {
String key = entry.getKey();
String val = entry.getValue();
if (!"".equals(val)) {
clients.put(key, val);
} else {

View File

@ -370,8 +370,7 @@ public class ReflectionUtil {
// use setter on dest, and getter on source to copy value over
Map<String, Field> fieldMap = getAttrFieldsForType(source.getClass());
try {
for (String attrName : fieldMap.keySet()) {
Field field = fieldMap.get(attrName);
for (Field field : fieldMap.values()) {
Object localValue = field.get(source);
if (localValue != null) {
field.set(dest, localValue);

View File

@ -223,9 +223,9 @@ public class DefaultMigrationManager implements MigrationManager {
public static ModelVersion convertRHSSOVersionToKeycloakVersion(String version) {
// look for the keycloakVersion pattern to identify it as RH SSO
for (Pattern pattern : PATTERN_MATCHER.keySet()) {
if (pattern.matcher(version).find()) {
return PATTERN_MATCHER.get(pattern);
for (var entry : PATTERN_MATCHER.entrySet()) {
if (entry.getKey().matcher(version).find()) {
return entry.getValue();
}
}
// chceck if the version is in format for CD releases, e.g.: "keycloakVersion": "6"

View File

@ -419,8 +419,8 @@ public class BaseSAML2BindingBuilder<T extends BaseSAML2BindingBuilder> {
builder.append("<p>Redirecting, please wait.</p>");
for (String key: inputTypes.keySet()) {
builder.append("<INPUT TYPE=\"HIDDEN\" NAME=\"").append(key).append("\"").append(" VALUE=\"").append(escapeAttribute(inputTypes.get(key))).append("\"/>");
for (var entry : inputTypes.entrySet()) {
builder.append("<INPUT TYPE=\"HIDDEN\" NAME=\"").append(entry.getKey()).append("\"").append(" VALUE=\"").append(escapeAttribute(entry.getValue())).append("\"/>");
}
builder.append("<NOSCRIPT>")

View File

@ -85,8 +85,8 @@ public class StatementUtil {
int i = 0;
Set<String> keys = attributes.keySet();
for (String key : keys) {
for (var entry : attributes.entrySet()) {
String key = entry.getKey();
if (i == 0) {
// Deal with the X500 Profile of SAML2
attrStatement = new AttributeStatementType();
@ -95,14 +95,14 @@ public class StatementUtil {
// if the attribute contains roles, add each role as an attribute.
if (AttributeConstants.ROLES.equalsIgnoreCase(key)) {
Object value = attributes.get(key);
Object value = entry.getValue();
if (value instanceof Collection<?>) {
Collection<?> roles = (Collection<?>) value;
attrStatement = createAttributeStatement(new ArrayList(roles));
}
} else {
AttributeType att;
Object value = attributes.get(key);
Object value = entry.getValue();
String uri = X500SAMLProfileConstants.getOID(key);
if (StringUtil.isNotNull(uri)) {
@ -233,4 +233,4 @@ public class StatementUtil {
att.setNameFormat(JBossSAMLURIConstants.ATTRIBUTE_FORMAT_URI.get());
return att;
}
}
}

View File

@ -162,15 +162,14 @@ public class BaseWriter {
if (otherAttribs != null) {
List<String> nameSpacesDealt = new ArrayList<>();
Iterator<QName> keySet = otherAttribs.keySet().iterator();
while (keySet != null && keySet.hasNext()) {
QName qname = keySet.next();
for (var entry : otherAttribs.entrySet()) {
QName qname = entry.getKey();
String ns = qname.getNamespaceURI();
if (!nameSpacesDealt.contains(ns)) {
StaxUtil.writeNameSpace(writer, qname.getPrefix(), ns);
nameSpacesDealt.add(ns);
}
String attribValue = otherAttribs.get(qname);
String attribValue = entry.getValue();
StaxUtil.writeAttribute(writer, qname, attribValue);
}
}
@ -392,4 +391,4 @@ public class BaseWriter {
private void write(BaseIDAbstractType baseId) throws ProcessingException {
throw logger.notImplementedYet("Method not implemented.");
}
}
}

View File

@ -61,10 +61,10 @@ public class NamespaceContext implements javax.xml.namespace.NamespaceContext {
* @see javax.xml.namespace.NamespaceContext#getPrefix(java.lang.String)
*/
public String getPrefix(String namespaceURI) {
for (String key : nsMap.keySet()) {
String value = nsMap.get(key);
for (var entry : nsMap.entrySet()) {
String value = entry.getValue();
if (value.equals(namespaceURI)) {
return key;
return entry.getKey();
}
}
return null;

View File

@ -1541,9 +1541,8 @@ public class RepresentationToModel {
Map<String, List<String>> attributes = resource.getAttributes();
if (attributes != null) {
Set<String> existingAttrNames = existing.getAttributes().keySet();
for (String name : existingAttrNames) {
for (String name : existing.getAttributes().keySet()) {
if (attributes.containsKey(name)) {
existing.setAttribute(name, attributes.get(name));
attributes.remove(name);
@ -1552,8 +1551,8 @@ public class RepresentationToModel {
}
}
for (String name : attributes.keySet()) {
existing.setAttribute(name, attributes.get(name));
for (var entry : attributes.entrySet()) {
existing.setAttribute(entry.getKey(), entry.getValue());
}
}

View File

@ -411,13 +411,14 @@ public class DefaultAttributes extends HashMap<String, List<String>> implements
}
// the profile should always hold all attributes defined in the config
for (String attributeName : metadataByAttribute.keySet()) {
for (var entry : metadataByAttribute.entrySet()) {
String attributeName = entry.getKey();
if (!isSupportedAttribute(attributeName) || newAttributes.containsKey(attributeName)) {
continue;
}
List<String> values = EMPTY_VALUE;
AttributeMetadata metadata = metadataByAttribute.get(attributeName);
AttributeMetadata metadata = entry.getValue();
if (user != null && isIncludeAttributeIfNotProvided(metadata)) {
values = user.getAttributes().getOrDefault(attributeName, EMPTY_VALUE);

View File

@ -114,14 +114,15 @@ public class ClientRolesPartialImport {
Map<String, List<RoleRepresentation>> repList = getRepList(partialImportRep);
if (repList == null || repList.isEmpty()) return;
for (String clientId : repList.keySet()) {
for (var entry : repList.entrySet()) {
String clientId = entry.getKey();
if (!clientExists(partialImportRep, realm, clientId)) {
throw noClientFound(clientId);
}
toOverwrite.put(clientId, new HashSet<>());
toSkip.put(clientId, new HashSet<>());
for (RoleRepresentation roleRep : repList.get(clientId)) {
for (RoleRepresentation roleRep : entry.getValue()) {
if (exists(realm, session, clientId, roleRep)) {
switch (partialImportRep.getPolicy()) {
case SKIP:

View File

@ -137,8 +137,8 @@ public class RolesPartialImport implements PartialImport<RolesRepresentation> {
}
private void setUniqueIds(Map<String, List<RoleRepresentation>> clientRoles) {
for (String clientId : clientRoles.keySet()) {
for (RoleRepresentation clientRole : clientRoles.get(clientId)) {
for (List<RoleRepresentation> roleRepresentations : clientRoles.values()) {
for (RoleRepresentation clientRole : roleRepresentations) {
clientRole.setId(KeycloakModelUtils.generateId());
}
}
@ -162,8 +162,9 @@ public class RolesPartialImport implements PartialImport<RolesRepresentation> {
RealmModel realm) {
if (isEmpty(clientRolesToSkip)) return;
for (String clientId : clientRolesToSkip.keySet()) {
for (RoleRepresentation roleRep : clientRolesToSkip.get(clientId)) {
for (var entry : clientRolesToSkip.entrySet()) {
String clientId = entry.getKey();
for (RoleRepresentation roleRep : entry.getValue()) {
rep.getRoles().getClient().get(clientId).remove(roleRep);
String modelId = clientRolesPI.getModelId(realm, clientId);
results.addResult(clientRolesPI.skipped(clientId, modelId, roleRep));
@ -191,9 +192,9 @@ public class RolesPartialImport implements PartialImport<RolesRepresentation> {
private void deleteClientRoleOverwrites(RealmModel realm) {
if (isEmpty(clientRolesToOverwrite)) return;
for (String clientId : clientRolesToOverwrite.keySet()) {
for (RoleRepresentation roleRep : clientRolesToOverwrite.get(clientId)) {
clientRolesPI.deleteRole(realm, clientId, roleRep);
for (var entry : clientRolesToOverwrite.entrySet()) {
for (RoleRepresentation roleRep : entry.getValue()) {
clientRolesPI.deleteRole(realm, entry.getKey(), roleRep);
}
}
}
@ -201,8 +202,9 @@ public class RolesPartialImport implements PartialImport<RolesRepresentation> {
private void addResultsForOverwrittenClientRoles(PartialImportResults results, RealmModel realm) {
if (isEmpty(clientRolesToOverwrite)) return;
for (String clientId : clientRolesToOverwrite.keySet()) {
for (RoleRepresentation roleRep : clientRolesToOverwrite.get(clientId)) {
for (var entry : clientRolesToOverwrite.entrySet()) {
String clientId = entry.getKey();
for (RoleRepresentation roleRep : entry.getValue()) {
String modelId = clientRolesPI.getModelId(realm, clientId);
results.addResult(clientRolesPI.overwritten(clientId, modelId, roleRep));
}
@ -238,8 +240,9 @@ public class RolesPartialImport implements PartialImport<RolesRepresentation> {
if (!rep.hasClientRoles()) return;
Map<String, List<RoleRepresentation>> repList = clientRolesPI.getRepList(rep);
for (String clientId : repList.keySet()) {
for (RoleRepresentation roleRep : repList.get(clientId)) {
for (var entry : repList.entrySet()) {
String clientId = entry.getKey();
for (RoleRepresentation roleRep : entry.getValue()) {
if (clientRolesToOverwrite.get(clientId).contains(roleRep)) continue;
if (clientRolesToSkip.get(clientId).contains(roleRep)) continue;

View File

@ -211,8 +211,8 @@ public class TokenEndpoint {
}
private void checkParameterDuplicated() {
for (String key : formParams.keySet()) {
if (formParams.get(key).size() != 1 && !grant.getSupportedMultivaluedRequestParameters().contains(key)) {
for (var entry : formParams.entrySet()) {
if (entry.getValue().size() != 1 && !grant.getSupportedMultivaluedRequestParameters().contains(entry.getKey())) {
throw new CorsErrorResponseException(cors, OAuthErrorException.INVALID_REQUEST, "duplicated parameter",
Response.Status.BAD_REQUEST);
}

View File

@ -40,6 +40,8 @@ import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import java.util.List;
/**
* A token introspection endpoint based on RFC-7662.
*
@ -150,8 +152,8 @@ public class TokenIntrospectionEndpoint {
private void checkParameterDuplicated(MultivaluedMap<String, String> formParams) {
for (String key : formParams.keySet()) {
if (formParams.get(key).size() != 1) {
for (List<String> strings : formParams.values()) {
if (strings.size() != 1) {
throw throwErrorResponseException(Errors.INVALID_REQUEST, "duplicated parameter", Status.BAD_REQUEST);
}
}

View File

@ -246,8 +246,8 @@ public class TokenRevocationEndpoint {
}
private void checkParameterDuplicated(MultivaluedMap<String, String> formParams) {
for (String key : formParams.keySet()) {
if (formParams.get(key).size() != 1) {
for (List<String> strings : formParams.values()) {
if (strings.size() != 1) {
throw new CorsErrorResponseException(cors, Errors.INVALID_REQUEST, "duplicated parameter", Response.Status.BAD_REQUEST);
}
}

View File

@ -213,8 +213,8 @@ public class CibaGrantType extends OAuth2GrantTypeBase {
authSession.setClientNote(OIDCLoginProtocol.ISSUER, Urls.realmIssuer(session.getContext().getUri().getBaseUri(), realm.getName()));
authSession.setClientNote(OIDCLoginProtocol.SCOPE_PARAM, request.getScope());
if (additionalParams != null) {
for (String paramName : additionalParams.keySet()) {
authSession.setClientNote(ADDITIONAL_CALLBACK_PARAMS_PREFIX + paramName, additionalParams.get(paramName));
for (var entry : additionalParams.entrySet()) {
authSession.setClientNote(ADDITIONAL_CALLBACK_PARAMS_PREFIX + entry.getKey(), entry.getValue());
}
}
if (request.getOtherClaims() != null) {

View File

@ -59,9 +59,9 @@ class CodeGenerateUtil {
static <CS extends CommonClientSessionModel> ClientSessionParser<CS> getParser(Class<CS> clientSessionClass) {
for (Class<?> c : PARSERS.keySet()) {
if (c.isAssignableFrom(clientSessionClass)) {
return PARSERS.get(c).get();
for (var entry : PARSERS.entrySet()) {
if (entry.getKey().isAssignableFrom(clientSessionClass)) {
return entry.getValue().get();
}
}
return null;

View File

@ -74,9 +74,9 @@ public class VaultTranscriberTest {
// attempt to obtain a secret using a proper vault expressions. The key may or may not exist in the vault, so we
// check both cases using the returned optional and comparing against the expected secret.
for (String key : validExpressions.keySet()) {
String expectedSecret = validExpressions.get(key);
try (VaultRawSecret secret = transcriber.getRawSecret(key)) {
for (var entry : validExpressions.entrySet()) {
String expectedSecret = entry.getValue();
try (VaultRawSecret secret = transcriber.getRawSecret(entry.getKey())) {
Optional<ByteBuffer> optional = secret.get();
Optional<byte[]> optionalArray = secret.getAsArray();
if (expectedSecret != null) {
@ -163,9 +163,9 @@ public class VaultTranscriberTest {
// attempt to obtain a secret using a proper vault expressions. The key may or may not exist in the vault, so we
// check both cases using the returned optional and comparing against the expected secret.
for (String key : validExpressions.keySet()) {
String expectedSecret = validExpressions.get(key);
try (VaultCharSecret secret = transcriber.getCharSecret(key)) {
for (var entry : validExpressions.entrySet()) {
String expectedSecret = entry.getValue();
try (VaultCharSecret secret = transcriber.getCharSecret(entry.getKey())) {
Optional<CharBuffer> optional = secret.get();
Optional<char[]> optionalArray = secret.getAsArray();
if (expectedSecret != null) {
@ -249,9 +249,9 @@ public class VaultTranscriberTest {
// attempt to obtain a secret using a proper vault expressions. The key may or may not exist in the vault, so we
// check both cases using the returned optional and comparing against the expected secret.
for (String key : validExpressions.keySet()) {
String expectedSecret = validExpressions.get(key);
try (VaultStringSecret secret = transcriber.getStringSecret(key)) {
for (var entry : validExpressions.entrySet()) {
String expectedSecret = entry.getValue();
try (VaultStringSecret secret = transcriber.getStringSecret(entry.getKey())) {
Optional<String> optional = secret.get();
if (expectedSecret != null) {
Assert.assertTrue(optional.isPresent());
@ -348,4 +348,4 @@ public class VaultTranscriberTest {
// nothing to do
}
}
}
}

View File

@ -396,8 +396,8 @@ public class InstallationTest {
Node element = elementsByTagName.item(0);
if (attrNamesAndValues != null) {
for (String attrName : attrNamesAndValues.keySet()) {
assertThat(element.getAttributes().getNamedItem(attrName).getNodeValue(), containsString(attrNamesAndValues.get(attrName)));
for (var entry : attrNamesAndValues.entrySet()) {
assertThat(element.getAttributes().getNamedItem(entry.getKey()).getNodeValue(), containsString(entry.getValue()));
}
}
}

View File

@ -168,9 +168,10 @@ public class Assert extends Assertions {
public static void assertRoleAttributes(Map<String, List<String>> expected, Map<String, List<String>> actual) {
MatcherAssert.assertThat(actual.keySet(), equalTo(expected.keySet()));
for (String expectedKey : expected.keySet()) {
MatcherAssert.assertThat(actual.get(expectedKey).size(), is(equalTo(expected.get(expectedKey).size())));
MatcherAssert.assertThat(actual.get(expectedKey), containsInAnyOrder(expected.get(expectedKey).toArray()));
for (var entry : expected.entrySet()) {
String expectedKey = entry.getKey();
MatcherAssert.assertThat(actual.get(expectedKey).size(), is(equalTo(entry.getValue().size())));
MatcherAssert.assertThat(actual.get(expectedKey), containsInAnyOrder(entry.getValue().toArray()));
}
}
}

View File

@ -193,10 +193,10 @@ public class FailableHardcodedStorageProvider implements UserStorageProvider, Us
local.setLastName(last);
local.setEmail(email);
local.setFederationLink(model.getId());
for (String key : attributes.keySet()) {
List<String> values = attributes.get(key);
for (var entry : attributes.entrySet()) {
List<String> values = entry.getValue();
if (values == null) continue;
local.setAttribute(key, values);
local.setAttribute(entry.getKey(), values);
}
return new Delegate(local);
}

View File

@ -103,12 +103,12 @@ public class Timer {
public void clearStats(boolean logStats, boolean saveData, boolean saveCharts) {
if (logStats) {
log.info("Timer Statistics:");
for (String op : stats.keySet()) {
for (var entry : stats.entrySet()) {
long sum = 0;
for (Long duration : stats.get(op)) {
for (Long duration : entry.getValue()) {
sum += duration;
}
log.info(String.format("Operation '%s' average: %s ms", op, sum / stats.get(op).size()));
log.info(String.format("Operation '%s' average: %s ms", entry.getKey(), sum / entry.getValue().size()));
}
}
if (PROJECT_BUILD_DIRECTORY.exists()) {

View File

@ -167,9 +167,10 @@ public class Assert extends org.junit.Assert {
public static void assertRoleAttributes(Map<String, List<String>> expected, Map<String, List<String>> actual) {
MatcherAssert.assertThat(actual.keySet(), equalTo(expected.keySet()));
for (String expectedKey : expected.keySet()) {
MatcherAssert.assertThat(actual.get(expectedKey).size(), is(equalTo(expected.get(expectedKey).size())));
MatcherAssert.assertThat(actual.get(expectedKey), containsInAnyOrder(expected.get(expectedKey).toArray()));
for (var entry : expected.entrySet()) {
String expectedKey = entry.getKey();
MatcherAssert.assertThat(actual.get(expectedKey).size(), is(equalTo(entry.getValue().size())));
MatcherAssert.assertThat(actual.get(expectedKey), containsInAnyOrder(entry.getValue().toArray()));
}
}
}

View File

@ -525,8 +525,8 @@ public class ExportImportUtil {
Map<String, ClientMappingsRepresentation> clientRoles = client.getScopeMappings().getAll().getClientMappings();
if (clientRoles == null) return clientScopeMappings;
for (String clientKey : clientRoles.keySet()) {
List<RoleRepresentation> clientRoleScopeMappings = clientRoles.get(clientKey).getMappings();
for (ClientMappingsRepresentation clientMappingsRepresentation : clientRoles.values()) {
List<RoleRepresentation> clientRoleScopeMappings = clientMappingsRepresentation.getMappings();
if (clientRoleScopeMappings != null) clientScopeMappings.addAll(clientRoleScopeMappings);
}
@ -538,8 +538,8 @@ public class ExportImportUtil {
Map<String, ClientMappingsRepresentation> clientRoles = client.getScopeMappings().getAll().getClientMappings();
if (clientRoles == null) return clientScopeMappings;
for (String clientKey : clientRoles.keySet()) {
List<RoleRepresentation> clientRoleScopeMappings = clientRoles.get(clientKey).getMappings();
for (ClientMappingsRepresentation clientMappingsRepresentation : clientRoles.values()) {
List<RoleRepresentation> clientRoleScopeMappings = clientMappingsRepresentation.getMappings();
if (clientRoleScopeMappings != null) clientScopeMappings.addAll(clientRoleScopeMappings);
}

View File

@ -227,13 +227,13 @@ public abstract class AbstractSessionCacheCommand extends AbstractCommand {
@Override
protected void doRunCacheCommand(KeycloakSession session, Cache<String, SessionEntityWrapper> cache) {
for (String id : cache.keySet()) {
SessionEntity entity = cache.get(id).getEntity();
for (var entry : cache.entrySet()) {
SessionEntity entity = entry.getValue().getEntity();
if (!(entity instanceof UserSessionEntity)) {
continue;
}
UserSessionEntity userSession = (UserSessionEntity) cache.get(id).getEntity();
log.info("list: key=" + id + ", value=" + toString(userSession));
UserSessionEntity userSession = (UserSessionEntity) entry.getValue().getEntity();
log.info("list: key=" + entry.getKey() + ", value=" + toString(userSession));
}
}
}