6.2. Jakarta Enterprise Beans 方法权限
6.2.1. 关于 Jakarta Enterprise Beans 方法权限 复制链接链接已复制到粘贴板!
Jakarta Enterprise Beans 可以将方法的访问权限限制为特定的安全角色。
Jakarta Enterprise Beans <method-permission> 元素声明指定可调用 Jakarta Enterprise Beans 接口方法的角色。您可以为以下组合指定权限:
- 名为 Jakarta Enterprise Beans 的所有家庭和组件接口方法
- 名为 Jakarta Enterprise Beans 的家或组件接口的指定方法
- 带有过载名称的一组方法中的指定方法
6.2.2. 使用 Jakarta Enterprise Beans 方法权限 复制链接链接已复制到粘贴板!
<method-permission> 元素定义允许访问 <method> 元素定义的 Jakarta Enterprise Beans 方法的逻辑角色。几个示例演示了 xml 的语法。可能存在多个方法权限语句,它们具有累积效果。<method-permission> 元素是 < 元素的子项。
ejb-jar> 描述符 <assembly-descriptor >
XML 语法是使用 Jakarta Enterprise Beans 方法权限标注的替代方案。
示例:允许角色访问 Jakarta Enterprise Beans 的所有方法
<method-permission>
<description>The employee and temp-employee roles may access any method
of the EmployeeService bean </description>
<role-name>employee</role-name>
<role-name>temp-employee</role-name>
<method>
<ejb-name>EmployeeService</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
示例:允许角色访问 Jakarta Enterprise Beans 和 Limit Method 参数的 Certain 方法
<method-permission>
<description>The employee role may access the findByPrimaryKey,
getEmployeeInfo, and the updateEmployeeInfo(String) method of
the AcmePayroll bean </description>
<role-name>employee</role-name>
<method>
<ejb-name>AcmePayroll</ejb-name>
<method-name>findByPrimaryKey</method-name>
</method>
<method>
<ejb-name>AcmePayroll</ejb-name>
<method-name>getEmployeeInfo</method-name>
</method>
<method>
<ejb-name>AcmePayroll</ejb-name>
<method-name>updateEmployeeInfo</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</method>
</method-permission>
示例:允许任何经过身份验证的用户访问 Jakarta Enterprise Beans 的方法
使用 <unchecked/> 元素时,任何经过身份验证的用户都可以使用指定的方法。
<method-permission>
<description>Any authenticated user may access any method of the
EmployeeServiceHelp bean</description>
<unchecked/>
<method>
<ejb-name>EmployeeServiceHelp</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
示例:完全排除特定的 Jakarta Enterprise Beans 方法
<exclude-list>
<description>No fireTheCTO methods of the EmployeeFiring bean may be
used in this deployment</description>
<method>
<ejb-name>EmployeeFiring</ejb-name>
<method-name>fireTheCTO</method-name>
</method>
</exclude-list>
示例:一个 Complete <assembly-descriptor> 包含 Severinal <method-permission> Blocks
<ejb-jar>
<assembly-descriptor>
<method-permission>
<description>The employee and temp-employee roles may access any method of the EmployeeService bean </description>
<role-name>employee</role-name>
<role-name>temp-employee</role-name>
<method>
<ejb-name>EmployeeService</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
<method-permission>
<description>The employee role may access the findByPrimaryKey, getEmployeeInfo, and the updateEmployeeInfo(String) method of the AcmePayroll bean </description>
<role-name>employee</role-name>
<method>
<ejb-name>AcmePayroll</ejb-name>
<method-name>findByPrimaryKey</method-name>
</method>
<method>
<ejb-name>AcmePayroll</ejb-name>
<method-name>getEmployeeInfo</method-name>
</method>
<method>
<ejb-name>AcmePayroll</ejb-name>
<method-name>updateEmployeeInfo</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</method>
</method-permission>
<method-permission>
<description>The admin role may access any method of the EmployeeServiceAdmin bean </description>
<role-name>admin</role-name>
<method>
<ejb-name>EmployeeServiceAdmin</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
<method-permission>
<description>Any authenticated user may access any method of the EmployeeServiceHelp bean</description>
<unchecked/>
<method>
<ejb-name>EmployeeServiceHelp</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
<exclude-list>
<description>No fireTheCTO methods of the EmployeeFiring bean may be used in this deployment</description>
<method>
<ejb-name>EmployeeFiring</ejb-name>
<method-name>fireTheCTO</method-name>
</method>
</exclude-list>
</assembly-descriptor>
</ejb-jar>