001    /**
002     * Copyright (c) 2000-2010 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.auth;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.AutoResetThreadLocal;
020    
021    /**
022     * @author Brian Wing Shun Chan
023     */
024    public class PrincipalThreadLocal {
025    
026            public static String getName() {
027                    String name = _name.get();
028    
029                    if (_log.isDebugEnabled()) {
030                            _log.debug("getName " + name);
031                    }
032    
033                    return name;
034            }
035    
036            public static void setName(long name) {
037                    setName(String.valueOf(name));
038            }
039    
040            public static void setName(String name) {
041                    if (_log.isDebugEnabled()) {
042                            _log.debug("setName " + name);
043                    }
044    
045                    _name.set(name);
046            }
047    
048            private static Log _log = LogFactoryUtil.getLog(PrincipalThreadLocal.class);
049    
050            private static ThreadLocal<String> _name =
051                    new AutoResetThreadLocal<String>(PrincipalThreadLocal.class + "._name");
052    
053    }