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.security.service.access.policy;
016    
017    import com.liferay.portal.kernel.util.AutoResetThreadLocal;
018    
019    import java.util.ArrayList;
020    import java.util.List;
021    
022    /**
023     * @author Mika Koivisto
024     */
025    public class ServiceAccessPolicyThreadLocal {
026    
027            public static void addActiveServiceAccessPolicyName(
028                    String serviceAccessPolicyName) {
029    
030                    List<String> activeServiceAccessPolicyNames =
031                            getActiveServiceAccessPolicyNames();
032    
033                    if (activeServiceAccessPolicyNames == null) {
034                            activeServiceAccessPolicyNames = new ArrayList<>();
035    
036                            setActiveServiceAccessPolicyNames(activeServiceAccessPolicyNames);
037                    }
038    
039                    activeServiceAccessPolicyNames.add(serviceAccessPolicyName);
040            }
041    
042            public static List<String> getActiveServiceAccessPolicyNames() {
043                    return _activeServiceAccessPolicyNames.get();
044            }
045    
046            public static void setActiveServiceAccessPolicyNames(
047                    List<String> activeServiceAccessPolicyNames) {
048    
049                    _activeServiceAccessPolicyNames.set(activeServiceAccessPolicyNames);
050            }
051    
052            private static final ThreadLocal<List<String>>
053                    _activeServiceAccessPolicyNames = new AutoResetThreadLocal<>(
054                            AutoResetThreadLocal.class + "._activeServiceAccessPolicyNames");
055    
056    }