Search in sources :

Example 1 with AuthenticationResultType

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

the class DocumentsRequestTest method testPost03.

/**
 * Save new File as 'USERS' group.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testPost03() throws Exception {
    // given
    final String siteId = "finance";
    AuthenticationResultType token = login(USER_EMAIL, USER_PASSWORD);
    FormKiqClientV1 client = createHttpClient(token);
    AddDocument post = new AddDocument();
    post.content("dummy data", StandardCharsets.UTF_8);
    post.contentType("application/pdf");
    AddDocumentRequest req = new AddDocumentRequest().document(post);
    // when
    final HttpResponse<String> responseNoSiteId = client.addDocumentAsHttpResponse(req);
    final HttpResponse<String> responseSiteId = client.addDocumentAsHttpResponse(req.siteId(siteId));
    // then
    assertEquals(STATUS_CREATED, responseNoSiteId.statusCode());
    assertRequestCorsHeaders(responseNoSiteId.headers());
    assertTrue(responseNoSiteId.body().startsWith("{\"documentId\":\""));
    assertEquals(STATUS_FORBIDDEN, responseSiteId.statusCode());
    assertRequestCorsHeaders(responseSiteId.headers());
    assertEquals("{\"message\":\"Access Denied\"}", responseSiteId.body());
}
Also used : AddDocument(com.formkiq.stacks.client.models.AddDocument) AuthenticationResultType(software.amazon.awssdk.services.cognitoidentityprovider.model.AuthenticationResultType) AddDocumentRequest(com.formkiq.stacks.client.requests.AddDocumentRequest) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Example 2 with AuthenticationResultType

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

the class DocumentsRequestTest method testGet05.

/**
 * Get Not existing file. Test user with 'FINANCE' roles with/out siteid
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testGet05() throws Exception {
    // given
    final String siteId = "finance";
    AuthenticationResultType token = login(FINANCE_EMAIL, USER_PASSWORD);
    FormKiqClientV1 client = createHttpClient(token);
    GetDocumentsRequest request = new GetDocumentsRequest().date(new Date());
    // when
    final HttpResponse<String> responseNoSiteId = client.getDocumentsAsHttpResponse(request);
    final HttpResponse<String> responseSiteId = client.getDocumentsAsHttpResponse(request.siteId(siteId));
    // then
    assertEquals(STATUS_OK, responseNoSiteId.statusCode());
    assertRequestCorsHeaders(responseNoSiteId.headers());
    assertTrue(responseNoSiteId.body().contains("\"documents\":["));
    assertEquals(STATUS_OK, responseSiteId.statusCode());
    assertRequestCorsHeaders(responseSiteId.headers());
    assertTrue(responseSiteId.body().contains("\"documents\":["));
}
Also used : GetDocumentsRequest(com.formkiq.stacks.client.requests.GetDocumentsRequest) AuthenticationResultType(software.amazon.awssdk.services.cognitoidentityprovider.model.AuthenticationResultType) Date(java.util.Date) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Example 3 with AuthenticationResultType

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

the class SitesRequestTest method testSites01.

/**
 * Test GET /version.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testSites01() throws Exception {
    // given
    AuthenticationResultType token = login(USER_EMAIL, USER_PASSWORD);
    putParameter("/formkiq/" + getAppenvironment() + "/maildomain", "tryformkiq.com");
    FormKiqClientV1 client = createHttpClient(token);
    // when
    Sites sites = client.getSites();
    // then
    assertEquals(1, sites.sites().size());
    assertNotNull(sites.sites().get(0).siteId());
    assertTrue(sites.sites().get(0).uploadEmail().endsWith("@tryformkiq.com"));
}
Also used : AuthenticationResultType(software.amazon.awssdk.services.cognitoidentityprovider.model.AuthenticationResultType) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Sites(com.formkiq.stacks.client.models.Sites) Test(org.junit.Test)

Example 4 with AuthenticationResultType

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

the class CognitoService method login.

/**
 * Login User.
 *
 * @param email {@link String}
 * @param password {@link String}
 * @return {@link AuthenticationResultType}
 */
