View Javadoc

1   /*
2    * Copyright 2007-2012 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springbyexample.httpclient.auth;
18  
19  import java.io.Serializable;
20  
21  /**
22   * <p>Credentials bean used to create 
23   * <code>org.apache.commons.httpclient.UsernamePasswordCredentials</code> 
24   * and <code>org.apache.commons.httpclient.auth.AuthScope</code>.</p>
25   * 
26   * <p><strong>Note</strong>: User authorization scope's host, 
27   * authorization scope's port, name, password are both required.</p>
28   * 
29   * @author David Winterfeldt
30   */
31  public class Credentials implements Serializable {
32  
33      private static final long serialVersionUID = 427351901207639483L;
34      
35      protected String authScopeHost = null;
36      protected int authScopePort = 80;
37      protected String userName = null;
38      protected String password = null;
39      
40      /**
41       * Constructor
42       */
43      public Credentials() {}
44      
45      /**
46       * Constructor
47       */
48      public Credentials(String authScopeHost, int authScopePort,
49                         String userName, String password) {
50          this.authScopeHost = authScopeHost;
51          this.authScopePort = authScopePort;
52          this.userName = userName;
53          this.password = password;
54      }
55  
56      /**
57       * Gets authorization scope's host.
58       */
59      public String getAuthScopeHost() {
60          return authScopeHost;
61      }
62  
63      /**
64       * Sets authorization scope's host.
65       */
66      public void setAuthScopeHost(String autoScopeHost) {
67          this.authScopeHost = autoScopeHost;
68      }
69  
70      /**
71       * Gets authorization scope's port.
72       */
73      public int getAuthScopePort() {
74          return authScopePort;
75      }
76  
77      /**
78       * Sets authorization scope's port.
79       */
80      public void setAuthScopePort(int authScopePort) {
81          this.authScopePort = authScopePort;
82      }
83  
84      /**
85       * Gets user name.
86       */
87      public String getUserName() {
88          return userName;
89      }
90  
91      /**
92       * Sets user name.
93       */
94      public void setUserName(String userName) {
95          this.userName = userName;
96      }
97      
98      /**
99       * Gets password.
100      */
101     public String getPassword() {
102         return password;
103     }
104     
105     /**
106      * Sets password.
107      */
108     public void setPassword(String password) {
109         this.password = password;
110     }
111     
112     /**
113      * Returns a string representation of the object.
114      */
115     public String toString() {
116         StringBuilder sb = new StringBuilder();
117         
118         sb.append(this.getClass().getName());
119         sb.append(" { ");
120         sb.append("authScopeHost=" + authScopeHost);
121         sb.append("  authScopePort=" + authScopePort);
122         sb.append("  userName=" + userName);
123         sb.append("  password=" + password);
124         sb.append(" }");
125         
126         return sb.toString();
127     }
128     
129 }