日历
网志分类
展开全部
· ***    All     ***
· ***    Mood    ***
· ***    Life    ***
· *** Technology ***
· ***     Yc     ***
· ***  Cartoon   ***
· *** Collection ***
· ***  Unsorted  ***
媒体播放器

Get the Flash Player to see this player.
SkyDrive is currently not available.

站内搜索
友情链接
· 我的歪酷 非非共享界
· 风雨妖虹
· kingbeful@csdn
· 手心的太阳@瞬间十年
· Moment@Travis
· 江南麒麟居
· εз毛线团εз
· 乌拉的neverland
· 碾过的日子 闲也陶陶
· 狡兔三窟 *^.^*
· 橄榄林的风
· 水色の街
· Powerful and delicate, Life struggling
· 阿德咖吧
· 陷阱
· 风之华
· vkobe的Neverland@@
· 白日梦已死 · 伤越夜海
· 望天
· 空の軌跡
· 没什么好东西的空间
· 心情...咖啡屋
· 随风独自凉
· Some where i belong
· .★·°双晨·故事°☆ .
· BigWorld的记事本
· *Sara's*
· 人生若只如初见
· 宠辱不惊闲看庭前花开花落·去留无意漫随天外云卷云舒
· 我思我不在
· 飞扬飘雨
· lazy的猫猫
常用链接
· [Google]
· [Google Accounts]
· [IT Items]
· [Telnet@Yanxi]
· [Wikipedia]
· [Linux Manpages]
· [Mofile.com]
· [163888.net]
· [fm.qq.com]
· [Proxy]
· [Animepaper.net]
· [FreeproxySite]
· [gonwan@fc2]
· [skydrive.live.com]
· [gonwan@lifelogger]

订阅 RSS

0109812

歪酷博客

逆さまの蝶
In this Craziness
Uncertainy
一人一人の想いを
僕らは何処かに遺せるだろうか

In this Craziness
You gave me life
一つの想いを
僕らは何処まで守れるだろうか



« 上一篇: Introduction to Cryptography (2) 下一篇: 叹息 »
丸子·酱 @ 2008-10-28 18:25

    说起来, authentication(认证)和authorization(授权)我一直都分不清的. authentication主要的工作是, a告诉server说我是a, 然后通过一系列手段, server知道他的确是a, 这一过程叫做认证. authorization主要的工作是认证是a了之后, a能做那些事情, 有哪些"权".
    写过Jsp的必然知道, servlet有4中认证方式: basic, digest, form-based, ssl. basic和digest都是http协议的标准, ssl也有专门的rfc, form-based好像是servlet独有的.
    Java有一套api叫做JAAS(Java Authentication and Authorization Service). 这个东西以前我也没见过, 说是包含authentication和authorization两块. authentication是plugable的, 其实就是用config file代替hard code, 然后加了一个strategy模式(callback handler的使用). authorization的实现也是基于config file. 看一段代码就大概知道什么样子了:
import javax.security.auth.Subject;
import java.security.PrivilegedAction;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;

public class MyClient {
public static void main(String argv[]) {
LoginContext ctx = null;
try {
ctx = new LoginContext("WeatherLogin", new MyCallbackHandler());
} catch(LoginException le) {
System.err.println("LoginContext cannot be created. "+ le.getMessage());
System.exit(-1);
} catch(SecurityException se) {
System.err.println("LoginContext cannot be created. "+ se.getMessage());
}
try {
ctx.login();
} catch(LoginException le) {
System.out.println("Authentication failed");
System.exit(-1);
}
System.out.println("Authentication succeeded");

Subject subject = ctx.getSubject();
PrivilegedAction action = new MyAction();
Subject.doAsPrivileged(subject, action, null);
try {
ctx.logout();
} catch(LoginException le) {
System.out.println("Logout: " + le.getMessage());
}

}
}
    非粗体的是认证部分, 粗体的是授权部分, My开头的类都是自己要实现的类. 可以看到所有的认证以后的信息实际上都被封装到了一个Subject的实例中去了, 于是之后再调用doAsPrivileged()按权限做事就行了.


参考:
http://www.modperl.com/book/chapters/ch6.html
http://java.sun.com/javase/6/docs/technotes/guides/security/jaas/JAASRefGuide.html
http://java.sun.com/developer/technicalArticles/Security/jaasv2/
http://en.wikipedia.org/wiki/Basic_access_authentication
http://en.wikipedia.org/wiki/Digest_access_authentication
http://en.wikipedia.org/wiki/Secure_Sockets_Layer


曾经的这一天...



评论 / 个人网页 / 扔小纸条
* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 


 

分类小组论坛
杂谈 , 娱乐、八卦 , 文学、艺术 , 体育 , 旅游、同城 , 象牙塔 , 情感 , 时尚、生活 , 星座 , 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定