+

Search Tips   |   Advanced Search

Implementing client-side components for native Android

We can implement client-side components for custom device provisioning in native Android.

For more information about the prerequisites, see Implementing client-side components for custom device provisioning.

To implement client-side components for custom device provisioning, complete the following steps.

  1. Create a MobileFirst native API application for Android.

  2. Configure the application for the Application Authenticity test. The authenticity test works only with MPF Consumer Edition, and MobileFirst Enterprise Edition. For more information about application authenticity, see MobileFirst application authenticity overview.

  3. Create an Android native application and use WLClient.getInstance().connect() to connect to server.

  4. For the WLClient.getInstance().connect() function to trigger authentication, specify the MobileFirst native API application as a protected resource by adding a custom security test or mobile security test in the application descriptor.

      <nativeAndroidApp securityTest="MySecurityTest" version="1.0">

  5. Add a new class CustomDeviceProvisioningRealmChallengeHandler, and register it in the main activity class using WLClient.getInstance().registerChallengeHandler(new CustomDeviceProvisioningRealmChallengeHandler('CustomDeviceProvisioningRealm')).

  6. Implement the following methods required by the device provisioning challenge handler:

    • The createCustomCsr(challenge) method is responsible for returning custom properties that are added to the certificate signing request (CSR). Add a custom activationCode property, used in the adapter's validateCSR function.

    • The handleSuccess(identity) method is called when certificate validation is successfully completed by the validateCertificate adapter function.

    • The handleFailure() method is called when certificate validation fails. We must call clearDeviceProvisioningCertificate() from this method to delete the stored certificate on the device.


Results

You implemented client-side components for custom device provisioning in native Android.


Example

The following sample shows the implementation of the challenge handler for custom device provisioning.

public class CustomDeviceProvisioningRealmChallengeHandler extends BaseProvisioningChallengeHandler {
  public CustomDeviceProvisioningRealmChallengeHandler(String realm) {
    super(realm);
  @Override
  protected void createCustomCsr(JSONObject challenge) {
    JSONObject customCsrProperties= new JSONObject();
    try {
      customCsrProperties.put(activationCode, activationCode.getText());
    } catch (JSONException e) {
  submitCustomCsr(customCsrProperties, challenge);
  @Override
  public void handleSuccess(JSONObject identity) {
    System.out.println("Device authentication with custom device provisioning was successfully completed");
  @Override
  public void handleFailure(JSONObject identity) {
    clearDeviceProvisioningCertificate();
    System.out.println("Server has rejected the device. We must reinstall the application and perform device provisioning again.");
}


What to do next

We can implement server-side components for custom device provisioning. For more information about implementing server-side components, see Implementing server-side components for custom device provisioning. For more information about custom device provisioning, see the tutorials on the Get Started page.


Parent topic: Implementing client-side components for custom device provisioning