Search in sources :

Example 1 with ListDevicesRequest

use of com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest in project aws-sdk-android by aws-amplify.

the class DeviceOperations method _listDevices.

private ReturningRunnable<ListDevicesResult> _listDevices(final Integer limit, final String paginationToken) {
    return new ReturningRunnable<ListDevicesResult>() {

        @Override
        public ListDevicesResult run() throws Exception {
            final ListDevicesRequest listDevicesRequest = new ListDevicesRequest();
            listDevicesRequest.setAccessToken(mobileClient.getTokens().getAccessToken().getTokenString());
            listDevicesRequest.setLimit(limit);
            listDevicesRequest.setPaginationToken(paginationToken);
            final com.amazonaws.services.cognitoidentityprovider.model.ListDevicesResult listDevicesResult = userpoolLL.listDevices(listDevicesRequest);
            final ArrayList<Device> devices = new ArrayList<Device>(limit);
            for (DeviceType deviceType : listDevicesResult.getDevices()) {
                devices.add(marshallDeviceTypeToDevice(deviceType));
            }
            return new ListDevicesResult(devices, listDevicesResult.getPaginationToken());
        }
    };
}
Also used : ListDevicesResult(com.amazonaws.mobile.client.results.ListDevicesResult) DeviceType(com.amazonaws.services.cognitoidentityprovider.model.DeviceType) ReturningRunnable(com.amazonaws.mobile.client.internal.ReturningRunnable) Device(com.amazonaws.mobile.client.results.Device) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) ArrayList(java.util.ArrayList) ListDevicesRequest(com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest)

Example 2 with ListDevicesRequest

use of com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest in project aws-sdk-android by aws-amplify.

the class CognitoUser method listDevicesInternal.

/**
 * Internal method to fetch all devices trusted by this user.
 *
 * @param session REQUIRED: A valid {@link CognitoUserSession}.
 * @param limit REQUIRED: Maximum number of devices to fetch.
 * @param paginationToken REQUIRED: Token to continue with the previous
 *            srearch.
 * @return {@link ListDevicesResult}, service response.
 */
private ListDevicesResult listDevicesInternal(CognitoUserSession session, int limit, String paginationToken) {
    if (session != null && session.isValid()) {
        final ListDevicesRequest listDevicesRequest = new ListDevicesRequest();
        if (limit < 1) {
            listDevicesRequest.setLimit(CognitoDeviceHelper.DEFAULT_DEVICE_PAGINATION_LIMIT);
        } else {
            listDevicesRequest.setLimit(limit);
        }
        listDevicesRequest.setPaginationToken(paginationToken);
        listDevicesRequest.setAccessToken(session.getAccessToken().getJWTToken());
        return cognitoIdentityProviderClient.listDevices(listDevicesRequest);
    } else {
        throw new CognitoNotAuthorizedException("User is not authorized");
    }
}
Also used : CognitoNotAuthorizedException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException) ListDevicesRequest(com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest)

Example 3 with ListDevicesRequest

use of com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderDevicesTest method listDevicesInCurrentThread.

@Test
public void listDevicesInCurrentThread() {
    // Set mock result for the change password request API call
    doReturn(TEST_VALID_LIST_DEVICES_RESPONSE).when(mockCSIClient).listDevices(any(ListDevicesRequest.class));
    // Store tokens in shared preferences
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + ".idToken", getValidJWT(3600L));
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", getValidJWT(3600L));
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
    testUser.listDevices(10, "ptoken", new DevicesHandler() {

        @Override
        public void onSuccess(List<CognitoDevice> devices) {
            assertNotNull(devices);
            ArgumentCaptor<ListDevicesRequest> argumentCaptor = ArgumentCaptor.forClass(ListDevicesRequest.class);
            verify(mockCSIClient).listDevices(argumentCaptor.capture());
            ListDevicesRequest requestSent = argumentCaptor.getValue();
            assertEquals("ptoken", requestSent.getPaginationToken());
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : DevicesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) ListDevicesRequest(com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest) Test(org.junit.Test)

Example 4 with ListDevicesRequest

use of com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderDevicesTest method listDevicesInBackgroundThread.

@Test
public void listDevicesInBackgroundThread() {
    // Set mock result for the change password request API call
    doReturn(TEST_VALID_LIST_DEVICES_RESPONSE).when(mockCSIClient).listDevices(any(ListDevicesRequest.class));
    // Store tokens in shared preferences
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(3600L));
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", getValidJWT(3600L));
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
    testUser.listDevicesInBackground(10, "ptoken", new DevicesHandler() {

        @Override
        public void onSuccess(List<CognitoDevice> devices) {
            assertNotNull(devices);
            ArgumentCaptor<ListDevicesRequest> argumentCaptor = ArgumentCaptor.forClass(ListDevicesRequest.class);
            verify(mockCSIClient).listDevices(argumentCaptor.capture());
            ListDevicesRequest requestSent = argumentCaptor.getValue();
            assertEquals("ptoken", requestSent.getPaginationToken());
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : DevicesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) ListDevicesRequest(com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest) Test(org.junit.Test)

Aggregations

ListDevicesRequest (com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest)4 CognitoDevice (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice)3 DevicesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler)2 Test (org.junit.Test)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 ReturningRunnable (com.amazonaws.mobile.client.internal.ReturningRunnable)1 Device (com.amazonaws.mobile.client.results.Device)1 ListDevicesResult (com.amazonaws.mobile.client.results.ListDevicesResult)1 CognitoNotAuthorizedException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)1 DeviceType (com.amazonaws.services.cognitoidentityprovider.model.DeviceType)1 ArrayList (java.util.ArrayList)1