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     *
027     * @deprecated As of 7.0.0, with no direct replacement
028     */
029    @Deprecated
030    public class RepositoryUserUtil {
031    
032            /**
033             * See {@link com.liferay.portal.service.BaseServiceImpl#getUserId()}
034             *
035             * @deprecated As of 7.0.0, with no direct replacement
036             */
037            @Deprecated
038            public static long getUserId() throws PrincipalException {
039                    String name = PrincipalThreadLocal.getName();
040    
041                    if (name == null) {
042                            throw new PrincipalException();
043                    }
044    
045                    if (Validator.isNull(name)) {
046                            throw new PrincipalException("Principal is null");
047                    }
048                    else {
049                            for (int i = 0; i < BaseServiceImpl.ANONYMOUS_NAMES.length; i++) {
050                                    if (StringUtil.equalsIgnoreCase(
051                                                    name, BaseServiceImpl.ANONYMOUS_NAMES[i])) {
052    
053                                            throw new PrincipalException(
054                                                    "Principal cannot be " +
055                                                            BaseServiceImpl.ANONYMOUS_NAMES[i]);
056                                    }
057                            }
058                    }
059    
060                    return GetterUtil.getLong(name);
061            }
062    
063    }