web.xml 中的 security-role 的運作剖析
来源:互联网 发布:长兴古银杏王数据 编辑:程序博客网 时间:2024/06/08 13:51
如果在 tomcat 之上執行程式
你撰寫的 security-role到底有沒有用呢 ?
當呼叫 isUserInRole 其實是去呼叫 RealmBase 中的 hasRole 透過 GenericPrincipal 去檢查
而 Principals 是在你 authentication 的時候就給了,
這是 取出 tomcat-users.xml 的 roles 去處理放在你的 Principal 中
不過還有一個情況, 有 servlet 採用 security-role-ref link security-role 的時候
如果是採用
FOO
manager
在 isUserInRole("FOO") 會使用 Wrapper 去找相關的 roles,
在 tomcat starup 的同時 ContextConfig 會建立
與 的關係
因此 , 當你使用 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 !
你撰寫的 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 的時候
如果是採用
在 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 !
- web.xml 中的 security-role 的運作剖析
- web.xml 中的 security-role 的運作剖析
- web.xml 中的 security-role 的運作剖析
- web.xml 中的 security-role 的運作剖析
- web.xml中的security-constraint
- Window Azure 中的Web Role详解
- 具体阐述windows Azure 中的web role
- Role-Based Security
- 用XML作sql和web应用的桥
- web.xml深度剖析
- spring security web.xml 监听器
- Windows Azure Web Role 的 IIS 重置
- applicationContext-security.xml配置中的<http></http>标签的意义
- 两个WEB.XML:servlet容器中的web.xml和WEB-INF下的web.xml
- tomcat对于web.xml的security-constraint使用的处理机制
- web.xml中的contextConfigLocation的作用
- servlet 的web.xml配置文件中的介绍
- web.xml中的字符过滤器的设置
- commons-beanutils 1.7 新增的 LazyDynaBean
- .net精简框架集(WinCE平台下),XML反序列化成功与否与时间相关
- 4th Asia Opensource Symposium in Taipei Howard
- Servlet Security 的缺憾 -- request.getUserSubject()
- JavaTWO 2004 in taiwan 紀事
- web.xml 中的 security-role 的運作剖析
- JAAS 基本概念 (1/3)
- VS2005 IDE开发环境两个不好的特性
- Struts原理与应用(三)
- Struts 原理与应用(一)
- SVN的良好使用习惯
- Struts原理与应用(二)
- Struts原理与应用(完)
- Struts快速入门(四)