mitreid-connect
クラス | 公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3 クラス
org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3 連携図
Collaboration graph

クラス

class  accessTokenIdComparator
 
class  refreshTokenIdComparator
 

公開メンバ関数

void prepare ()
 
void testExportRefreshTokens () throws IOException, ParseException
 
void testImportRefreshTokens () throws IOException, ParseException
 
void testExportAccessTokens () throws IOException, ParseException
 
void testImportAccessTokens () throws IOException, ParseException
 
void testExportClients () throws IOException
 
void testImportClients () throws IOException
 
void testExportBlacklistedSites () throws IOException
 
void testImportBlacklistedSites () throws IOException
 
void testExportWhitelistedSites () throws IOException
 
void testImportWhitelistedSites () throws IOException
 
void testExportGrants () throws IOException, ParseException
 
void testImportGrants () throws IOException, ParseException
 
void testExportAuthenticationHolders () throws IOException
 
void testImportAuthenticationHolders () throws IOException
 
void testExportSystemScopes () throws IOException
 
void testImportSystemScopes () throws IOException
 
void testFixRefreshTokenAuthHolderReferencesOnImport () throws IOException, ParseException
 

非公開メンバ関数

Set< String > jsonArrayToStringSet (JsonArray a)
 

非公開変数類

OAuth2ClientRepository clientRepository
 
ApprovedSiteRepository approvedSiteRepository
 
WhitelistedSiteRepository wlSiteRepository
 
BlacklistedSiteRepository blSiteRepository
 
AuthenticationHolderRepository authHolderRepository
 
OAuth2TokenRepository tokenRepository
 
SystemScopeRepository sysScopeRepository
 
ArgumentCaptor< OAuth2RefreshTokenEntitycapturedRefreshTokens
 
ArgumentCaptor< OAuth2AccessTokenEntitycapturedAccessTokens
 
ArgumentCaptor< ClientDetailsEntitycapturedClients
 
ArgumentCaptor< BlacklistedSitecapturedBlacklistedSites
 
ArgumentCaptor< WhitelistedSitecapturedWhitelistedSites
 
ArgumentCaptor< ApprovedSitecapturedApprovedSites
 
ArgumentCaptor< AuthenticationHolderEntitycapturedAuthHolders
 
ArgumentCaptor< SystemScopecapturedScope
 
MITREidDataService_1_3 dataService
 
DateFormatter formatter
 

静的非公開変数類

static Logger logger = LoggerFactory.getLogger(TestMITREidDataService_1_3.class)
 

詳解

関数詳解

◆ jsonArrayToStringSet()

Set<String> org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.jsonArrayToStringSet ( JsonArray  a)
inlineprivate
1850  {
1851  Set<String> s = new HashSet<>();
1852  for (JsonElement jsonElement : a) {
1853  s.add(jsonElement.getAsString());
1854  }
1855  return s;
1856  }

◆ prepare()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.prepare ( )
inline
144  {
145  formatter = new DateFormatter();
146  formatter.setIso(ISO.DATE_TIME);
147 
149  }
DateFormatter formatter
Definition: TestMITREidDataService_1_3.java:141
WhitelistedSiteRepository wlSiteRepository
Definition: TestMITREidDataService_1_3.java:112
ApprovedSiteRepository approvedSiteRepository
Definition: TestMITREidDataService_1_3.java:110
OAuth2ClientRepository clientRepository
Definition: TestMITREidDataService_1_3.java:108
AuthenticationHolderRepository authHolderRepository
Definition: TestMITREidDataService_1_3.java:116
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_3.java:120
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_3.java:114

◆ testExportAccessTokens()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testExportAccessTokens ( ) throws IOException, ParseException
inline
387  {
388  String expiration1 = "2014-09-10T22:49:44.090+0000";
389  Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
390 
391  ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
392  when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
393 
394  AuthenticationHolderEntity mockedAuthHolder1 = mock(AuthenticationHolderEntity.class);
395  when(mockedAuthHolder1.getId()).thenReturn(1L);
396 
397  OAuth2AccessTokenEntity token1 = new OAuth2AccessTokenEntity();
398  token1.setId(1L);
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");
405 
406  String expiration2 = "2015-01-07T18:31:50.079+0000";
407  Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
408 
409  ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
410  when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
411 
412  AuthenticationHolderEntity mockedAuthHolder2 = mock(AuthenticationHolderEntity.class);
413  when(mockedAuthHolder2.getId()).thenReturn(2L);
414 
415  OAuth2RefreshTokenEntity mockRefreshToken2 = mock(OAuth2RefreshTokenEntity.class);
416  when(mockRefreshToken2.getId()).thenReturn(1L);
417 
418  OAuth2AccessTokenEntity token2 = new OAuth2AccessTokenEntity();
419  token2.setId(2L);
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");
427 
428  Set<OAuth2AccessTokenEntity> allAccessTokens = ImmutableSet.of(token1, token2);
429 
430  Mockito.when(clientRepository.getAllClients()).thenReturn(new HashSet<ClientDetailsEntity>());
431  Mockito.when(approvedSiteRepository.getAll()).thenReturn(new HashSet<ApprovedSite>());
432  Mockito.when(wlSiteRepository.getAll()).thenReturn(new HashSet<WhitelistedSite>());
433  Mockito.when(blSiteRepository.getAll()).thenReturn(new HashSet<BlacklistedSite>());
434  Mockito.when(authHolderRepository.getAll()).thenReturn(new ArrayList<AuthenticationHolderEntity>());
435  Mockito.when(tokenRepository.getAllRefreshTokens()).thenReturn(new HashSet<OAuth2RefreshTokenEntity>());
436  Mockito.when(tokenRepository.getAllAccessTokens()).thenReturn(allAccessTokens);
437  Mockito.when(sysScopeRepository.getAll()).thenReturn(new HashSet<SystemScope>());
438 
439  // do the data export
440  StringWriter stringWriter = new StringWriter();
441  JsonWriter writer = new JsonWriter(stringWriter);
442  writer.beginObject();
443  dataService.exportData(writer);
444  writer.endObject();
445  writer.close();
446 
447  // parse the output as a JSON object for testing
448  JsonElement elem = new JsonParser().parse(stringWriter.toString());
449  JsonObject root = elem.getAsJsonObject();
450 
451  // make sure the root is there
452  assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_3), is(true));
453 
454  JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_3).getAsJsonObject();
455 
456  // make sure all the root elements are there
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));
465 
466  // make sure the root elements are all arrays
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));
475 
476 
477  // check our access token list (this test)
478  JsonArray accessTokens = config.get(MITREidDataService.ACCESSTOKENS).getAsJsonArray();
479 
480  assertThat(accessTokens.size(), is(2));
481  // check for both of our access tokens in turn
482  Set<OAuth2AccessTokenEntity> checked = new HashSet<>();
483  for (JsonElement e : accessTokens) {
484  assertTrue(e.isJsonObject());
485  JsonObject token = e.getAsJsonObject();
486 
487  OAuth2AccessTokenEntity compare = null;
488  if (token.get("id").getAsLong() == token1.getId().longValue()) {
489  compare = token1;
490  } else if (token.get("id").getAsLong() == token2.getId().longValue()) {
491  compare = token2;
492  }
493 
494  if (compare == null) {
495  fail("Could not find matching id: " + token.get("id").getAsString());
496  } else {
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());
504  assertThat(jsonArrayToStringSet(token.getAsJsonArray("scope")), equalTo(compare.getScope()));
505  if(token.get("refreshTokenId").isJsonNull()) {
506  assertNull(compare.getRefreshToken());
507  } else {
508  assertThat(token.get("refreshTokenId").getAsLong(), equalTo(compare.getRefreshToken().getId()));
509  }
510  checked.add(compare);
511  }
512  }
513  // make sure all of our access tokens were found
514  assertThat(checked.containsAll(allAccessTokens), is(true));
515  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
Set< String > jsonArrayToStringSet(JsonArray a)
Definition: TestMITREidDataService_1_3.java:1850
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()
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_3.java:120
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_3.java:114
Collection< ClientDetailsEntity > getAllClients()

◆ testExportAuthenticationHolders()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testExportAuthenticationHolders ( ) throws IOException
inline
1362  {
1363  OAuth2Request req1 = new OAuth2Request(new HashMap<String, String>(), "client1", new ArrayList<GrantedAuthority>(),
1364  true, new HashSet<String>(), new HashSet<String>(), "http://foo.com",
1365  new HashSet<String>(), null);
1366  Authentication mockAuth1 = new UsernamePasswordAuthenticationToken("user1", "pass1", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
1367  OAuth2Authentication auth1 = new OAuth2Authentication(req1, mockAuth1);
1368 
1369  AuthenticationHolderEntity holder1 = new AuthenticationHolderEntity();
1370  holder1.setId(1L);
1371  holder1.setAuthentication(auth1);
1372 
1373  OAuth2Request req2 = new OAuth2Request(new HashMap<String, String>(), "client2", new ArrayList<GrantedAuthority>(),
1374  true, new HashSet<String>(), new HashSet<String>(), "http://bar.com",
1375  new HashSet<String>(), null);
1376  OAuth2Authentication auth2 = new OAuth2Authentication(req2, null);
1377 
1378  AuthenticationHolderEntity holder2 = new AuthenticationHolderEntity();
1379  holder2.setId(2L);
1380  holder2.setAuthentication(auth2);
1381 
1382  List<AuthenticationHolderEntity> allAuthHolders = ImmutableList.of(holder1, holder2);
1383 
1384  when(clientRepository.getAllClients()).thenReturn(new HashSet<ClientDetailsEntity>());
1385  when(approvedSiteRepository.getAll()).thenReturn(new HashSet<ApprovedSite>());
1386  when(wlSiteRepository.getAll()).thenReturn(new HashSet<WhitelistedSite>());
1387  when(blSiteRepository.getAll()).thenReturn(new HashSet<BlacklistedSite>());
1388  when(authHolderRepository.getAll()).thenReturn(allAuthHolders);
1389  when(tokenRepository.getAllAccessTokens()).thenReturn(new HashSet<OAuth2AccessTokenEntity>());
1390  when(tokenRepository.getAllRefreshTokens()).thenReturn(new HashSet<OAuth2RefreshTokenEntity>());
1391  when(sysScopeRepository.getAll()).thenReturn(new HashSet<SystemScope>());
1392 
1393  // do the data export
1394  StringWriter stringWriter = new StringWriter();
1395  JsonWriter writer = new JsonWriter(stringWriter);
1396  writer.beginObject();
1397  dataService.exportData(writer);
1398  writer.endObject();
1399  writer.close();
1400 
1401  // parse the output as a JSON object for testing
1402  JsonElement elem = new JsonParser().parse(stringWriter.toString());
1403  JsonObject root = elem.getAsJsonObject();
1404 
1405  // make sure the root is there
1406  assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_3), is(true));
1407 
1408  JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_3).getAsJsonObject();
1409 
1410  // make sure all the root elements are there
1411  assertThat(config.has(MITREidDataService.CLIENTS), is(true));
1412  assertThat(config.has(MITREidDataService.GRANTS), is(true));
1413  assertThat(config.has(MITREidDataService.WHITELISTEDSITES), is(true));
1414  assertThat(config.has(MITREidDataService.BLACKLISTEDSITES), is(true));
1415  assertThat(config.has(MITREidDataService.REFRESHTOKENS), is(true));
1416  assertThat(config.has(MITREidDataService.ACCESSTOKENS), is(true));
1417  assertThat(config.has(MITREidDataService.SYSTEMSCOPES), is(true));
1418  assertThat(config.has(MITREidDataService.AUTHENTICATIONHOLDERS), is(true));
1419 
1420  // make sure the root elements are all arrays
1421  assertThat(config.get(MITREidDataService.CLIENTS).isJsonArray(), is(true));
1422  assertThat(config.get(MITREidDataService.GRANTS).isJsonArray(), is(true));
1423  assertThat(config.get(MITREidDataService.WHITELISTEDSITES).isJsonArray(), is(true));
1424  assertThat(config.get(MITREidDataService.BLACKLISTEDSITES).isJsonArray(), is(true));
1425  assertThat(config.get(MITREidDataService.REFRESHTOKENS).isJsonArray(), is(true));
1426  assertThat(config.get(MITREidDataService.ACCESSTOKENS).isJsonArray(), is(true));
1427  assertThat(config.get(MITREidDataService.SYSTEMSCOPES).isJsonArray(), is(true));
1428  assertThat(config.get(MITREidDataService.AUTHENTICATIONHOLDERS).isJsonArray(), is(true));
1429 
1430 
1431  // check our holder list (this test)
1432  JsonArray holders = config.get(MITREidDataService.AUTHENTICATIONHOLDERS).getAsJsonArray();
1433 
1434  assertThat(holders.size(), is(2));
1435  // check for both of our clients in turn
1436  Set<AuthenticationHolderEntity> checked = new HashSet<>();
1437  for (JsonElement e : holders) {
1438  assertThat(e.isJsonObject(), is(true));
1439  JsonObject holder = e.getAsJsonObject();
1440 
1441  AuthenticationHolderEntity compare = null;
1442  if (holder.get("id").getAsLong() == holder1.getId()) {
1443  compare = holder1;
1444  } else if (holder.get("id").getAsLong() == holder2.getId()) {
1445  compare = holder2;
1446  }
1447 
1448  if (compare == null) {
1449  fail("Could not find matching authentication holder id: " + holder.get("id").getAsString());
1450  } else {
1451  assertTrue(holder.get("clientId").getAsString().equals(compare.getClientId()));
1452  assertTrue(holder.get("approved").getAsBoolean() == compare.isApproved());
1453  assertTrue(holder.get("redirectUri").getAsString().equals(compare.getRedirectUri()));
1454  if (compare.getUserAuth() != null) {
1455  assertTrue(holder.get("savedUserAuthentication").isJsonObject());
1456  JsonObject savedAuth = holder.get("savedUserAuthentication").getAsJsonObject();
1457  assertTrue(savedAuth.get("name").getAsString().equals(compare.getUserAuth().getName()));
1458  assertTrue(savedAuth.get("authenticated").getAsBoolean() == compare.getUserAuth().isAuthenticated());
1459  assertTrue(savedAuth.get("sourceClass").getAsString().equals(compare.getUserAuth().getSourceClass()));
1460  }
1461  checked.add(compare);
1462  }
1463  }
1464  // make sure all of our clients were found
1465  assertThat(checked.containsAll(allAuthHolders), is(true));
1466  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
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()
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_3.java:120
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_3.java:114
Collection< ClientDetailsEntity > getAllClients()

