Search in sources :

Example 1 with StsService

use of com.formkiq.aws.sts.StsService 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);
}
Also used : StsClient(software.amazon.awssdk.services.sts.StsClient) IamConnectionBuilder(com.formkiq.aws.iam.IamConnectionBuilder) GetCallerIdentityResponse(software.amazon.awssdk.services.sts.model.GetCallerIdentityResponse) StsConnectionBuilder(com.formkiq.aws.sts.StsConnectionBuilder) Aws4SignerParamsBuilder(com.formkiq.aws.sts.Aws4SignerParamsBuilder) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) CognitoConnectionBuilder(com.formkiq.aws.cognito.CognitoConnectionBuilder) IamClient(software.amazon.awssdk.services.iam.IamClient) StsService(com.formkiq.aws.sts.StsService) FormKiqClientConnection(com.formkiq.stacks.client.FormKiqClientConnection) ProfileCredentialsProvider(software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider) IamService(com.formkiq.aws.iam.IamService) CognitoService(com.formkiq.aws.cognito.CognitoService) BeforeClass(org.junit.BeforeClass)

Aggregations

CognitoConnectionBuilder (com.formkiq.aws.cognito.CognitoConnectionBuilder)1 CognitoService (com.formkiq.aws.cognito.CognitoService)1 IamConnectionBuilder (com.formkiq.aws.iam.IamConnectionBuilder)1 IamService (com.formkiq.aws.iam.IamService)1 Aws4SignerParamsBuilder (com.formkiq.aws.sts.Aws4SignerParamsBuilder)1 StsConnectionBuilder (com.formkiq.aws.sts.StsConnectionBuilder)1 StsService (com.formkiq.aws.sts.StsService)1 FormKiqClientConnection (com.formkiq.stacks.client.FormKiqClientConnection)1 FormKiqClientV1 (com.formkiq.stacks.client.FormKiqClientV1)1 BeforeClass (org.junit.BeforeClass)1 ProfileCredentialsProvider (software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider)1 IamClient (software.amazon.awssdk.services.iam.IamClient)1 StsClient (software.amazon.awssdk.services.sts.StsClient)1 GetCallerIdentityResponse (software.amazon.awssdk.services.sts.model.GetCallerIdentityResponse)1