Mercurial Hosting > luan
comparison src/luan/modules/url/WwwAuthenticate.java @ 1317:c286c1e36b81
add client digest authentication
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 01 Feb 2019 03:46:56 -0700 |
parents | |
children | 27efb1fcbcb5 |
comparison
equal
deleted
inserted
replaced
1316:11d3640e739d | 1317:c286c1e36b81 |
---|---|
1 package luan.modules.url; | |
2 | |
3 import java.util.Map; | |
4 import java.util.HashMap; | |
5 import luan.lib.parser.Parser; | |
6 import luan.lib.parser.ParseException; | |
7 | |
8 | |
9 public final class WwwAuthenticate { | |
10 public final String type; | |
11 public final Map<String,String> options = new HashMap<String,String>(); | |
12 private final Parser parser; | |
13 | |
14 public WwwAuthenticate(String header) throws ParseException { | |
15 parser = new Parser(header); | |
16 type = parseType(); | |
17 if( !matchSpace() ) | |
18 throw new ParseException(parser,"space expected"); | |
19 do { | |
20 while( matchSpace() ); | |
21 int start = parser.currentIndex(); | |
22 while( parser.inCharRange('a','z') ); | |
23 String name = parser.textFrom(start); | |
24 if( name.length() == 0 ) | |
25 throw new ParseException(parser,"option name not found"); | |
26 if( !parser.match('=') ) | |
27 throw new ParseException(parser,"'=' expected"); | |
28 if( !parser.match('"') ) | |
29 throw new ParseException(parser,"'\"' expected"); | |
30 start = parser.currentIndex(); | |
31 while( !parser.test('"') ) { | |
32 if( !parser.anyChar() ) | |
33 throw new ParseException(parser,"unexpected end of text"); | |
34 } | |
35 String value = parser.textFrom(start); | |
36 if( !parser.match('"') ) | |
37 throw new ParseException(parser,"'\"' expected"); | |
38 options.put(name,value); | |
39 while( matchSpace() ); | |
40 } while( parser.match(',') ); | |
41 if( !parser.endOfInput() ) | |
42 throw new ParseException(parser,"unexpected input"); | |
43 } | |
44 | |
45 private String parseType() throws ParseException { | |
46 if( parser.match("Basic") ) | |
47 return "Basic"; | |
48 if( parser.match("Digest") ) | |
49 return "Digest"; | |
50 throw new ParseException(parser,"invalid type"); | |
51 } | |
52 | |
53 private boolean matchSpace() { | |
54 return parser.anyOf(" \t\r\n"); | |
55 } | |
56 } |