public AuthenticationResultType login(final String email, final String password) {
    AdminInitiateAuthResponse authResult = loginInternal(email, password);
    AuthenticationResultType authentication = authResult.authenticationResult();
    return authentication;
}
Also used : AdminInitiateAuthResponse(software.amazon.awssdk.services.cognitoidentityprovider.model.AdminInitiateAuthResponse) AuthenticationResultType(software.amazon.awssdk.services.cognitoidentityprovider.model.AuthenticationResultType)

Example 5 with AuthenticationResultType

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

the class CognitoService method loginWithNewPassword.

/**
 * Login User in NEW_PASSWORD_REQUIRED status.
 *
 * @param email {@link String}
 * @param password {@link String}
 * @param newpassword {@link String}
 * @return {@link AuthenticationResultType}
 */
public AuthenticationResultType loginWithNewPassword(final String email, final String password, final String newpassword) {
    AuthenticationResultType authentication = null;
    final AdminInitiateAuthResponse authResult = loginInternal(email, password);
    if ("NEW_PASSWORD_REQUIRED".equals(authResult.challengeName().name())) {
        final Map<String, String> challengeResponses = new HashMap<>();
        challengeResponses.put("USERNAME", email);
        challengeResponses.put("PASSWORD", password);
        challengeResponses.put("NEW_PASSWORD", newpassword);
        // populate the challenge response
        AdminRespondToAuthChallengeRequest request = AdminRespondToAuthChallengeRequest.builder().challengeName(ChallengeNameType.NEW_PASSWORD_REQUIRED).challengeResponses(challengeResponses).clientId(this.clientId).userPoolId(this.userPoolId).session(authResult.session()).build();
        AdminRespondToAuthChallengeResponse resultChallenge = this.cognitoProvider.adminRespondToAuthChallenge(request);
        authentication = resultChallenge.authenticationResult();
    } else {
        authentication = authResult.authenticationResult();
    }
    return authentication;
}
Also used : AdminRespondToAuthChallengeResponse(software.amazon.awssdk.services.cognitoidentityprovider.model.AdminRespondToAuthChallengeResponse) HashMap(java.util.HashMap) AdminRespondToAuthChallengeRequest(software.amazon.awssdk.services.cognitoidentityprovider.model.AdminRespondToAuthChallengeRequest) AdminInitiateAuthResponse(software.amazon.awssdk.services.cognitoidentityprovider.model.AdminInitiateAuthResponse) AuthenticationResultType(software.amazon.awssdk.services.cognitoidentityprovider.model.AuthenticationResultType)

Aggregations

AuthenticationResultType (software.amazon.awssdk.services.cognitoidentityprovider.model.AuthenticationResultType)10 FormKiqClientV1 (com.formkiq.stacks.client.FormKiqClientV1)8 Test (org.junit.Test)8 AddDocument (com.formkiq.stacks.client.models.AddDocument)4 AddDocumentRequest (com.formkiq.stacks.client.requests.AddDocumentRequest)4 GetDocumentsRequest (com.formkiq.stacks.client.requests.GetDocumentsRequest)3 Date (java.util.Date)3 FormKiqClientConnection (com.formkiq.stacks.client.FormKiqClientConnection)2 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)2 AdminInitiateAuthResponse (software.amazon.awssdk.services.cognitoidentityprovider.model.AdminInitiateAuthResponse)2 Sites (com.formkiq.stacks.client.models.Sites)1 HashMap (java.util.HashMap)1 AdminRespondToAuthChallengeRequest (software.amazon.awssdk.services.cognitoidentityprovider.model.AdminRespondToAuthChallengeRequest)1 AdminRespondToAuthChallengeResponse (software.amazon.awssdk.services.cognitoidentityprovider.model.AdminRespondToAuthChallengeResponse)1