Search in sources :

Example 1 with Credentials

use of software.amazon.awssdk.services.cognitoidentity.model.Credentials in project formkiq-core by formkiq.

the class AwsResourceTest method testAdminAddUserToGroup.

/**
 * Test Having Admin add new user to group.
 */
@Test(timeout = TEST_TIMEOUT)
public void testAdminAddUserToGroup() {
    // given
    String email = UUID.randomUUID() + "@formkiq.com";
    String group = getParameterStoreValue("/formkiq/" + getAppenvironment() + "/cognito/AdminGroup");
    Credentials cred = getAdminCognitoService().getCredentials(getAdminToken());
    AwsCredentials basic = AwsSessionCredentials.create(cred.accessKeyId(), cred.secretKey(), cred.sessionToken());
    CognitoConnectionBuilder userBuilder = createCognitoConnectionBuilder().setCredentials(StaticCredentialsProvider.create(basic));
    CognitoService userCognitoService = new CognitoService(userBuilder);
    // when
    GetUserResponse user = userCognitoService.getUser(getAdminToken());
    userCognitoService.addUser(email, USER_TEMP_PASSWORD);
    userCognitoService.addUserToGroup(email, group);
    // then
    assertNotNull(user.username());
    assertEquals("testadminuser@formkiq.com", user.userAttributes().stream().filter(f -> f.name().equals("email")).findFirst().get().value());
}
Also used : CognitoConnectionBuilder(com.formkiq.aws.cognito.CognitoConnectionBuilder) GetUserResponse(software.amazon.awssdk.services.cognitoidentityprovider.model.GetUserResponse) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) AwsSessionCredentials(software.amazon.awssdk.auth.credentials.AwsSessionCredentials) Credentials(software.amazon.awssdk.services.cognitoidentity.model.Credentials) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) CognitoService(com.formkiq.aws.cognito.CognitoService) Test(org.junit.Test)

Aggregations

CognitoConnectionBuilder (com.formkiq.aws.cognito.CognitoConnectionBuilder)1 CognitoService (com.formkiq.aws.cognito.CognitoService)1 Test (org.junit.Test)1 AwsCredentials (software.amazon.awssdk.auth.credentials.AwsCredentials)1 AwsSessionCredentials (software.amazon.awssdk.auth.credentials.AwsSessionCredentials)1 Credentials (software.amazon.awssdk.services.cognitoidentity.model.Credentials)1 GetUserResponse (software.amazon.awssdk.services.cognitoidentityprovider.model.GetUserResponse)1