动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   Xml → 阅读文章

 web.xml中的 security-role 的運\作剖析

作者来源: 
阅读 1264 人次 , 2006-3-29 3:29:00 

如果在 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 !
  
 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:XML解析自动机
· 下一篇:Java编程中更新XML文档的常用方法
· 把HTML表单提交的数据转化成XML文件
· .Net的精髓-XML和SOAP(三)
· 保护 XML Web 服务免受黑客攻击(4)
· 使用XML和SQL Server 2000管理存储过程调用
· 用asp.net和xml做的新闻更新系统(1)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077