You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "efegokdemir (via GitHub)" <gi...@apache.org> on 2026/09/26 11:18:56 UTC
[PR] Honor legacy basic authentication encoding property [logging-log4j2]
efegokdemir opened a new pull request, #4358:
URL: https://github.com/apache/logging-log4j2/pull/4358
Fixes #4347
## Problem
`BasicAuthorizationProvider` reads `logging.auth.encoding` with an overload that applies the platform default charset. When that property is absent, it also discarded the fallback lookup for the Spring-compatible property.
## Solution
- Read the legacy property without an implicit platform-default fallback.
- Assign the Spring-compatible property lookup result so UTF-8 is used when neither property is configured.
- Add a regression test covering non-ASCII credentials and the legacy encoding property.
- Add the required 2.x changelog entry.
## Testing
- `./mvnw -pl :log4j-core-test -am -Dtest=BasicAuthorizationProviderTest -Dsurefire.failIfNoSpecifiedTests=false -Dspotless.check.skip=true -Dspotless.apply.skip=true -Drat.skip=true -Dcheckstyle.skip=true test` — passed
- `git diff --check` — passed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Honor legacy basic authentication encoding property [logging-log4j2]
Posted by "ramanathan1504 (via GitHub)" <gi...@apache.org>.
ramanathan1504 commented on code in PR #4358:
URL: https://github.com/apache/logging-log4j2/pull/4358#discussion_r4126734642
##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/BasicAuthorizationProviderTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.core.util;
+
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.net.URLConnection;
+import java.util.Base64;
+import java.util.Properties;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.junit.jupiter.api.Test;
+
+class BasicAuthorizationProviderTest {
+
+ @Test
+ void usesLegacyEncodingPropertyWhenPrimaryPropertyIsAbsent() throws Exception {
+ final Properties properties = new Properties();
+ properties.setProperty("logging.auth.username", "usér");
+ properties.setProperty("logging.auth.password", "passé");
+ properties.setProperty("logging.auth.encoding", ISO_8859_1.name());
+ final BasicAuthorizationProvider provider = new BasicAuthorizationProvider(new PropertiesUtil(properties));
+
+ final RecordingURLConnection connection = new RecordingURLConnection();
+ provider.addAuthorization(connection);
+
+ final String credentials = "usér:passé";
+ final String expected = "Basic " + Base64.getEncoder().encodeToString(credentials.getBytes(ISO_8859_1));
+ assertThat(connection.requestValue).isEqualTo(expected);
+ }
Review Comment:
The UTF-8 default is the other half of #4347 and has no test. Changing the fallback to `ISO_8859_1` keeps this class green.
```suggestion
}
@Test
void defaultsToUtf8WhenNoEncodingPropertyIsSet() throws Exception {
final Properties properties = new Properties();
properties.setProperty("logging.auth.username", "usér");
properties.setProperty("logging.auth.password", "passé");
final BasicAuthorizationProvider provider = new BasicAuthorizationProvider(new PropertiesUtil(properties));
final RecordingURLConnection connection = new RecordingURLConnection();
provider.addAuthorization(connection);
final String expected = "Basic " + Base64.getEncoder().encodeToString("usér:passé".getBytes(UTF_8));
assertThat(connection.requestValue).isEqualTo(expected);
}
```
Needs `import static java.nio.charset.StandardCharsets.UTF_8;`.
##########
src/changelog/.2.x.x/4347_auth_encoding.xml:
##########
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="https://logging.apache.org/xml/ns"
+ xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="fixed">
+ <issue id="4347" link="https://github.com/apache/logging-log4j2/issues/4347"/>
+ <description format="asciidoc">
+ Honor the legacy `logging.auth.encoding` property when configuring HTTP Basic Authentication.
Review Comment:
```suggestion
Honor `logging.auth.encoding` and default to UTF-8 when encoding HTTP Basic Authentication credentials.
```
##########
src/changelog/.2.x.x/4347_auth_encoding.xml:
##########
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="https://logging.apache.org/xml/ns"
+ xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="fixed">
+ <issue id="4347" link="https://github.com/apache/logging-log4j2/issues/4347"/>
Review Comment:
```suggestion
<issue id="4347" link="https://github.com/apache/logging-log4j2/issues/4347"/>
<issue id="4358" link="https://github.com/apache/logging-log4j2/pull/4358"/>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Honor legacy basic authentication encoding property [logging-log4j2]
Posted by "ramanathan1504 (via GitHub)" <gi...@apache.org>.
ramanathan1504 commented on code in PR #4358:
URL: https://github.com/apache/logging-log4j2/pull/4358#discussion_r4199809000
##########
src/changelog/.2.x.x/4347_auth_encoding.xml:
##########
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="https://logging.apache.org/xml/ns"
+ xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="fixed">
+ <issue id="4347" link="https://github.com/apache/logging-log4j2/issues/4347"/>
Review Comment:
The changelog at e76c3a6 still has only the 4347 issue line. Can you add the pull/4358 line from the suggestion?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Honor legacy basic authentication encoding property [logging-log4j2]
Posted by "efegokdemir (via GitHub)" <gi...@apache.org>.
efegokdemir commented on code in PR #4358:
URL: https://github.com/apache/logging-log4j2/pull/4358#discussion_r4149809286
##########
src/changelog/.2.x.x/4347_auth_encoding.xml:
##########
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="https://logging.apache.org/xml/ns"
+ xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="fixed">
+ <issue id="4347" link="https://github.com/apache/logging-log4j2/issues/4347"/>
Review Comment:
Correction: current HEAD e76c3a6 documents the UTF-8 default and links PR 4358 in the changelog.
##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/BasicAuthorizationProviderTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.core.util;
+
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.net.URLConnection;
+import java.util.Base64;
+import java.util.Properties;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.junit.jupiter.api.Test;
+
+class BasicAuthorizationProviderTest {
+
+ @Test
+ void usesLegacyEncodingPropertyWhenPrimaryPropertyIsAbsent() throws Exception {
+ final Properties properties = new Properties();
+ properties.setProperty("logging.auth.username", "usér");
+ properties.setProperty("logging.auth.password", "passé");
+ properties.setProperty("logging.auth.encoding", ISO_8859_1.name());
+ final BasicAuthorizationProvider provider = new BasicAuthorizationProvider(new PropertiesUtil(properties));
+
+ final RecordingURLConnection connection = new RecordingURLConnection();
+ provider.addAuthorization(connection);
+
+ final String credentials = "usér:passé";
+ final String expected = "Basic " + Base64.getEncoder().encodeToString(credentials.getBytes(ISO_8859_1));
+ assertThat(connection.requestValue).isEqualTo(expected);
+ }
Review Comment:
Correction: current HEAD e76c3a6 adds the no-encoding regression with non-ASCII credentials and asserts exact UTF-8 Basic Auth bytes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Honor legacy basic authentication encoding property [logging-log4j2]
Posted by "ramanathan1504 (via GitHub)" <gi...@apache.org>.
ramanathan1504 commented on code in PR #4358:
URL: https://github.com/apache/logging-log4j2/pull/4358#discussion_r4202925198
##########
src/changelog/.2.x.x/4347_auth_encoding.xml:
##########
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="https://logging.apache.org/xml/ns"
+ xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="fixed">
+ <issue id="4347" link="https://github.com/apache/logging-log4j2/issues/4347"/>
+ <issue id="4358" link="https://github.com/apache/logging-log4j2/pull/4358"/>
+ <description format="asciidoc">
+ Honor the legacy `logging.auth.encoding` property when configuring HTTP Basic Authentication and default to UTF-8 when no encoding property is configured.
Review Comment:
```suggestion
Honor `logging.auth.encoding` and default to UTF-8 in HTTP Basic Authentication.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Honor legacy basic authentication encoding property [logging-log4j2]
Posted by "efegokdemir (via GitHub)" <gi...@apache.org>.
efegokdemir commented on code in PR #4358:
URL: https://github.com/apache/logging-log4j2/pull/4358#discussion_r4149807274
##########
src/changelog/.2.x.x/4347_auth_encoding.xml:
##########
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="https://logging.apache.org/xml/ns"
+ xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="fixed">
+ <issue id="4347" link="https://github.com/apache/logging-log4j2/issues/4347"/>
Review Comment:
Implemented in the current HEAD ; the changelog now explicitly documents the UTF-8 default and links PR #4358.
##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/BasicAuthorizationProviderTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.core.util;
+
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.net.URLConnection;
+import java.util.Base64;
+import java.util.Properties;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.junit.jupiter.api.Test;
+
+class BasicAuthorizationProviderTest {
+
+ @Test
+ void usesLegacyEncodingPropertyWhenPrimaryPropertyIsAbsent() throws Exception {
+ final Properties properties = new Properties();
+ properties.setProperty("logging.auth.username", "usér");
+ properties.setProperty("logging.auth.password", "passé");
+ properties.setProperty("logging.auth.encoding", ISO_8859_1.name());
+ final BasicAuthorizationProvider provider = new BasicAuthorizationProvider(new PropertiesUtil(properties));
+
+ final RecordingURLConnection connection = new RecordingURLConnection();
+ provider.addAuthorization(connection);
+
+ final String credentials = "usér:passé";
+ final String expected = "Basic " + Base64.getEncoder().encodeToString(credentials.getBytes(ISO_8859_1));
+ assertThat(connection.requestValue).isEqualTo(expected);
+ }
Review Comment:
Implemented in the current HEAD . The new regression sets non-ASCII credentials with no encoding property and asserts the exact UTF-8 Basic Auth bytes, so an ISO-8859-1 fallback no longer passes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Honor legacy basic authentication encoding property [logging-log4j2]
Posted by "ramanathan1504 (via GitHub)" <gi...@apache.org>.
ramanathan1504 merged PR #4358:
URL: https://github.com/apache/logging-log4j2/pull/4358
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Honor legacy basic authentication encoding property [logging-log4j2]
Posted by "efegokdemir (via GitHub)" <gi...@apache.org>.
efegokdemir commented on PR #4358:
URL: https://github.com/apache/logging-log4j2/pull/4358#issuecomment-5888727670
Updated in `07623e6`. Added a regression test that verifies non-ASCII credentials use UTF-8 when no encoding property is configured, and clarified the changelog entry to document that default.
`git diff --check` passes. The focused Maven test could not start in this environment because only Java 8 is installed while the Maven wrapper requires `--add-exports`; CI should provide the supported JDK.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org