![]() |
![]() |
e-docs > WebLogic Server > Programming WebLogic Security > Securing Enterprise JavaBeans (EJBs) |
Programming WebLogic Security
|
Securing Enterprise JavaBeans (EJBs)
WebLogic Server supports the J2EE security model for securing Enterprise JavaBeans (EJBs), which includes support for declarative authorization (also referred to in this document as declarative security) and programmatic authorization (referred to in this document as programmatic security).
The following topics are covered in this section:
Note: You can use deployment descriptor files and the Administration Console to secure EJBs. For information on using the Administration Console to secure EJBs, see Securing WebLogic Resources.
The document Designing Enterprise Applications with the J2EE Platform, Second Edition, published by Sun Microsystems, Inc., states in Section 9.3 Authorization:
"In the J2EE architecture, a container serves as an authorization boundary between the components it hosts and their callers. The authorization boundary exists inside the container's authentication boundary so that authorization is considered in the context of successful authentication. For inbound calls, the container compares security attributes from the caller's credential with the access control rules for the target component. If the rules are satisfied, the call is allowed. Otherwise, the call is rejected."
"There are two fundamental approaches to defining access control rules: capabilities and permissions. Capabilities focus on what a caller can do. Permissions focus on who can do something. The J2EE application programming model focuses on permissions. In the J2EE architecture, the job of the deployer is to map the permission model of the application to the capabilities of users in the operational environment."
The same document then discusses two ways to control access to application resources using the J2EE architecture, declarative authorization and programmatic authorization.
The document Designing Enterprise Applications with the J2EE Platform, Second Edition, published by Sun Microsystems, Inc., in available online at http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/security/security4.html.
The document Designing Enterprise Applications with the J2EE Platform, Second Edition, published by Sun Microsystems, Inc., states in Section 9.3.1 Authorization:
"The deployer establishes the container-enforced access control rules associated with a J2EE application. The deployer uses a deployment tool to map an application permission model, which is typically supplied by the application assembler, to policy and mechanisms specific to the operational environment. The application permission model is defined in a deployment descriptor."
WebLogic Server supports the use of deployment descriptors to implement declarative authorization in EJBs.
Note: Declarative authorization is also referred in this document as declarative security.
The document Designing Enterprise Applications with the J2EE Platform, Second Edition, published by Sun Microsystems, Inc., in available online at http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/security/security4.html.
The document Designing Enterprise Applications with the J2EE Platform, Second Edition, published by Sun Microsystems, Inc., states in Section 9.3.2 Programmatic Authorization:
"A J2EE container makes access control decisions before dispatching method calls to a component. The logic or state of the component doesn't factor in these access decisions. However, a component can use two methods, EJBContext.isCallerInRole (for use by enterprise bean code) and HttpServletRequest.isUserInRole (for use by Web components), to perform finer-grained access control. A component uses these methods to determine whether a caller has been granted a privilege selected by the component based on the parameters of the call, the internal state of the component, or other factors such as the time of the call."
"The application component provider of a component that calls one of these functions must declare the complete set of distinct roleName values to be used in all calls. These declarations appear in the deployment descriptor as security-role-ref elements. Each security-role-ref element links a privilege name embedded in the application as a roleName to a security role. Ultimately, the deployer establishes the link between the privilege names embedded in the application and the security roles defined in the deployment descriptor. The link between privilege names and security roles may differ for components in the same application."
"In addition to testing for specific privileges, an application component can compare the identity of its caller, acquired using EJBContext.getCallerPrincipal or HttpServletRequest.getUserPrincipal, to the distinguished caller identities embedded in the state of the component when it was created. If the identity of the caller is equivalent to a distinguished caller, the component can allow the caller to proceed. If not, the component can prevent the caller from further interaction. The caller principal returned by a container depends on the authentication mechanism used by the caller. Also, containers from different vendors may return different principals for the same user authenticating by the same mechanism. To account for variability in principal forms, an application developer who chooses to apply distinguished caller state in component access decisions should allow multiple distinguished caller identities, representing the same user, to be associated with components. This is recommended especially where application flexibility or portability is a priority."
WebLogic Server supports the use of the EJBContext.isCallerInRole and EJBContext.getCallerPrincipal methods and the use of the security-role-ref element in deployment descriptors to implement programmatic authorization in EJBs.
Note: Programmatic authorization is also referred in this document as programmatic security.
The document Designing Enterprise Applications with the J2EE Platform, Second Edition, published by Sun Microsystems, Inc., in available online at http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/security/security4.html.
Declarative Versus Programmatic Authorization
The document Designing Enterprise Applications with the J2EE Platform, Second Edition, published by Sun Microsystems, Inc., states in Section 9.3.3 Declarative Versus Programmatic Authorization:
"There is a trade-off between the external access control policy configured by the deployer and the internal policy embedded in the application by the component provider. The external policy is more flexible after the application has been written. The internal policy provides more flexible functionality while the application is being written. In addition, the external policy is transparent and completely comprehensible to the deployer, while internal policy is buried in the application and may only be completely understood by the application developer. These trade-offs should be considered in choosing the authorization model for particular components and methods."
The document Designing Enterprise Applications with the J2EE Platform, Second Edition, published by Sun Microsystems, Inc., in available online at http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/security/security4.html.
Using Declarative Security With EJBs
To implement declarative security in EJBs you use deployment descriptors (ejb-jar.xml and weblogic-ejb-jar.xml) to define the security requirements. Listing 5-1 shows examples of how to use the ejb-jar.xml and weblogic-ejb-jar.xml deployment descriptors to map security role names to a security realm. The deployment descriptors map the application's logical security requirements to its runtime definitions. And at runtime, the EJB container uses the security definitions to enforce the requirements.
To configure security in the EJB deployment descriptors, perform the following steps (see Listing 5-1):
For more information on configuring security in the ejb-jar.xml file, see the Sun Microsystems Enterprise JavaBeans Specification, Version 2.0 which is at this location on the Internet: http://java.sun.com/products/ejb/docs.html.
For more information on configuring security in the weblogic-ejb-jar.xml file, see weblogic-ejb-jar.xml Deployment Descriptor Elements in Programming WebLogic Enterprise JavaBeans.
Listing 5-1 Using the ejb-jar.xml and weblogic-ejb-jar.xml Files to Map Security Role Names to a Security Realm
ejb-jar.xml entries:
...
<assembly-descriptor>
<security-role>
<role-name>manger</role-name>
</security-role>
<security-role>
<role-name>east</role-name>
</security-role>
<method-permission>
<role-name>manager</role-name>
<role-name>east</role-name>
<method>
<ejb-name>accountsPayable</ejb-name>
<method-name>getReceipts</method-name>
</method>
</method-permission>
<method-permission>
<unchecked/>
<method>
<ejb-name>vacationAccrued</ejb-name>
<method-name>uncheckedGetCompanyTotal</method-name>
</method>
</method-permission>
...
</assembly-descriptor>
...
weblogic-ejb-jar.xml entries:
<security-role-assignment>
<role-name>manager</role-name>
<principal-name>al</principal-name>
<principal-name>george</principal-name>
<principal-name>ralph</principal-name>
</security-role-assignment>
...
EJB Security-Related Deployment Descriptors
The following topics describe the deployment descriptor elements that are used in the ejb-jar.xml and weblogic-ejb-jar.xml files to define security requirements in EJBs:
ejb-jar.xml Deployment Descriptors
The following ejb-jar.xml deployment descriptor elements are used to define security requirements in WebLogic Server:
The information in this section is based on the Document Type Descriptor (DTD) for ejb-jar.xml provided by Sun Microsystems, Inc. The DTD for ejb-jar.xml is available on the Web at http://java.sun.com/dtd/ejb-jar_2_0.dtd.
The method element is used to denote a method of an enterprise bean's home or component interface, or, in the case of a message-driven bean, the bean's onMessage method, or a set of methods.
The following table describes the elements you can define within an method element.
The method element is used within the method-permission element.
For an example of how to use the method element, see Listing 5-1.
The method-permission element specifies that one or more security roles are allowed to invoke one or more enterprise bean methods. The method-permission element consists of an optional description, a list of security role names or an indicator to state that the method is unchecked for authorization, and a list of method elements.
The security roles used in the method-permission element must be defined in the security-role elements of the deployment descriptor, and the methods must be methods defined in the enterprise bean's component and/or home interfaces.
The following table describes the elements you can define within an method-permission element.
The method-permission element is used within the assembly-descriptor element.
For an example of how to use the method-permission element, see Listing 5-1.
The role-name element contains the name of a security role. The name must conform to the lexical rules for an NMTOKEN.
The role-name element is used within the method-permission, run-as, security-role, and security-role-ref elements.
For an example of how to use the role-name element, see Listing 5-7.
The run-as element specifies the run-as identity to be used for the execution of the enterprise bean. It contains an optional description, and the name of a security role.
The run-as element is used within the security-identity element.
For an example of how to use the run-as element, see Listing 5-7.
The security-identity element specifies whether the caller's security identity is to be used for the execution of the methods of the enterprise bean or whether a specific run-as identity is to be used. It contains an optional description and a specification of the security identity to be used.
The following table describes the elements you can define within an security-identity element.
The use-caller-identity element or the run-as element must be specified. |
The security-identity element is used within the entity, message-driven, and session elements.
For an example of how to use the security-identity element, see Listing 5-3 and Listing 5-7.
The security-role element contains the definition of a security role. The definition consists of an optional description of the security role, and the security role name.
The security-role element is used within the assembly-descriptor element.
For an example of how to use the assembly-descriptor element, see Listing 5-1.
The security-role-ref element contains the declaration of a security role reference in the enterprise bean's code. The declaration consists of an optional description, the security role name used in the code, and an optional link to a security role. If the security role is not specified, the Deployer must choose an appropriate security role.
The value of the role-name element must be the String used as the parameter to the EJBContext.isCallerInRole(String roleName) method or the HttpServletRequest.isUserInRole(String role) method.
The security-role-ref element is used within the entity and session elements.
For an example of how to use the security-role-ref element, see Listing 5-2.
Listing 5-2 Security-role-ref Element Example
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar>
<enterprise-beans>
...
<session>
<ejb-name>SecuritySLEJB</ejb-name>
<home>weblogic.ejb20.security.SecuritySLHome</home>
<remote>weblogic.ejb20.security.SecuritySL</remote>
<ejb-class>weblogic.ejb20.security.SecuritySLBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<security-role-ref>
<role-name>rolenamedifffromlink</role-name>
<role-link>role121SL</role-link>
</security-role-ref>
<security-role-ref>
<role-name>roleForRemotes</role-name>
<role-link>roleForRemotes</role-link>
</security-role-ref>
<security-role-ref>
<role-name>roleForLocalAndRemote</role-name>
<role-link>roleForLocalAndRemote</role-link>
</security-role-ref>
</session>
...
</enterprise-beans>
</ejb-jar>
The unchecked element specifies that a method is not checked for authorization by the container prior to invocation of the method.
The unchecked element is used within the method-permission element.
For an example of how to use the unchecked element, see Listing 5-1.
The use-caller-identity element specifies that the caller's security identity be used as the security identity for the execution of the enterprise bean's methods.
The use-caller-identity element is used within the security-identity element.
For an example of how to use the use-caller-identity element, see Listing 5-3.
Listing 5-3 use-caller-identity Element Example
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>SecurityEJB</ejb-name>
<home>weblogic.ejb20.SecuritySLHome</home>
<remote>weblogic.ejb20.SecuritySL</remote>
<local-home>
weblogic.ejb20.SecurityLocalSLHome
</local-home>
<local>weblogic.ejb20.SecurityLocalSL</local>
<ejb-class>weblogic.ejb20.SecuritySLBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
<message-driven>
<ejb-name>SecurityEJB</ejb-name>
<ejb-class>weblogic.ejb20.SecuritySLBean</ejb-class>
<transaction-type>Container</transaction-type>
<security-identity>
<use-caller-identity/>
</security-identity>
</message-driven>
</enterprise-beans>
</ejb-jar>
weblogic-ejb-jar.xml Deployment Descriptors
The following weblogic-ejb-jar.xml deployment descriptor elements are used to define security requirements in WebLogic Server:
The client-authentication element specifies whether the EJB supports or requires client authentication.
The following table defines the possible settings.
For an example of how to use the client-authentication element, see Listing 5-6.
The client-cert-authentication element specifies whether the EJB supports or requires client certificate authentication at the transport level.
The following table defines the possible settings.
For an example of how to use the client-cert-authentication element, see Listing 5-9.
The confidentiality element specifies the transport confidentiality requirements for the EJB. Using the confidentiality element ensures that the data is sent between the client and server in such a way as to prevent other entities from observing the contents.
The following table defines the possible settings.
For an example of how to use the confidentiality element, see Listing 5-9.
In WebLogic Server 7.0 SP1 and later, the global-role element is supported for use in the weblogic-ejb-jar.xml deployment descriptors. You can use this element—instead of the principal-name element—to explicitly indicate that you want the security roles defined in the deployment descriptors by the role-name element in the weblogic-ejb-jar.xml file to use the mappings that you specify in the Administration Console.
The global-role element gives you the flexibility of not having to specify a specific role mapping for each security role defined in the deployment descriptors for a particular EJB. Rather, you can use the Administration Console to specify and modify a specific role mapping for each defined role at anytime. Additionally, because you may elect to use this element on some EJBs and not others, it is not necessary to check the Ignore Security Data In Deployment Descriptors attribute on the General tab of the security realm. Thus, within the same security realm, deployment descriptors can be used to specify and modify security for some EJBs, while the Administration Console can be used to specify and modify security for others.
Note: When specifying security role names, observe the following conventions and restrictions:
The global-role element is used within the security-role-assignment element.
Listing 5-4 and Listing 5-5 show by comparison how to use the global-role element in the weblogic-ejb-jar.xml deployment descriptors. In Listing 5-5, the specification of the "manager" global-role element in the weblogic-ejb-jar.xml means that for security to be correctly configured on the getReceipts method, the principals for manager will have to be created in the Administration Console.
Listing 5-4 Using the ejb-jar.xml and weblogic-ejb-jar.xml Deployment Descriptors to Map Security Roles in EJBs
ejb-jar.xml entries:
...
<assembly-descriptor>
<security-role>
<role-name>manger</role-name>
</security-role>
<security-role>
<role-name>east</role-name>
</security-role>
<method-permission>
<role-name>manager</role-name>
<role-name>east</role-name>
<method>
<ejb-name>accountsPayable</ejb-name>
<method-name>getReceipts</method-name>
</method>
</method-permission>
...
</assembly-descriptor>
...
weblogic-ejb-jar.xml entries:
<security-role-assignment>
<role-name>manager</role-name>
<principal-name>joe</principal-name>
<principal-name>Bill</principal-name>
<principal-name>Mary</principal-name>
...
</security-role-assignment>
...
Listing 5-5 Using the <global-role/> tag in EJB Deployment Descriptors for Role Mapping
ejb-jar.xml entries:
...
<assembly-descriptor>
<security-role>
<role-name>manger</role-name>
</security-role>
<security-role>
<role-name>east</role-name>
</security-role>
<method-permission>
<role-name>manager</role-name>
<role-name>east</role-name>
<method>
<ejb-name>accountsPayable</ejb-name>
<method-name>getReceipts</method-name>
</method>
</method-permission>
...
</assembly-descriptor>
...
weblogic-ejb-jar.xml entries:
<security-role-assignment>
<role-name>manager</role-name>
<global-role/>
...
</security-role-assignment>
...
For more information on using the Administration Console to configure security for EJBs, see Securing WebLogic Resources.
The identity-assertion element specifies whether the EJB supports identity assertion.
The following table defines the possible settings.
The identity-assertion element is used with the iiop-security-descriptor element.
For an example of how to the identity-assertion element, see Listing 5-6.
The iiop-security-descriptor element specifies security configuration parameters at the bean-level. These parameters determine the IIOP security information contained in the interoperable object reference (IOR).
For an example of how to use the iiop-security-descriptor element, see Listing 5-6.
Listing 5-6 iiop-security-descriptor Element Example
<weblogic-enterprise-bean>
<iiop-security-descriptor>
<transport-requirements>
<confidentiality>supported</confidentiality>
<integrity>supported</integrity>
<client-cert-authorization>
supported
</client-cert-authentication>
</transport-requirements>
<client-authentication>supported<client-authentication>
<identity-assertion>supported</identity-assertion>
</iiop-security-descriptor>
</weblogic-enterprise-bean>
The integrity element specifies the transport integrity requirements for the EJB. Using the integrity element ensures that the data is sent between the client and server in such a way that it cannot be changed in transit.
The following table defines the possible settings.
The integrity element is used within the transport-requirements element.
For an example of how to use the integrity element, see Listing 5-9.
The principal-name element specifies the name of the principal in the WebLogic Server security realm that applies to role name specified in the security-role-assignment element. At least one principal is required in the security-role-assignment element. You may define more than one principal-name for each role name.
The principal-name element is used within the security-role-assignment element.
For an example of how to use the principal-name element, see Listing 5-1.
The role-name element identifies an application role name that the EJB provider placed in the companion ejb-jar.xml file. Subsequent principal-name elements in the stanza map WebLogic Server principals to the specified role-name.
The role-name element is used within the security-role-assignment element.
For an example of how to use the role-name element, see Listing 5-1.
The run-as-identity-principal element specifies which security principal is to be used for the run-as identity. This element is necessary if the role specified in the run-as element of the ejb-jar.xml file does not map to a single security principal representing a User in the security realm. This could be true in two cases.
The run-as-identity-principal element is used within the weblogic-enterprise-bean element.
For an example of how to use the run-as-identity-principal element, see Listing 5-7.
Listing 5-7 run-as-identity-principal Element Example
ebj-jar.xml:
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>Caller2EJB</ejb-name>
<home>weblogic.ejb11.security.CallerBeanHome</home>
<remote>weblogic.ejb11.security.CallerBeanRemote</remote>
<ejb-class>weblogic.ejb11.security.CallerBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
<ejb-ref><ejb-ref-name>Callee2Bean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>weblogic.ejb11.security.CalleeBeanHome</home>
<remote>weblogic.ejb11.security.CalleeBeanRemote</remote>
</ejb-ref>
<security-role-ref>
<role-name>users1</role-name>
<role-link>users1</role-link>
</security-role-ref>
<security-identity>
<run-as>
<role-name>users2</role-name>
</run-as>
</security-identity>
</session>
</enterprise-beans>
</ejb-jar>
woblogic-ejb-jar.xml:
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>Caller2EJB</ejb-name>
<reference-descriptor>
<ejb-reference-description>
<ejb-ref-name>Callee2Bean</ejb-ref-name>
<jndi-name>security.Callee2Bean</jndi-name>
</ejb-reference-description>
</reference-descriptor>
<run-as-identity-principal>wsUser3</run-as-identity-principal>
</weblogic-enterprise-bean>
<security-role-assignment>
<role-name>user</role-name>
<principal-name>wsUser2</principal-name>
<principal-name>wsUser3</principal-name>
<principal-name>wsUser4</principal-name>
</security-role-assignment>
</weblogic-ejb-jar>
The security-permission element specifies a security permission that is associated with a J2EE Sandbox.
For an example of how to use the security-permission element, see Listing 5-8.
The security-permission-spec element specifies a single security permission based on the Security policy file syntax.
For more information, see Sun's implementation of the security permission specification:
http://java.sun.com/j2se/1.3/docs/guide/security/PolicyFiles.html#FileSyntax
Note: Disregard the optional codebase and signedBy clauses.
The security-permission-spec element is used within the security-permission element.
For an example of how to use the security-permission-spec element, see Listing 5-8.
Listing 5-8 security-permission-spec Element Example
In Listing 5-8, permission java.net.SocketPermission is the permission class name, "*" represents the target name, and resolve (resolve host/IP name service lookups) indicates the action.
The security-role-assignment element maps application roles in the ejb-jar.xml file to the names of security principals available in WebLogic Server.
For an example of how to use the security-role-assignment element, see Listing 5-1.
The transport-requirements element defines the transport requirements for the EJB.
The transport-requirements element is used within the iiop-security-descriptor element.
For an example of how to use the transport-requirements element, see Listing 5-9.
Listing 5-9 transport-requirements Element Example
<weblogic-enterprise-bean>
<iiop-security-descriptor>
<transport-requirements>
<confidentiality>supported</confidentiality>
<integrity>supported</integrity>
<client-cert-authorization>
supported
</client-cert-authentication>
</transport-requirements>
</iiop-security-descriptor>
</weblogic-enterprise-bean>
Using Programmatic Security With EJBs
To implement programmatic security in EJBs you use the javax.ejb.EJBContext.getCallerPrincipal() and the javax.ejb.EJBContext.isCallerInRole() methods.
You use the getCallerPrincipal() method to determine the caller of the EJB. The javax.ejb.EJBContext.getCallerPrincipal() method returns a WLSUser Principal if one exists in the Subject of the calling user. In the case of multiple WLSUser Principals, the method returns the first in the ordering defined by the Subject.getPrincipals().iterator() method. If there are no WLSUser Principals, then the getCallerPrincipal() method returns the first non-WLSGroup Principal. If there are no Principals or all Principals are of type WLSGroup, this method returns weblogic.security.WLSPrincipals.getAnonymousUserPrincipal(). This behavior is similar to the semantics of weblogic.security.SubjectUtils.getUserPrincipal() except that SubjectUtils.getUserPrincipal() returns a null whereas EJBContext.getCallerPrincipal()returns WLSPrincipals.getAnonmyousUserPrincipal().
For more information about how to use the getCallerPrincipal() method, see http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Security5.html
The isCallerInRole() method is used to determine if the caller (the current user) has been assigned a security role that is authorized to perform actions on the WebLogic resources in that thread of execution. For example, the method javax.ejb.EJBContext.isCallerInRole("admin")will return true if the current user has admin privileges.
For more information about how to use the isCallerInRole() method, see http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Security5.html
For Javadoc for the isCallerInRole() method, see http://java.sun.com/products/ejb/javadoc-1.1/javax/ejb/EJBContext.html#isCallerInRole(java.lang.String)
![]() |
![]() |
![]() |
![]() |
||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |