You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2025/02/01 20:16:57 UTC
(cxf) branch 4.0.x-fixes updated (918f9a3ef4 -> eb3b85326e)
This is an automated email from the ASF dual-hosted git repository.
reta pushed a change to branch 4.0.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
from 918f9a3ef4 Recording .gitmergeinfo Changes
new 28612db362 [CXF-9105] add synchronized to the principal iteration (#2245)
new 56aad2830e If is unnecessary - return value is same with or without the if (#2243)
new eb3b85326e [CXF-9105] add synchronized to the principal iteration. Fix DefaultLogEventMapperTest for JDK-23 and above
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../ext/logging/event/DefaultLogEventMapper.java | 37 +++++++++-----
.../cxf/ext/logging/DefaultLogEventMapperTest.java | 59 ++++++++++++++++++++++
.../cxf/tools/validator/internal/Stax2DOM.java | 3 --
3 files changed, 83 insertions(+), 16 deletions(-)
(cxf) 01/03: [CXF-9105] add synchronized to the principal iteration (#2245)
Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch 4.0.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 28612db362733d9bb23e4007b8ffcdddea831d7b
Author: sstremler <st...@gmail.com>
AuthorDate: Sat Feb 1 15:33:35 2025 +0100
[CXF-9105] add synchronized to the principal iteration (#2245)
(cherry picked from commit 96aca2ebaece9348c9e3a7538e4d45b66537c22c)
---
.../ext/logging/event/DefaultLogEventMapper.java | 37 ++++++++++++++--------
.../cxf/ext/logging/DefaultLogEventMapperTest.java | 29 +++++++++++++++++
2 files changed, 53 insertions(+), 13 deletions(-)
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/DefaultLogEventMapper.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/DefaultLogEventMapper.java
index 2e77c8df64..6140201fee 100644
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/DefaultLogEventMapper.java
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/DefaultLogEventMapper.java
@@ -19,6 +19,7 @@
package org.apache.cxf.ext.logging.event;
import java.security.AccessController;
+import java.security.Principal;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -109,7 +110,7 @@ public class DefaultLogEventMapper {
}
private String getPrincipal(Message message) {
- String principal = getJAASPrincipal();
+ String principal = getConcatenatedJAASPrincipals();
if (principal != null) {
return principal;
}
@@ -125,31 +126,41 @@ public class DefaultLogEventMapper {
return null;
}
- private String getJAASPrincipal() {
- StringBuilder principals = new StringBuilder();
- Iterator<? extends Object> principalIt = getJAASPrincipals();
- while (principalIt.hasNext()) {
- principals.append(principalIt.next());
- if (principalIt.hasNext()) {
- principals.append(',');
+ private String getConcatenatedJAASPrincipals() {
+ StringBuilder principalsStringBuilder = new StringBuilder();
+ Set<Principal> principals = getJAASPrincipals();
+
+ if (principals.isEmpty()) {
+ return null;
+ }
+
+ synchronized (principals) {
+ Iterator<Principal> principalIt = principals.iterator();
+ while (principalIt.hasNext()) {
+ principalsStringBuilder.append(principalIt.next());
+ if (principalIt.hasNext()) {
+ principalsStringBuilder.append(',');
+ }
}
}
- if (principals.length() == 0) {
+
+ if (principalsStringBuilder.length() == 0) {
return null;
}
- return principals.toString();
+
+ return principalsStringBuilder.toString();
}
- private Iterator<? extends Object> getJAASPrincipals() {
+ private Set<Principal> getJAASPrincipals() {
try {
Subject subject = Subject.getSubject(AccessController.getContext());
return subject != null && subject.getPrincipals() != null
- ? subject.getPrincipals().iterator() : Collections.emptyIterator();
+ ? subject.getPrincipals() : Collections.emptySet();
} catch (UnsupportedOperationException e) {
// JDK 23: The terminally deprecated method Subject.getSubject(AccessControlContext) has been re-specified
// to throw UnsupportedOperationException if invoked when a Security Manager is not allowed.
// see https://jdk.java.net/23/release-notes#JDK-8296244
- return Collections.emptyIterator();
+ return Collections.emptySet();
}
}
diff --git a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/DefaultLogEventMapperTest.java b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/DefaultLogEventMapperTest.java
index 9df839e6b6..f7c2a765c1 100644
--- a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/DefaultLogEventMapperTest.java
+++ b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/DefaultLogEventMapperTest.java
@@ -18,13 +18,20 @@
*/
package org.apache.cxf.ext.logging;
+import java.security.Principal;
+import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import javax.security.auth.Subject;
+
+import org.apache.cxf.common.security.SimplePrincipal;
import org.apache.cxf.ext.logging.event.DefaultLogEventMapper;
import org.apache.cxf.ext.logging.event.EventType;
import org.apache.cxf.ext.logging.event.LogEvent;
@@ -147,4 +154,26 @@ public class DefaultLogEventMapperTest {
assertEquals("PUT[test]", event.getOperationName());
}
+ @Test
+ public void testMultiplePrincipalsReturnedByAccessControllerContext() {
+ DefaultLogEventMapper mapper = new DefaultLogEventMapper();
+ Message message = new MessageImpl();
+ message.put(Message.HTTP_REQUEST_METHOD, "GET");
+ message.put(Message.REQUEST_URI, "test");
+ Exchange exchange = new ExchangeImpl();
+ message.setExchange(exchange);
+
+ Set<Principal> principals = IntStream.range(0, 3)
+ .mapToObj(i -> new SimplePrincipal("principal-" + i))
+ .collect(Collectors.toSet());
+
+ Subject subject = new Subject(false, principals, Set.of(), Set.of());
+
+ LogEvent event = Subject.doAs(subject, (PrivilegedAction<LogEvent>) () -> mapper.map(message));
+ String[] splitPrincipals = event.getPrincipal().split(",");
+ Set<String> expected = Set.of("principal-0", "principal-1", "principal-2");
+
+ assertEquals(expected, Arrays.stream(splitPrincipals).collect(Collectors.toSet()));
+ }
+
}
(cxf) 03/03: [CXF-9105] add synchronized to the principal iteration. Fix DefaultLogEventMapperTest for JDK-23 and above
Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch 4.0.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit eb3b85326e018291c6ef98404ccea4c65abeab0f
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Sat Feb 1 10:53:46 2025 -0500
[CXF-9105] add synchronized to the principal iteration. Fix DefaultLogEventMapperTest for JDK-23 and above
(cherry picked from commit 9b2ad3e96cd723cebb66d08b7bbd534148c3a999)
---
.../cxf/ext/logging/DefaultLogEventMapperTest.java | 30 ++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/DefaultLogEventMapperTest.java b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/DefaultLogEventMapperTest.java
index f7c2a765c1..f502d8e8de 100644
--- a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/DefaultLogEventMapperTest.java
+++ b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/DefaultLogEventMapperTest.java
@@ -43,7 +43,13 @@ import org.apache.cxf.message.MessageImpl;
import org.junit.Test;
import static org.apache.cxf.ext.logging.event.DefaultLogEventMapper.MASKED_HEADER_VALUE;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeThat;
public class DefaultLogEventMapperTest {
@@ -156,6 +162,9 @@ public class DefaultLogEventMapperTest {
@Test
public void testMultiplePrincipalsReturnedByAccessControllerContext() {
+ assumeThat("Subject::getSubject is not supported in JDK-23 and above",
+ Runtime.version().feature(), lessThanOrEqualTo(22));
+
DefaultLogEventMapper mapper = new DefaultLogEventMapper();
Message message = new MessageImpl();
message.put(Message.HTTP_REQUEST_METHOD, "GET");
@@ -176,4 +185,25 @@ public class DefaultLogEventMapperTest {
assertEquals(expected, Arrays.stream(splitPrincipals).collect(Collectors.toSet()));
}
+ @Test
+ public void testNoSubjectReturned() {
+ assumeThat("Subject::getSubject is not supported in JDK-23 and above",
+ Runtime.version().feature(), greaterThanOrEqualTo(23));
+
+ DefaultLogEventMapper mapper = new DefaultLogEventMapper();
+ Message message = new MessageImpl();
+ message.put(Message.HTTP_REQUEST_METHOD, "GET");
+ message.put(Message.REQUEST_URI, "test");
+ Exchange exchange = new ExchangeImpl();
+ message.setExchange(exchange);
+
+ Set<Principal> principals = IntStream.range(0, 3)
+ .mapToObj(i -> new SimplePrincipal("principal-" + i))
+ .collect(Collectors.toSet());
+
+ Subject subject = new Subject(false, principals, Set.of(), Set.of());
+
+ LogEvent event = Subject.doAs(subject, (PrivilegedAction<LogEvent>) () -> mapper.map(message));
+ assertThat(event.getPrincipal(), is(nullValue()));
+ }
}
(cxf) 02/03: If is unnecessary - return value is same with or without the if (#2243)
Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch 4.0.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 56aad2830e4160170b3ba42089fed72ff512b181
Author: Tom Cunningham <tc...@redhat.com>
AuthorDate: Sat Feb 1 09:33:59 2025 -0500
If is unnecessary - return value is same with or without the if (#2243)
(cherry picked from commit 9aa8c12da8ecaeb34dcc6bd740d75d8ce73bea46)
---
.../main/java/org/apache/cxf/tools/validator/internal/Stax2DOM.java | 3 ---
1 file changed, 3 deletions(-)
diff --git a/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Stax2DOM.java b/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Stax2DOM.java
index 3bb20866b0..ad18295247 100644
--- a/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Stax2DOM.java
+++ b/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Stax2DOM.java
@@ -43,9 +43,6 @@ public class Stax2DOM {
public Document getDocument(String wsdl) throws ToolException {
try {
URI wsdlURI = new URI(URIParserUtil.getAbsoluteURI(wsdl));
- if (wsdlURI.toString().startsWith("http")) {
- return getDocument(wsdlURI.toURL());
- }
return getDocument(wsdlURI.toURL());
} catch (ToolException e) {
throw e;