- 浏览: 222417 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
yjz毕竟是云:
总结的不错!
字符流与字节流的区别 -
yiqing:
不错 有帮助
HTTP Basic Authentication认证 -
assertme:
a8350020 写道第一种方法的线程池其实是没有意义的Fut ...
线程返回值的方式介绍 -
a8350020:
第一种方法的线程池其实是没有意义的Future.get()会阻 ...
线程返回值的方式介绍 -
endual:
一个上午都无法配置好的我的eclipse使用svn 哎。。。
总结一下SVN的用法
什么是HTTP Basic Authentication?直接看http://en.wikipedia.org/wiki/Basic_authentication_scheme吧。 在你访问一个需要HTTP Basic Authentication的URL的时候,如果你没有提供用户名和密码,服务器就会返回401,如果你直接在浏览器中打开,浏览器会提示你输入用户名和密码(google浏览器不会,bug?)。你可以尝试点击这个url看看效果:http://api.minicloud.com.cn/statuses/friends_timeline.xml 要在发送请求的时候添加HTTP Basic Authentication认证信息到请求中,有两种方法: 一是在请求头中添加Authorization: Authorization: "Basic 用户名和密码的base64加密字符串" 二是在url中添加用户名和密码: http://userName:password@api.minicloud.com.cn/statuses/friends_timeline.xml //需要Base64见:http://www.webtoolkit.info/javascript-base64.html function make_base_auth(user, password) { var tok = user + ':' + pass; var hash = Base64.encode(tok); return "Basic " + hash; } var auth = make_basic_auth('QLeelulu','mypassword'); var url = 'http://example.com'; // 原始JavaScript xml = new XMLHttpRequest(); xml.setRequestHeader('Authorization', auth); xml.open('GET',url) // ExtJS Ext.Ajax.request({ url : url, method : 'GET', headers : { Authorization : auth } }); // jQuery $.ajax({ url : url, method : 'GET', beforeSend : function(req) { req.setRequestHeader('Authorization', auth); } });
下面摘录一段 Jsp实现鉴权的代码逻辑
以下是一段Jsp鉴权操作 1、server发送一个要求认证代码401和一个头信息WWW-authenticate,激发browser弹出一个认证窗口 2、server取得browser送来的认证头"Authorization",它是加密的了,要用Base64方法解密,取得明文的用户名和密码 3、检查用户名和密码,根据结果传送不同的页面
=========Jsp代码===================
<jsp:useBean id="base64" scope="page" class="Base64"/> <% if(request.getHeader("Authorization")==null){ response.setStatus(401); response.setHeader("WWW-authenticate", "Basic realm="unixboy.com""); }else{ String encoded=(request.getHeader("Authorization")); String tmp=encoded.substring(6); String up=Base64.decode(tmp); String user=""; String password=""; if(up!=null){ user=up.substring(0,up.indexOf(":")); password=up.substring(up.indexOf(":")+1); } if(user.equals("unixboy")&&password.equals("123456")){ //认证成功 }else{ //认证失败 } } %> =======Java段代码================== //消息加解密class public class Base64 { /** decode a Base 64 encoded String. * <p><h4>String to byte conversion</h4> * This method uses a naive String to byte interpretation, it simply gets each * char of the String and calls it a byte.</p> * <p>Since we should be dealing with Base64 encoded Strings that is a reasonable * assumption.</p> * <p><h4>End of data</h4> * We don′t try to stop the converion when we find the "=" end of data padding char. * We simply add zero bytes to the unencode buffer.</p> */ public static String decode(String encoded) { StringBuffer sb=new StringBuffer(); int maxturns; //work out how long to loop for. if(encoded.length()%3==0) maxturns=encoded.length(); else maxturns=encoded.length()+(3-(encoded.length()%3)); //tells us whether to include the char in the unencode boolean skip; //the unencode buffer byte[] unenc=new byte[4]; byte b; for(int i=0,j=0; i<maxturns; i++) { skip=false; //get the byte to convert or 0 if(i<encoded.length()) b=(byte)encoded.charAt(i); else b=0; //test and convert first capital letters, lowercase, digits then ′+′ and ′/′ if(b>=65 && b<91) unenc[j]=(byte)(b-65); else if(b>=97 && b<123) unenc[j]=(byte)(b-71); else if(b>=48 && b<58) unenc[j]=(byte)(b+4); else if(b==′+′) unenc[j]=62; else if(b==′/′) unenc[j]=63; //if we find "=" then data has finished, we′re not really dealing with this now else if(b==′=′) unenc[j]=0; else { char c=(char)b; if(c==′ ′ || c==′ ′ || c==′ ′ || c==′ ′) skip=true; else //could throw an exception here? it′s input we don′t understand. ; } //once the array has boiled convert the bytes back into chars if(!skip && ++j==4) { //shift the 6 bit bytes into a single 4 octet word int res=(unenc[0] << 18)+(unenc[1] << 12)+(unenc[2] << 6)+unenc[3]; byte c; int k=16; //shift each octet down to read it as char and add to StringBuffer while(k>=0) { c=(byte)(res >> k); if ( c > 0 ) sb.append((char)c); k-=8; } //reset j and the unencode buffer j=0; unenc[0]=0;unenc[1]=0;unenc[2]=0;unenc[3]=0; } } return sb.toString(); } /** encode plaintext data to a base 64 string * @param plain the text to convert. If plain is longer than 76 characters this method * returns null (see RFC2045). * @return the encoded text (or null if string was longer than 76 chars). */ public static String encode(String plain) { if(plain.length()>76) return null; int maxturns; StringBuffer sb=new StringBuffer(); //the encode buffer byte[] enc=new byte[3]; boolean end=false; for(int i=0,j=0; !end; i++) { char _ch=plain.charAt(i); if(i==plain.length()-1) end=true; enc[j++]=(byte)plain.charAt(i); if(j==3 || end) { int res; //this is a bit inefficient at the end point //worth it for the small decrease in code size? res=(enc[0] << 16)+(enc[1] << 8)+enc[2]; int b; int lowestbit=18-(j*6); for(int toshift=18; toshift>=lowestbit; toshift-=6) { b=res >>> toshift; b&=63; if(b>=0 && b<26) sb.append((char)(b+65)); if(b>=26 && b<52) sb.append((char)(b+71)); if(b>=52 && b<62) sb.append((char)(b-4)); if(b==62) sb.append(′+′); if(b==63) sb.append(′/′); if(sb.length()%76==0) sb.append(′ ′); } //now set the end chars to be pad character if there //was less than integral input (ie: less than 24 bits) if(end) { if(j==1) sb.append("=="); if(j==2) sb.append(′=′); } enc[0]=0; enc[1]=0; enc[2]=0; j=0; } } return sb.toString(); } }
发表评论
-
转载 HashMap实现分析
2011-08-29 00:30 791** *@author annegu *@da ... -
Index Full Scan vs Index Fast Full Scan
2011-08-25 15:24 893Index Full Scan vs Index Fas ... -
oracle语句优化
2011-08-25 13:52 890Dear All 系统里有下面的语句,其中MDN是 ... -
转 读写分离
2011-08-23 23:51 1210随着一个网站的业务 ... -
拦截器与过滤器
2011-08-21 22:36 968很多人都了解过滤器也听说过拦截器,但是要是区分它们的不同 ... -
sql写法的注意事项
2011-08-20 23:20 913基本的Sql编写注意事 ... -
字符流与字节流的区别
2011-08-20 22:50 11931 推荐 流是一个有序的字节序列,可作为一个输 ... -
SOCKET 与 HTTP
2011-08-20 22:32 10844.1 SOCKET与TCP/IP 关系 Sock ... -
tomcat中的几点配置说明
2011-08-19 22:20 9231. 如何加大tomcat连接数 在tomcat配置文 ... -
关于struts1和struts2及webork的单例和多实例
2011-08-18 23:31 810老是看到不会的问题就像转过来,记录下来,以后好看,一定 ... -
线程池的原理和连接池的原理
2011-08-18 23:18 774线程池的原理: ... -
非常好的Spring源码分析链接
2011-08-18 23:06 790http://www.ibm.com/developerwor ... -
oralce sql监控
2011-06-23 16:48 895emctl start dbconsole访问地址为:http ... -
Linux系统 学习
2011-05-31 15:33 843%mem 内存使用率 virt ... -
如何重新配置Oracle的EM Database Control
2011-05-30 17:59 835如何重新配置Oracle的 ... -
流控 demo
2011-05-05 23:05 792http://www.iteye.com/topic/19 ... -
基础VI命令学习
2011-04-21 14:13 761i编辑器是所有Unix及Linux系统下标准的编辑器,它 ... -
hibernate session统一管理的配置
2011-03-31 10:24 1018public class FlushedOpenSess ... -
查看连接池的配置
2011-03-30 16:51 974<servlet> <serv ... -
保留一些 电信方面知识的链接
2011-03-21 14:46 773保留一些 电信方面知识的链接 写道 http://ww ...
相关推荐
在HTTP中,基本认证是一种用来允许Web浏览器或其他客户端程序在请求时提供以用户名和口令形式的凭证,这篇文章主要介绍了http basic authentication通过post方式访问api示例,大家参考使用吧
java实现HTTP 基本认证 (Basic Authentication) 大家在登录网站的时候,大部分时候是通过一个表单提交登录信息。 但是有时候浏览器会弹出一个登录验证的对话框,如下图,这就是使用 HTTP 基本认证。 下面来看看一...
针对PB 开发者,并需要访问Digest Authentication认证。 该案例是通过PB 2019 R3 Build 2170版本来开发的。需要使用到PB 2017 版本后的新功能httpclient对象及加密对象。
webService添加basic验证,为了WebService的安全,将webservice添加basic验证,用户在调用时需要提供授权信息进行调用
然后进入新浪微博开放平台查看相关文档,在文档中(使用Basic Auth进行用户验证)发现新浪微博开发团队推荐了园子里的Q.Lee.lulu写的一篇博文:访问需要HTTP Basic Authentication认证的资源的各种语言的实现。...
采用VC编程,源碼VS2010编译...针对使用Basic Authentication认证的管理后台登录方式做暴力破解 程序有小BUG,但是猜解没有问题 相关开发进度请参阅CSDN BLOG http://blog.csdn.net/yehjordan/article/details/18892355
Laravel非常基本的身份验证 文档可在以下位置找到: :United_Kingdom: :Japan:该软件包允许您在路由上添加HTTP Basic Auth过滤器,而无需使用数据库-Laravel默认auth.basic -middleware所依赖。 当您想让客户在尚未...
springboot 核心技术讲解笔记,从入门到精通,对springboot的各方面知识点讲解,非常的细致
基本认证 HTTP基本支持与兼容。 它太酷了。 使用: var express = require ( 'express' ) , auth = require ( 'express-authentication' ) , basic = require ( 'express-authentication-basic' ) ; var app =...
基本身份验证插件 - 保持简单 请注意,此扩展程序不会收集,存储或处理您的私人信息,也不会收集任何分析数据。基本身份验证凭据存储在本地计算机上,并且不与任何外部服务同步。扩展程序卸载后,所有保存的数据都将...
自述文件基本认证应用什么剂量呢? 它是平面用户认证应用程序。类图待定如何使用它提供了网络视图和API。 您可以创建测试帐户。 $ rails db:seed 这是测试帐户信息。 昵称:“ test”, 电子邮件:“ ”, 密码:“ ...
axis2客户端,调用带ntlm认证的web service的代码例子和所需jar和java
HTTP Basic Authentication session-cookie Token 验证 OAuth(开放授权) 一.HTTP Basic Authentication 这种授权方式是浏览器遵守http协议实现的基本授权方式,HTTP协议进行通信的过程中,HTTP协议定义了基本...
本篇文章主要介绍了详解nginx basic auth配置踩坑记,nginx的basic auth配置由ngx_http_auth_basic_module模块提供,对HTTP Basic Authentication协议进行了支持,感兴趣的小伙伴们可以参考一下
Dispatcher :: run ([ new Middlewares \ BasicAuthentication ([ 'username1' => 'password1' , 'username2' => 'password2' ])]); (可选)您可以提供Psr\Http\Message\ResponseFactoryInterface作为第二个参数,...
要实现登录认证功能,常用的有以下这两种方法:这两种方法各有优劣,Basic access authentication 主要是胜在简单,只需要在Requset Header中加入 Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==,其中字符串...
Elasticsearch、grafana 和用户客户端之间的代理支持基本认证保护的 Elasticsearch,只有 grafana-authentication-proxy 知道用户/密码兼容最新的grafana 增强的身份验证方法。 现在支持客户端的 Google OAuth2、...
HTTP BASIC authentication headers (一个基于IEFT RFC 的标准) HTTP Digest authentication headers (一个基于IEFT RFC 的标准) HTTP X.509 client certificate exchange (一个基于IEFT RFC 的标准) LDAP (一个非常...
springsecurity是一个功能强大且高度可定制的身份验证和访问控制框架。springsecurity是一个...最核心的就是 Basic Authentication Filter 用来认证用户的身份,一个在spring security中一种过滤器处理一种认证方式。
在HTTP中,HTTP基本认证(Basic Authentication)是一种允许网页浏览器或其他客户端程序以(用户名:口令) 请求资源的身份验证方式,不要求cookie,session identifier、login page等标记或载体。 – 所有浏览器据支持...