|
我們訪問tomcat服務(wù)器的時候如果試圖訪問Tomcat Manager就會發(fā)現(xiàn)瀏覽器彈出一個登陸對話框,和我們平常的網(wǎng)頁對話框不同,而且查看頁面的時候查不到生成這個對話框的代碼,禁止腳本也毫無作用。手頭的資料對這個東西沒有任何介紹,它到底是怎么彈出來的呢? <% 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"); } %>![]()
|
|
|