@Test public void getCredentialHistoryShouldBeAbleToHandleLegacyCredentialEntries() { List<DBCredential> fakeData = new ArrayList<>(); DBCredential fakeCred1 = new DBCredential(); fakeCred1.setName("APP.TestComponent.dev.testKey"); fakeCred1.setSdlc("dev"); fakeCred1.setComponent("TestComponent"); fakeCred1.setVersion("0001"); fakeData.add(fakeCred1); when(dynamoDBService.scanDynamoDB(any(), eq(DBCredential.class), any())).thenReturn(fakeData); credentialsService.getCredentialHistory("table", "dev", "us-east-1", "APP", "dev", "TestComponent", "testKey"); }
@PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public List<HistoryEntry> getCredentialHistory(String tableName, String account, String region, String application, String environment, String component, String key) throws FideliusException { List<HistoryEntry> results = new ArrayList<>(); DynamoDBMapper mapper = dynamoDBService.createMapper(account, region, tableName); setFideliusEnvironment(account, region); StringBuilder fullKeyBuilder = new StringBuilder(); fullKeyBuilder.append(String.format("%s", application.toUpperCase())); if (component != null && !component.equals("null")) { fullKeyBuilder.append(String.format(".%s", component)); } fullKeyBuilder.append(String.format(".%s", environment)); fullKeyBuilder.append(String.format(".%s", key)); Map<String, String> ean = new HashMap<>(); ean.put("#tempname", "name"); Map<String, AttributeValue> eav = new HashMap<>(); eav.put(":key", new AttributeValue().withS(fullKeyBuilder.toString())); DynamoDBQueryExpression<DBCredential> queryExpression = new DynamoDBQueryExpression<DBCredential>() .withExpressionAttributeNames(ean) .withKeyConditionExpression("#tempname = :key") .withExpressionAttributeValues(eav); logger.info(String.format("Retrieving history of credential %s using account %s and region %s", fullKeyBuilder, account, region)); List<DBCredential> queryResults = dynamoDBService.queryDynamoDB(queryExpression, DBCredential.class, mapper); for (DBCredential dbCred : queryResults) { results.add(new HistoryEntry(new Integer(dbCred.getVersion()), splitRoleARN(dbCred.getUpdatedBy()), dbCred.getUpdatedDate())); } logger.info(String.format("Found %d entries for credential %s.", results.size(), fullKeyBuilder)); return results; }
CredentialsService { @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public List<HistoryEntry> getCredentialHistory(String tableName, String account, String region, String application, String environment, String component, String key) throws FideliusException { List<HistoryEntry> results = new ArrayList<>(); DynamoDBMapper mapper = dynamoDBService.createMapper(account, region, tableName); setFideliusEnvironment(account, region); StringBuilder fullKeyBuilder = new StringBuilder(); fullKeyBuilder.append(String.format("%s", application.toUpperCase())); if (component != null && !component.equals("null")) { fullKeyBuilder.append(String.format(".%s", component)); } fullKeyBuilder.append(String.format(".%s", environment)); fullKeyBuilder.append(String.format(".%s", key)); Map<String, String> ean = new HashMap<>(); ean.put("#tempname", "name"); Map<String, AttributeValue> eav = new HashMap<>(); eav.put(":key", new AttributeValue().withS(fullKeyBuilder.toString())); DynamoDBQueryExpression<DBCredential> queryExpression = new DynamoDBQueryExpression<DBCredential>() .withExpressionAttributeNames(ean) .withKeyConditionExpression("#tempname = :key") .withExpressionAttributeValues(eav); logger.info(String.format("Retrieving history of credential %s using account %s and region %s", fullKeyBuilder, account, region)); List<DBCredential> queryResults = dynamoDBService.queryDynamoDB(queryExpression, DBCredential.class, mapper); for (DBCredential dbCred : queryResults) { results.add(new HistoryEntry(new Integer(dbCred.getVersion()), splitRoleARN(dbCred.getUpdatedBy()), dbCred.getUpdatedDate())); } logger.info(String.format("Found %d entries for credential %s.", results.size(), fullKeyBuilder)); return results; } }
CredentialsService { @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public List<HistoryEntry> getCredentialHistory(String tableName, String account, String region, String application, String environment, String component, String key) throws FideliusException { List<HistoryEntry> results = new ArrayList<>(); DynamoDBMapper mapper = dynamoDBService.createMapper(account, region, tableName); setFideliusEnvironment(account, region); StringBuilder fullKeyBuilder = new StringBuilder(); fullKeyBuilder.append(String.format("%s", application.toUpperCase())); if (component != null && !component.equals("null")) { fullKeyBuilder.append(String.format(".%s", component)); } fullKeyBuilder.append(String.format(".%s", environment)); fullKeyBuilder.append(String.format(".%s", key)); Map<String, String> ean = new HashMap<>(); ean.put("#tempname", "name"); Map<String, AttributeValue> eav = new HashMap<>(); eav.put(":key", new AttributeValue().withS(fullKeyBuilder.toString())); DynamoDBQueryExpression<DBCredential> queryExpression = new DynamoDBQueryExpression<DBCredential>() .withExpressionAttributeNames(ean) .withKeyConditionExpression("#tempname = :key") .withExpressionAttributeValues(eav); logger.info(String.format("Retrieving history of credential %s using account %s and region %s", fullKeyBuilder, account, region)); List<DBCredential> queryResults = dynamoDBService.queryDynamoDB(queryExpression, DBCredential.class, mapper); for (DBCredential dbCred : queryResults) { results.add(new HistoryEntry(new Integer(dbCred.getVersion()), splitRoleARN(dbCred.getUpdatedBy()), dbCred.getUpdatedDate())); } logger.info(String.format("Found %d entries for credential %s.", results.size(), fullKeyBuilder)); return results; }  }
CredentialsService { @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public List<HistoryEntry> getCredentialHistory(String tableName, String account, String region, String application, String environment, String component, String key) throws FideliusException { List<HistoryEntry> results = new ArrayList<>(); DynamoDBMapper mapper = dynamoDBService.createMapper(account, region, tableName); setFideliusEnvironment(account, region); StringBuilder fullKeyBuilder = new StringBuilder(); fullKeyBuilder.append(String.format("%s", application.toUpperCase())); if (component != null && !component.equals("null")) { fullKeyBuilder.append(String.format(".%s", component)); } fullKeyBuilder.append(String.format(".%s", environment)); fullKeyBuilder.append(String.format(".%s", key)); Map<String, String> ean = new HashMap<>(); ean.put("#tempname", "name"); Map<String, AttributeValue> eav = new HashMap<>(); eav.put(":key", new AttributeValue().withS(fullKeyBuilder.toString())); DynamoDBQueryExpression<DBCredential> queryExpression = new DynamoDBQueryExpression<DBCredential>() .withExpressionAttributeNames(ean) .withKeyConditionExpression("#tempname = :key") .withExpressionAttributeValues(eav); logger.info(String.format("Retrieving history of credential %s using account %s and region %s", fullKeyBuilder, account, region)); List<DBCredential> queryResults = dynamoDBService.queryDynamoDB(queryExpression, DBCredential.class, mapper); for (DBCredential dbCred : queryResults) { results.add(new HistoryEntry(new Integer(dbCred.getVersion()), splitRoleARN(dbCred.getUpdatedBy()), dbCred.getUpdatedDate())); } logger.info(String.format("Found %d entries for credential %s.", results.size(), fullKeyBuilder)); return results; }  @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") List<Credential> getAllCredentials(String tableName, String account, String region, String application); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") Credential getCredential(String account, String region, String application, String longKey); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") List<HistoryEntry> getCredentialHistory(String tableName, String account, String region, String application, String environment, String component, String key); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account)") Credential getCredentialSecret(String account, String region, String application, String environment,
                                      String component, String shortKey); @PreAuthorize("@fideliusRoleService.isAuthorized(#credential.application, #credential.account)") Credential putCredential(Credential credential); @PreAuthorize("@fideliusRoleService.isAuthorized(#credential.application, #credential.account)") Credential createCredential(Credential credential); @PreAuthorize("@fideliusRoleService.isAuthorizedToDelete(#credential.getApplication(), #credential.getAccount())") Credential deleteCredential(Credential credential); }
