+
Skip to content

Replace keySet with entrySet. #40685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions common/src/main/java/org/keycloak/common/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ public enum ProfileName {
}

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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public void testStackOverflow() {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ private void mergeClients(RealmConfigData source) {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,7 @@ public static <T> void merge(T source, T dest) {
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ public void migrate(RealmModel realm, RealmRepresentation rep, boolean skipUserD

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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ public String buildHtmlForm(String actionUrl, Map<String, String> inputTypes) {

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>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public static AttributeStatementType createAttributeStatement(Map<String, Object

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();
Expand All @@ -95,14 +95,14 @@ public static AttributeStatementType createAttributeStatement(Map<String, Object

// 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)) {
Expand Down Expand Up @@ -233,4 +233,4 @@ private static AttributeType getX500Attribute(String name) {
att.setNameFormat(JBossSAMLURIConstants.ATTRIBUTE_FORMAT_URI.get());
return att;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,14 @@ public void writeAttributeTypeWithoutRootTag(AttributeType attributeType) throws
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);
}
}
Expand Down Expand Up @@ -392,4 +391,4 @@ private void write(SubjectConfirmationDataType subjectConfirmationData) throws P
private void write(BaseIDAbstractType baseId) throws ProcessingException {
throw logger.notImplementedYet("Method not implemented.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public String getNamespaceURI(String prefix) {
* @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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1539,9 +1539,8 @@ public static Resource toModel(ResourceRepresentation resource, ResourceServer r
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);
Expand All @@ -1550,8 +1549,8 @@ public static Resource toModel(ResourceRepresentation resource, ResourceServer r
}
}

for (String name : attributes.keySet()) {
existing.setAttribute(name, attributes.get(name));
for (var entry : attributes.entrySet()) {
existing.setAttribute(entry.getKey(), entry.getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,14 @@ private Map<String, List<String>> normalizeAttributes(Map<String, ?> attributes)
}

// 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 = normalizeAttributeValues(attributeName, user.getAttributes().getOrDefault(attributeName, EMPTY_VALUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@ public void prepare(PartialImportRepresentation partialImportRep, RealmModel rea
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ private void setUniqueIds(List<RoleRepresentation> realmRoles) {
}

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());
}
}
Expand All @@ -162,8 +162,9 @@ private void removeClientRoleSkips(PartialImportResults results,
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));
Expand Down Expand Up @@ -191,18 +192,19 @@ private void addResultsForOverwrittenRealmRoles(PartialImportResults results, Re
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);
}
}
}

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));
}
Expand Down Expand Up @@ -238,8 +240,9 @@ private void clientRoleAdds(PartialImportResults results,
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ private CorsErrorResponseException newUnsupportedGrantTypeException() {
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
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.
*
Expand Down Expand Up @@ -150,8 +152,8 @@ private void checkRealm() {


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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ private void checkUser() {
}

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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ private UserSessionModel createUserSession(CIBAAuthenticationRequest request, Ma
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public void testGetRawSecretUsingValidExpressions() {

// 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) {
Expand Down Expand Up @@ -163,9 +163,9 @@ public void testGetCharSecretUsingValidExpressions() {

// 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) {
Expand Down Expand Up @@ -249,9 +249,9 @@ public void testGetStringSecretUsingValidExpressions() {

// 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());
Expand Down Expand Up @@ -348,4 +348,4 @@ public void close() {
// nothing to do
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ private void assertElements(Document doc, String tagNamespace, String tagName, M
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()));
}
}
}
Expand Down
Loading
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载