equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
52 return realm; |
52 return realm; |
53 } |
53 } |
54 |
54 |
55 public Result authenticate (HttpExchange t) |
55 public Result authenticate (HttpExchange t) |
56 { |
56 { |
57 Headers rmap = (Headers) t.getRequestHeaders(); |
57 Headers rmap = t.getRequestHeaders(); |
58 /* |
58 /* |
59 * look for auth token |
59 * look for auth token |
60 */ |
60 */ |
61 String auth = rmap.getFirst ("Authorization"); |
61 String auth = rmap.getFirst ("Authorization"); |
62 if (auth == null) { |
62 if (auth == null) { |
63 Headers map = (Headers) t.getResponseHeaders(); |
63 Headers map = t.getResponseHeaders(); |
64 map.set ("WWW-Authenticate", "Basic realm=" + "\""+realm+"\""); |
64 map.set ("WWW-Authenticate", "Basic realm=" + "\""+realm+"\""); |
65 return new Authenticator.Retry (401); |
65 return new Authenticator.Retry (401); |
66 } |
66 } |
67 int sp = auth.indexOf (' '); |
67 int sp = auth.indexOf (' '); |
68 if (sp == -1 || !auth.substring(0, sp).equals ("Basic")) { |
68 if (sp == -1 || !auth.substring(0, sp).equals ("Basic")) { |
81 ) |
81 ) |
82 ); |
82 ); |
83 } else { |
83 } else { |
84 /* reject the request again with 401 */ |
84 /* reject the request again with 401 */ |
85 |
85 |
86 Headers map = (Headers) t.getResponseHeaders(); |
86 Headers map = t.getResponseHeaders(); |
87 map.set ("WWW-Authenticate", "Basic realm=" + "\""+realm+"\""); |
87 map.set ("WWW-Authenticate", "Basic realm=" + "\""+realm+"\""); |
88 return new Authenticator.Failure(401); |
88 return new Authenticator.Failure(401); |
89 } |
89 } |
90 } |
90 } |
91 |
91 |