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());
}
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\":["));
}
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"));
}
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;
}
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;
}
Aggregations