001    /**
002     * Copyright (c) 2000-2013 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.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            }
031    
032            public HttpPrincipal(String url) {
033                    _url = url;
034            }
035    
036            public HttpPrincipal(String url, String login, String password) {
037                    this(url, login, password, false);
038            }
039    
040            public HttpPrincipal(
041                    String url, String login, String password, boolean digested) {
042    
043                    _url = url;
044                    _login = login;
045    
046                    if (digested) {
047                            _password = password;
048                    }
049                    else {
050                            try {
051                                    _password = PasswordEncryptorUtil.encrypt(password);
052                            }
053                            catch (PwdEncryptorException pee) {
054                                    _log.error(pee, pee);
055                            }
056                    }
057            }
058    
059            public long getCompanyId() {
060                    return _companyId;
061            }
062    
063            public String getLogin() {
064                    return _login;
065            }
066    
067            public String getPassword() {
068                    return _password;
069            }
070    
071            public String getUrl() {
072                    return _url;
073            }
074    
075            public void setCompanyId(long companyId) {
076                    _companyId = companyId;
077            }
078    
079            public void setPassword(String password) {
080                    _password = password;
081            }
082    
083            private static Log _log = LogFactoryUtil.getLog(HttpPrincipal.class);
084    
085            private long _companyId;
086            private String _login;
087            private String _password;
088            private String _url;
089    
090    }