CredentialsService { @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public List<HistoryEntry> getCredentialHistory(String tableName, String account, String region, String application, String environment, String component, String key) throws FideliusException { List<HistoryEntry> results = new ArrayList<>(); DynamoDBMapper mapper = dynamoDBService.createMapper(account, region, tableName); setFideliusEnvironment(account, region); StringBuilder fullKeyBuilder = new StringBuilder(); fullKeyBuilder.append(String.format("%s", application.toUpperCase())); if (component != null && !component.equals("null")) { fullKeyBuilder.append(String.format(".%s", component)); } fullKeyBuilder.append(String.format(".%s", environment)); fullKeyBuilder.append(String.format(".%s", key)); Map<String, String> ean = new HashMap<>(); ean.put("#tempname", "name"); Map<String, AttributeValue> eav = new HashMap<>(); eav.put(":key", new AttributeValue().withS(fullKeyBuilder.toString())); DynamoDBQueryExpression<DBCredential> queryExpression = new DynamoDBQueryExpression<DBCredential>() .withExpressionAttributeNames(ean) .withKeyConditionExpression("#tempname = :key") .withExpressionAttributeValues(eav); logger.info(String.format("Retrieving history of credential %s using account %s and region %s", fullKeyBuilder, account, region)); List<DBCredential> queryResults = dynamoDBService.queryDynamoDB(queryExpression, DBCredential.class, mapper); for (DBCredential dbCred : queryResults) { results.add(new HistoryEntry(new Integer(dbCred.getVersion()), splitRoleARN(dbCred.getUpdatedBy()), dbCred.getUpdatedDate())); } logger.info(String.format("Found %d entries for credential %s.", results.size(), fullKeyBuilder)); return results; }  @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") List<Credential> getAllCredentials(String tableName, String account, String region, String application); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") Credential getCredential(String account, String region, String application, String longKey); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") List<HistoryEntry> getCredentialHistory(String tableName, String account, String region, String application, String environment, String component, String key); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account)") Credential getCredentialSecret(String account, String region, String application, String environment,
                                      String component, String shortKey); @PreAuthorize("@fideliusRoleService.isAuthorized(#credential.application, #credential.account)") Credential putCredential(Credential credential); @PreAuthorize("@fideliusRoleService.isAuthorized(#credential.application, #credential.account)") Credential createCredential(Credential credential); @PreAuthorize("@fideliusRoleService.isAuthorizedToDelete(#credential.getApplication(), #credential.getAccount())") Credential deleteCredential(Credential credential);  }