Configure authentication aliases for Liberty
We can configure an authentication data alias to use with a resource reference for authentication in Liberty.
To avoid having to code user IDs and passwords for data sources in the applications, we can configure the application server to use authentication data to provide the user IDs and passwords. For resources that use container authentication, we can configure authentication data and aliases in several ways, some of which include:
- Create a unique authentication data element (authData) with the proper credentials and refer to it in your application bindings file.
- Create a container default authentication element (containerAuthData) with the necessary credentials. We don't need to refer to the alias or the name of the authData element in your application bindings file.
- Create a unique authentication data element (authData) with the proper credentials and make it the default container authentication for a data source by referring to it with containerAuthDataRef on the dataSource element.
Create an authData element enables each resource reference to a data source to use different authentication credentials. The containerAuthData element establishes default credentials for container authentication in the absence of an authentication alias in the bindings for a resource reference.
Note: Unlike WebSphere Application Server traditional, Liberty has no authentication alias principal mapping module support.
Configure authentication data and aliases with authData and a resource reference
Create an authentication data element (authData) with the proper credentials and refer to it in your application bindings file.
- Add the following elements to the server configuration file, server.xml.
- Add the wanted version of the JDBC feature to the feature manager
element.
<featureManager> <feature>jdbc-4.1</feature> </featureManager>
- Add an authData element. If the authData element is a top-level configuration element, set the id attribute value to a unique authentication alias.
<authData id="auth1" user="dbuser1" password="dbuser1pwd"/>
- Add a data source element.
<dataSource jndiName="jdbc/mydbresource"> ... </dataSource>
- Add the wanted version of the JDBC feature to the feature manager
element.
- Configure the IBM deployment descriptor bindings file of the application, for example, the ibm-web-bnd.xml file. Use the authentication-alias element in the resource reference. The name attribute value must match the id attribute in server.xml.
<resource-ref name="jdbc/mydbresource" binding-name="jdbc/mydbresource"> <authentication-alias name="auth1"/> </resource-ref>
- Add a Resource annotation to the application to enable the application server to inject the resource reference or add the resource to the application deployment
descriptor.
@Resource (lookup="jdbc/mydbresource") DataSource mydbresource;
Configure authentication data and aliases with containerAuthData
Use a nested container default authentication data element without needing to reference an authData alias in your application bindings file.
- Add the following elements to the server configuration file, server.xml.
- Add the wanted version of the JDBC feature to the feature manager
element.
<featureManager> <feature>jdbc-4.1</feature> </featureManager>
- Create a data source with a nested container authentication data element.
<dataSource id="myDS" jndiName="jdbc/mydbresource" > <containerAuthData user="myUserid" password="myPassword"></containerAuthData> ... </dataSource>
- Add the wanted version of the JDBC feature to the feature manager
element.
- Add a Resource annotation to the application to enable the application server to inject the resource reference or add the resource to the application deployment
descriptor.
@Resource (lookup="jdbc/mydbresource") DataSource mydbresource;
Configure authentication data and aliases with authData and containerAuthDataRef
Create an authData element with the proper credentials and make it the default container authentication for a data source by referring to it with containerAuthDataRef on the dataSource element.
- Add the following elements to the server configuration file, server.xml.
- Add the wanted version of the JDBC feature to the feature manager
element.
<featureManager> <feature>jdbc-4.1</feature> </featureManager>
- Create a data source with a container authentication reference to an authData
element.
<authData id="auth1" user="dbuser1" password="dbuser1pwd"/> <dataSource id="myDS" jndiName="jdbc/mydbresource" containerAuthDataRef="auth1"> ... </dataSource>
- Add the wanted version of the JDBC feature to the feature manager
element.
- Add a Resource annotation to the application to enable the application server to inject the resource reference or add the resource to the application deployment
descriptor.
@Resource (lookup="jdbc/mydbresource") DataSource mydbresource;