|
49 | 49 | import java.util.Collections; |
50 | 50 | import java.util.List; |
51 | 51 | import java.util.Map; |
| 52 | +import java.util.regex.Pattern; |
52 | 53 |
|
53 | 54 | /** |
54 | 55 | * This represents a user-pool in a Cognito identity provider account. The user-pools are called as |
|
75 | 76 | public class CognitoUserPool { |
76 | 77 |
|
77 | 78 | private static final Log logger = LogFactory.getLog(CognitoUserPool.class); |
| 79 | + |
| 80 | + private static final int USER_POOL_ID_MAX_LENGTH = 55; |
| 81 | + private static final String USER_POOL_ID_PATTERN = "^[\\w-]+_[0-9a-zA-Z]+$"; |
| 82 | + |
78 | 83 | /** |
79 | 84 | * Cognito Your Identity Pool ID |
80 | 85 | */ |
@@ -268,6 +273,12 @@ public CognitoUserPool(Context context, String userPoolId, String clientId, Stri |
268 | 273 | public CognitoUserPool(Context context, String userPoolId, String clientId, String clientSecret, ClientConfiguration clientConfiguration, Regions region, String pinpointAppId) { |
269 | 274 | initialize(context); |
270 | 275 | this.context = context; |
| 276 | + if (userPoolId.isEmpty() || clientId.isEmpty()) { |
| 277 | + throw new IllegalArgumentException("Both UserPoolId and ClientId are required."); |
| 278 | + } |
| 279 | + if (userPoolId.length() > USER_POOL_ID_MAX_LENGTH || !Pattern.matches(USER_POOL_ID_PATTERN, userPoolId)) { |
| 280 | + throw new IllegalArgumentException("Invalid userPoolId format."); |
| 281 | + } |
271 | 282 | this.userPoolId = userPoolId; |
272 | 283 | this.clientId = clientId; |
273 | 284 | this.clientSecret = clientSecret; |
@@ -322,6 +333,12 @@ public CognitoUserPool(Context context, String userPoolId, String clientId, Stri |
322 | 333 | public CognitoUserPool(Context context, String userPoolId, String clientId, String clientSecret, AmazonCognitoIdentityProvider client, String pinpointAppId, String cognitoUserPoolCustomEndpoint) { |
323 | 334 | initialize(context); |
324 | 335 | this.context = context; |
| 336 | + if (userPoolId.isEmpty() || clientId.isEmpty()) { |
| 337 | + throw new IllegalArgumentException("Both UserPoolId and ClientId are required."); |
| 338 | + } |
| 339 | + if (userPoolId.length() > USER_POOL_ID_MAX_LENGTH || !Pattern.matches(USER_POOL_ID_PATTERN, userPoolId)) { |
| 340 | + throw new IllegalArgumentException("Invalid userPoolId format."); |
| 341 | + } |
325 | 342 | this.userPoolId = userPoolId; |
326 | 343 | this.clientId = clientId; |
327 | 344 | this.clientSecret = clientSecret; |
|
0 commit comments