Declare application-specific configuration properties
Use the ${propertyName} notation to reuse application-specific properties that are declared in worklight.properties.
As a developer, you might want to parameterize some elements in the configuration of the server side of the MobileFirst application so that an IT administrator can change the value in production. For example, a MobileFirst adapter might need to call a back-end service, and the URL of this service might be different in a production environment from its value in a development environment. In this scenario, create a new MobileFirst configuration property to store the URL, and the IT administrator can then set the final production value as a JNDI environment entry.
We can declare application-specific properties in worklight.properties. Then reuse the value of those properties within the authentication configuration file (authenticationConfig.xml) and the adapter descriptor file (adapter.xml) using the ${propertyName} notation.
Here is an example for declaring a data source and reusing it in an adapter:
- In worklight.properties, define a new (custom) property:
my.adapter.db.jndi.name=jdbc/MyAdapterDS
- Then include a property declaration in the adapter.xml file:
<wl:adapter> ... <connectivity> <connectionPolicy xsi:type="sql:SQLConnectionPolicy"> <dataSourceJNDIName> ${my.adapter.db.jndi.name} </dataSourceJNDIName> </connectionPolicy> ...Such properties are exposed as JNDI entries (see Configure a MobileFirst project in production using JNDI environment entries) for the project WAR file. In this example, the JNDI name of the adapter data source becomes parametric and can be changed from the server configuration files.
In authenticationConfig.xml, we can use ${propertyName} notation for all realm and loginModule parameters. Here are examples (in bold typeface) for such properties:
<securityTests> <customSecurityTest name="MySecurityTest"> <test realm="MySecurityRealm" isInternalUserID="true"/> </customSecurityTest> </securityTests> <realms> <realm name="MySecurityRealm" loginModule="MySecurityLoginModule"> <className>com.test.auth.MyAuthenticator</className> <parameter name="login-mode" value="${my.security.realm.mode}"/> <parameter name="my-other-realm-param" value="${my.security.realm.param}"/> </realm> </realms> <loginModules> <loginModule name="MySecurityLoginModule"> <className>com.test.auth.MyLoginModule</className> <parameter name="roles-allowed" value="${my.security.allowed.roles}"/> <parameter name="my-other-login-param" value="${my.security.login.param}"/> </loginModule> </loginModules>For more information about configuring realm parameters, see Configure authenticators and realms. For loginModule parameters, see Configure login modules.
In adapter.xml, we can use the ${propertyName} notation in the following elements:
- For HTTP adapters:
<connectivity> <connectionPolicy xsi:type="http:HTTPConnectionPolicyType"> <protocol>${my.protocol}</protocol> <domain>${my.domain}</domain> <port>${my.port}</port> <authentication> <ntlm workstation="${local.hostname}" /> <serverIdentity> <username>${my.server.identity.username}</username> <password>${my.server.identity.password}</password> </serverIdentity> </authentication> <!-- Following properties used by adapter's key manager for choosing specific certificate from key store --> <sslCertificateAlias>${my.ssl.certificate.alias}</sslCertificateAlias> <sslCertificatePassword>${my.ssl.certificate.password}</sslCertificatePassword> </connectionPolicy> <loadConstraints maxConcurrentConnectionsPerNode="${max.connections.per.node}"/> </connectivity>
- For SQL adapters:
<connectivity> <connectionPolicy xsi:type="sql:SQLConnectionPolicy"> <!-- Example for using a JNDI data source, replace with actual data source name --> <!-- <dataSourceJNDIName>${my.data.source.jndi.name}</dataSourceJNDIName> --> <!-- Example for using MySQL connector, do not forget to put the MySQL connector library in the project's lib folder --> <dataSourceDefinition> <driverClass>${my.driver.class.name}</driverClass> <url>${my.data.source.url}</url> <user>${my.data.source.username}</user> <password>${my.data.source.password}</password> </dataSourceDefinition> </connectionPolicy> <loadConstraints maxConcurrentConnectionsPerNode="${max.connections.per.node}" /> </connectivity>
- For JMS adapters:
<connectivity> <connectionPolicy xsi:type="jms:JMSConnectionPolicyType"> <!-- uncomment this to use an external JNDI repository --> <!-- <namingConnection url="${my.naming.connection.url}" initialContextFactory="${my.initial.context.factory}" user="${my.naming.connection.username}" password="${my.naming.connection.password}"/> --> <jmsConnection connectionFactory="${my.jms.connection.factory}" user="${my.jms.connection.username}" password="${my.jms.connection.password}" /> </connectionPolicy> <loadConstraints maxConcurrentConnectionsPerNode="${max.connections.per.node}"/> </connectivity>
For more information about configuring adapters, see The <authentication> element of the HTTP adapter.
Parent topic: Application server-side configuration parameters