Path: blob/master/src/java.naming/share/classes/com/sun/jndi/ldap/LdapBindingEnumeration.java
41161 views
/*1* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.jndi.ldap;2627import java.security.AccessControlContext;28import java.security.AccessController;29import java.security.PrivilegedActionException;30import java.security.PrivilegedExceptionAction;31import java.util.Vector;32import javax.naming.*;33import javax.naming.directory.*;34import javax.naming.ldap.Control;35import javax.naming.spi.*;3637import com.sun.jndi.toolkit.ctx.Continuation;3839final class LdapBindingEnumeration40extends AbstractLdapNamingEnumeration<Binding> {4142@SuppressWarnings("removal")43private final AccessControlContext acc = AccessController.getContext();4445LdapBindingEnumeration(LdapCtx homeCtx, LdapResult answer, Name remain,46Continuation cont) throws NamingException47{48super(homeCtx, answer, remain, cont);49}5051@SuppressWarnings("removal")52@Override53protected Binding54createItem(String dn, Attributes attrs, Vector<Control> respCtls)55throws NamingException {5657Object obj = null;58String atom = getAtom(dn);5960if (attrs.get(Obj.JAVA_ATTRIBUTES[Obj.CLASSNAME]) != null) {61// serialized object or object reference62try {63PrivilegedExceptionAction<Object> pa = () -> Obj.decodeObject(attrs);64obj = AccessController.doPrivileged(pa, acc);65} catch (PrivilegedActionException e) {66throw (NamingException)e.getException();67}68}69if (obj == null) {70// DirContext object71obj = new LdapCtx(homeCtx, dn);72}7374CompositeName cn = new CompositeName();75cn.add(atom);7677try {78obj = DirectoryManager.getObjectInstance(obj, cn, homeCtx,79homeCtx.envprops, attrs);8081} catch (NamingException e) {82throw e;8384} catch (Exception e) {85NamingException ne =86new NamingException(87"problem generating object using object factory");88ne.setRootCause(e);89throw ne;90}9192Binding binding;93if (respCtls != null) {94binding = new BindingWithControls(cn.toString(), obj,95homeCtx.convertControls(respCtls));96} else {97binding = new Binding(cn.toString(), obj);98}99binding.setNameInNamespace(dn);100return binding;101}102103@Override104protected AbstractLdapNamingEnumeration<? extends NameClassPair> getReferredResults(105LdapReferralContext refCtx) throws NamingException{106// repeat the original operation at the new context107return (AbstractLdapNamingEnumeration<? extends NameClassPair>)refCtx.listBindings(listArg);108}109}110111112