Declaring and using application-specific configuration properties

Use the ${propertyName} notation to reuse application-specific properties that are declared in the worklight.properties file.

As a developer, you might want to parameterize some elements in the configuration of the server side of your 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, you can 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.

You can declare application-specific properties in the worklight.properties file. You can then reuse the value of those properties within the authentication configuration file (authenticationConfig.xml) and the adapter descriptor file (adapter.xml) by using the ${propertyName} notation.

Here is an example for declaring a data source and reusing it in an adapter:

  1. In the worklight.properties file, define a new (custom) property:
    my.adapter.db.jndi.name=jdbc/MyAdapterDS
  2. You can 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 JNDI environment entries for MobileFirst projects in production) 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, you 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 Configuring authenticators and realms. For loginModule parameters, see Configuring login modules.

In adapter.xml, you 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 if you want 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 HTTP adapter connectionPolicy element.