JSP强制浏览器弹出身份验证窗口
2013-01-24 00:00
387 查看
我们访问tomcat服务器的时候如果试图访问Tomcat Manager就会发现浏览器弹出一个登陆对话框,和我们平常的网页对话框不同,用jmeter创建一个http request的sampler,再建一个view result tree的lisenter来看看服务器返回了些什么污七八糟的:
HTTP response headers:
HTTP/1.1 401 Unauthorized
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 08:00:00 CST
WWW-Authenticate: Basic realm="Tomcat Manager Application"
Content-Type: text/html;charset=utf-8
Content-Length: 954
Date: Thu, 30 Jun 2005 09:27:26 GMT
Server: Apache-Coyote/1.1
嘿嘿,原来是一个带WWW-Authenticate的401错误啊。自己写个JSP模拟一下看看怎么样:
<%
response.addHeader("WWW-Authenticate","Basic realm=\"Tomcat Manager Application\"");
response.sendError(401,"Unauthorized");
%>
果然,一个一模一样的登陆窗口跳出来了。不过身份验证的具体过程要怎么做呢?
cool,和tomcat一模一样的登陆页面做出来了。
用户名密码均为abc,hard code在代码里面了。
另外一个资料:http://www.jspwiki.org/wiki/NTLMAuthentication
HTTP response headers:
HTTP/1.1 401 Unauthorized
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 08:00:00 CST
WWW-Authenticate: Basic realm="Tomcat Manager Application"
Content-Type: text/html;charset=utf-8
Content-Length: 954
Date: Thu, 30 Jun 2005 09:27:26 GMT
Server: Apache-Coyote/1.1
嘿嘿,原来是一个带WWW-Authenticate的401错误啊。自己写个JSP模拟一下看看怎么样:
<%
response.addHeader("WWW-Authenticate","Basic realm=\"Tomcat Manager Application\"");
response.sendError(401,"Unauthorized");
%>
果然,一个一模一样的登陆窗口跳出来了。不过身份验证的具体过程要怎么做呢?
<% 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"); } %>
cool,和tomcat一模一样的登陆页面做出来了。
用户名密码均为abc,hard code在代码里面了。
另外一个资料:http://www.jspwiki.org/wiki/NTLMAuthentication
相关文章推荐
- 服务器是怎么要求客户端强行弹出身份验证窗口的
- 用AS+JS实现IE等浏览器的强制弹出窗口源代码
- forms角色验证,以普通用户身份登陆管理页面先弹出警告信息窗口
- [iis6]站点未设置身份验证,却弹出“需要身份验证”的登陆窗口
- forms角色验证,以普通用户身份登陆管理页面先弹出警告信息窗口
- 服务器是怎么要求客户端强行弹出身份验证窗口的
- 浏览器是否自动屏蔽了弹出窗口的检测
- Angular2项目中浏览器拦截弹出窗口的解决方法
- jsp弹出新窗口
- flex界面弹出jsp模态窗口,并向js传值
- js验证弹出窗口登陆
- 浏览器弹出窗口被拦截解决办法
- window.open() 某些情况会被浏览器阻止弹出窗口
- 单击浏览器右上角的X关闭窗口弹出提示的小例子
- 让弹出窗口在自己的浏览器中显示
- 如何在关闭窗口的时候,不让浏览器自动弹出确认关闭对话框
- 延迟/定时/强制弹出窗口的JS代码
- 打开网站弹出:需要进行身份验证_IIS网站弹出域名登陆框的解决办法
- IE 浏览器设置 打开新的选项卡而不是弹出窗口
- 解决JS弹出新窗口被浏览器阻止的解决方案