1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.client.security;
15
16
17 import java.io.IOException;
18
19 import org.eclipse.jetty.client.HttpExchange;
20 import org.eclipse.jetty.http.HttpHeaders;
21 import org.eclipse.jetty.io.Buffer;
22 import org.eclipse.jetty.io.ByteArrayBuffer;
23 import org.eclipse.jetty.util.B64Code;
24 import org.eclipse.jetty.util.StringUtil;
25
26
27
28
29
30
31 public class BasicAuthentication implements Authentication
32 {
33 private Buffer _authorization;
34
35 public BasicAuthentication(Realm realm) throws IOException
36 {
37 String authenticationString = "Basic " + B64Code.encode( realm.getPrincipal() + ":" + realm.getCredentials(), StringUtil.__ISO_8859_1);
38 _authorization= new ByteArrayBuffer(authenticationString);
39 }
40
41
42
43
44
45
46
47
48 public void setCredentials( HttpExchange exchange ) throws IOException
49 {
50 exchange.setRequestHeader( HttpHeaders.AUTHORIZATION_BUFFER, _authorization);
51 }
52 }