Search in sources :

Example 1 with AwsStsHttpHeader

use of com.nike.cerberus.aws.sts.AwsStsHttpHeader in project cerberus by Nike-Inc.

the class AwsIamStsAuthController method authenticate.

@RequestMapping(method = POST)
public AuthTokenResponse authenticate(@RequestHeader(value = HEADER_X_AMZ_DATE, required = false) String headerXAmzDate, @RequestHeader(value = HEADER_X_AMZ_SECURITY_TOKEN, required = false) String headerXAmzSecurityToken, @RequestHeader(value = HEADER_AUTHORIZATION, required = false) String headerAuthorization) {
    String iamPrincipalArn;
    AuthTokenResponse authResponse;
    try {
        if (headerAuthorization == null || headerXAmzDate == null) {
            throw new ApiException(DefaultApiError.MISSING_AWS_SIGNATURE_HEADERS);
        }
        AwsStsHttpHeader header = new AwsStsHttpHeader(headerXAmzDate, headerXAmzSecurityToken, headerAuthorization);
        GetCallerIdentityResponse getCallerIdentityResponse = awsStsClient.getCallerIdentity(header);
        iamPrincipalArn = getCallerIdentityResponse.getGetCallerIdentityResult().getArn();
        authResponse = authenticationService.stsAuthenticate(iamPrincipalArn);
        auditLoggingFilterDetails.setAction("Successfully authenticated with AWS IAM STS Auth");
    } catch (Exception e) {
        String auditMessage = String.format("Failed to authenticate with AWS IAM STS Auth: %s", e.getMessage());
        auditLoggingFilterDetails.setAction(auditMessage);
        throw e;
    }
    return authResponse;
}
Also used : AuthTokenResponse(com.nike.cerberus.domain.AuthTokenResponse) GetCallerIdentityResponse(com.nike.cerberus.aws.sts.GetCallerIdentityResponse) ApiException(com.nike.backstopper.exception.ApiException) ApiException(com.nike.backstopper.exception.ApiException) AwsStsHttpHeader(com.nike.cerberus.aws.sts.AwsStsHttpHeader) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApiException (com.nike.backstopper.exception.ApiException)1 AwsStsHttpHeader (com.nike.cerberus.aws.sts.AwsStsHttpHeader)1 GetCallerIdentityResponse (com.nike.cerberus.aws.sts.GetCallerIdentityResponse)1 AuthTokenResponse (com.nike.cerberus.domain.AuthTokenResponse)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1