1 22 package org.jboss.web.tomcat.security; 23 24 import java.io.IOException ; 25 import javax.security.auth.callback.CallbackHandler ; 26 import javax.security.auth.callback.Callback ; 27 import javax.security.auth.callback.UnsupportedCallbackException ; 28 29 import org.jboss.security.auth.callback.MapCallback; 30 import org.jboss.security.auth.spi.RFC2617Digest; 31 32 39 public class DigestCallbackHandler implements CallbackHandler 40 { 41 private String username; 42 private String nonce; 43 private String nc; 44 private String cnonce; 45 private String qop; 46 private String realm; 47 private String md5a2; 48 49 DigestCallbackHandler(String username, String nonce, 50 String nc, String cnonce, String qop, String realm, String md5a2) 51 { 52 this.username = username; 53 this.nonce = nonce; 54 this.nc = nc; 55 this.cnonce = cnonce; 56 this.qop = qop; 57 this.realm = realm; 58 this.md5a2 = md5a2; 59 } 60 61 public void handle(Callback [] callbacks) throws IOException , UnsupportedCallbackException 62 { 63 boolean foundCallback = false; 64 Callback firstUnknown = null; 65 int count = callbacks != null ? callbacks.length : 0; 66 for(int n = 0; n < count; n ++) 67 { 68 Callback c = callbacks[n]; 69 if( c instanceof MapCallback ) 70 { 71 MapCallback mc = (MapCallback) c; 72 mc.setInfo(RFC2617Digest.USERNAME, username); 73 mc.setInfo(RFC2617Digest.CNONCE, cnonce); 74 mc.setInfo(RFC2617Digest.NONCE, nonce); 75 mc.setInfo(RFC2617Digest.NONCE_COUNT, nc); 76 mc.setInfo(RFC2617Digest.QOP, qop); 77 mc.setInfo(RFC2617Digest.REALM, realm); 78 mc.setInfo(RFC2617Digest.A2HASH, md5a2); 79 foundCallback = true; 80 } 81 else if( firstUnknown == null ) 82 { 83 firstUnknown = c; 84 } 85 } 86 if( foundCallback == false ) 87 throw new UnsupportedCallbackException (firstUnknown, "Unrecognized Callback"); 88 } 89 } 90 | Popular Tags |