|
Home TOC Index |
|
Search
Feedback |
EJB-Tier Security
The following sections describe declarative and programmatic security mechanisms that can be used to protect resources in the EJB tier. The protected resources include methods of enterprise beans that are called from the application clients, Web components, or other enterprise beans.
You can protect EJB-tier resources by doing the following:
Declaring Method Permissions
After you've defined the roles, you can define the method permissions of an enterprise bean. Method permissions indicate which roles are allowed to invoke which methods.
Use the following procedure in
deploytoolto specify method permissions by mapping roles to methods.
- Select the enterprise bean.
- Select the Security tab.
- In the Method Permissions table, select Sel Roles in the Availability column.
- Then select a role's checkbox if that role should be allowed to invoke a method.
Using Programmatic Security in the EJB Tier
Programmatic security in the EJB tier consists of the
getCallerPrincipaland theisCallerInRolemethods. You can use thegetCallerPrincipalmethod to determine the caller of the enterprise bean, and theisCallerInRolemethod to determine the caller's role.The
getCallerPrincipalmethod of theEJBContextinterface returns thejava.security.Principalobject that identifies the caller of the enterprise bean. (In this case, a principal is the same as a user.) In the following example, thegetUsermethod of an enterprise bean returns the name of the J2EE user that invoked it:public String getUser() { return context.getCallerPrincipal().getName(); }You can determine whether an enterprise bean's caller belongs to a particular role by invoking the
isCallerInRolemethod:boolean result = context.isCallerInRole("Customer");Unprotected EJB-Tier Resources
By default, the J2EE SDK assigns the
ANYONErole to a method. Theguestuser, which is anonymous and unauthenticated, belongs to theANYONErole. Therefore, if you do not map the roles, any user may invoke the methods of an enterprise bean.
|
Home TOC Index |
|
Search
Feedback |