web.xml 中的 security-role 的運作剖析
2008-03-11 15:29
330 查看
如果在 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 的時候
如果是採用
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 !
相关文章推荐
- web.xml 中的 security-role 的運作剖析
- web.xml 中的 security-role 的運作剖析
- web.xml 中的 security-role 的運作剖析
- Spring MVC 框架pom.xml, web.xml, spring-mvc-servlet.xml, security.xml相关知识学习
- web.xml中的security-constraint
- web.xml中<security-constraint>和四种认证类型
- web.xml中<security-constraint>和四种认证类型
- PHP Oracle Web Development: Data processing, Security, Caching, XML, Web Services, and Ajax
- Tomcat全局/局部https访问配置方法【tomcat容器的配置文件web.xml中添加security-constraint】
- web.xml中<security-constraint>和四种认证类型
- web.xml中<security-constraint>和四种认证类型
- tomcat对于web.xml的security-constraint使用的处理机制
- web.xml中<security-constraint>和四种认证类型
- spring security web.xml 监听器
- web.xml深度剖析
- PHP Oracle Web Development: Data processing, Security, Caching, XML, Web Services, and Ajax (Paperback) Aug.2007.eBook-BBL
- tomcat对于web.xml的security-constraint使用的处理机制
- web.xml中<security-constraint>和四种认证类型
- XML Web 服务生存期剖析
- web.xml中<security-constraint>和四种认证类型