1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.security.auth;
24  
25  import com.liferay.portal.PwdEncryptorException;
26  import com.liferay.portal.kernel.log.Log;
27  import com.liferay.portal.kernel.log.LogFactoryUtil;
28  import com.liferay.portal.security.pwd.PwdEncryptor;
29  
30  import java.io.Serializable;
31  
32  /**
33   * <a href="HttpPrincipal.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   *
37   */
38  public class HttpPrincipal implements Serializable {
39  
40      public HttpPrincipal(String url) {
41          _url = url;
42      }
43  
44      public HttpPrincipal(String url, String login, String password) {
45          this(url, login, password, false);
46      }
47  
48      public HttpPrincipal(
49          String url, String login, String password, boolean digested) {
50  
51          _url = url;
52          _login = login;
53  
54          if (digested) {
55              _password = password;
56          }
57          else {
58              try {
59                  _password = PwdEncryptor.encrypt(password);
60              }
61              catch (PwdEncryptorException pee) {
62                  _log.error(pee, pee);
63              }
64          }
65      }
66  
67      public String getUrl() {
68          return _url;
69      }
70  
71      public long getCompanyId() {
72          return _companyId;
73      }
74  
75      public void setCompanyId(long companyId) {
76          _companyId = companyId;
77      }
78  
79      public String getLogin() {
80          return _login;
81      }
82  
83      public String getPassword() {
84          return _password;
85      }
86  
87      private static Log _log = LogFactoryUtil.getLog(HttpPrincipal.class);
88  
89      private String _url;
90      private long _companyId;
91      private String _login;
92      private String _password;
93  
94  }