001    /**
002     * Copyright (c) 2000-2013 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.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    }