◆ testExportBlacklistedSites()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testExportBlacklistedSites ( ) throws IOException
inline
830  {
831  BlacklistedSite site1 = new BlacklistedSite();
832  site1.setId(1L);
833  site1.setUri("http://foo.com");
834 
835  BlacklistedSite site2 = new BlacklistedSite();
836  site2.setId(2L);
837  site2.setUri("http://bar.com");
838 
839  BlacklistedSite site3 = new BlacklistedSite();
840  site3.setId(3L);
841  site3.setUri("http://baz.com");
842 
843  Set<BlacklistedSite> allBlacklistedSites = ImmutableSet.of(site1, site2, site3);
844 
845  Mockito.when(clientRepository.getAllClients()).thenReturn(new HashSet<ClientDetailsEntity>());
846  Mockito.when(approvedSiteRepository.getAll()).thenReturn(new HashSet<ApprovedSite>());
847  Mockito.when(wlSiteRepository.getAll()).thenReturn(new HashSet<WhitelistedSite>());
848  Mockito.when(blSiteRepository.getAll()).thenReturn(allBlacklistedSites);
849  Mockito.when(authHolderRepository.getAll()).thenReturn(new ArrayList<AuthenticationHolderEntity>());
850  Mockito.when(tokenRepository.getAllAccessTokens()).thenReturn(new HashSet<OAuth2AccessTokenEntity>());
851  Mockito.when(tokenRepository.getAllRefreshTokens()).thenReturn(new HashSet<OAuth2RefreshTokenEntity>());
852  Mockito.when(sysScopeRepository.getAll()).thenReturn(new HashSet<SystemScope>());
853 
854  // do the data export
855  StringWriter stringWriter = new StringWriter();
856  JsonWriter writer = new JsonWriter(stringWriter);
857  writer.beginObject();
858  dataService.exportData(writer);
859  writer.endObject();
860  writer.close();
861 
862  // parse the output as a JSON object for testing
863  JsonElement elem = new JsonParser().parse(stringWriter.toString());
864  JsonObject root = elem.getAsJsonObject();
865 
866  // make sure the root is there
867  assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_3), is(true));
868 
869  JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_3).getAsJsonObject();
870 
871  // make sure all the root elements are there
872  assertThat(config.has(MITREidDataService.CLIENTS), is(true));
873  assertThat(config.has(MITREidDataService.GRANTS), is(true));
874  assertThat(config.has(MITREidDataService.WHITELISTEDSITES), is(true));
875  assertThat(config.has(MITREidDataService.BLACKLISTEDSITES), is(true));
876  assertThat(config.has(MITREidDataService.REFRESHTOKENS), is(true));
877  assertThat(config.has(MITREidDataService.ACCESSTOKENS), is(true));
878  assertThat(config.has(MITREidDataService.SYSTEMSCOPES), is(true));
879  assertThat(config.has(MITREidDataService.AUTHENTICATIONHOLDERS), is(true));
880 
881  // make sure the root elements are all arrays
882  assertThat(config.get(MITREidDataService.CLIENTS).isJsonArray(), is(true));
883  assertThat(config.get(MITREidDataService.GRANTS).isJsonArray(), is(true));
884  assertThat(config.get(MITREidDataService.WHITELISTEDSITES).isJsonArray(), is(true));
885  assertThat(config.get(MITREidDataService.BLACKLISTEDSITES).isJsonArray(), is(true));
886  assertThat(config.get(MITREidDataService.REFRESHTOKENS).isJsonArray(), is(true));
887  assertThat(config.get(MITREidDataService.ACCESSTOKENS).isJsonArray(), is(true));
888  assertThat(config.get(MITREidDataService.SYSTEMSCOPES).isJsonArray(), is(true));
889  assertThat(config.get(MITREidDataService.AUTHENTICATIONHOLDERS).isJsonArray(), is(true));
890 
891  // check our scope list (this test)
892  JsonArray sites = config.get(MITREidDataService.BLACKLISTEDSITES).getAsJsonArray();
893 
894  assertThat(sites.size(), is(3));
895  // check for both of our sites in turn
896  Set<BlacklistedSite> checked = new HashSet<>();
897  for (JsonElement e : sites) {
898  assertThat(e.isJsonObject(), is(true));
899  JsonObject site = e.getAsJsonObject();
900 
901  BlacklistedSite compare = null;
902  if (site.get("id").getAsLong() == site1.getId().longValue()) {
903  compare = site1;
904  } else if (site.get("id").getAsLong() == site2.getId().longValue()) {
905  compare = site2;
906  } else if (site.get("id").getAsLong() == site3.getId().longValue()) {
907  compare = site3;
908  }
909 
910  if (compare == null) {
911  fail("Could not find matching blacklisted site id: " + site.get("id").getAsString());
912  } else {
913  assertThat(site.get("uri").getAsString(), equalTo(compare.getUri()));
914  checked.add(compare);
915  }
916  }
917  // make sure all of our clients were found
918  assertThat(checked.containsAll(allBlacklistedSites), is(true));
919 
920  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
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()
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_3.java:120
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_3.java:114
Collection< ClientDetailsEntity > getAllClients()

◆ testExportClients()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testExportClients ( ) throws IOException
inline
649  {
650  ClientDetailsEntity client1 = new ClientDetailsEntity();
651  client1.setId(1L);
652  client1.setAccessTokenValiditySeconds(3600);
653  client1.setClientId("client1");
654  client1.setClientSecret("clientsecret1");
655  client1.setRedirectUris(ImmutableSet.of("http://foo.com/"));
656  client1.setScope(ImmutableSet.of("foo", "bar", "baz", "dolphin"));
657  client1.setGrantTypes(ImmutableSet.of("implicit", "authorization_code", "urn:ietf:params:oauth:grant_type:redelegate", "refresh_token"));
658  client1.setAllowIntrospection(true);
659 
660  ClientDetailsEntity client2 = new ClientDetailsEntity();
661  client2.setId(2L);
662  client2.setAccessTokenValiditySeconds(3600);
663  client2.setClientId("client2");
664  client2.setClientSecret("clientsecret2");
665  client2.setRedirectUris(ImmutableSet.of("http://bar.baz.com/"));
666  client2.setScope(ImmutableSet.of("foo", "dolphin", "electric-wombat"));
667  client2.setGrantTypes(ImmutableSet.of("client_credentials", "urn:ietf:params:oauth:grant_type:redelegate"));
668  client2.setAllowIntrospection(false);
669  client2.setCodeChallengeMethod(PKCEAlgorithm.S256);
670 
671  Set<ClientDetailsEntity> allClients = ImmutableSet.of(client1, client2);
672 
673  Mockito.when(clientRepository.getAllClients()).thenReturn(allClients);
674  Mockito.when(approvedSiteRepository.getAll()).thenReturn(new HashSet<ApprovedSite>());
675  Mockito.when(wlSiteRepository.getAll()).thenReturn(new HashSet<WhitelistedSite>());
676  Mockito.when(blSiteRepository.getAll()).thenReturn(new HashSet<BlacklistedSite>());
677  Mockito.when(authHolderRepository.getAll()).thenReturn(new ArrayList<AuthenticationHolderEntity>());
678  Mockito.when(tokenRepository.getAllAccessTokens()).thenReturn(new HashSet<OAuth2AccessTokenEntity>());
679  Mockito.when(tokenRepository.getAllRefreshTokens()).thenReturn(new HashSet<OAuth2RefreshTokenEntity>());
680  Mockito.when(sysScopeRepository.getAll()).thenReturn(new HashSet<SystemScope>());
681 
682  // do the data export
683  StringWriter stringWriter = new StringWriter();
684  JsonWriter writer = new JsonWriter(stringWriter);
685  writer.beginObject();
686  dataService.exportData(writer);
687  writer.endObject();
688  writer.close();
689 
690  // parse the output as a JSON object for testing
691  JsonElement elem = new JsonParser().parse(stringWriter.toString());
692  JsonObject root = elem.getAsJsonObject();
693 
694  // make sure the root is there
695  assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_3), is(true));
696 
697  JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_3).getAsJsonObject();
698 
699  // make sure all the root elements are there
700  assertThat(config.has(MITREidDataService.CLIENTS), is(true));
701  assertThat(config.has(MITREidDataService.GRANTS), is(true));
702  assertThat(config.has(MITREidDataService.WHITELISTEDSITES), is(true));
703  assertThat(config.has(MITREidDataService.BLACKLISTEDSITES), is(true));
704  assertThat(config.has(MITREidDataService.REFRESHTOKENS), is(true));
705  assertThat(config.has(MITREidDataService.ACCESSTOKENS), is(true));
706  assertThat(config.has(MITREidDataService.SYSTEMSCOPES), is(true));
707  assertThat(config.has(MITREidDataService.AUTHENTICATIONHOLDERS), is(true));
708 
709  // make sure the root elements are all arrays
710  assertThat(config.get(MITREidDataService.CLIENTS).isJsonArray(), is(true));
711  assertThat(config.get(MITREidDataService.GRANTS).isJsonArray(), is(true));
712  assertThat(config.get(MITREidDataService.WHITELISTEDSITES).isJsonArray(), is(true));
713  assertThat(config.get(MITREidDataService.BLACKLISTEDSITES).isJsonArray(), is(true));
714  assertThat(config.get(MITREidDataService.REFRESHTOKENS).isJsonArray(), is(true));
715  assertThat(config.get(MITREidDataService.ACCESSTOKENS).isJsonArray(), is(true));
716  assertThat(config.get(MITREidDataService.SYSTEMSCOPES).isJsonArray(), is(true));
717  assertThat(config.get(MITREidDataService.AUTHENTICATIONHOLDERS).isJsonArray(), is(true));
718 
719 
720  // check our client list (this test)
721  JsonArray clients = config.get(MITREidDataService.CLIENTS).getAsJsonArray();
722 
723  assertThat(clients.size(), is(2));
724  // check for both of our clients in turn
725  Set<ClientDetailsEntity> checked = new HashSet<>();
726  for (JsonElement e : clients) {
727  assertThat(e.isJsonObject(), is(true));
728  JsonObject client = e.getAsJsonObject();
729 
730  ClientDetailsEntity compare = null;
731  if (client.get("clientId").getAsString().equals(client1.getClientId())) {
732  compare = client1;
733  } else if (client.get("clientId").getAsString().equals(client2.getClientId())) {
734  compare = client2;
735  }
736 
737  if (compare == null) {
738  fail("Could not find matching clientId: " + client.get("clientId").getAsString());
739  } else {
740  assertThat(client.get("clientId").getAsString(), equalTo(compare.getClientId()));
741  assertThat(client.get("secret").getAsString(), equalTo(compare.getClientSecret()));
742  assertThat(client.get("accessTokenValiditySeconds").getAsInt(), equalTo(compare.getAccessTokenValiditySeconds()));
743  assertThat(client.get("allowIntrospection").getAsBoolean(), equalTo(compare.isAllowIntrospection()));
744  assertThat(jsonArrayToStringSet(client.get("redirectUris").getAsJsonArray()), equalTo(compare.getRedirectUris()));
745  assertThat(jsonArrayToStringSet(client.get("scope").getAsJsonArray()), equalTo(compare.getScope()));
746  assertThat(jsonArrayToStringSet(client.get("grantTypes").getAsJsonArray()), equalTo(compare.getGrantTypes()));
747  assertThat((client.has("codeChallengeMethod") && !client.get("codeChallengeMethod").isJsonNull()) ? PKCEAlgorithm.parse(client.get("codeChallengeMethod").getAsString()) : null, equalTo(compare.getCodeChallengeMethod()));
748  checked.add(compare);
749  }
750  }
751  // make sure all of our clients were found
752  assertThat(checked.containsAll(allClients), is(true));
753  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
Set< String > jsonArrayToStringSet(JsonArray a)
Definition: TestMITREidDataService_1_3.java:1850
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()
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_3.java:120
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_3.java:114
Collection< ClientDetailsEntity > getAllClients()

