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