Skip to content

Commit d37ce4c

Browse files
committed
8290368: Introduce LDAP and RMI protocol-specific object factory filters to JNDI implementation
Reviewed-by: dfuchs, rriggs, jpai
1 parent 21aeb9e commit d37ce4c

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
@@ -1376,17 +1376,18 @@ jdk.io.permissionsUseCanonicalPath=false
13761376
jdk.tls.alpnCharset=ISO_8859_1
13771377

13781378
#
1379-
# JNDI Object Factories Filter
1379+
# Global JNDI Object Factories Filter
13801380
#
13811381
# This filter is used by the JNDI runtime to control the set of object factory classes
13821382
# which will be allowed to instantiate objects from object references returned by
13831383
# naming/directory systems. The factory class named by the reference instance will be
13841384
# matched against this filter. The filter property supports pattern-based filter syntax
1385-
# with the same format as jdk.serialFilter.
1385+
# with the same format as jdk.serialFilter. Limit patterns specified in the filter property
1386+
# are unused.
13861387
#
1387-
# Each pattern is matched against the factory class name to allow or disallow it's
1388-
# instantiation. The access to a factory class is allowed unless the filter returns
1389-
# REJECTED.
1388+
# Each class name pattern is matched against the factory class name to allow or disallow its
1389+
# instantiation. The access to a factory class is allowed if the filter returns
1390+
# ALLOWED.
13901391
#
13911392
# Note: This property is currently used by the JDK Reference implementation.
13921393
# It is not guaranteed to be examined and used by other implementations.
@@ -1398,6 +1399,58 @@ jdk.tls.alpnCharset=ISO_8859_1
13981399
# instance to recreate the referenced object.
13991400
#jdk.jndi.object.factoriesFilter=*
14001401

1402+
#
1403+
# Protocol Specific JNDI/LDAP Object Factories Filter
1404+
#
1405+
# This filter is used by the JNDI/LDAP provider implementation in the JDK to further control the
1406+
# set of object factory classes which will be allowed to instantiate objects from object
1407+
# references bound to LDAP contexts. The factory class named by the reference instance will
1408+
# be matched against this filter. The filter property supports pattern-based filter syntax
1409+
# with the same format as jdk.serialFilter. Limit patterns specified in the filter property
1410+
# are unused.
1411+
#
1412+
# Each class name pattern is matched against the factory class name to allow or disallow its
1413+
# instantiation. The access to a factory class is allowed only when it is not rejected by this filter
1414+
# or by the global filter defined by "jdk.jndi.object.factoriesFilter", and at least one of these
1415+
# two filters returns ALLOWED.
1416+
#
1417+
# Note: This property is currently used by the JDK Reference implementation.
1418+
# It is not guaranteed to be examined and used by other implementations.
1419+
#
1420+
# If the system property jdk.jndi.ldap.object.factoriesFilter is also specified, it supersedes
1421+
# the security property value defined here. The default value of the property is
1422+
# "java.naming/com.sun.jndi.ldap.**;!*".
1423+
#
1424+
# The default pattern value allows any object factory class defined in the java.naming module
1425+
# to be specified by the reference instance, but rejects any other.
1426+
#jdk.jndi.ldap.object.factoriesFilter=java.naming/com.sun.jndi.ldap.**;!*
1427+
1428+
#
1429+
# Protocol Specific JNDI/RMI Object Factories Filter
1430+
#
1431+
# This filter is used by the JNDI/RMI provider implementation in the JDK to further control the
1432+
# set of object factory classes which will be allowed to instantiate objects from object
1433+
# references bound to RMI names. The factory class named by the reference instance will
1434+
# be matched against this filter. The filter property supports pattern-based filter syntax
1435+
# with the same format as jdk.serialFilter. Limit patterns specified in the filter property
1436+
# are unused.
1437+
#
1438+
# Each class name pattern is matched against the factory class name to allow or disallow its
1439+
# instantiation. The access to a factory class is allowed only when it is not rejected by this filter
1440+
# or by the global filter defined by "jdk.jndi.object.factoriesFilter", and at least one of these
1441+
# two filters returns ALLOWED.
1442+
#
1443+
# Note: This property is currently used by the JDK Reference implementation.
1444+
# It is not guaranteed to be examined and used by other implementations.
1445+
#
1446+
# If the system property jdk.jndi.rmi.object.factoriesFilter is also specified, it supersedes
1447+
# the security property value defined here. The default value of the property is
1448+
# "jdk.naming.rmi/com.sun.jndi.rmi.**;!*".
1449+
#
1450+
# The default pattern value allows any object factory class defined in the jdk.naming.rmi module
1451+
# to be specified by the reference instance, but rejects any other.
1452+
#jdk.jndi.rmi.object.factoriesFilter=jdk.naming.rmi/com.sun.jndi.rmi.**;!*
1453+
14011454
#
14021455
# Policy for non-forwardable service ticket in a S4U2proxy request
14031456
#

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, 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,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)