◆ testExportGrants()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testExportGrants ( ) throws IOException, ParseException
inline
1133  {
1134  Date creationDate1 = formatter.parse("2014-09-10T22:49:44.090+0000", Locale.ENGLISH);
1135  Date accessDate1 = formatter.parse("2014-09-10T23:49:44.090+0000", Locale.ENGLISH);
1136 
1137  OAuth2AccessTokenEntity mockToken1 = mock(OAuth2AccessTokenEntity.class);
1138  when(mockToken1.getId()).thenReturn(1L);
1139 
1140  ApprovedSite site1 = new ApprovedSite();
1141  site1.setId(1L);
1142  site1.setClientId("foo");
1143  site1.setCreationDate(creationDate1);
1144  site1.setAccessDate(accessDate1);
1145  site1.setUserId("user1");
1146  site1.setAllowedScopes(ImmutableSet.of("openid", "phone"));
1147  when(mockToken1.getApprovedSite()).thenReturn(site1);
1148 
1149  Date creationDate2 = formatter.parse("2014-09-11T18:49:44.090+0000", Locale.ENGLISH);
1150  Date accessDate2 = formatter.parse("2014-09-11T20:49:44.090+0000", Locale.ENGLISH);
1151  Date timeoutDate2 = formatter.parse("2014-10-01T20:49:44.090+0000", Locale.ENGLISH);
1152 
1153  ApprovedSite site2 = new ApprovedSite();
1154  site2.setId(2L);
1155  site2.setClientId("bar");
1156  site2.setCreationDate(creationDate2);
1157  site2.setAccessDate(accessDate2);
1158  site2.setUserId("user2");
1159  site2.setAllowedScopes(ImmutableSet.of("openid", "offline_access", "email", "profile"));
1160  site2.setTimeoutDate(timeoutDate2);
1161 
1162  Set<ApprovedSite> allApprovedSites = ImmutableSet.of(site1, site2);
1163 
1164  Mockito.when(clientRepository.getAllClients()).thenReturn(new HashSet<ClientDetailsEntity>());
1165  Mockito.when(approvedSiteRepository.getAll()).thenReturn(allApprovedSites);
1166  Mockito.when(blSiteRepository.getAll()).thenReturn(new HashSet<BlacklistedSite>());
1167  Mockito.when(wlSiteRepository.getAll()).thenReturn(new HashSet<WhitelistedSite>());
1168  Mockito.when(authHolderRepository.getAll()).thenReturn(new ArrayList<AuthenticationHolderEntity>());
1169  Mockito.when(tokenRepository.getAllAccessTokens()).thenReturn(new HashSet<OAuth2AccessTokenEntity>());
1170  Mockito.when(tokenRepository.getAllRefreshTokens()).thenReturn(new HashSet<OAuth2RefreshTokenEntity>());
1171  Mockito.when(sysScopeRepository.getAll()).thenReturn(new HashSet<SystemScope>());
1172 
1173  // do the data export
1174  StringWriter stringWriter = new StringWriter();
1175  JsonWriter writer = new JsonWriter(stringWriter);
1176  writer.beginObject();
1177  dataService.exportData(writer);
1178  writer.endObject();
1179  writer.close();
1180 
1181  // parse the output as a JSON object for testing
1182  JsonElement elem = new JsonParser().parse(stringWriter.toString());
1183  JsonObject root = elem.getAsJsonObject();
1184 
1185  // make sure the root is there
1186  assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_3), is(true));
1187 
1188  JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_3).getAsJsonObject();
1189 
1190  // make sure all the root elements are there
1191  assertThat(config.has(MITREidDataService.CLIENTS), is(true));
1192  assertThat(config.has(MITREidDataService.GRANTS), is(true));
1193  assertThat(config.has(MITREidDataService.WHITELISTEDSITES), is(true));
1194  assertThat(config.has(MITREidDataService.BLACKLISTEDSITES), is(true));
1195  assertThat(config.has(MITREidDataService.REFRESHTOKENS), is(true));
1196  assertThat(config.has(MITREidDataService.ACCESSTOKENS), is(true));
1197  assertThat(config.has(MITREidDataService.SYSTEMSCOPES), is(true));
1198  assertThat(config.has(MITREidDataService.AUTHENTICATIONHOLDERS), is(true));
1199 
1200  // make sure the root elements are all arrays
1201  assertThat(config.get(MITREidDataService.CLIENTS).isJsonArray(), is(true));
1202  assertThat(config.get(MITREidDataService.GRANTS).isJsonArray(), is(true));
1203  assertThat(config.get(MITREidDataService.WHITELISTEDSITES).isJsonArray(), is(true));
1204  assertThat(config.get(MITREidDataService.BLACKLISTEDSITES).isJsonArray(), is(true));
1205  assertThat(config.get(MITREidDataService.REFRESHTOKENS).isJsonArray(), is(true));
1206  assertThat(config.get(MITREidDataService.ACCESSTOKENS).isJsonArray(), is(true));
1207  assertThat(config.get(MITREidDataService.SYSTEMSCOPES).isJsonArray(), is(true));
1208  assertThat(config.get(MITREidDataService.AUTHENTICATIONHOLDERS).isJsonArray(), is(true));
1209 
1210  // check our scope list (this test)
1211  JsonArray sites = config.get(MITREidDataService.GRANTS).getAsJsonArray();
1212 
1213  assertThat(sites.size(), is(2));
1214  // check for both of our sites in turn
1215  Set<ApprovedSite> checked = new HashSet<>();
1216  for (JsonElement e : sites) {
1217  assertThat(e.isJsonObject(), is(true));
1218  JsonObject site = e.getAsJsonObject();
1219 
1220  ApprovedSite compare = null;
1221  if (site.get("id").getAsLong() == site1.getId().longValue()) {
1222  compare = site1;
1223  } else if (site.get("id").getAsLong() == site2.getId().longValue()) {
1224  compare = site2;
1225  }
1226 
1227  if (compare == null) {
1228  fail("Could not find matching whitelisted site id: " + site.get("id").getAsString());
1229  } else {
1230  assertThat(site.get("clientId").getAsString(), equalTo(compare.getClientId()));
1231  assertThat(site.get("creationDate").getAsString(), equalTo(formatter.print(compare.getCreationDate(), Locale.ENGLISH)));
1232  assertThat(site.get("accessDate").getAsString(), equalTo(formatter.print(compare.getAccessDate(), Locale.ENGLISH)));
1233  if(site.get("timeoutDate").isJsonNull()) {
1234  assertNull(compare.getTimeoutDate());
1235  } else {
1236  assertThat(site.get("timeoutDate").getAsString(), equalTo(formatter.print(compare.getTimeoutDate(), Locale.ENGLISH)));
1237  }
1238  assertThat(site.get("userId").getAsString(), equalTo(compare.getUserId()));
1239  assertThat(jsonArrayToStringSet(site.getAsJsonArray("allowedScopes")), equalTo(compare.getAllowedScopes()));
1240  checked.add(compare);
1241  }
1242  }
1243  // make sure all of our clients were found
1244  assertThat(checked.containsAll(allApprovedSites), is(true));
1245  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
Set< String > jsonArrayToStringSet(JsonArray a)
Definition: TestMITREidDataService_1_3.java:1850
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()
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_3.java:120
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_3.java:114
Collection< ClientDetailsEntity > getAllClients()

◆ testExportRefreshTokens()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testExportRefreshTokens ( ) throws IOException, ParseException
inline
152  {
153  String expiration1 = "2014-09-10T22:49:44.090+0000";
154  Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
155 
156  ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
157  when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
158 
159  AuthenticationHolderEntity mockedAuthHolder1 = mock(AuthenticationHolderEntity.class);
160  when(mockedAuthHolder1.getId()).thenReturn(1L);
161 
162  OAuth2RefreshTokenEntity token1 = new OAuth2RefreshTokenEntity();
163  token1.setId(1L);
164  token1.setClient(mockedClient1);
165  token1.setExpiration(expirationDate1);
166  token1.setJwt(JWTParser.parse("eyJhbGciOiJub25lIn0.eyJqdGkiOiJmOTg4OWQyOS0xMTk1LTQ4ODEtODgwZC1lZjVlYzAwY2Y4NDIifQ."));
167  token1.setAuthenticationHolder(mockedAuthHolder1);
168 
169  String expiration2 = "2015-01-07T18:31:50.079+0000";
170  Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
171 
172  ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
173  when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
174 
175  AuthenticationHolderEntity mockedAuthHolder2 = mock(AuthenticationHolderEntity.class);
176  when(mockedAuthHolder2.getId()).thenReturn(2L);
177 
178  OAuth2RefreshTokenEntity token2 = new OAuth2RefreshTokenEntity();
179  token2.setId(2L);
180  token2.setClient(mockedClient2);
181  token2.setExpiration(expirationDate2);
182  token2.setJwt(JWTParser.parse("eyJhbGciOiJub25lIn0.eyJqdGkiOiJlYmEyYjc3My0xNjAzLTRmNDAtOWQ3MS1hMGIxZDg1OWE2MDAifQ."));
183  token2.setAuthenticationHolder(mockedAuthHolder2);
184 
185  Set<OAuth2RefreshTokenEntity> allRefreshTokens = ImmutableSet.of(token1, token2);
186 
187  Mockito.when(clientRepository.getAllClients()).thenReturn(new HashSet<ClientDetailsEntity>());
188  Mockito.when(approvedSiteRepository.getAll()).thenReturn(new HashSet<ApprovedSite>());
189  Mockito.when(wlSiteRepository.getAll()).thenReturn(new HashSet<WhitelistedSite>());
190  Mockito.when(blSiteRepository.getAll()).thenReturn(new HashSet<BlacklistedSite>());
191  Mockito.when(authHolderRepository.getAll()).thenReturn(new ArrayList<AuthenticationHolderEntity>());
192  Mockito.when(tokenRepository.getAllAccessTokens()).thenReturn(new HashSet<OAuth2AccessTokenEntity>());
193  Mockito.when(tokenRepository.getAllRefreshTokens()).thenReturn(allRefreshTokens);
194  Mockito.when(sysScopeRepository.getAll()).thenReturn(new HashSet<SystemScope>());
195 
196  // do the data export
197  StringWriter stringWriter = new StringWriter();
198  JsonWriter writer = new JsonWriter(stringWriter);
199  writer.beginObject();
200  dataService.exportData(writer);
201  writer.endObject();
202  writer.close();
203 
204  // parse the output as a JSON object for testing
205  JsonElement elem = new JsonParser().parse(stringWriter.toString());
206  JsonObject root = elem.getAsJsonObject();
207 
208  // make sure the root is there
209  assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_3), is(true));
210 
211  JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_3).getAsJsonObject();
212 
213  // make sure all the root elements are there
214  assertThat(config.has(MITREidDataService.CLIENTS), is(true));
215  assertThat(config.has(MITREidDataService.GRANTS), is(true));
216  assertThat(config.has(MITREidDataService.WHITELISTEDSITES), is(true));
217  assertThat(config.has(MITREidDataService.BLACKLISTEDSITES), is(true));
218  assertThat(config.has(MITREidDataService.REFRESHTOKENS), is(true));
219  assertThat(config.has(MITREidDataService.ACCESSTOKENS), is(true));
220  assertThat(config.has(MITREidDataService.SYSTEMSCOPES), is(true));
221  assertThat(config.has(MITREidDataService.AUTHENTICATIONHOLDERS), is(true));
222 
223  // make sure the root elements are all arrays
224  assertThat(config.get(MITREidDataService.CLIENTS).isJsonArray(), is(true));
225  assertThat(config.get(MITREidDataService.GRANTS).isJsonArray(), is(true));
226  assertThat(config.get(MITREidDataService.WHITELISTEDSITES).isJsonArray(), is(true));
227  assertThat(config.get(MITREidDataService.BLACKLISTEDSITES).isJsonArray(), is(true));
228  assertThat(config.get(MITREidDataService.REFRESHTOKENS).isJsonArray(), is(true));
229  assertThat(config.get(MITREidDataService.ACCESSTOKENS).isJsonArray(), is(true));
230  assertThat(config.get(MITREidDataService.SYSTEMSCOPES).isJsonArray(), is(true));
231  assertThat(config.get(MITREidDataService.AUTHENTICATIONHOLDERS).isJsonArray(), is(true));
232 
233 
234  // check our refresh token list (this test)
235  JsonArray refreshTokens = config.get(MITREidDataService.REFRESHTOKENS).getAsJsonArray();
236 
237  assertThat(refreshTokens.size(), is(2));
238  // check for both of our refresh tokens in turn
239  Set<OAuth2RefreshTokenEntity> checked = new HashSet<>();
240  for (JsonElement e : refreshTokens) {
241  assertThat(e.isJsonObject(), is(true));
242  JsonObject token = e.getAsJsonObject();
243 
244  OAuth2RefreshTokenEntity compare = null;
245  if (token.get("id").getAsLong() == token1.getId()) {
246  compare = token1;
247  } else if (token.get("id").getAsLong() == token2.getId()) {
248  compare = token2;
249  }
250 
251  if (compare == null) {
252  fail("Could not find matching id: " + token.get("id").getAsString());
253  } else {
254  assertThat(token.get("id").getAsLong(), equalTo(compare.getId()));
255  assertThat(token.get("clientId").getAsString(), equalTo(compare.getClient().getClientId()));
256  assertThat(token.get("expiration").getAsString(), equalTo(formatter.print(compare.getExpiration(), Locale.ENGLISH)));
257  assertThat(token.get("value").getAsString(), equalTo(compare.getValue()));
258  assertThat(token.get("authenticationHolderId").getAsLong(), equalTo(compare.getAuthenticationHolder().getId()));
259  checked.add(compare);
260  }
261  }
262  // make sure all of our refresh tokens were found
263  assertThat(checked.containsAll(allRefreshTokens), is(true));
264  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
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()
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_3.java:120
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_3.java:114
Collection< ClientDetailsEntity > getAllClients()

