Skip to content

Commit

Permalink
Merge pull request #25076 from avpinchuk/remote-jndi-lookup
Browse files Browse the repository at this point in the history
Fixes remote JNDI lookup
  • Loading branch information
dmatej authored Aug 8, 2024
2 parents 27557a2 + 65a7d23 commit f147fb9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -65,7 +66,7 @@ public Hashtable list(String name) throws NamingException, RemoteException {
for(Iterator<Map.Entry> it = entrySet.iterator(); it.hasNext();) {
Object val = it.next().getValue();
// Issue 17219 skip non-serializable values for remote client.
if(!(val instanceof java.io.Serializable) || val instanceof Context) {
if(!(val instanceof java.io.Serializable)) {
it.remove();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,6 +17,7 @@

package com.sun.enterprise.naming.impl;

import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.Enumeration;
import java.util.HashMap;
Expand Down Expand Up @@ -60,7 +61,7 @@ public class TransientContext implements Context, Serializable {
private static NameParser myParser = new SerialNameParser();

private Hashtable<Object, Object> myEnv;
private final Map<String, Object> bindings = new HashMap<>();
private final Map<String, Object> bindings = new BindingMap();

// Issue 7067: lots of lookup failures in a heavily concurrent client.
// So add a read/write lock, which allows unlimited concurrent readers,
Expand Down Expand Up @@ -809,4 +810,19 @@ public void close() {
//no-op since no steps needed to free up resources
}
}

/**
* A map that excludes non-serializable values from serialization.
*/
static class BindingMap extends HashMap<String, Object> {

private static final long serialVersionUID = 1L;

public Object writeReplace() throws ObjectStreamException {
BindingMap bindingMap = (BindingMap) clone();
// Skip non-serializable values for remote client
bindingMap.entrySet().removeIf(binding -> !(binding.getValue() instanceof Serializable));
return bindingMap;
}
}
}

0 comments on commit f147fb9

Please sign in to comment.