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.PwdEncryptorException;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.security.pwd.PwdEncryptor;
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(String url) {
030                    _url = url;
031            }
032    
033            public HttpPrincipal(String url, String login, String password) {
034                    this(url, login, password, false);
035            }
036    
037            public HttpPrincipal(
038                    String url, String login, String password, boolean digested) {
039    
040                    _url = url;
041                    _login = login;
042    
043                    if (digested) {
044                            _password = password;
045                    }
046                    else {
047                            try {
048                                    _password = PwdEncryptor.encrypt(password);
049                            }
050                            catch (PwdEncryptorException pee) {
051                                    _log.error(pee, pee);
052                            }
053                    }
054            }
055    
056            public String getUrl() {
057                    return _url;
058            }
059    
060            public long getCompanyId() {
061                    return _companyId;
062            }
063    
064            public void setCompanyId(long companyId) {
065                    _companyId = companyId;
066            }
067    
068            public String getLogin() {
069                    return _login;
070            }
071    
072            public String getPassword() {
073                    return _password;
074            }
075    
076            private static Log _log = LogFactoryUtil.getLog(HttpPrincipal.class);
077    
078            private String _url;
079            private long _companyId;
080            private String _login;
081            private String _password;
082    
083    }