Find Container

View this page for | |

Each time an end user triggers the registration process, a new container is provisioned containing cyptographic keys and policy information corresponding to a service. This implies that an integrating application might need to manage multiple containers from either the same or multiple servers.

The HID Approve SDK provides an API to list and filter all registered containers. Identifying the relevant container is generally the starting point for most operations.

Typical Use Case

The mobile application locates a container as follows:

  1. Create an instance of the Device (DeviceFactory.getDevice).

  2. Define the filter parameter to search for a container (or, by default, list all):

    • CONTAINER_NAME – friendly name of container

    • CONTAINER_URL – server URL

    • CONTAINER_USERID – user identifier

    • CONTAINER_EXPIRY_DATE – container expiration date

    • CONTAINER_CREATION_DATE – container creation date

  3. Get the instance of the Container (Device.findContainers).

Copy
// Get Device instance with default connection configuration 
    // context is specific to the platform. On Android, it is an instance of android.content.Context.
    val connectionConfiguration = ConnectionConfiguration()
    var device: Device? = null

    try {
        device = DeviceFactory.getDevice(context, connectionConfiguration)
    } catch (ex: Exception) {
        when(ex) {
            is InvalidParameterException, is LostCredentialsException, is UnsupportedDeviceException, is InternalException  -> {
                ex.printStackTrace()
            }
            else -> throw ex
        }
    }

    // We assume that you have already provisioned one or several containers.
    // findContainers will provide you the full list of containers registered, sorted by the creation date.
    var containers:Array<Container>? = null
    var params = arrayOfNulls<Parameter>(0)
    try {
        containers = device!!.findContainers(params)
        // Find the container you want
        for (i in containers.indices) {
            val containerName = containers[i].name
            println("Found container: ${containerName}")
        }
    } catch (ex: Exception) {
        when(ex) {
            is InternalException, is UnsupportedDeviceException, is InvalidParameterException  -> {
                ex.printStackTrace()
            }
            else -> throw ex
        }
    }
    //Alternatively, you can search a container through a filter for example, the user id and the name
    params = arrayOf(
        Parameter(SDKConstants.CONTAINER_USERID, userId.toCharArray()  ),
        Parameter(SDKConstants.CONTAINER_NAME, name.toCharArray())
    )
    var filteredcontainers:Array<Container>? = null
    try {
        filteredcontainers = device!!.findContainers(params)
    } catch (e: InternalException) {
        e.printStackTrace()
    } catch (e: UnsupportedDeviceException) {
        e.printStackTrace()
    } catch (e: InvalidParameterException) {
        e.printStackTrace()
    }
Copy
// Get Device instance with default connection configuration
    // Context is specific to the platform. On Android, it is an instance of android.content.Context.
    Device device = null;
    try {
        device = DeviceFactory.getDevice(context, new ConnectionConfiguration());
    } catch ( InvalidParameterException | LostCredentialsException | UnsupportedDeviceException | InternalException e) {
        e.printStackTrace();
    }

    // We assume that you have already provisioned one or several containers.
    // findContainers will provide you the full list of containers registered, sorted by the creation date.
    Parameter[] params = new Parameter[0];
    Container[] containers = null;
    try {
        containers = device.findContainers(params);
        // Find the container you want
        for (int i = 0; i < containers.length; i++) {
            String containerName = containers[i].getName();
            Log.d(LOG_TAG,"Found container: "+containerName);
        }
    } catch (InternalException | UnsupportedDeviceException | InvalidParameterException e) {
        e.printStackTrace();
    }

    //Alternatively, you can search a container through a filter for example, the user id and the name
    params = new Parameter[]{new Parameter(SDKConstants.CONTAINER_USERID, userId.toCharArray()),
            new Parameter(SDKConstants.CONTAINER_NAME, name.toCharArray())};
    Container[] filteredcontainers = null;
    try {
        filteredcontainers = device.findContainers(params);
    } catch (InternalException | UnsupportedDeviceException | InvalidParameterException e) {
        e.printStackTrace();
    }