◆ testExportSystemScopes()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testExportSystemScopes ( ) throws IOException
inline
1536  {
1537  SystemScope scope1 = new SystemScope();
1538  scope1.setId(1L);
1539  scope1.setValue("scope1");
1540  scope1.setDescription("Scope 1");
1541  scope1.setRestricted(true);
1542  scope1.setDefaultScope(false);
1543  scope1.setIcon("glass");
1544 
1545  SystemScope scope2 = new SystemScope();
1546  scope2.setId(2L);
1547  scope2.setValue("scope2");
1548  scope2.setDescription("Scope 2");
1549  scope2.setRestricted(false);
1550  scope2.setDefaultScope(false);
1551  scope2.setIcon("ball");
1552 
1553  SystemScope scope3 = new SystemScope();
1554  scope3.setId(3L);
1555  scope3.setValue("scope3");
1556  scope3.setDescription("Scope 3");
1557  scope3.setRestricted(false);
1558  scope3.setDefaultScope(true);
1559  scope3.setIcon("road");
1560 
1561  Set<SystemScope> allScopes = ImmutableSet.of(scope1, scope2, scope3);
1562 
1563  Mockito.when(clientRepository.getAllClients()).thenReturn(new HashSet<ClientDetailsEntity>());
1564  Mockito.when(approvedSiteRepository.getAll()).thenReturn(new HashSet<ApprovedSite>());
1565  Mockito.when(wlSiteRepository.getAll()).thenReturn(new HashSet<WhitelistedSite>());
1566  Mockito.when(blSiteRepository.getAll()).thenReturn(new HashSet<BlacklistedSite>());
1567  Mockito.when(authHolderRepository.getAll()).thenReturn(new ArrayList<AuthenticationHolderEntity>());
1568  Mockito.when(tokenRepository.getAllAccessTokens()).thenReturn(new HashSet<OAuth2AccessTokenEntity>());
1569  Mockito.when(tokenRepository.getAllRefreshTokens()).thenReturn(new HashSet<OAuth2RefreshTokenEntity>());
1570  Mockito.when(sysScopeRepository.getAll()).thenReturn(allScopes);
1571 
1572  // do the data export
1573  StringWriter stringWriter = new StringWriter();
1574  JsonWriter writer = new JsonWriter(stringWriter);
1575  writer.beginObject();
1576  dataService.exportData(writer);
1577  writer.endObject();
1578  writer.close();
1579 
1580  // parse the output as a JSON object for testing
1581  JsonElement elem = new JsonParser().parse(stringWriter.toString());
1582  JsonObject root = elem.getAsJsonObject();
1583 
1584  // make sure the root is there
1585  assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_3), is(true));
1586 
1587  JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_3).getAsJsonObject();
1588 
1589  // make sure all the root elements are there
1590  assertThat(config.has(MITREidDataService.CLIENTS), is(true));
1591  assertThat(config.has(MITREidDataService.GRANTS), is(true));
1592  assertThat(config.has(MITREidDataService.WHITELISTEDSITES), is(true));
1593  assertThat(config.has(MITREidDataService.BLACKLISTEDSITES), is(true));
1594  assertThat(config.has(MITREidDataService.REFRESHTOKENS), is(true));
1595  assertThat(config.has(MITREidDataService.ACCESSTOKENS), is(true));
1596  assertThat(config.has(MITREidDataService.SYSTEMSCOPES), is(true));
1597  assertThat(config.has(MITREidDataService.AUTHENTICATIONHOLDERS), is(true));
1598 
1599  // make sure the root elements are all arrays
1600  assertThat(config.get(MITREidDataService.CLIENTS).isJsonArray(), is(true));
1601  assertThat(config.get(MITREidDataService.GRANTS).isJsonArray(), is(true));
1602  assertThat(config.get(MITREidDataService.WHITELISTEDSITES).isJsonArray(), is(true));
1603  assertThat(config.get(MITREidDataService.BLACKLISTEDSITES).isJsonArray(), is(true));
1604  assertThat(config.get(MITREidDataService.REFRESHTOKENS).isJsonArray(), is(true));
1605  assertThat(config.get(MITREidDataService.ACCESSTOKENS).isJsonArray(), is(true));
1606  assertThat(config.get(MITREidDataService.SYSTEMSCOPES).isJsonArray(), is(true));
1607  assertThat(config.get(MITREidDataService.AUTHENTICATIONHOLDERS).isJsonArray(), is(true));
1608 
1609 
1610  // check our scope list (this test)
1611  JsonArray scopes = config.get(MITREidDataService.SYSTEMSCOPES).getAsJsonArray();
1612 
1613  assertThat(scopes.size(), is(3));
1614  // check for both of our clients in turn
1615  Set<SystemScope> checked = new HashSet<>();
1616  for (JsonElement e : scopes) {
1617  assertThat(e.isJsonObject(), is(true));
1618  JsonObject scope = e.getAsJsonObject();
1619 
1620  SystemScope compare = null;
1621  if (scope.get("value").getAsString().equals(scope1.getValue())) {
1622  compare = scope1;
1623  } else if (scope.get("value").getAsString().equals(scope2.getValue())) {
1624  compare = scope2;
1625  } else if (scope.get("value").getAsString().equals(scope3.getValue())) {
1626  compare = scope3;
1627  }
1628 
1629  if (compare == null) {
1630  fail("Could not find matching scope value: " + scope.get("value").getAsString());
1631  } else {
1632  assertThat(scope.get("value").getAsString(), equalTo(compare.getValue()));
1633  assertThat(scope.get("description").getAsString(), equalTo(compare.getDescription()));
1634  assertThat(scope.get("icon").getAsString(), equalTo(compare.getIcon()));
1635  assertThat(scope.get("restricted").getAsBoolean(), equalTo(compare.isRestricted()));
1636  assertThat(scope.get("defaultScope").getAsBoolean(), equalTo(compare.isDefaultScope()));
1637  checked.add(compare);
1638  }
1639  }
1640  // make sure all of our clients were found
1641  assertThat(checked.containsAll(allScopes), is(true));
1642 
1643  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
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()
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_3.java:120
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_3.java:114
Collection< ClientDetailsEntity > getAllClients()

◆ testExportWhitelistedSites()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testExportWhitelistedSites ( ) throws IOException
inline
971  {
972  WhitelistedSite site1 = new WhitelistedSite();
973  site1.setId(1L);
974  site1.setClientId("foo");
975 
976  WhitelistedSite site2 = new WhitelistedSite();
977  site2.setId(2L);
978  site2.setClientId("bar");
979 
980  WhitelistedSite site3 = new WhitelistedSite();
981  site3.setId(3L);
982  site3.setClientId("baz");
983 
984  Set<WhitelistedSite> allWhitelistedSites = ImmutableSet.of(site1, site2, site3);
985 
986  Mockito.when(clientRepository.getAllClients()).thenReturn(new HashSet<ClientDetailsEntity>());
987  Mockito.when(approvedSiteRepository.getAll()).thenReturn(new HashSet<ApprovedSite>());
988  Mockito.when(blSiteRepository.getAll()).thenReturn(new HashSet<BlacklistedSite>());
989  Mockito.when(wlSiteRepository.getAll()).thenReturn(allWhitelistedSites);
990  Mockito.when(authHolderRepository.getAll()).thenReturn(new ArrayList<AuthenticationHolderEntity>());
991  Mockito.when(tokenRepository.getAllAccessTokens()).thenReturn(new HashSet<OAuth2AccessTokenEntity>());
992  Mockito.when(tokenRepository.getAllRefreshTokens()).thenReturn(new HashSet<OAuth2RefreshTokenEntity>());
993  Mockito.when(sysScopeRepository.getAll()).thenReturn(new HashSet<SystemScope>());
994 
995  // do the data export
996  StringWriter stringWriter = new StringWriter();
997  JsonWriter writer = new JsonWriter(stringWriter);
998  writer.beginObject();
999  dataService.exportData(writer);
1000  writer.endObject();
1001  writer.close();
1002 
1003  // parse the output as a JSON object for testing
1004  JsonElement elem = new JsonParser().parse(stringWriter.toString());
1005  JsonObject root = elem.getAsJsonObject();
1006 
1007  // make sure the root is there
1008  assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_3), is(true));
1009 
1010  JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_3).getAsJsonObject();
1011 
1012  // make sure all the root elements are there
1013  assertThat(config.has(MITREidDataService.CLIENTS), is(true));
1014  assertThat(config.has(MITREidDataService.GRANTS), is(true));
1015  assertThat(config.has(MITREidDataService.WHITELISTEDSITES), is(true));
1016  assertThat(config.has(MITREidDataService.BLACKLISTEDSITES), is(true));
1017  assertThat(config.has(MITREidDataService.REFRESHTOKENS), is(true));
1018  assertThat(config.has(MITREidDataService.ACCESSTOKENS), is(true));
1019  assertThat(config.has(MITREidDataService.SYSTEMSCOPES), is(true));
1020  assertThat(config.has(MITREidDataService.AUTHENTICATIONHOLDERS), is(true));
1021 
1022  // make sure the root elements are all arrays
1023  assertThat(config.get(MITREidDataService.CLIENTS).isJsonArray(), is(true));
1024  assertThat(config.get(MITREidDataService.GRANTS).isJsonArray(), is(true));
1025  assertThat(config.get(MITREidDataService.WHITELISTEDSITES).isJsonArray(), is(true));
1026  assertThat(config.get(MITREidDataService.BLACKLISTEDSITES).isJsonArray(), is(true));
1027  assertThat(config.get(MITREidDataService.REFRESHTOKENS).isJsonArray(), is(true));
1028  assertThat(config.get(MITREidDataService.ACCESSTOKENS).isJsonArray(), is(true));
1029  assertThat(config.get(MITREidDataService.SYSTEMSCOPES).isJsonArray(), is(true));
1030  assertThat(config.get(MITREidDataService.AUTHENTICATIONHOLDERS).isJsonArray(), is(true));
1031 
1032  // check our scope list (this test)
1033  JsonArray sites = config.get(MITREidDataService.WHITELISTEDSITES).getAsJsonArray();
1034 
1035  assertThat(sites.size(), is(3));
1036  // check for both of our sites in turn
1037  Set<WhitelistedSite> checked = new HashSet<>();
1038  for (JsonElement e : sites) {
1039  assertThat(e.isJsonObject(), is(true));
1040  JsonObject site = e.getAsJsonObject();
1041 
1042  WhitelistedSite compare = null;
1043  if (site.get("id").getAsLong() == site1.getId().longValue()) {
1044  compare = site1;
1045  } else if (site.get("id").getAsLong() == site2.getId().longValue()) {
1046  compare = site2;
1047  } else if (site.get("id").getAsLong() == site3.getId().longValue()) {
1048  compare = site3;
1049  }
1050 
1051  if (compare == null) {
1052  fail("Could not find matching whitelisted site id: " + site.get("id").getAsString());
1053  } else {
1054  assertThat(site.get("clientId").getAsString(), equalTo(compare.getClientId()));
1055  checked.add(compare);
1056  }
1057  }
1058  // make sure all of our clients were found
1059  assertThat(checked.containsAll(allWhitelistedSites), is(true));
1060 
1061  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
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()
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_3.java:120
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_3.java:114
Collection< ClientDetailsEntity > getAllClients()

