@Override
    public void doInject(RequestResource resource, RamContext context, LoginIdentityContext result) {
        if (context.validate()) {
            try {
                String accessKey = context.getAccessKey();
                String secretKey = context.getSecretKey();
                // STS 临时凭证鉴权的优先级高于 AK/SK 鉴权
                if (StsConfig.getInstance().isStsOn()) {
                    StsCredential stsCredential = StsCredentialHolder.getInstance().getStsCredential();
                    accessKey = stsCredential.getAccessKeyId();
                    secretKey = stsCredential.getAccessKeySecret();
                    result.setParameter(IdentifyConstants.SECURITY_TOKEN_HEADER, stsCredential.getSecurityToken());
                }
                String signatureKey = secretKey;
                if (StringUtils.isNotEmpty(context.getRegionId())) {
                    signatureKey = CalculateV4SigningKeyUtil
                            .finalSigningKeyStringWithDefaultInfo(secretKey, context.getRegionId());
                    result.setParameter(RamConstants.SIGNATURE_VERSION, RamConstants.V4);
                }
                String signData = getSignData(getGroupedServiceName(resource));
                String signature = SignUtil.sign(signData, signatureKey);
                result.setParameter(SIGNATURE_FILED, signature);
                result.setParameter(DATA_FILED, signData);
                result.setParameter(AK_FILED, accessKey);
            } catch (Exception e) {
                NAMING_LOGGER.error("inject ak/sk failed.", e);
            }
        }
    }
@Test
    void testDoInjectForStsWithException() throws Exception {
        prepareForSts();
        stsCredential.setExpiration(new Date());
        resource = RequestResource.namingBuilder().setResource("aaa").setGroup("group").build();
        LoginIdentityContext actual = new LoginIdentityContext();
        namingResourceInjector.doInject(resource, ramContext, actual);
        assertEquals(0, actual.getAllKey().size());
    }