001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import com.liferay.portal.kernel.io.ProtectedObjectInputStream;
018    
019    import java.io.IOException;
020    import java.io.InputStream;
021    import java.io.ObjectStreamClass;
022    
023    /**
024     * @author Mika Koivisto
025     */
026    public class ProtectedClassLoaderObjectInputStream
027            extends ProtectedObjectInputStream {
028    
029            public ProtectedClassLoaderObjectInputStream(
030                            InputStream inputStream, ClassLoader classLoader)
031                    throws IOException {
032    
033                    super(inputStream);
034    
035                    _classLoader = classLoader;
036            }
037    
038            @Override
039            protected Class<?> doResolveClass(ObjectStreamClass objectStreamClass)
040                    throws ClassNotFoundException {
041    
042                    String name = objectStreamClass.getName();
043    
044                    return ClassResolverUtil.resolve(name, _classLoader);
045            }
046    
047            private final ClassLoader _classLoader;
048    
049    }