Authentication takes place by means of user name and password. A distinction is made between
It is recommended that you use container-managed authentication.
Container-managed authentication
In the case of container-managed authentication, the access data is handled by the container. The EJB deployer configures the container-managed authentication with the following entry in the EJB deployment descriptor:
<res-auth>Container</res-auth>
When using container-managed authentication, you call the getConnection()
method without parameters.
Please refer to section "Container-managed authentication" in Defining security settings (managing sign-on) for details.
Application-managed authentication
In the case of application-managed authentication, the access data is handled in the program code of the EJB. The EJB deployer configures the application-managed authentication in the EJB deployment descriptor with the following entry:
<res-auth>Application</res-auth>
In the EJB source code, you use, for example, the following code sequence instead of the getConnection()
call without parameters:
javax.naming.InitialContext ic = new InitialContext(); String user = (String)ic.lookup("java:comp/env/User"); String password = (String)ic.lookup("java:comp/env/Password"); net.fsc.jca.communication.PasswordCredential pwc = new net.fsc.jca.communication.PasswordCredential (user, password); con= (net.fsc.jca.communication.EISConnection)cf.getConnection(pwc);
Here, the user ID (user in the example) and the password (password in the example) are defined as environment variables of the EJB. The deployer can adapt environment variables as required. The environment variables can be accessed using the lookup()
method.