| 搜索频道 | 源码下载 | 站长代码论坛 | 文章分类 | 最新专题 | 源码交易 | 加入收藏
首页|资讯|图形图像|网站开发|程序设计|数据库|多媒体|机械电子|办公系列|路由技术|原理|应用|考试|系统
文章搜索:
 您的位置:首页网站开发XML → web.xml中的 security-role 的運\作剖析
web.xml中的 security-role 的運\作剖析

日期:2006-7-12 11:54:42 人气:     [ ]
如果在 tomcat 之上執行程式
你撰寫的 security-role 到底有沒有用呢 ?

當呼叫 isUserInRole 其實是去呼叫 RealmBase 中的 hasRole 透過 GenericPrincipal 去檢查

GenericPrincipal gp = (GenericPrincipal) principal;
boolean result = gp.hasRole(role);
return result;


而 Principals 是在你 authentication 的時候就給了,
這是 取出 tomcat-users.xml 的 roles 去處理放在你的 Principal 中

void addUser(String username, String password, String roles) {

// Accumulate the list of roles for this user
ArrayList list = new ArrayList();
roles += ",";
while (true) {
int comma = roles.indexOf(',');
if (comma < 0)
break;
String role = roles.substring(0, comma).trim();
list.add(role);
roles = roles.substring(comma + 1);
}

// Construct and cache the Principal for this user
GenericPrincipal principal =
new GenericPrincipal(this, username, password, list);
principals.put(username, principal);

}


不過還有一個情況, 有 servlet 採用 security-role-ref link security-role 的時候
如果是採用

FOO
manager


在 isUserInRole("FOO") 會使用 Wrapper 去找相關的 roles,

if (wrapper != null) {
String realRole = wrapper.findSecurityReference(role);
if ((realRole != null) &&
realm.hasRole(userPrincipal, realRole))
return (true);
}


在 tomcat starup 的同時 ContextConfig 會建立
的關係

Container wrappers[] = context.findChildren();
for (int i = 0; i < wrappers.length; i++) {
Wrapper wrapper = (Wrapper) wrappers[i];
String runAs = wrapper.getRunAs();
if ((runAs != null) && !context.findSecurityRole(runAs)) {
log(sm.getString("contextConfig.role.runas", runAs));
context.addSecurityRole(runAs);
}
String names[] = wrapper.findSecurityReferences();
for (int j = 0; j < names.length; j++) {
String link = wrapper.findSecurityReference(names[j]);
if ((link != null) && !context.findSecurityRole(link)) {
log(sm.getString("contextConfig.role.link", link));
context.addSecurityRole(link);
}
}
}

因此 , 當你使用 servlet 時, 裡面可能會寫
isUserInRole("FOO"), 但是對應到的應該是整個系統的 manager,
如果在 security-role 之中沒有定義相關的 manager role,

則會新增一個 manager role 在 context 之中, 相當於建立了
你就會在 servlet 中撰寫相關的"FOO" role ref link 到 manager role,
這樣, 就可以使用 FOO 成為 manager 的角色了

因此 security-constraint 裡面的 role 與 security-role 是沒有關係的 ^^~

所以呢, 如果你在 tomcat 上面執行, security-role 有沒有設定的結果應該都是一樣的.

至於其他商業用的 commercial application server, 通常會在專用部署檔中參考 web.xml 中的 security-role 去做 role-mapping !
出处:本站原创 作者:zzcode
 

 热点文章

·用ASP、VB和XML建立互..
·XML新增批注、处理指令..
·XML 中的常见问题
·带可选项、带图片的无..
·简单的XML留言板
·将XML文件链接至HTML网..
·XML与其相关技术
·用XML实现国家、省的动..
·构造未来Web页面的工具..
·web.xml中的 security..
·简析JAVA的XML编程
·使用xmlhttp 实现多文..
·利用XML不离开页面刷新..
·XML入门精解之结构与语..
·XML技术上传文件

 推荐文章

·端午非物质文化遗产登..
·动态网站Web开发PHP、..
·PS绘中秋佳节的一轮明..
·细谈网页优化和网站优..
·建站常识:如何使用FT..
·如何快速建造一个成功..
·ASP.NET 2.0 中的创建..
·ASP.NET2.0服务器控件..
·在ASP.NET应用中插入f..
·用Photoshop打造逼真立..
·Windows 2003搭建虚拟..
·站长必读:Web创业的1..
·如何测试机房的速度和..
·北京奥运体育图标发布..
·网络视频广告将身价百..