View Full Version : Problems with wms layer manager and .net service with digest authorization
I have problems with wms layer manager and a iis service with digest authorization. All time response 401 Error.
If I try getcapabilities in the browser, it works fine. I recieve a form for write user and password, I write correctly the user and password, and finally I recieve the xml.
But, if I try with wms layer manager I recieve the form for write user and password all time, although the user and password have been types correctly.
03-30-2011, 01:12 AM
WMS code in worldwind is not designed with authenticated services in mind. Are you using the demo WMS code ? We added support for basic auth and https (http://forum.worldwindcentral.com/showthread.php?t=26052). For digest auth you will have to use :
URLConnection uc = url.openConnection();
uc.setRequestProperty ("Authorization", "Digest " + encoding);
Where encoding is generated with md5, sha1 or whichever digest provider you use on the server side as shown here:
See here on how to generate the digest on the client side once the Authentication scheme has been identified:
But I have the same problem. IIS 6.0 with win2003 use MD5-sess and I don't know how to get the request body. I found some examples which explain how to get the request header with md5-sess (http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java) and I need to get the getcapabilities.
I hope the answer from someone with more knowledge about java than me.
I have found a solution for authentication md5-sess:
* First step: Calculate nonce and realm with a request:
HttpClient client = new HttpClient();
GetMethod getMethod = new GetMethod(host+urlStr+parameters);
Header wwAuthHeader = getMethod.getResponseHeader("WWW-Authenticate");
for (HeaderElement element : wwAuthHeader.getElements())
nonce = element.getValue();
realm = element.getValue();
*Second step: Calculate response:
String user = "usuario";
String password = "contrasenia";
String cnonce = "inventado";
String nc = "00000001";
String qop = "auth";
String A1 = MD5Encrypt(user+":"+realm+":"+password)+":"+nonce+":"+cnonce;
String response = MD5Encrypt(MD5Encrypt(A1)+":"+nonce+":"+nc+":"+cnonce+":"+qop+":"+ MD5Encrypt("GET:"+urlStr));
* The function MD5Encrypt is:
private String MD5Encrypt(String text)
byte b = java.security.MessageDigest.getInstance("MD5").digest((text).getBytes());
java.math.BigInteger bi = new java.math.BigInteger(1,b);
String s = bi.toString(16);
while(s.length() < 32)
* Third step: Perform the GetCapabilities request and save in a xml:
URL url = new URL(urlStr);
URLConnection urlCon = url.openConnection();
String header = "username=\""+user+"\",realm=\""+realm+"\",nonce=\""+nonce+"\",uri=\""+urlStr+"\",cnonce=\""+cnonce+"\",nc="+nc+",algorithm=MD5-sess,response=\""+response+"\",qop=\""+qop+"\",charset=utf-8";
urlCon.setRequestProperty("Authorization", "Digest "+header);
InputStream is = urlCon.getInputStream();
FileOutputStream fos = new FileOutputStream("C:/temp.xml");
byte array = new byte;
int step = is.read(array);
while (step > 0)
fos.write(array, 0, step);
step = is.read(array);
* But, now, this is my question: How to avoid IE prompt to send the request code as shown above?
vBulletin® v3.7.1, Copyright ©2000-2013, Jelsoft Enterprises Ltd.