Skip to content

Commit 39a6bf2

Browse files
committed
8290368: Introduce LDAP and RMI protocol-specific object factory filters to JNDI implementation
Reviewed-by: phh, rrich Backport-of: d37ce4cdd18afc4facf996598f79e72aae68f4ff
1 parent e827597 commit 39a6bf2

File tree

22 files changed

+1263
-355
lines changed

22 files changed

+1263
-355
lines changed

src/java.base/share/conf/security/java.security

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,17 +1372,18 @@ jdk.io.permissionsUseCanonicalPath=false
13721372
jdk.tls.alpnCharset=ISO_8859_1
13731373

13741374
#
1375-
# JNDI Object Factories Filter
1375+
# Global JNDI Object Factories Filter
13761376
#
13771377
# This filter is used by the JNDI runtime to control the set of object factory classes
13781378
# which will be allowed to instantiate objects from object references returned by
13791379
# naming/directory systems. The factory class named by the reference instance will be
13801380
# matched against this filter. The filter property supports pattern-based filter syntax
1381-
# with the same format as jdk.serialFilter.
1381+
# with the same format as jdk.serialFilter. Limit patterns specified in the filter property
1382+
# are unused.
13821383
#
1383-
# Each pattern is matched against the factory class name to allow or disallow it's
1384-
# instantiation. The access to a factory class is allowed unless the filter returns
1385-
# REJECTED.
1384+
# Each class name pattern is matched against the factory class name to allow or disallow its
1385+
# instantiation. The access to a factory class is allowed if the filter returns
1386+
# ALLOWED.
13861387
#
13871388
# Note: This property is currently used by the JDK Reference implementation.
13881389
# It is not guaranteed to be examined and used by other implementations.
@@ -1393,3 +1394,55 @@ jdk.tls.alpnCharset=ISO_8859_1
13931394
# The default pattern value allows any object factory class specified by the reference
13941395
# instance to recreate the referenced object.
13951396
#jdk.jndi.object.factoriesFilter=*
1397+
1398+
#
1399+
# Protocol Specific JNDI/LDAP Object Factories Filter
1400+
#
1401+
# This filter is used by the JNDI/LDAP provider implementation in the JDK to further control the
1402+
# set of object factory classes which will be allowed to instantiate objects from object
1403+
# references bound to LDAP contexts. The factory class named by the reference instance will
1404+
# be matched against this filter. The filter property supports pattern-based filter syntax
1405+
# with the same format as jdk.serialFilter. Limit patterns specified in the filter property
1406+
# are unused.
1407+
#
1408+
# Each class name pattern is matched against the factory class name to allow or disallow its
1409+
# instantiation. The access to a factory class is allowed only when it is not rejected by this filter
1410+
# or by the global filter defined by "jdk.jndi.object.factoriesFilter", and at least one of these
1411+
# two filters returns ALLOWED.
1412+
#
1413+
# Note: This property is currently used by the JDK Reference implementation.
1414+
# It is not guaranteed to be examined and used by other implementations.
1415+
#
1416+
# If the system property jdk.jndi.ldap.object.factoriesFilter is also specified, it supersedes
1417+
# the security property value defined here. The default value of the property is
1418+
# "java.naming/com.sun.jndi.ldap.**;!*".
1419+
#
1420+
# The default pattern value allows any object factory class defined in the java.naming module
1421+
# to be specified by the reference instance, but rejects any other.
1422+
#jdk.jndi.ldap.object.factoriesFilter=java.naming/com.sun.jndi.ldap.**;!*
1423+
1424+
#
1425+
# Protocol Specific JNDI/RMI Object Factories Filter
1426+
#
1427+
# This filter is used by the JNDI/RMI provider implementation in the JDK to further control the
1428+
# set of object factory classes which will be allowed to instantiate objects from object
1429+
# references bound to RMI names. The factory class named by the reference instance will
1430+
# be matched against this filter. The filter property supports pattern-based filter syntax
1431+
# with the same format as jdk.serialFilter. Limit patterns specified in the filter property
1432+
# are unused.
1433+
#
1434+
# Each class name pattern is matched against the factory class name to allow or disallow its
1435+
# instantiation. The access to a factory class is allowed only when it is not rejected by this filter
1436+
# or by the global filter defined by "jdk.jndi.object.factoriesFilter", and at least one of these
1437+
# two filters returns ALLOWED.
1438+
#
1439+
# Note: This property is currently used by the JDK Reference implementation.
1440+
# It is not guaranteed to be examined and used by other implementations.
1441+
#
1442+
# If the system property jdk.jndi.rmi.object.factoriesFilter is also specified, it supersedes
1443+
# the security property value defined here. The default value of the property is
1444+
# "jdk.naming.rmi/com.sun.jndi.rmi.**;!*".
1445+
#
1446+
# The default pattern value allows any object factory class defined in the jdk.naming.rmi module
1447+
# to be specified by the reference instance, but rejects any other.
1448+
#jdk.jndi.rmi.object.factoriesFilter=jdk.naming.rmi/com.sun.jndi.rmi.**;!*

