KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > http > BasicAuthCredentials


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.http;
18
19 import org.apache.commons.httpclient.HttpClient;
20 import org.apache.commons.httpclient.Credentials;
21 import org.apache.commons.httpclient.UsernamePasswordCredentials;
22 import org.apache.commons.httpclient.auth.AuthScope;
23
24 /**
25  *
26  * @author roehl.sioson
27  * @org.apache.xbean.XBean element="basicAuthCredentials"
28  * description="This class contains parameters needed to send basic authentication credentials"
29  *
30  */

31 public class BasicAuthCredentials {
32
33     protected String JavaDoc username;
34     protected String JavaDoc password;
35     
36     public BasicAuthCredentials()
37     {
38     }
39
40     /**
41      * @return Returns the username.
42      */

43     public String JavaDoc getUsername() {
44         return username;
45     }
46
47     /**
48      * @param ssl The username to set.
49      */

50     public void setUsername(String JavaDoc username) {
51         this.username = username;
52     }
53     
54     /**
55      * @return Returns the password.
56      */

57     public String JavaDoc getPassword() {
58         return password;
59     }
60
61     /**
62      * @param ssl The password to set.
63      */

64     public void setPassword(String JavaDoc password) {
65         this.password = password;
66     }
67     
68     /**
69      * Applies this authentication to the given method.
70      * @param method The method to receive authentication headers.
71      */

72     public void applyCredentials( HttpClient client )
73     {
74         AuthScope scope = new AuthScope( AuthScope.ANY_HOST, AuthScope.ANY_PORT );
75         Credentials credentials = new UsernamePasswordCredentials( this.username, this.password );
76         client.getState().setCredentials( scope, credentials );
77     }
78     
79 }
80
Popular Tags