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.repository.util;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.StringUtil;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.security.auth.PrincipalException;
021    import com.liferay.portal.security.auth.PrincipalThreadLocal;
022    import com.liferay.portal.service.BaseServiceImpl;
023    
024    /**
025     * @author     Adolfo P??rez
026     * @deprecated As of 7.0.0, with no direct replacement
027     */
028    @Deprecated
029    public class RepositoryUserUtil {
030    
031            /**
032             * See {@link BaseServiceImpl#getUserId()}
033             *
034             * @deprecated As of 7.0.0, with no direct replacement
035             */
036            @Deprecated
037            public static long getUserId() throws PrincipalException {
038                    String name = PrincipalThreadLocal.getName();
039    
040                    if (Validator.isNull(name)) {
041                            throw new PrincipalException("Principal is null");
042                    }
043                    else {
044                            for (int i = 0; i < BaseServiceImpl.ANONYMOUS_NAMES.length; i++) {
045                                    if (StringUtil.equalsIgnoreCase(
046                                                    name, BaseServiceImpl.ANONYMOUS_NAMES[i])) {
047    
048                                            throw new PrincipalException(
049                                                    "Principal cannot be " +
050                                                            BaseServiceImpl.ANONYMOUS_NAMES[i]);
051                                    }
052                            }
053                    }
054    
055                    return GetterUtil.getLong(name);
056            }
057    
058    }