CognitoUserPoolSecurityContextFactory extends AbstractSecurityContextFactory { @Override protected boolean isValid() { Object rawClaims = getRawClaimsSafe(); if (!(rawClaims instanceof Map)) { LOG.debug("claims must be a map"); return false; } @SuppressWarnings("unchecked") Map<String, Object> claims = (Map<String, Object>) rawClaims; if (!(claims.get(OpenIdClaimFieldNames.STANDARD_CLAIM_SUB) instanceof String)) { LOG.debug("sub claim must be present and of type string"); return false; } Object rawAddressClaim = claims.get(OpenIdClaimFieldNames.STANDARD_CLAIM_ADDRESS); if (rawAddressClaim != null && !(rawAddressClaim instanceof Map)) { LOG.debug("address claim must be a map if present"); return false; } return true; } protected  CognitoUserPoolSecurityContextFactory(@Nonnull GatewayRequest request);   }
@Test public void isValid_InvalidClaimTypeGiven_ShouldNotBeValid() { GatewayRequestContext context = mock(GatewayRequestContext.class); when(context.getAuthorizer()).thenReturn(Collections.singletonMap("claims", 1)); GatewayRequest request = mock(GatewayRequest.class); when(request.getRequestContext()).thenReturn(context); assertFalse(createSecurityContextFactory(request).isValid()); }
@Test public void isValid_NoSubClaimGiven_ShouldNotBeValid() { GatewayRequest request = createRequestMock(null, null); assertFalse(createSecurityContextFactory(request).isValid()); }
@Test public void isValid_InvalidSubClaimTypeGiven_ShouldNotBeValid() { GatewayRequest request = createRequestMock(1, null); assertFalse(createSecurityContextFactory(request).isValid()); }
@Test public void isValid_InvalidAddressClaimTypeGiven_ShouldNotBeValid() { GatewayRequest request = createRequestMock("subClaim", 1); assertFalse(createSecurityContextFactory(request).isValid()); }
@Test public void isValid_SubClaimAndNoAddressGiven_ShouldBeValid() { GatewayRequest request = createRequestMock("subClaim", null); assertTrue(createSecurityContextFactory(request).isValid()); }
@Test public void isValid_SubClaimAndAddressGiven_ShouldBeValid() { GatewayRequest request = createRequestMock("subClaim", Collections.emptyMap()); assertTrue(createSecurityContextFactory(request).isValid()); }