Search in sources :

Example 1 with GetUserResponse

use of software.amazon.awssdk.services.cognitoidentityprovider.model.GetUserResponse in project formkiq-core by formkiq.

the class CognitoService method getUser.

/**
 * Get User.
 *
 * @param token {@link AuthenticationResultType}.
 * @return {@link GetUserResponse}
 */
public GetUserResponse getUser(final AuthenticationResultType token) {
    GetUserRequest req = GetUserRequest.builder().accessToken(token.accessToken()).build();
    GetUserResponse resp = this.cognitoProvider.getUser(req);
    return resp;
}
Also used : AdminGetUserRequest(software.amazon.awssdk.services.cognitoidentityprovider.model.AdminGetUserRequest) GetUserRequest(software.amazon.awssdk.services.cognitoidentityprovider.model.GetUserRequest) GetUserResponse(software.amazon.awssdk.services.cognitoidentityprovider.model.GetUserResponse) AdminGetUserResponse(software.amazon.awssdk.services.cognitoidentityprovider.model.AdminGetUserResponse)

Example 2 with GetUserResponse

use of software.amazon.awssdk.services.cognitoidentityprovider.model.GetUserResponse 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

GetUserResponse (software.amazon.awssdk.services.cognitoidentityprovider.model.GetUserResponse)2 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 AdminGetUserRequest (software.amazon.awssdk.services.cognitoidentityprovider.model.AdminGetUserRequest)1 AdminGetUserResponse (software.amazon.awssdk.services.cognitoidentityprovider.model.AdminGetUserResponse)1 GetUserRequest (software.amazon.awssdk.services.cognitoidentityprovider.model.GetUserRequest)1