◆ testFixRefreshTokenAuthHolderReferencesOnImport()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testFixRefreshTokenAuthHolderReferencesOnImport ( ) throws IOException, ParseException
inline
1719  {
1720  String expiration1 = "2014-09-10T22:49:44.090+0000";
1721  Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
1722 
1723  ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
1724  when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
1725 
1726  OAuth2Request req1 = new OAuth2Request(new HashMap<String, String>(), "client1", new ArrayList<GrantedAuthority>(),
1727  true, new HashSet<String>(), new HashSet<String>(), "http://foo.com",
1728  new HashSet<String>(), null);
1729  Authentication mockAuth1 = mock(Authentication.class, withSettings().serializable());
1730  OAuth2Authentication auth1 = new OAuth2Authentication(req1, mockAuth1);
1731 
1732  AuthenticationHolderEntity holder1 = new AuthenticationHolderEntity();
1733  holder1.setId(1L);
1734  holder1.setAuthentication(auth1);
1735 
1736  OAuth2RefreshTokenEntity token1 = new OAuth2RefreshTokenEntity();
1737  token1.setId(1L);
1738  token1.setClient(mockedClient1);
1739  token1.setExpiration(expirationDate1);
1740  token1.setJwt(JWTParser.parse("eyJhbGciOiJub25lIn0.eyJqdGkiOiJmOTg4OWQyOS0xMTk1LTQ4ODEtODgwZC1lZjVlYzAwY2Y4NDIifQ."));
1741  token1.setAuthenticationHolder(holder1);
1742 
1743  String expiration2 = "2015-01-07T18:31:50.079+0000";
1744  Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
1745 
1746  ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
1747  when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
1748 
1749  OAuth2Request req2 = new OAuth2Request(new HashMap<String, String>(), "client2", new ArrayList<GrantedAuthority>(),
1750  true, new HashSet<String>(), new HashSet<String>(), "http://bar.com",
1751  new HashSet<String>(), null);
1752  Authentication mockAuth2 = mock(Authentication.class, withSettings().serializable());
1753  OAuth2Authentication auth2 = new OAuth2Authentication(req2, mockAuth2);
1754 
1755  AuthenticationHolderEntity holder2 = new AuthenticationHolderEntity();
1756  holder2.setId(2L);
1757  holder2.setAuthentication(auth2);
1758 
1759  OAuth2RefreshTokenEntity token2 = new OAuth2RefreshTokenEntity();
1760  token2.setId(2L);
1761  token2.setClient(mockedClient2);
1762  token2.setExpiration(expirationDate2);
1763  token2.setJwt(JWTParser.parse("eyJhbGciOiJub25lIn0.eyJqdGkiOiJlYmEyYjc3My0xNjAzLTRmNDAtOWQ3MS1hMGIxZDg1OWE2MDAifQ."));
1764  token2.setAuthenticationHolder(holder2);
1765 
1766  String configJson = "{" +
1767  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
1768  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
1769  "\"" + MITREidDataService.CLIENTS + "\": [], " +
1770  "\"" + MITREidDataService.GRANTS + "\": [], " +
1771  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
1772  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
1773  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [" +
1774 
1775  "{\"id\":1,\"authentication\":{\"authorizationRequest\":{\"clientId\":\"client1\",\"redirectUri\":\"http://foo.com\"},"
1776  + "\"userAuthentication\":null}}," +
1777  "{\"id\":2,\"authentication\":{\"authorizationRequest\":{\"clientId\":\"client2\",\"redirectUri\":\"http://bar.com\"},"
1778  + "\"userAuthentication\":null}}" +
1779  " ]," +
1780  "\"" + MITREidDataService.REFRESHTOKENS + "\": [" +
1781 
1782  "{\"id\":1,\"clientId\":\"mocked_client_1\",\"expiration\":\"2014-09-10T22:49:44.090+0000\","
1783  + "\"authenticationHolderId\":1,\"value\":\"eyJhbGciOiJub25lIn0.eyJqdGkiOiJmOTg4OWQyOS0xMTk1LTQ4ODEtODgwZC1lZjVlYzAwY2Y4NDIifQ.\"}," +
1784  "{\"id\":2,\"clientId\":\"mocked_client_2\",\"expiration\":\"2015-01-07T18:31:50.079+0000\","
1785  + "\"authenticationHolderId\":2,\"value\":\"eyJhbGciOiJub25lIn0.eyJqdGkiOiJlYmEyYjc3My0xNjAzLTRmNDAtOWQ3MS1hMGIxZDg1OWE2MDAifQ.\"}" +
1786 
1787  " ]" +
1788  "}";
1789  logger.debug(configJson);
1790 
1791  JsonReader reader = new JsonReader(new StringReader(configJson));
1792  final Map<Long, OAuth2RefreshTokenEntity> fakeRefreshTokenTable = new HashMap<>();
1793  final Map<Long, AuthenticationHolderEntity> fakeAuthHolderTable = new HashMap<>();
1794  when(tokenRepository.saveRefreshToken(isA(OAuth2RefreshTokenEntity.class))).thenAnswer(new Answer<OAuth2RefreshTokenEntity>() {
1795  Long id = 343L;
1796  @Override
1797  public OAuth2RefreshTokenEntity answer(InvocationOnMock invocation) throws Throwable {
1798  OAuth2RefreshTokenEntity _token = (OAuth2RefreshTokenEntity) invocation.getArguments()[0];
1799  if(_token.getId() == null) {
1800  _token.setId(id++);
1801  }
1802  fakeRefreshTokenTable.put(_token.getId(), _token);
1803  return _token;
1804  }
1805  });
1806  when(tokenRepository.getRefreshTokenById(anyLong())).thenAnswer(new Answer<OAuth2RefreshTokenEntity>() {
1807  @Override
1808  public OAuth2RefreshTokenEntity answer(InvocationOnMock invocation) throws Throwable {
1809  Long _id = (Long) invocation.getArguments()[0];
1810  return fakeRefreshTokenTable.get(_id);
1811  }
1812  });
1813  when(clientRepository.getClientByClientId(anyString())).thenAnswer(new Answer<ClientDetailsEntity>() {
1814  @Override
1815  public ClientDetailsEntity answer(InvocationOnMock invocation) throws Throwable {
1816  String _clientId = (String) invocation.getArguments()[0];
1817  ClientDetailsEntity _client = mock(ClientDetailsEntity.class);
1818  when(_client.getClientId()).thenReturn(_clientId);
1819  return _client;
1820  }
1821  });
1822  when(authHolderRepository.save(isA(AuthenticationHolderEntity.class))).thenAnswer(new Answer<AuthenticationHolderEntity>() {
1823  Long id = 356L;
1824  @Override
1825  public AuthenticationHolderEntity answer(InvocationOnMock invocation) throws Throwable {
1826  AuthenticationHolderEntity _holder = (AuthenticationHolderEntity) invocation.getArguments()[0];
1827  if(_holder.getId() == null) {
1828  _holder.setId(id++);
1829  }
1830  fakeAuthHolderTable.put(_holder.getId(), _holder);
1831  return _holder;
1832  }
1833  });
1834  when(authHolderRepository.getById(anyLong())).thenAnswer(new Answer<AuthenticationHolderEntity>() {
1835  @Override
1836  public AuthenticationHolderEntity answer(InvocationOnMock invocation) throws Throwable {
1837  Long _id = (Long) invocation.getArguments()[0];
1838  return fakeAuthHolderTable.get(_id);
1839  }
1840  });
1841  dataService.importData(reader);
1842 
1843  List<OAuth2RefreshTokenEntity> savedRefreshTokens = new ArrayList(fakeRefreshTokenTable.values()); //capturedRefreshTokens.getAllValues();
1844  Collections.sort(savedRefreshTokens, new refreshTokenIdComparator());
1845 
1846  assertThat(savedRefreshTokens.get(0).getAuthenticationHolder().getId(), equalTo(356L));
1847  assertThat(savedRefreshTokens.get(1).getAuthenticationHolder().getId(), equalTo(357L));
1848  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
ClientDetailsEntity getClientByClientId(String clientId)
DateFormatter formatter
Definition: TestMITREidDataService_1_3.java:141
static Logger logger
Definition: TestMITREidDataService_1_3.java:105
OAuth2RefreshTokenEntity saveRefreshToken(OAuth2RefreshTokenEntity refreshToken)
AuthenticationHolderEntity save(AuthenticationHolderEntity a)
OAuth2ClientRepository clientRepository
Definition: TestMITREidDataService_1_3.java:108
void importData(JsonReader reader)
Definition: MITREidDataService_1_3.java:567
AuthenticationHolderRepository authHolderRepository
Definition: TestMITREidDataService_1_3.java:116
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118
OAuth2RefreshTokenEntity getRefreshTokenById(Long Id)

◆ testImportAccessTokens()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testImportAccessTokens ( ) throws IOException, ParseException
inline
525  {
526  String expiration1 = "2014-09-10T22:49:44.090+0000";
527  Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
528 
529  ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
530  when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
531 
532  AuthenticationHolderEntity mockedAuthHolder1 = mock(AuthenticationHolderEntity.class);
533  when(mockedAuthHolder1.getId()).thenReturn(1L);
534 
535  OAuth2AccessTokenEntity token1 = new OAuth2AccessTokenEntity();
536  token1.setId(1L);
537  token1.setClient(mockedClient1);
538  token1.setExpiration(expirationDate1);
539  token1.setJwt(JWTParser.parse("eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE0MTI3ODk5NjgsInN1YiI6IjkwMzQyLkFTREZKV0ZBIiwiYXRfaGFzaCI6InptTmt1QmNRSmNYQktNaVpFODZqY0EiLCJhdWQiOlsiY2xpZW50Il0sImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo4MDgwXC9vcGVuaWQtY29ubmVjdC1zZXJ2ZXItd2ViYXBwXC8iLCJpYXQiOjE0MTI3ODkzNjh9.xkEJ9IMXpH7qybWXomfq9WOOlpGYnrvGPgey9UQ4GLzbQx7JC0XgJK83PmrmBZosvFPCmota7FzI_BtwoZLgAZfFiH6w3WIlxuogoH-TxmYbxEpTHoTsszZppkq9mNgOlArV4jrR9y3TPo4MovsH71dDhS_ck-CvAlJunHlqhs0"));
540  token1.setAuthenticationHolder(mockedAuthHolder1);
541  token1.setScope(ImmutableSet.of("id-token"));
542  token1.setTokenType("Bearer");
543 
544  String expiration2 = "2015-01-07T18:31:50.079+0000";
545  Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
546 
547  ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
548  when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
549 
550  AuthenticationHolderEntity mockedAuthHolder2 = mock(AuthenticationHolderEntity.class);
551  when(mockedAuthHolder2.getId()).thenReturn(2L);
552 
553  OAuth2RefreshTokenEntity mockRefreshToken2 = mock(OAuth2RefreshTokenEntity.class);
554  when(mockRefreshToken2.getId()).thenReturn(1L);
555 
556  OAuth2AccessTokenEntity token2 = new OAuth2AccessTokenEntity();
557  token2.setId(2L);
558  token2.setClient(mockedClient2);
559  token2.setExpiration(expirationDate2);
560  token2.setJwt(JWTParser.parse("eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE0MTI3OTI5NjgsImF1ZCI6WyJjbGllbnQiXSwiaXNzIjoiaHR0cDpcL1wvbG9jYWxob3N0OjgwODBcL29wZW5pZC1jb25uZWN0LXNlcnZlci13ZWJhcHBcLyIsImp0aSI6IjBmZGE5ZmRiLTYyYzItNGIzZS05OTdiLWU0M2VhMDUwMzNiOSIsImlhdCI6MTQxMjc4OTM2OH0.xgaVpRLYE5MzbgXfE0tZt823tjAm6Oh3_kdR1P2I9jRLR6gnTlBQFlYi3Y_0pWNnZSerbAE8Tn6SJHZ9k-curVG0-ByKichV7CNvgsE5X_2wpEaUzejvKf8eZ-BammRY-ie6yxSkAarcUGMvGGOLbkFcz5CtrBpZhfd75J49BIQ"));
561  token2.setAuthenticationHolder(mockedAuthHolder2);
562  token2.setRefreshToken(mockRefreshToken2);
563  token2.setScope(ImmutableSet.of("openid", "offline_access", "email", "profile"));
564  token2.setTokenType("Bearer");
565 
566  String configJson = "{" +
567  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
568  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
569  "\"" + MITREidDataService.CLIENTS + "\": [], " +
570  "\"" + MITREidDataService.GRANTS + "\": [], " +
571  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
572  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
573  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
574  "\"" + MITREidDataService.ACCESSTOKENS + "\": [" +
575 
576  "{\"id\":1,\"clientId\":\"mocked_client_1\",\"expiration\":\"2014-09-10T22:49:44.090+0000\","
577  + "\"refreshTokenId\":null,\"idTokenId\":null,\"scope\":[\"id-token\"],\"type\":\"Bearer\","
578  + "\"authenticationHolderId\":1,\"value\":\"eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE0MTI3ODk5NjgsInN1YiI6IjkwMzQyLkFTREZKV0ZBIiwiYXRfaGFzaCI6InptTmt1QmNRSmNYQktNaVpFODZqY0EiLCJhdWQiOlsiY2xpZW50Il0sImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo4MDgwXC9vcGVuaWQtY29ubmVjdC1zZXJ2ZXItd2ViYXBwXC8iLCJpYXQiOjE0MTI3ODkzNjh9.xkEJ9IMXpH7qybWXomfq9WOOlpGYnrvGPgey9UQ4GLzbQx7JC0XgJK83PmrmBZosvFPCmota7FzI_BtwoZLgAZfFiH6w3WIlxuogoH-TxmYbxEpTHoTsszZppkq9mNgOlArV4jrR9y3TPo4MovsH71dDhS_ck-CvAlJunHlqhs0\"}," +
579  "{\"id\":2,\"clientId\":\"mocked_client_2\",\"expiration\":\"2015-01-07T18:31:50.079+0000\","
580  + "\"refreshTokenId\":1,\"idTokenId\":1,\"scope\":[\"openid\",\"offline_access\",\"email\",\"profile\"],\"type\":\"Bearer\","
581  + "\"authenticationHolderId\":2,\"value\":\"eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE0MTI3OTI5NjgsImF1ZCI6WyJjbGllbnQiXSwiaXNzIjoiaHR0cDpcL1wvbG9jYWxob3N0OjgwODBcL29wZW5pZC1jb25uZWN0LXNlcnZlci13ZWJhcHBcLyIsImp0aSI6IjBmZGE5ZmRiLTYyYzItNGIzZS05OTdiLWU0M2VhMDUwMzNiOSIsImlhdCI6MTQxMjc4OTM2OH0.xgaVpRLYE5MzbgXfE0tZt823tjAm6Oh3_kdR1P2I9jRLR6gnTlBQFlYi3Y_0pWNnZSerbAE8Tn6SJHZ9k-curVG0-ByKichV7CNvgsE5X_2wpEaUzejvKf8eZ-BammRY-ie6yxSkAarcUGMvGGOLbkFcz5CtrBpZhfd75J49BIQ\"}" +
582 
583  " ]" +
584  "}";
585 
586 
587  logger.debug(configJson);
588 
589  JsonReader reader = new JsonReader(new StringReader(configJson));
590 
591  final Map<Long, OAuth2AccessTokenEntity> fakeDb = new HashMap<>();
592  when(tokenRepository.saveAccessToken(isA(OAuth2AccessTokenEntity.class))).thenAnswer(new Answer<OAuth2AccessTokenEntity>() {
593  Long id = 324L;
594  @Override
595  public OAuth2AccessTokenEntity answer(InvocationOnMock invocation) throws Throwable {
596  OAuth2AccessTokenEntity _token = (OAuth2AccessTokenEntity) invocation.getArguments()[0];
597  if(_token.getId() == null) {
598  _token.setId(id++);
599  }
600  fakeDb.put(_token.getId(), _token);
601  return _token;
602  }
603  });
604  when(tokenRepository.getAccessTokenById(anyLong())).thenAnswer(new Answer<OAuth2AccessTokenEntity>() {
605  @Override
606  public OAuth2AccessTokenEntity answer(InvocationOnMock invocation) throws Throwable {
607  Long _id = (Long) invocation.getArguments()[0];
608  return fakeDb.get(_id);
609  }
610  });
611  when(clientRepository.getClientByClientId(anyString())).thenAnswer(new Answer<ClientDetailsEntity>() {
612  @Override
613  public ClientDetailsEntity answer(InvocationOnMock invocation) throws Throwable {
614  String _clientId = (String) invocation.getArguments()[0];
615  ClientDetailsEntity _client = mock(ClientDetailsEntity.class);
616  when(_client.getClientId()).thenReturn(_clientId);
617  return _client;
618  }
619  });
620  when(authHolderRepository.getById(isNull(Long.class))).thenAnswer(new Answer<AuthenticationHolderEntity>() {
621  Long id = 133L;
622  @Override
623  public AuthenticationHolderEntity answer(InvocationOnMock invocation) throws Throwable {
624  AuthenticationHolderEntity _auth = mock(AuthenticationHolderEntity.class);
625  when(_auth.getId()).thenReturn(id);
626  id++;
627  return _auth;
628  }
629  });
630  dataService.importData(reader);
631  //2 times for token, 2 times to update client, 2 times to update authHolder, 1 times to update refresh token
632  verify(tokenRepository, times(7)).saveAccessToken(capturedAccessTokens.capture());
633 
634  List<OAuth2AccessTokenEntity> savedAccessTokens = new ArrayList(fakeDb.values()); //capturedAccessTokens.getAllValues();
635  Collections.sort(savedAccessTokens, new accessTokenIdComparator());
636 
637  assertThat(savedAccessTokens.size(), is(2));
638 
639  assertThat(savedAccessTokens.get(0).getClient().getClientId(), equalTo(token1.getClient().getClientId()));
640  assertThat(savedAccessTokens.get(0).getExpiration(), equalTo(token1.getExpiration()));
641  assertThat(savedAccessTokens.get(0).getValue(), equalTo(token1.getValue()));
642 
643  assertThat(savedAccessTokens.get(1).getClient().getClientId(), equalTo(token2.getClient().getClientId()));
644  assertThat(savedAccessTokens.get(1).getExpiration(), equalTo(token2.getExpiration()));
645  assertThat(savedAccessTokens.get(1).getValue(), equalTo(token2.getValue()));
646  }
OAuth2AccessTokenEntity saveAccessToken(OAuth2AccessTokenEntity token)
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
ClientDetailsEntity getClientByClientId(String clientId)
OAuth2AccessTokenEntity getAccessTokenById(Long id)
DateFormatter formatter
Definition: TestMITREidDataService_1_3.java:141
static Logger logger
Definition: TestMITREidDataService_1_3.java:105
OAuth2ClientRepository clientRepository
Definition: TestMITREidDataService_1_3.java:108
void importData(JsonReader reader)
Definition: MITREidDataService_1_3.java:567
AuthenticationHolderRepository authHolderRepository
Definition: TestMITREidDataService_1_3.java:116
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118
ArgumentCaptor< OAuth2AccessTokenEntity > capturedAccessTokens
Definition: TestMITREidDataService_1_3.java:125

◆ testImportAuthenticationHolders()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testImportAuthenticationHolders ( ) throws IOException
inline
1469  {
1470  OAuth2Request req1 = new OAuth2Request(new HashMap<String, String>(), "client1", new ArrayList<GrantedAuthority>(),
1471  true, new HashSet<String>(), new HashSet<String>(), "http://foo.com",
1472  new HashSet<String>(), null);
1473  Authentication mockAuth1 = mock(Authentication.class, withSettings().serializable());
1474  OAuth2Authentication auth1 = new OAuth2Authentication(req1, mockAuth1);
1475 
1476  AuthenticationHolderEntity holder1 = new AuthenticationHolderEntity();
1477  holder1.setId(1L);
1478  holder1.setAuthentication(auth1);
1479 
1480  OAuth2Request req2 = new OAuth2Request(new HashMap<String, String>(), "client2", new ArrayList<GrantedAuthority>(),
1481  true, new HashSet<String>(), new HashSet<String>(), "http://bar.com",
1482  new HashSet<String>(), null);
1483  Authentication mockAuth2 = mock(Authentication.class, withSettings().serializable());
1484  OAuth2Authentication auth2 = new OAuth2Authentication(req2, mockAuth2);
1485 
1486  AuthenticationHolderEntity holder2 = new AuthenticationHolderEntity();
1487  holder2.setId(2L);
1488  holder2.setAuthentication(auth2);
1489 
1490  String configJson = "{" +
1491  "\"" + MITREidDataService.CLIENTS + "\": [], " +
1492  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
1493  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
1494  "\"" + MITREidDataService.GRANTS + "\": [], " +
1495  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
1496  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
1497  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
1498  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [" +
1499 
1500  "{\"id\":1,\"clientId\":\"client1\",\"redirectUri\":\"http://foo.com\","
1501  + "\"savedUserAuthentication\":null}," +
1502  "{\"id\":2,\"clientId\":\"client2\",\"redirectUri\":\"http://bar.com\","
1503  + "\"savedUserAuthentication\":null}" +
1504  " ]" +
1505  "}";
1506 
1507  logger.debug(configJson);
1508 
1509  JsonReader reader = new JsonReader(new StringReader(configJson));
1510 
1511  final Map<Long, AuthenticationHolderEntity> fakeDb = new HashMap<>();
1512  when(authHolderRepository.save(isA(AuthenticationHolderEntity.class))).thenAnswer(new Answer<AuthenticationHolderEntity>() {
1513  Long id = 243L;
1514  @Override
1515  public AuthenticationHolderEntity answer(InvocationOnMock invocation) throws Throwable {
1516  AuthenticationHolderEntity _site = (AuthenticationHolderEntity) invocation.getArguments()[0];
1517  if(_site.getId() == null) {
1518  _site.setId(id++);
1519  }
1520  fakeDb.put(_site.getId(), _site);
1521  return _site;
1522  }
1523  });
1524 
1525  dataService.importData(reader);
1526  verify(authHolderRepository, times(2)).save(capturedAuthHolders.capture());
1527 
1528  List<AuthenticationHolderEntity> savedAuthHolders = capturedAuthHolders.getAllValues();
1529 
1530  assertThat(savedAuthHolders.size(), is(2));
1531  assertThat(savedAuthHolders.get(0).getAuthentication().getOAuth2Request().getClientId(), equalTo(holder1.getAuthentication().getOAuth2Request().getClientId()));
1532  assertThat(savedAuthHolders.get(1).getAuthentication().getOAuth2Request().getClientId(), equalTo(holder2.getAuthentication().getOAuth2Request().getClientId()));
1533  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
static Logger logger
Definition: TestMITREidDataService_1_3.java:105
AuthenticationHolderEntity save(AuthenticationHolderEntity a)
ArgumentCaptor< AuthenticationHolderEntity > capturedAuthHolders
Definition: TestMITREidDataService_1_3.java:135
void importData(JsonReader reader)
Definition: MITREidDataService_1_3.java:567
AuthenticationHolderRepository authHolderRepository
Definition: TestMITREidDataService_1_3.java:116

◆ testImportBlacklistedSites()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testImportBlacklistedSites ( ) throws IOException
inline
923  {
924  BlacklistedSite site1 = new BlacklistedSite();
925  site1.setId(1L);
926  site1.setUri("http://foo.com");
927 
928  BlacklistedSite site2 = new BlacklistedSite();
929  site2.setId(2L);
930  site2.setUri("http://bar.com");
931 
932  BlacklistedSite site3 = new BlacklistedSite();
933  site3.setId(3L);
934  site3.setUri("http://baz.com");
935 
936  String configJson = "{" +
937  "\"" + MITREidDataService.CLIENTS + "\": [], " +
938  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
939  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
940  "\"" + MITREidDataService.GRANTS + "\": [], " +
941  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
942  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
943  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
944  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [" +
945 
946  "{\"id\":1,\"uri\":\"http://foo.com\"}," +
947  "{\"id\":2,\"uri\":\"http://bar.com\"}," +
948  "{\"id\":3,\"uri\":\"http://baz.com\"}" +
949 
950  " ]" +
951  "}";
952 
953 
954  logger.debug(configJson);
955 
956  JsonReader reader = new JsonReader(new StringReader(configJson));
957 
958  dataService.importData(reader);
959  verify(blSiteRepository, times(3)).save(capturedBlacklistedSites.capture());
960 
961  List<BlacklistedSite> savedSites = capturedBlacklistedSites.getAllValues();
962 
963  assertThat(savedSites.size(), is(3));
964 
965  assertThat(savedSites.get(0).getUri(), equalTo(site1.getUri()));
966  assertThat(savedSites.get(1).getUri(), equalTo(site2.getUri()));
967  assertThat(savedSites.get(2).getUri(), equalTo(site3.getUri()));
968  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
ArgumentCaptor< BlacklistedSite > capturedBlacklistedSites
Definition: TestMITREidDataService_1_3.java:129
static Logger logger
Definition: TestMITREidDataService_1_3.java:105
void importData(JsonReader reader)
Definition: MITREidDataService_1_3.java:567
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_3.java:114

◆ testImportClients()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testImportClients ( ) throws IOException
inline
756  {
757  ClientDetailsEntity client1 = new ClientDetailsEntity();
758  client1.setId(1L);
759  client1.setAccessTokenValiditySeconds(3600);
760  client1.setClientId("client1");
761  client1.setClientSecret("clientsecret1");
762  client1.setRedirectUris(ImmutableSet.of("http://foo.com/"));
763  client1.setScope(ImmutableSet.of("foo", "bar", "baz", "dolphin"));
764  client1.setGrantTypes(ImmutableSet.of("implicit", "authorization_code", "urn:ietf:params:oauth:grant_type:redelegate", "refresh_token"));
765  client1.setAllowIntrospection(true);
766 
767  ClientDetailsEntity client2 = new ClientDetailsEntity();
768  client2.setId(2L);
769  client2.setAccessTokenValiditySeconds(3600);
770  client2.setClientId("client2");
771  client2.setClientSecret("clientsecret2");
772  client2.setRedirectUris(ImmutableSet.of("http://bar.baz.com/"));
773  client2.setScope(ImmutableSet.of("foo", "dolphin", "electric-wombat"));
774  client2.setGrantTypes(ImmutableSet.of("client_credentials", "urn:ietf:params:oauth:grant_type:redelegate"));
775  client2.setAllowIntrospection(false);
776 
777  String configJson = "{" +
778  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
779  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
780  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
781  "\"" + MITREidDataService.GRANTS + "\": [], " +
782  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
783  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
784  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
785  "\"" + MITREidDataService.CLIENTS + "\": [" +
786 
787  "{\"id\":1,\"accessTokenValiditySeconds\":3600,\"clientId\":\"client1\",\"secret\":\"clientsecret1\","
788  + "\"redirectUris\":[\"http://foo.com/\"],"
789  + "\"scope\":[\"foo\",\"bar\",\"baz\",\"dolphin\"],"
790  + "\"grantTypes\":[\"implicit\",\"authorization_code\",\"urn:ietf:params:oauth:grant_type:redelegate\",\"refresh_token\"],"
791  + "\"allowIntrospection\":true}," +
792  "{\"id\":2,\"accessTokenValiditySeconds\":3600,\"clientId\":\"client2\",\"secret\":\"clientsecret2\","
793  + "\"redirectUris\":[\"http://bar.baz.com/\"],"
794  + "\"scope\":[\"foo\",\"dolphin\",\"electric-wombat\"],"
795  + "\"grantTypes\":[\"client_credentials\",\"urn:ietf:params:oauth:grant_type:redelegate\"],"
796  + "\"allowIntrospection\":false}" +
797 
798  " ]" +
799  "}";
800 
801  logger.debug(configJson);
802 
803  JsonReader reader = new JsonReader(new StringReader(configJson));
804 
805  dataService.importData(reader);
806  verify(clientRepository, times(2)).saveClient(capturedClients.capture());
807 
808  List<ClientDetailsEntity> savedClients = capturedClients.getAllValues();
809 
810  assertThat(savedClients.size(), is(2));
811 
812  assertThat(savedClients.get(0).getAccessTokenValiditySeconds(), equalTo(client1.getAccessTokenValiditySeconds()));
813  assertThat(savedClients.get(0).getClientId(), equalTo(client1.getClientId()));
814  assertThat(savedClients.get(0).getClientSecret(), equalTo(client1.getClientSecret()));
815  assertThat(savedClients.get(0).getRedirectUris(), equalTo(client1.getRedirectUris()));
816  assertThat(savedClients.get(0).getScope(), equalTo(client1.getScope()));
817  assertThat(savedClients.get(0).getGrantTypes(), equalTo(client1.getGrantTypes()));
818  assertThat(savedClients.get(0).isAllowIntrospection(), equalTo(client1.isAllowIntrospection()));
819 
820  assertThat(savedClients.get(1).getAccessTokenValiditySeconds(), equalTo(client2.getAccessTokenValiditySeconds()));
821  assertThat(savedClients.get(1).getClientId(), equalTo(client2.getClientId()));
822  assertThat(savedClients.get(1).getClientSecret(), equalTo(client2.getClientSecret()));
823  assertThat(savedClients.get(1).getRedirectUris(), equalTo(client2.getRedirectUris()));
824  assertThat(savedClients.get(1).getScope(), equalTo(client2.getScope()));
825  assertThat(savedClients.get(1).getGrantTypes(), equalTo(client2.getGrantTypes()));
826  assertThat(savedClients.get(1).isAllowIntrospection(), equalTo(client2.isAllowIntrospection()));
827  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
ArgumentCaptor< ClientDetailsEntity > capturedClients
Definition: TestMITREidDataService_1_3.java:127
static Logger logger
Definition: TestMITREidDataService_1_3.java:105
OAuth2ClientRepository clientRepository
Definition: TestMITREidDataService_1_3.java:108
void importData(JsonReader reader)
Definition: MITREidDataService_1_3.java:567

◆ testImportGrants()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testImportGrants ( ) throws IOException, ParseException
inline
1248  {
1249  Date creationDate1 = formatter.parse("2014-09-10T22:49:44.090+0000", Locale.ENGLISH);
1250  Date accessDate1 = formatter.parse("2014-09-10T23:49:44.090+0000", Locale.ENGLISH);
1251 
1252  OAuth2AccessTokenEntity mockToken1 = mock(OAuth2AccessTokenEntity.class);
1253  when(mockToken1.getId()).thenReturn(1L);
1254 
1255  ApprovedSite site1 = new ApprovedSite();
1256  site1.setId(1L);
1257  site1.setClientId("foo");
1258  site1.setCreationDate(creationDate1);
1259  site1.setAccessDate(accessDate1);
1260  site1.setUserId("user1");
1261  site1.setAllowedScopes(ImmutableSet.of("openid", "phone"));
1262  when(mockToken1.getApprovedSite()).thenReturn(site1);
1263 
1264  Date creationDate2 = formatter.parse("2014-09-11T18:49:44.090+0000", Locale.ENGLISH);
1265  Date accessDate2 = formatter.parse("2014-09-11T20:49:44.090+0000", Locale.ENGLISH);
1266  Date timeoutDate2 = formatter.parse("2014-10-01T20:49:44.090+0000", Locale.ENGLISH);
1267 
1268  ApprovedSite site2 = new ApprovedSite();
1269  site2.setId(2L);
1270  site2.setClientId("bar");
1271  site2.setCreationDate(creationDate2);
1272  site2.setAccessDate(accessDate2);
1273  site2.setUserId("user2");
1274  site2.setAllowedScopes(ImmutableSet.of("openid", "offline_access", "email", "profile"));
1275  site2.setTimeoutDate(timeoutDate2);
1276 
1277  String configJson = "{" +
1278  "\"" + MITREidDataService.CLIENTS + "\": [], " +
1279  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
1280  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
1281  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
1282  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
1283  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
1284  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
1285  "\"" + MITREidDataService.GRANTS + "\": [" +
1286 
1287  "{\"id\":1,\"clientId\":\"foo\",\"creationDate\":\"2014-09-10T22:49:44.090+0000\",\"accessDate\":\"2014-09-10T23:49:44.090+0000\","
1288  + "\"userId\":\"user1\",\"whitelistedSiteId\":null,\"allowedScopes\":[\"openid\",\"phone\"], \"whitelistedSiteId\":1,"
1289  + "\"approvedAccessTokens\":[1]}," +
1290  "{\"id\":2,\"clientId\":\"bar\",\"creationDate\":\"2014-09-11T18:49:44.090+0000\",\"accessDate\":\"2014-09-11T20:49:44.090+0000\","
1291  + "\"timeoutDate\":\"2014-10-01T20:49:44.090+0000\",\"userId\":\"user2\","
1292  + "\"allowedScopes\":[\"openid\",\"offline_access\",\"email\",\"profile\"]}" +
1293 
1294  " ]" +
1295  "}";
1296 
1297  logger.debug(configJson);
1298 
1299  JsonReader reader = new JsonReader(new StringReader(configJson));
1300 
1301  final Map<Long, ApprovedSite> fakeDb = new HashMap<>();
1302  when(approvedSiteRepository.save(isA(ApprovedSite.class))).thenAnswer(new Answer<ApprovedSite>() {
1303  Long id = 364L;
1304  @Override
1305  public ApprovedSite answer(InvocationOnMock invocation) throws Throwable {
1306  ApprovedSite _site = (ApprovedSite) invocation.getArguments()[0];
1307  if(_site.getId() == null) {
1308  _site.setId(id++);
1309  }
1310  fakeDb.put(_site.getId(), _site);
1311  return _site;
1312  }
1313  });
1314  when(approvedSiteRepository.getById(anyLong())).thenAnswer(new Answer<ApprovedSite>() {
1315  @Override
1316  public ApprovedSite answer(InvocationOnMock invocation) throws Throwable {
1317  Long _id = (Long) invocation.getArguments()[0];
1318  return fakeDb.get(_id);
1319  }
1320  });
1321  when(wlSiteRepository.getById(isNull(Long.class))).thenAnswer(new Answer<WhitelistedSite>() {
1322  Long id = 432L;
1323  @Override
1324  public WhitelistedSite answer(InvocationOnMock invocation) throws Throwable {
1325  WhitelistedSite _site = mock(WhitelistedSite.class);
1326  when(_site.getId()).thenReturn(id++);
1327  return _site;
1328  }
1329  });
1330  when(tokenRepository.getAccessTokenById(isNull(Long.class))).thenAnswer(new Answer<OAuth2AccessTokenEntity>() {
1331  Long id = 245L;
1332  @Override
1333  public OAuth2AccessTokenEntity answer(InvocationOnMock invocation) throws Throwable {
1334  OAuth2AccessTokenEntity _token = mock(OAuth2AccessTokenEntity.class);
1335  when(_token.getId()).thenReturn(id++);
1336  return _token;
1337  }
1338  });
1339 
1340  dataService.importData(reader);
1341  //2 for sites, 1 for updating access token ref on #1
1342  verify(approvedSiteRepository, times(3)).save(capturedApprovedSites.capture());
1343 
1344  List<ApprovedSite> savedSites = new ArrayList(fakeDb.values());
1345 
1346  assertThat(savedSites.size(), is(2));
1347 
1348  assertThat(savedSites.get(0).getClientId(), equalTo(site1.getClientId()));
1349  assertThat(savedSites.get(0).getAccessDate(), equalTo(site1.getAccessDate()));
1350  assertThat(savedSites.get(0).getCreationDate(), equalTo(site1.getCreationDate()));
1351  assertThat(savedSites.get(0).getAllowedScopes(), equalTo(site1.getAllowedScopes()));
1352  assertThat(savedSites.get(0).getTimeoutDate(), equalTo(site1.getTimeoutDate()));
1353 
1354  assertThat(savedSites.get(1).getClientId(), equalTo(site2.getClientId()));
1355  assertThat(savedSites.get(1).getAccessDate(), equalTo(site2.getAccessDate()));
1356  assertThat(savedSites.get(1).getCreationDate(), equalTo(site2.getCreationDate()));
1357  assertThat(savedSites.get(1).getAllowedScopes(), equalTo(site2.getAllowedScopes()));
1358  assertThat(savedSites.get(1).getTimeoutDate(), equalTo(site2.getTimeoutDate()));
1359  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
ArgumentCaptor< ApprovedSite > capturedApprovedSites
Definition: TestMITREidDataService_1_3.java:133
OAuth2AccessTokenEntity getAccessTokenById(Long id)
ApprovedSite save(ApprovedSite approvedSite)
DateFormatter formatter
Definition: TestMITREidDataService_1_3.java:141
WhitelistedSiteRepository wlSiteRepository
Definition: TestMITREidDataService_1_3.java:112
static Logger logger
Definition: TestMITREidDataService_1_3.java:105
ApprovedSiteRepository approvedSiteRepository
Definition: TestMITREidDataService_1_3.java:110
void importData(JsonReader reader)
Definition: MITREidDataService_1_3.java:567
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118

◆ testImportRefreshTokens()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testImportRefreshTokens ( ) throws IOException, ParseException
inline
275  {
276  String expiration1 = "2014-09-10T22:49:44.090+0000";
277  Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
278 
279  ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
280  when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
281 
282  AuthenticationHolderEntity mockedAuthHolder1 = mock(AuthenticationHolderEntity.class);
283  when(mockedAuthHolder1.getId()).thenReturn(1L);
284 
285  OAuth2RefreshTokenEntity token1 = new OAuth2RefreshTokenEntity();
286  token1.setId(1L);
287  token1.setClient(mockedClient1);
288  token1.setExpiration(expirationDate1);
289  token1.setJwt(JWTParser.parse("eyJhbGciOiJub25lIn0.eyJqdGkiOiJmOTg4OWQyOS0xMTk1LTQ4ODEtODgwZC1lZjVlYzAwY2Y4NDIifQ."));
290  token1.setAuthenticationHolder(mockedAuthHolder1);
291 
292  String expiration2 = "2015-01-07T18:31:50.079+0000";
293  Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
294 
295  ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
296  when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
297 
298  AuthenticationHolderEntity mockedAuthHolder2 = mock(AuthenticationHolderEntity.class);
299  when(mockedAuthHolder2.getId()).thenReturn(2L);
300 
301  OAuth2RefreshTokenEntity token2 = new OAuth2RefreshTokenEntity();
302  token2.setId(2L);
303  token2.setClient(mockedClient2);
304  token2.setExpiration(expirationDate2);
305  token2.setJwt(JWTParser.parse("eyJhbGciOiJub25lIn0.eyJqdGkiOiJlYmEyYjc3My0xNjAzLTRmNDAtOWQ3MS1hMGIxZDg1OWE2MDAifQ."));
306  token2.setAuthenticationHolder(mockedAuthHolder2);
307 
308  String configJson = "{" +
309  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
310  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
311  "\"" + MITREidDataService.CLIENTS + "\": [], " +
312  "\"" + MITREidDataService.GRANTS + "\": [], " +
313  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
314  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
315  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
316  "\"" + MITREidDataService.REFRESHTOKENS + "\": [" +
317 
318  "{\"id\":1,\"clientId\":\"mocked_client_1\",\"expiration\":\"2014-09-10T22:49:44.090+0000\","
319  + "\"authenticationHolderId\":1,\"value\":\"eyJhbGciOiJub25lIn0.eyJqdGkiOiJmOTg4OWQyOS0xMTk1LTQ4ODEtODgwZC1lZjVlYzAwY2Y4NDIifQ.\"}," +
320  "{\"id\":2,\"clientId\":\"mocked_client_2\",\"expiration\":\"2015-01-07T18:31:50.079+0000\","
321  + "\"authenticationHolderId\":2,\"value\":\"eyJhbGciOiJub25lIn0.eyJqdGkiOiJlYmEyYjc3My0xNjAzLTRmNDAtOWQ3MS1hMGIxZDg1OWE2MDAifQ.\"}" +
322 
323  " ]" +
324  "}";
325 
326  logger.debug(configJson);
327  JsonReader reader = new JsonReader(new StringReader(configJson));
328 
329  final Map<Long, OAuth2RefreshTokenEntity> fakeDb = new HashMap<>();
330  when(tokenRepository.saveRefreshToken(isA(OAuth2RefreshTokenEntity.class))).thenAnswer(new Answer<OAuth2RefreshTokenEntity>() {
331  Long id = 332L;
332  @Override
333  public OAuth2RefreshTokenEntity answer(InvocationOnMock invocation) throws Throwable {
334  OAuth2RefreshTokenEntity _token = (OAuth2RefreshTokenEntity) invocation.getArguments()[0];
335  if(_token.getId() == null) {
336  _token.setId(id++);
337  }
338  fakeDb.put(_token.getId(), _token);
339  return _token;
340  }
341  });
342  when(tokenRepository.getRefreshTokenById(anyLong())).thenAnswer(new Answer<OAuth2RefreshTokenEntity>() {
343  @Override
344  public OAuth2RefreshTokenEntity answer(InvocationOnMock invocation) throws Throwable {
345  Long _id = (Long) invocation.getArguments()[0];
346  return fakeDb.get(_id);
347  }
348  });
349  when(clientRepository.getClientByClientId(anyString())).thenAnswer(new Answer<ClientDetailsEntity>() {
350  @Override
351  public ClientDetailsEntity answer(InvocationOnMock invocation) throws Throwable {
352  String _clientId = (String) invocation.getArguments()[0];
353  ClientDetailsEntity _client = mock(ClientDetailsEntity.class);
354  when(_client.getClientId()).thenReturn(_clientId);
355  return _client;
356  }
357  });
358  when(authHolderRepository.getById(isNull(Long.class))).thenAnswer(new Answer<AuthenticationHolderEntity>() {
359  Long id = 131L;
360  @Override
361  public AuthenticationHolderEntity answer(InvocationOnMock invocation) throws Throwable {
362  AuthenticationHolderEntity _auth = mock(AuthenticationHolderEntity.class);
363  when(_auth.getId()).thenReturn(id);
364  id++;
365  return _auth;
366  }
367  });
368  dataService.importData(reader);
369  //2 times for token, 2 times to update client, 2 times to update authHolder
370  verify(tokenRepository, times(6)).saveRefreshToken(capturedRefreshTokens.capture());
371 
372  List<OAuth2RefreshTokenEntity> savedRefreshTokens = new ArrayList(fakeDb.values()); //capturedRefreshTokens.getAllValues();
373  Collections.sort(savedRefreshTokens, new refreshTokenIdComparator());
374 
375  assertThat(savedRefreshTokens.size(), is(2));
376 
377  assertThat(savedRefreshTokens.get(0).getClient().getClientId(), equalTo(token1.getClient().getClientId()));
378  assertThat(savedRefreshTokens.get(0).getExpiration(), equalTo(token1.getExpiration()));
379  assertThat(savedRefreshTokens.get(0).getValue(), equalTo(token1.getValue()));
380 
381  assertThat(savedRefreshTokens.get(1).getClient().getClientId(), equalTo(token2.getClient().getClientId()));
382  assertThat(savedRefreshTokens.get(1).getExpiration(), equalTo(token2.getExpiration()));
383  assertThat(savedRefreshTokens.get(1).getValue(), equalTo(token2.getValue()));
384  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
ClientDetailsEntity getClientByClientId(String clientId)
DateFormatter formatter
Definition: TestMITREidDataService_1_3.java:141
static Logger logger
Definition: TestMITREidDataService_1_3.java:105
OAuth2RefreshTokenEntity saveRefreshToken(OAuth2RefreshTokenEntity refreshToken)
ArgumentCaptor< OAuth2RefreshTokenEntity > capturedRefreshTokens
Definition: TestMITREidDataService_1_3.java:123
OAuth2ClientRepository clientRepository
Definition: TestMITREidDataService_1_3.java:108
void importData(JsonReader reader)
Definition: MITREidDataService_1_3.java:567
AuthenticationHolderRepository authHolderRepository
Definition: TestMITREidDataService_1_3.java:116
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_3.java:118
OAuth2RefreshTokenEntity getRefreshTokenById(Long Id)

◆ testImportSystemScopes()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testImportSystemScopes ( ) throws IOException
inline
1646  {
1647  SystemScope scope1 = new SystemScope();
1648  scope1.setId(1L);
1649  scope1.setValue("scope1");
1650  scope1.setDescription("Scope 1");
1651  scope1.setRestricted(true);
1652  scope1.setDefaultScope(false);
1653  scope1.setIcon("glass");
1654 
1655  SystemScope scope2 = new SystemScope();
1656  scope2.setId(2L);
1657  scope2.setValue("scope2");
1658  scope2.setDescription("Scope 2");
1659  scope2.setRestricted(false);
1660  scope2.setDefaultScope(false);
1661  scope2.setIcon("ball");
1662 
1663  SystemScope scope3 = new SystemScope();
1664  scope3.setId(3L);
1665  scope3.setValue("scope3");
1666  scope3.setDescription("Scope 3");
1667  scope3.setRestricted(false);
1668  scope3.setDefaultScope(true);
1669  scope3.setIcon("road");
1670 
1671  String configJson = "{" +
1672  "\"" + MITREidDataService.CLIENTS + "\": [], " +
1673  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
1674  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
1675  "\"" + MITREidDataService.GRANTS + "\": [], " +
1676  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
1677  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
1678  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
1679  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [" +
1680 
1681  "{\"id\":1,\"description\":\"Scope 1\",\"icon\":\"glass\",\"value\":\"scope1\",\"restricted\":true,\"defaultScope\":false}," +
1682  "{\"id\":2,\"description\":\"Scope 2\",\"icon\":\"ball\",\"value\":\"scope2\",\"restricted\":false,\"defaultScope\":false}," +
1683  "{\"id\":3,\"description\":\"Scope 3\",\"icon\":\"road\",\"value\":\"scope3\",\"restricted\":false,\"defaultScope\":true}" +
1684 
1685  " ]" +
1686  "}";
1687 
1688  logger.debug(configJson);
1689 
1690  JsonReader reader = new JsonReader(new StringReader(configJson));
1691 
1692  dataService.importData(reader);
1693  verify(sysScopeRepository, times(3)).save(capturedScope.capture());
1694 
1695  List<SystemScope> savedScopes = capturedScope.getAllValues();
1696 
1697  assertThat(savedScopes.size(), is(3));
1698  assertThat(savedScopes.get(0).getValue(), equalTo(scope1.getValue()));
1699  assertThat(savedScopes.get(0).getDescription(), equalTo(scope1.getDescription()));
1700  assertThat(savedScopes.get(0).getIcon(), equalTo(scope1.getIcon()));
1701  assertThat(savedScopes.get(0).isDefaultScope(), equalTo(scope1.isDefaultScope()));
1702  assertThat(savedScopes.get(0).isRestricted(), equalTo(scope1.isRestricted()));
1703 
1704  assertThat(savedScopes.get(1).getValue(), equalTo(scope2.getValue()));
1705  assertThat(savedScopes.get(1).getDescription(), equalTo(scope2.getDescription()));
1706  assertThat(savedScopes.get(1).getIcon(), equalTo(scope2.getIcon()));
1707  assertThat(savedScopes.get(1).isDefaultScope(), equalTo(scope2.isDefaultScope()));
1708  assertThat(savedScopes.get(1).isRestricted(), equalTo(scope2.isRestricted()));
1709 
1710  assertThat(savedScopes.get(2).getValue(), equalTo(scope3.getValue()));
1711  assertThat(savedScopes.get(2).getDescription(), equalTo(scope3.getDescription()));
1712  assertThat(savedScopes.get(2).getIcon(), equalTo(scope3.getIcon()));
1713  assertThat(savedScopes.get(2).isDefaultScope(), equalTo(scope3.isDefaultScope()));
1714  assertThat(savedScopes.get(2).isRestricted(), equalTo(scope3.isRestricted()));
1715 
1716  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
static Logger logger
Definition: TestMITREidDataService_1_3.java:105
ArgumentCaptor< SystemScope > capturedScope
Definition: TestMITREidDataService_1_3.java:137
void importData(JsonReader reader)
Definition: MITREidDataService_1_3.java:567
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_3.java:120

◆ testImportWhitelistedSites()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.testImportWhitelistedSites ( ) throws IOException
inline
1064  {
1065  WhitelistedSite site1 = new WhitelistedSite();
1066  site1.setId(1L);
1067  site1.setClientId("foo");
1068 
1069  WhitelistedSite site2 = new WhitelistedSite();
1070  site2.setId(2L);
1071  site2.setClientId("bar");
1072 
1073  WhitelistedSite site3 = new WhitelistedSite();
1074  site3.setId(3L);
1075  site3.setClientId("baz");
1076  //site3.setAllowedScopes(null);
1077 
1078  String configJson = "{" +
1079  "\"" + MITREidDataService.CLIENTS + "\": [], " +
1080  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
1081  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
1082  "\"" + MITREidDataService.GRANTS + "\": [], " +
1083  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
1084  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
1085  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
1086  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [" +
1087 
1088  "{\"id\":1,\"clientId\":\"foo\"}," +
1089  "{\"id\":2,\"clientId\":\"bar\"}," +
1090  "{\"id\":3,\"clientId\":\"baz\"}" +
1091 
1092  " ]" +
1093  "}";
1094 
1095  logger.debug(configJson);
1096 
1097  JsonReader reader = new JsonReader(new StringReader(configJson));
1098 
1099  final Map<Long, WhitelistedSite> fakeDb = new HashMap<>();
1100  when(wlSiteRepository.save(isA(WhitelistedSite.class))).thenAnswer(new Answer<WhitelistedSite>() {
1101  Long id = 333L;
1102  @Override
1103  public WhitelistedSite answer(InvocationOnMock invocation) throws Throwable {
1104  WhitelistedSite _site = (WhitelistedSite) invocation.getArguments()[0];
1105  if(_site.getId() == null) {
1106  _site.setId(id++);
1107  }
1108  fakeDb.put(_site.getId(), _site);
1109  return _site;
1110  }
1111  });
1112  when(wlSiteRepository.getById(anyLong())).thenAnswer(new Answer<WhitelistedSite>() {
1113  @Override
1114  public WhitelistedSite answer(InvocationOnMock invocation) throws Throwable {
1115  Long _id = (Long) invocation.getArguments()[0];
1116  return fakeDb.get(_id);
1117  }
1118  });
1119 
1120  dataService.importData(reader);
1121  verify(wlSiteRepository, times(3)).save(capturedWhitelistedSites.capture());
1122 
1123  List<WhitelistedSite> savedSites = capturedWhitelistedSites.getAllValues();
1124 
1125  assertThat(savedSites.size(), is(3));
1126 
1127  assertThat(savedSites.get(0).getClientId(), equalTo(site1.getClientId()));
1128  assertThat(savedSites.get(1).getClientId(), equalTo(site2.getClientId()));
1129  assertThat(savedSites.get(2).getClientId(), equalTo(site3.getClientId()));
1130  }
MITREidDataService_1_3 dataService
Definition: TestMITREidDataService_1_3.java:140
WhitelistedSiteRepository wlSiteRepository
Definition: TestMITREidDataService_1_3.java:112
static Logger logger
Definition: TestMITREidDataService_1_3.java:105
WhitelistedSite save(WhitelistedSite whiteListedSite)
void importData(JsonReader reader)
Definition: MITREidDataService_1_3.java:567
ArgumentCaptor< WhitelistedSite > capturedWhitelistedSites
Definition: TestMITREidDataService_1_3.java:131

メンバ詳解

◆ approvedSiteRepository

ApprovedSiteRepository org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.approvedSiteRepository
private

◆ authHolderRepository

AuthenticationHolderRepository org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.authHolderRepository
private

◆ blSiteRepository

BlacklistedSiteRepository org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.blSiteRepository
private

◆ capturedAccessTokens

ArgumentCaptor<OAuth2AccessTokenEntity> org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.capturedAccessTokens
private

◆ capturedApprovedSites

ArgumentCaptor<ApprovedSite> org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.capturedApprovedSites
private

◆ capturedAuthHolders

ArgumentCaptor<AuthenticationHolderEntity> org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.capturedAuthHolders
private

◆ capturedBlacklistedSites

ArgumentCaptor<BlacklistedSite> org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.capturedBlacklistedSites
private

◆ capturedClients

ArgumentCaptor<ClientDetailsEntity> org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.capturedClients
private

◆ capturedRefreshTokens

ArgumentCaptor<OAuth2RefreshTokenEntity> org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.capturedRefreshTokens
private

◆ capturedScope

ArgumentCaptor<SystemScope> org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.capturedScope
private

◆ capturedWhitelistedSites

ArgumentCaptor<WhitelistedSite> org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.capturedWhitelistedSites
private

◆ clientRepository

OAuth2ClientRepository org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.clientRepository
private

◆ dataService

MITREidDataService_1_3 org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.dataService
private

◆ formatter

DateFormatter org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.formatter
private

◆ logger

Logger org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.logger = LoggerFactory.getLogger(TestMITREidDataService_1_3.class)
staticprivate

◆ sysScopeRepository

SystemScopeRepository org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.sysScopeRepository
private

◆ tokenRepository

OAuth2TokenRepository org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.tokenRepository
private

◆ wlSiteRepository

WhitelistedSiteRepository org.mitre.openid.connect.service.impl.TestMITREidDataService_1_3.wlSiteRepository
private

このクラス詳解は次のファイルから抽出されました: