001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.spring.servlet;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.security.ac.AccessControlThreadLocal;
020    import com.liferay.portal.spring.context.TunnelApplicationContext;
021    
022    import javax.servlet.ServletException;
023    import javax.servlet.http.HttpServletRequest;
024    import javax.servlet.http.HttpServletResponse;
025    
026    import org.springframework.web.servlet.DispatcherServlet;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class RemotingServlet extends DispatcherServlet {
032    
033            public static final String CONTEXT_CLASS =
034                    TunnelApplicationContext.class.getName();
035    
036            public static final String CONTEXT_CONFIG_LOCATION =
037                    "/WEB-INF/remoting-servlet.xml,/WEB-INF/remoting-servlet-ext.xml";
038    
039            @Override
040            public Class<?> getContextClass() {
041                    try {
042                            return Class.forName(CONTEXT_CLASS);
043                    }
044                    catch (Exception e) {
045                            _log.error(e, e);
046                    }
047    
048                    return null;
049            }
050    
051            @Override
052            public String getContextConfigLocation() {
053                    return CONTEXT_CONFIG_LOCATION;
054            }
055    
056            @Override
057            public void service(
058                            HttpServletRequest request, HttpServletResponse response)
059                    throws ServletException {
060    
061                    boolean remoteAccess = AccessControlThreadLocal.isRemoteAccess();
062    
063                    try {
064                            AccessControlThreadLocal.setRemoteAccess(true);
065    
066                            super.service(request, response);
067                    }
068                    catch (Exception e) {
069                            throw new ServletException(e);
070                    }
071                    finally {
072                            AccessControlThreadLocal.setRemoteAccess(remoteAccess);
073                    }
074            }
075    
076            private static Log _log = LogFactoryUtil.getLog(RemotingServlet.class);
077    
078    }