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.security.ac;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.AutoResetThreadLocal;
020    import com.liferay.portal.security.auth.AccessControlContext;
021    import com.liferay.portal.security.auth.AuthException;
022    import com.liferay.portal.security.auth.AuthVerifierResult;
023    
024    import java.util.Map;
025    
026    import javax.servlet.http.HttpServletRequest;
027    import javax.servlet.http.HttpServletResponse;
028    
029    /**
030     * @author Tomas Polesovsky
031     * @author Michael C. Han
032     * @author Raymond Aug??
033     */
034    public class AccessControlUtil {
035    
036            public static AccessControl getAccessControl() {
037                    if (_accessControl == null) {
038                            _accessControl = new AccessControlImpl();
039                    }
040    
041                    return _accessControl;
042            }
043    
044            public static AccessControlContext getAccessControlContext() {
045                    return _accessControlContext.get();
046            }
047    
048            public static void initAccessControlContext(
049                    HttpServletRequest request, HttpServletResponse response,
050                    Map<String, Object> settings) {
051    
052                    getAccessControl().initAccessControlContext(
053                            request, response, settings);
054            }
055    
056            public static void initContextUser(long userId) throws AuthException {
057                    getAccessControl().initContextUser(userId);
058            }
059    
060            public static void setAccessControlContext(
061                    AccessControlContext accessControlContext) {
062    
063                    _accessControlContext.set(accessControlContext);
064            }
065    
066            public static AuthVerifierResult.State verifyRequest()
067                    throws PortalException, SystemException {
068    
069                    return getAccessControl().verifyRequest();
070            }
071    
072            public void setAccessControl(AccessControl accessControl) {
073                    _accessControl = accessControl;
074            }
075    
076            private static AccessControl _accessControl;
077            private static ThreadLocal<AccessControlContext> _accessControlContext =
078                    new AutoResetThreadLocal<AccessControlContext>(
079                            AccessControlUtil.class + "._accessControlContext");
080    
081    }