Mercurial Hosting > luan
comparison src/luan/modules/url/LuanUrl.java @ 1575:0160650180bc
better http authentication
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 27 Jan 2021 15:31:26 -0700 |
parents | 3ebf9781707c |
children | f7e2df85fc0a |
comparison
equal
deleted
inserted
replaced
1574:f118ead273a1 | 1575:0160650180bc |
---|---|
278 } catch(IOException e) { | 278 } catch(IOException e) { |
279 int responseCode = httpCon.getResponseCode(); | 279 int responseCode = httpCon.getResponseCode(); |
280 if( responseCode == 401 && authUsername != null && authorization==null ) { | 280 if( responseCode == 401 && authUsername != null && authorization==null ) { |
281 String authStr = httpCon.getHeaderField("www-authenticate"); | 281 String authStr = httpCon.getHeaderField("www-authenticate"); |
282 //System.out.println("auth = "+authStr); | 282 //System.out.println("auth = "+authStr); |
283 List<WwwAuthenticate> auths; | |
283 try { | 284 try { |
284 WwwAuthenticate auth = new WwwAuthenticate(authStr); | 285 auths = WwwAuthenticate.parse(authStr); |
286 } catch(ParseException pe) { | |
287 throw new LuanException(pe); | |
288 } | |
289 for( WwwAuthenticate auth : auths ) { | |
285 if( auth.type.equals("Basic") ) { | 290 if( auth.type.equals("Basic") ) { |
286 String val = basicAuth(authUsername,authPassword); | 291 String val = basicAuth(authUsername,authPassword); |
287 throw new AuthException(val); | 292 throw new AuthException(val); |
288 } else if( auth.type.equals("Digest") ) { | 293 } else if( auth.type.equals("Digest") ) { |
289 String realm = auth.options.get("realm"); | 294 String realm = auth.options.get("realm"); |
318 val += ", nc=" + nc; | 323 val += ", nc=" + nc; |
319 val += ", cnonce=\"" + cnonce + "\""; | 324 val += ", cnonce=\"" + cnonce + "\""; |
320 } | 325 } |
321 //System.out.println("val = "+val); | 326 //System.out.println("val = "+val); |
322 throw new AuthException(val); | 327 throw new AuthException(val); |
323 } else | 328 } |
324 throw new RuntimeException(auth.type); | 329 } |
325 } catch(ParseException pe) { | 330 throw new RuntimeException(authStr); |
326 throw new LuanException(pe); | |
327 } | |
328 } | 331 } |
329 String msg = "" + responseCode; | 332 String msg = "" + responseCode; |
330 String responseMessage = httpCon.getResponseMessage(); | 333 String responseMessage = httpCon.getResponseMessage(); |
331 if( responseMessage != null ) | 334 if( responseMessage != null ) |
332 msg += " - " + responseMessage; | 335 msg += " - " + responseMessage; |