服务器是怎么要求客户端强行弹出身份验证窗口的 - 中国WEB开发者网络 (http://www.webasp.net) -- 技术教程 (http://www.webasp.net/article/) --- 服务器是怎么要求客户端强行弹出身份验证窗口的 (http://www.webasp.net/article/26/25667.htm) |
| -- 作者:未知 -- 发布日期: 2005-07-15 |
|
我们访问tomcat服务器的时候如果试图访问Tomcat Manager就会发现浏览器弹出一个登陆对话框,和我们平常的网页对话框不同,而且查看页面的时候查不到生成这个对话框的代码,禁止脚本也毫无作用。手头的资料对这个东西没有任何介绍,它到底是怎么弹出来的呢? <% sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder(); boolean authenticated = false; String authorization = request.getHeader("authorization"); System.out.println("authorization:"+authorization);![]() if (authorization != null) {![]() if (authorization.startsWith("Basic")) { authorization = authorization.substring(authorization.indexOf(' ')+1); byte[] bytes = decoder.decodeBuffer(authorization); authorization = new String(bytes); String userName = authorization.substring(0,authorization.indexOf(':')); String password = authorization.substring(authorization.indexOf(':')+1); System.out.println("userName:"+userName); System.out.println("password:"+password); authenticated =userName.equals("abc") && password.equals("abc");![]() }else if (authorization.startsWith("Digest")) { String userName = authorization.substring(authorization.indexOf("username=")); userName = userName.substring("username=\"".length()); userName = userName.substring(0,userName.indexOf('"')); String password = authorization.substring(authorization.indexOf("response=")); password = password.substring("response=\"".length()); password = password.substring(0,password.indexOf('"')); authenticated =userName.equals("abc") && password.equals("3cf1135d3b8e20dd9272d06288569a56"); } }![]() if (!authenticated) { // response.addHeader("WWW-Authenticate","Digest realm=\"Tomcat Manager Application\""); response.addHeader("WWW-Authenticate","Basic realm=\"Tomcat Manager Application\""); response.sendError(401,"Unauthorized");![]() }else { out.println("hello abc"); } %>![]()
|
| webasp.net |