src/java.naming/share/classes/com/sun/jndi/ldap/LdapBindingEnumeration.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,9 +33,10 @@
3333
import javax.naming.*;
3434
import javax.naming.directory.*;
3535
import javax.naming.ldap.Control;
36-
import javax.naming.spi.*;
3736

3837
import com.sun.jndi.toolkit.ctx.Continuation;
38+
import com.sun.naming.internal.NamingManagerHelper;
39+
import com.sun.naming.internal.ObjectFactoriesFilter;
3940

4041
final class LdapBindingEnumeration
4142
extends AbstractLdapNamingEnumeration<Binding> {
@@ -76,8 +77,8 @@ final class LdapBindingEnumeration
7677
cn.add(atom);
7778

7879
try {
79-
obj = DirectoryManager.getObjectInstance(obj, cn, homeCtx,
80-
homeCtx.envprops, attrs);
80+
obj = NamingManagerHelper.getDirObjectInstance(obj, cn, homeCtx,
81+
homeCtx.envprops, attrs, ObjectFactoriesFilter::checkLdapFilter);
8182

8283
} catch (NamingException e) {
8384
throw e;

src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,6 @@
2727

2828
import javax.naming.*;
2929
import javax.naming.directory.*;
30-
import javax.naming.spi.*;
3130
import javax.naming.event.*;
3231
import javax.naming.ldap.*;
3332
import javax.naming.ldap.LdapName;
@@ -54,6 +53,8 @@
5453
import com.sun.jndi.toolkit.dir.HierMemDirCtx;
5554
import com.sun.jndi.toolkit.dir.SearchFilter;
5655
import com.sun.jndi.ldap.ext.StartTlsResponseImpl;
56+
import com.sun.naming.internal.NamingManagerHelper;
57+
import com.sun.naming.internal.ObjectFactoriesFilter;
5758

5859
/**
5960
* The LDAP context implementation.
@@ -1111,8 +1112,8 @@ protected Object c_lookup(Name name, Continuation cont)
11111112
}
11121113

11131114
try {
1114-
return DirectoryManager.getObjectInstance(obj, name,
1115-
this, envprops, attrs);
1115+
return NamingManagerHelper.getDirObjectInstance(obj, name, this,
1116+
envprops, attrs, ObjectFactoriesFilter::checkLdapFilter);
11161117

11171118
} catch (NamingException e) {
11181119
throw cont.fillInException(e);

src/java.naming/share/classes/com/sun/jndi/ldap/LdapReferralContext.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,12 +27,13 @@
2727

2828
import javax.naming.*;
2929
import javax.naming.directory.*;
30-
import javax.naming.spi.*;
3130
import javax.naming.ldap.*;
3231

3332
import java.util.Hashtable;
3433
import java.util.StringTokenizer;
3534
import com.sun.jndi.toolkit.dir.SearchFilter;
35+
import com.sun.naming.internal.NamingManagerHelper;
36+
import com.sun.naming.internal.ObjectFactoriesFilter;
3637

3738
/**
3839
* A context for handling referrals.
@@ -116,8 +117,8 @@ final class LdapReferralContext implements DirContext, LdapContext {
116117

117118
Object obj;
118119
try {
119-
obj = NamingManager.getObjectInstance(ref, null, null, env);
120-
120+
obj = NamingManagerHelper.getObjectInstance(ref, null, null,
121+
env, ObjectFactoriesFilter::checkLdapFilter);
121122
} catch (NamingException e) {
122123

123124
if (handleReferrals == LdapClient.LDAP_REF_THROW) {

src/java.naming/share/classes/com/sun/jndi/ldap/LdapSearchEnumeration.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,11 +32,12 @@
3232
import java.util.Vector;
3333
import javax.naming.*;
3434
import javax.naming.directory.*;
35-
import javax.naming.spi.*;
3635
import javax.naming.ldap.*;
3736
import javax.naming.ldap.LdapName;
3837

3938
import com.sun.jndi.toolkit.ctx.Continuation;
39+
import com.sun.naming.internal.NamingManagerHelper;
40+
import com.sun.naming.internal.ObjectFactoriesFilter;
4041

4142
final class LdapSearchEnumeration
4243
extends AbstractLdapNamingEnumeration<SearchResult> {
@@ -134,9 +135,9 @@ protected SearchResult createItem(String dn, Attributes attrs,
134135
// Call getObjectInstance before removing unrequested attributes
135136
try {
136137
// rcn is either relative to homeCtx or a fully qualified DN
137-
obj = DirectoryManager.getObjectInstance(
138+
obj = NamingManagerHelper.getDirObjectInstance(
138139
obj, rcn, (relative ? homeCtx : null),
139-
homeCtx.envprops, attrs);
140+
homeCtx.envprops, attrs, ObjectFactoriesFilter::checkLdapFilter);
140141
} catch (NamingException e) {
141142
throw e;
142143
} catch (Exception e) {

0 commit comments

Comments
 (0)