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