388 String expiration1 =
"2014-09-10T22:49:44.090+0000";
389 Date expirationDate1 =
formatter.parse(expiration1, Locale.ENGLISH);
391 ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
392 when(mockedClient1.getClientId()).thenReturn(
"mocked_client_1");
394 AuthenticationHolderEntity mockedAuthHolder1 = mock(AuthenticationHolderEntity.class);
395 when(mockedAuthHolder1.getId()).thenReturn(1L);
397 OAuth2AccessTokenEntity token1 =
new OAuth2AccessTokenEntity();
399 token1.setClient(mockedClient1);
400 token1.setExpiration(expirationDate1);
401 token1.setJwt(JWTParser.parse(
"eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE0MTI3ODk5NjgsInN1YiI6IjkwMzQyLkFTREZKV0ZBIiwiYXRfaGFzaCI6InptTmt1QmNRSmNYQktNaVpFODZqY0EiLCJhdWQiOlsiY2xpZW50Il0sImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo4MDgwXC9vcGVuaWQtY29ubmVjdC1zZXJ2ZXItd2ViYXBwXC8iLCJpYXQiOjE0MTI3ODkzNjh9.xkEJ9IMXpH7qybWXomfq9WOOlpGYnrvGPgey9UQ4GLzbQx7JC0XgJK83PmrmBZosvFPCmota7FzI_BtwoZLgAZfFiH6w3WIlxuogoH-TxmYbxEpTHoTsszZppkq9mNgOlArV4jrR9y3TPo4MovsH71dDhS_ck-CvAlJunHlqhs0"));
402 token1.setAuthenticationHolder(mockedAuthHolder1);
403 token1.setScope(ImmutableSet.of(
"id-token"));
404 token1.setTokenType(
"Bearer");
406 String expiration2 =
"2015-01-07T18:31:50.079+0000";
407 Date expirationDate2 =
formatter.parse(expiration2, Locale.ENGLISH);
409 ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
410 when(mockedClient2.getClientId()).thenReturn(
"mocked_client_2");
412 AuthenticationHolderEntity mockedAuthHolder2 = mock(AuthenticationHolderEntity.class);
413 when(mockedAuthHolder2.getId()).thenReturn(2L);
415 OAuth2RefreshTokenEntity mockRefreshToken2 = mock(OAuth2RefreshTokenEntity.class);
416 when(mockRefreshToken2.getId()).thenReturn(1L);
418 OAuth2AccessTokenEntity token2 =
new OAuth2AccessTokenEntity();
420 token2.setClient(mockedClient2);
421 token2.setExpiration(expirationDate2);
422 token2.setJwt(JWTParser.parse(
"eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE0MTI3OTI5NjgsImF1ZCI6WyJjbGllbnQiXSwiaXNzIjoiaHR0cDpcL1wvbG9jYWxob3N0OjgwODBcL29wZW5pZC1jb25uZWN0LXNlcnZlci13ZWJhcHBcLyIsImp0aSI6IjBmZGE5ZmRiLTYyYzItNGIzZS05OTdiLWU0M2VhMDUwMzNiOSIsImlhdCI6MTQxMjc4OTM2OH0.xgaVpRLYE5MzbgXfE0tZt823tjAm6Oh3_kdR1P2I9jRLR6gnTlBQFlYi3Y_0pWNnZSerbAE8Tn6SJHZ9k-curVG0-ByKichV7CNvgsE5X_2wpEaUzejvKf8eZ-BammRY-ie6yxSkAarcUGMvGGOLbkFcz5CtrBpZhfd75J49BIQ"));
423 token2.setAuthenticationHolder(mockedAuthHolder2);
424 token2.setRefreshToken(mockRefreshToken2);
425 token2.setScope(ImmutableSet.of(
"openid",
"offline_access",
"email",
"profile"));
426 token2.setTokenType(
"Bearer");
428 Set<OAuth2AccessTokenEntity> allAccessTokens = ImmutableSet.of(token1, token2);
440 StringWriter stringWriter =
new StringWriter();
441 JsonWriter writer =
new JsonWriter(stringWriter);
442 writer.beginObject();
448 JsonElement elem =
new JsonParser().parse(stringWriter.toString());
449 JsonObject root = elem.getAsJsonObject();
452 assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_3), is(
true));
454 JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_3).getAsJsonObject();
457 assertThat(config.has(MITREidDataService.CLIENTS), is(
true));
458 assertThat(config.has(MITREidDataService.GRANTS), is(
true));
459 assertThat(config.has(MITREidDataService.WHITELISTEDSITES), is(
true));
460 assertThat(config.has(MITREidDataService.BLACKLISTEDSITES), is(
true));
461 assertThat(config.has(MITREidDataService.REFRESHTOKENS), is(
true));
462 assertThat(config.has(MITREidDataService.ACCESSTOKENS), is(
true));
463 assertThat(config.has(MITREidDataService.SYSTEMSCOPES), is(
true));
464 assertThat(config.has(MITREidDataService.AUTHENTICATIONHOLDERS), is(
true));
467 assertThat(config.get(MITREidDataService.CLIENTS).isJsonArray(), is(
true));
468 assertThat(config.get(MITREidDataService.GRANTS).isJsonArray(), is(
true));
469 assertThat(config.get(MITREidDataService.WHITELISTEDSITES).isJsonArray(), is(
true));
470 assertThat(config.get(MITREidDataService.BLACKLISTEDSITES).isJsonArray(), is(
true));
471 assertThat(config.get(MITREidDataService.REFRESHTOKENS).isJsonArray(), is(
true));
472 assertThat(config.get(MITREidDataService.ACCESSTOKENS).isJsonArray(), is(
true));
473 assertThat(config.get(MITREidDataService.SYSTEMSCOPES).isJsonArray(), is(
true));
474 assertThat(config.get(MITREidDataService.AUTHENTICATIONHOLDERS).isJsonArray(), is(
true));
478 JsonArray accessTokens = config.get(MITREidDataService.ACCESSTOKENS).getAsJsonArray();
480 assertThat(accessTokens.size(), is(2));
482 Set<OAuth2AccessTokenEntity> checked =
new HashSet<>();
483 for (JsonElement e : accessTokens) {
484 assertTrue(e.isJsonObject());
485 JsonObject token = e.getAsJsonObject();
487 OAuth2AccessTokenEntity compare = null;
488 if (token.get(
"id").getAsLong() == token1.getId().longValue()) {
490 }
else if (token.get(
"id").getAsLong() == token2.getId().longValue()) {
494 if (compare == null) {
495 fail(
"Could not find matching id: " + token.get(
"id").getAsString());
497 assertThat(token.get(
"id").getAsLong(), equalTo(compare.getId()));
498 assertThat(token.get(
"clientId").getAsString(), equalTo(compare.getClient().getClientId()));
499 assertThat(token.get(
"expiration").getAsString(), equalTo(
formatter.print(compare.getExpiration(), Locale.ENGLISH)));
500 assertThat(token.get(
"value").getAsString(), equalTo(compare.getValue()));
501 assertThat(token.get(
"type").getAsString(), equalTo(compare.getTokenType()));
502 assertThat(token.get(
"authenticationHolderId").getAsLong(), equalTo(compare.getAuthenticationHolder().getId()));
503 assertTrue(token.get(
"scope").isJsonArray());
505 if(token.get(
"refreshTokenId").isJsonNull()) {
506 assertNull(compare.getRefreshToken());
508 assertThat(token.get(
"refreshTokenId").getAsLong(), equalTo(compare.getRefreshToken().getId()));
510 checked.add(compare);
514 assertThat(checked.containsAll(allAccessTokens), is(
true));
Set< SystemScope > getAll()
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
Set< String > jsonArrayToStringSet(JsonArray a)
Definition: TestMITREidDataService_1_3.java:1850
Collection< BlacklistedSite > getAll()
Collection< WhitelistedSite > getAll()
DateFormatter formatter
Definition: TestMITREidDataService_1_3.java:141
void exportData(JsonWriter writer)
Definition: MITREidDataService_1_3.java:188
WhitelistedSiteRepository wlSiteRepository
Definition: TestMITREidDataService_1_3.java:112
ApprovedSiteRepository approvedSiteRepository
Definition: TestMITREidDataService_1_3.java:110
OAuth2ClientRepository clientRepository
Definition: TestMITREidDataService_1_3.java:108
Set< OAuth2AccessTokenEntity > getAllAccessTokens()
AuthenticationHolderRepository authHolderRepository
Definition: TestMITREidDataService_1_3.java:116
Set< OAuth2RefreshTokenEntity > getAllRefreshTokens()
List< AuthenticationHolderEntity > getAll()
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_3.java:120
Collection< ApprovedSite > getAll()
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_3.java:114
Collection< ClientDetailsEntity > getAllClients()