@@ -58,14 +58,14 @@ public class DigestAuthenticator extends LoginAuthenticator
58
58
private final ConcurrentMap <String , Nonce > _nonceMap = new ConcurrentHashMap <>();
59
59
private long _maxNonceAgeMs = 60 * 1000 ;
60
60
private int _maxNC = 1024 ;
61
- private Algorithm algorithm = Algorithm . MD5 ;
61
+ private String algorithm = " MD5" ;
62
62
63
- public void setAlgorithm (Algorithm a )
63
+ public void setAlgorithm (String a )
64
64
{
65
65
algorithm = a ;
66
66
}
67
67
68
- public Algorithm getAlgorithm ()
68
+ public String getAlgorithm ()
69
69
{
70
70
return algorithm ;
71
71
}
@@ -188,7 +188,7 @@ else if (n == 0)
188
188
res .getHeaders ().put (HttpHeader .WWW_AUTHENTICATE .asString (), "Digest realm=\" " + _loginService .getName () +
189
189
"\" , domain=\" " + domain +
190
190
"\" , nonce=\" " + newNonce (req ) +
191
- "\" , algorithm=" + algorithm . getName () +
191
+ "\" , algorithm=" + getAlgorithm () +
192
192
", qop=\" auth\" " +
193
193
", stale=" + stale );
194
194
@@ -297,7 +297,7 @@ private static class Digest extends Credential
297
297
{
298
298
@ Serial
299
299
private static final long serialVersionUID = -2484639019549527724L ;
300
- private Algorithm algorithm ;
300
+ private String algorithm ;
301
301
final String method ;
302
302
String username = "" ;
303
303
String realm = "" ;
@@ -313,38 +313,28 @@ private static class Digest extends Credential
313
313
method = m ;
314
314
}
315
315
316
- Digest (String m , Algorithm a )
316
+ Digest (String m , String a )
317
317
{
318
318
method = m ;
319
319
algorithm = a ;
320
320
}
321
-
322
- @ Override
323
- public boolean check (Object credentials )
324
- {
325
- byte [] digest = new byte []{};
326
- digest = calcDigest (credentials , algorithm .getName ());
327
-
328
- // check digest
329
- return stringEquals (TypeUtil .toString (digest , 16 ).toLowerCase (), response == null ? null : response .toLowerCase ());
330
- }
331
-
332
- @ Override
333
- public String toString ()
321
+
322
+ private String getAlgorithm ()
334
323
{
335
- return username + "," + response ;
324
+ return algorithm ;
336
325
}
337
326
338
- private byte [] calcDigest (Object credentials , String algorithm )
339
- {
327
+ @ Override
328
+ public boolean check (Object credentials )
329
+ {
340
330
if (credentials instanceof char [])
341
331
credentials = new String ((char [])credentials );
342
332
String password = (credentials instanceof String ) ? (String )credentials : credentials .toString ();
343
333
344
334
try
345
335
{
346
336
// MD5 required by the specification
347
- MessageDigest md = MessageDigest .getInstance (algorithm );
337
+ MessageDigest md = MessageDigest .getInstance (getAlgorithm () );
348
338
byte [] ha1 ;
349
339
if (credentials instanceof MD5 )
350
340
{
@@ -389,32 +379,21 @@ private byte[] calcDigest(Object credentials, String algorithm)
389
379
md .update ((byte )':' );
390
380
md .update (TypeUtil .toString (ha2 , 16 ).getBytes (StandardCharsets .ISO_8859_1 ));
391
381
392
- return md .digest ();
382
+ // check digest
383
+ return stringEquals (TypeUtil .toString (md .digest (), 16 ).toLowerCase (), response == null ? null : response .toLowerCase ());
384
+
393
385
}
394
386
catch (Exception e )
395
387
{
396
388
LOG .warn ("Unable to process digest" , e );
397
389
}
398
-
399
- return new byte [] {};
390
+ return false ;
391
+ }
392
+
393
+ @ Override
394
+ public String toString ()
395
+ {
396
+ return username + "," + response ;
400
397
}
401
398
}
402
-
403
- public static enum Algorithm
404
- {
405
- MD5 ("MD5" ),
406
- SHA256 ("SHA-256" );
407
-
408
- private String name ;
409
-
410
- Algorithm (String name )
411
- {
412
- this .name = name ;
413
- }
414
-
415
- public String getName ()
416
- {
417
- return this .name ;
418
- }
419
- }
420
- }
399
+ }
0 commit comments