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.security.auth;
016    
017    import com.liferay.portal.exception.PwdEncryptorException;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.security.pwd.PasswordEncryptorUtil;
021    
022    import java.io.Serializable;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class HttpPrincipal implements Serializable {
028    
029            public HttpPrincipal() {
030                    this(null, null, null, true);
031            }
032    
033            public HttpPrincipal(String url) {
034                    this(url, null, null, true);
035            }
036    
037            public HttpPrincipal(String url, String login, String password) {
038                    this(url, login, password, false);
039            }
040    
041            public HttpPrincipal(
042                    String url, String login, String password, boolean digested) {
043    
044                    _url = url;
045                    _login = login;
046    
047                    if (digested) {
048                            _password = password;
049                    }
050                    else {
051                            try {
052                                    _password = PasswordEncryptorUtil.encrypt(password);
053                            }
054                            catch (PwdEncryptorException pee) {
055                                    _log.error(pee, pee);
056                            }
057                    }
058            }
059    
060            public long getCompanyId() {
061                    return _companyId;
062            }
063    
064            public String getLogin() {
065                    return _login;
066            }
067    
068            public String getPassword() {
069                    return _password;
070            }
071    
072            public String getUrl() {
073                    return _url;
074            }
075    
076            public void setCompanyId(long companyId) {
077                    _companyId = companyId;
078            }
079    
080            public void setPassword(String password) {
081                    _password = password;
082            }
083    
084            private static final Log _log = LogFactoryUtil.getLog(HttpPrincipal.class);
085    
086            private long _companyId;
087            private final String _login;
088            private String _password;
089            private final String _url;
090    
091    }