use of com.formkiq.aws.cognito.CognitoService in project formkiq-core by formkiq.
the class WebsocketTest method beforeClass.
/**
* beforeclass.
*
* @throws IOException IOException
* @throws URISyntaxException URISyntaxException
*/
@BeforeClass
public static void beforeClass() throws IOException, URISyntaxException {
Region awsregion = Region.of(System.getProperty("testregion"));
String awsprofile = System.getProperty("testprofile");
String app = System.getProperty("testappenvironment");
SqsConnectionBuilder sqsConnection = new SqsConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
sqsService = new SqsService(sqsConnection);
SsmConnectionBuilder ssmBuilder = new SsmConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
SsmService ssmService = new SsmServiceImpl(ssmBuilder);
websocketSqsUrl = ssmService.getParameterValue("/formkiq/" + app + "/sqs/WebsocketUrl");
websocketUrl = ssmService.getParameterValue("/formkiq/" + app + "/api/WebsocketUrl");
String cognitoUserPoolId = ssmService.getParameterValue("/formkiq/" + app + "/cognito/UserPoolId");
String cognitoClientId = ssmService.getParameterValue("/formkiq/" + app + "/cognito/UserPoolClientId");
String cognitoIdentitypool = ssmService.getParameterValue("/formkiq/" + app + "/cognito/IdentityPoolId");
CognitoConnectionBuilder adminBuilder = new CognitoConnectionBuilder(cognitoClientId, cognitoUserPoolId, cognitoIdentitypool).setCredentials(awsprofile).setRegion(awsregion);
adminCognitoService = new CognitoService(adminBuilder);
addAndLoginCognito(USER_EMAIL, GROUP);
token = adminCognitoService.login(USER_EMAIL, USER_PASSWORD);
String rootHttpUrl = ssmService.getParameterValue("/formkiq/" + app + "/api/DocumentsHttpUrl");
FormKiqClientConnection connection = new FormKiqClientConnection(rootHttpUrl).cognitoIdToken(token.idToken()).header("Origin", Arrays.asList("http://localhost")).header("Access-Control-Request-Method", Arrays.asList("GET"));
httpClient = new FormKiqClientV1(connection);
webconnectionsTable = ssmService.getParameterValue("/formkiq/" + app + "/dynamodb/WebConnectionsTableName");
dbConnection = new DynamoDbConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
}
use of com.formkiq.aws.cognito.CognitoService 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());
}
use of com.formkiq.aws.cognito.CognitoService in project formkiq-core by formkiq.
the class AbstractApiTest method beforeClass.
/**
* Before Class.
*
* @throws IOException IOException
*/
@BeforeClass
public static void beforeClass() throws IOException {
awsregion = Region.of(System.getProperty("testregion"));
String awsprofile = System.getProperty("testprofile");
appenvironment = System.getProperty("testappenvironment");
loadSsmParameterVariables(awsprofile);
try (ProfileCredentialsProvider credentials = ProfileCredentialsProvider.builder().profileName(awsprofile).build()) {
FormKiqClientConnection connection = new FormKiqClientConnection(rootRestUrl).region(awsregion).credentials(credentials.resolveCredentials()).header("Origin", Arrays.asList("http://localhost")).header("Access-Control-Request-Method", Arrays.asList("GET"));
restClient = new FormKiqClientV1(connection);
}
CognitoConnectionBuilder adminBuilder = new CognitoConnectionBuilder(cognitoClientId, cognitoUserPoolId, cognitoIdentitypool).setCredentials(awsprofile).setRegion(awsregion);
adminCognitoService = new CognitoService(adminBuilder);
stsBuilder = new StsConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
stsService = new StsService(stsBuilder);
try (StsClient stsClient = stsBuilder.build()) {
GetCallerIdentityResponse identity = stsClient.getCallerIdentity();
String user = identity.arn().substring(identity.arn().lastIndexOf("/") + 1);
IamConnectionBuilder iamBuilder = new IamConnectionBuilder().setCredentials(awsprofile);
IamService iam = new IamService(iamBuilder);
try (IamClient iamClient = iamBuilder.build()) {
iam.addUserToGroup(iamClient, user, apiGatewayInvokeGroup);
}
executeApiSigner = new Aws4SignerParamsBuilder().setRegion(awsregion).setSigningName("execute-api").setCredentials(awsprofile).build();
}
setupCognito();
setupConfigService(awsprofile);
}
Aggregations