01: /*
02: * ====================================================================
03: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
04: *
05: * This software is licensed as described in the file COPYING, which
06: * you should have received as part of this distribution. The terms
07: * are also available at http://svnkit.com/license.html
08: * If newer versions of this license are posted there, you may use a
09: * newer version instead, at your option.
10: * ====================================================================
11: */
12: package org.tmatesoft.svn.core.internal.io.dav.http;
13:
14: import java.io.UnsupportedEncodingException;
15:
16: import org.tmatesoft.svn.core.auth.SVNPasswordAuthentication;
17: import org.tmatesoft.svn.core.internal.util.SVNBase64;
18:
19: /**
20: * @version 1.1.1
21: * @author TMate Software Ltd.
22: */
23: class HTTPBasicAuthentication extends HTTPAuthentication {
24:
25: private String myCharset;
26:
27: public HTTPBasicAuthentication(
28: SVNPasswordAuthentication credentials, String charset) {
29: super (credentials);
30: myCharset = charset;
31: }
32:
33: protected HTTPBasicAuthentication(String name, String password,
34: String charset) {
35: super (name, password);
36: myCharset = charset;
37: }
38:
39: protected HTTPBasicAuthentication(String charset) {
40: myCharset = charset;
41: }
42:
43: public String authenticate() {
44: if (getUserName() == null || getPassword() == null) {
45: return null;
46: }
47:
48: StringBuffer result = new StringBuffer();
49: String authStr = getUserName() + ":" + getPassword();
50: try {
51: authStr = SVNBase64.byteArrayToBase64(authStr
52: .getBytes(myCharset));
53: } catch (UnsupportedEncodingException e) {
54: authStr = SVNBase64.byteArrayToBase64(authStr.getBytes());
55: }
56: result.append("Basic ");
57: result.append(authStr);
58: return result.toString();
59: }
60:
61: public String getAuthenticationScheme() {
62: return "Basic";
63: }
64:
65: }
|