Skip to content

Commit

Permalink
ALS-1694 validateIdentityPoolId bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shah272728 committed Oct 6, 2023
1 parent d1ef9de commit 6d0ee31
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const val LAT_LNG_REG_EXP = "([+-]?\\d+\\.?\\d+)\\s*,\\s*([+-]?\\d+\\.?\\d+)"
const val GEOFENCE_NAME_REG_EXP = "^[-._\\p{L}\\p{N}]+\$"
const val userPoolIdPattern = "[\\w-]+_[0-9a-zA-Z]+"
const val userPoolClientId = "[\\w+]+"
const val regionPattern = "^[a-zA-Z-]+-\\d+$"

const val LOCATION_AWS_PREFIX = "location.aws.com.demo."
const val LOCATION_MAPS_PREFIX = "maps."
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/java/com/aws/amazonlocation/utils/GeneralUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -566,16 +566,22 @@ fun Context.isInternetAvailable(): Boolean {
}

fun validateIdentityPoolId(mIdentityPoolId: String?, region: String?): Boolean {
val cognitoCredentialsProvider = CognitoCredentialsProvider(
mIdentityPoolId,
Regions.fromName(region)
)
val pattern = Pattern.compile(regionPattern)
val matcher = region?.let { pattern.matcher(it) }
if (matcher?.matches() != true) return false
try {
val cognitoCredentialsProvider = CognitoCredentialsProvider(
mIdentityPoolId,
Regions.fromName(region)
)
cognitoCredentialsProvider.refresh()
} catch (exception: Exception) {
if (exception is com.amazonaws.services.cognitoidentity.model.ResourceNotFoundException) {
return false
}
if (exception is IllegalArgumentException) {
return false
}
}
return true
}
Expand Down

0 comments on commit 6d0ee31

Please sign in to comment.