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

クラス

class  accessTokenIdComparator
 
class  refreshTokenIdComparator
 

公開メンバ関数

void prepare ()
 
void testImportRefreshTokens () throws IOException, ParseException
 
void testImportAccessTokens () throws IOException, ParseException
 
void testImportClients () throws IOException
 
void testImportBlacklistedSites () throws IOException
 
void testImportWhitelistedSites () throws IOException
 
void testImportGrants () throws IOException, ParseException
 
void testImportAuthenticationHolders () throws IOException
 
void testImportSystemScopes () throws IOException
 
void testFixRefreshTokenAuthHolderReferencesOnImport () throws IOException, ParseException
 
void testExportDisabled () throws IOException
 

非公開変数類

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_1 dataService
 
DateFormatter formatter
 

詳解

関数詳解

◆ prepare()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_1.prepare ( )
inline
130  {
131  formatter = new DateFormatter();
132  formatter.setIso(ISO.DATE_TIME);
133 
135  }
ApprovedSiteRepository approvedSiteRepository
Definition: TestMITREidDataService_1_1.java:96
OAuth2ClientRepository clientRepository
Definition: TestMITREidDataService_1_1.java:94
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_1.java:104
WhitelistedSiteRepository wlSiteRepository
Definition: TestMITREidDataService_1_1.java:98
AuthenticationHolderRepository authHolderRepository
Definition: TestMITREidDataService_1_1.java:102
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_1.java:100
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_1.java:106
DateFormatter formatter
Definition: TestMITREidDataService_1_1.java:127

◆ testExportDisabled()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_1.testExportDisabled ( ) throws IOException
inline
967  {
968  JsonWriter writer = new JsonWriter(new StringWriter());
969  dataService.exportData(writer);
970  }
MITREidDataService_1_1 dataService
Definition: TestMITREidDataService_1_1.java:126
void exportData(JsonWriter writer)
Definition: MITREidDataService_1_1.java:123

◆ testFixRefreshTokenAuthHolderReferencesOnImport()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_1.testFixRefreshTokenAuthHolderReferencesOnImport ( ) throws IOException, ParseException
inline
835  {
836  String expiration1 = "2014-09-10T22:49:44.090+0000";
837  Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
838 
839  ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
840  when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
841 
842  OAuth2Request req1 = new OAuth2Request(new HashMap<String, String>(), "client1", new ArrayList<GrantedAuthority>(),
843  true, new HashSet<String>(), new HashSet<String>(), "http://foo.com",
844  new HashSet<String>(), null);
845  Authentication mockAuth1 = mock(Authentication.class, withSettings().serializable());
846  OAuth2Authentication auth1 = new OAuth2Authentication(req1, mockAuth1);
847 
848  AuthenticationHolderEntity holder1 = new AuthenticationHolderEntity();
849  holder1.setId(1L);
850  holder1.setAuthentication(auth1);
851 
852  OAuth2RefreshTokenEntity token1 = new OAuth2RefreshTokenEntity();
853  token1.setId(1L);
854  token1.setClient(mockedClient1);
855  token1.setExpiration(expirationDate1);
856  token1.setJwt(JWTParser.parse("eyJhbGciOiJub25lIn0.eyJqdGkiOiJmOTg4OWQyOS0xMTk1LTQ4ODEtODgwZC1lZjVlYzAwY2Y4NDIifQ."));
857  token1.setAuthenticationHolder(holder1);
858 
859  String expiration2 = "2015-01-07T18:31:50.079+0000";
860  Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
861 
862  ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
863  when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
864 
865  OAuth2Request req2 = new OAuth2Request(new HashMap<String, String>(), "client2", new ArrayList<GrantedAuthority>(),
866  true, new HashSet<String>(), new HashSet<String>(), "http://bar.com",
867  new HashSet<String>(), null);
868  Authentication mockAuth2 = mock(Authentication.class, withSettings().serializable());
869  OAuth2Authentication auth2 = new OAuth2Authentication(req2, mockAuth2);
870 
871  AuthenticationHolderEntity holder2 = new AuthenticationHolderEntity();
872  holder2.setId(2L);
873  holder2.setAuthentication(auth2);
874 
875  OAuth2RefreshTokenEntity token2 = new OAuth2RefreshTokenEntity();
876  token2.setId(2L);
877  token2.setClient(mockedClient2);
878  token2.setExpiration(expirationDate2);
879  token2.setJwt(JWTParser.parse("eyJhbGciOiJub25lIn0.eyJqdGkiOiJlYmEyYjc3My0xNjAzLTRmNDAtOWQ3MS1hMGIxZDg1OWE2MDAifQ."));
880  token2.setAuthenticationHolder(holder2);
881 
882  String configJson = "{" +
883  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
884  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
885  "\"" + MITREidDataService.CLIENTS + "\": [], " +
886  "\"" + MITREidDataService.GRANTS + "\": [], " +
887  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
888  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
889  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [" +
890 
891  "{\"id\":1,\"authentication\":{\"clientAuthorization\":{\"clientId\":\"client1\",\"redirectUri\":\"http://foo.com\"},"
892  + "\"userAuthentication\":null}}," +
893  "{\"id\":2,\"authentication\":{\"clientAuthorization\":{\"clientId\":\"client2\",\"redirectUri\":\"http://bar.com\"},"
894  + "\"userAuthentication\":null}}" +
895  " ]," +
896  "\"" + MITREidDataService.REFRESHTOKENS + "\": [" +
897 
898  "{\"id\":1,\"clientId\":\"mocked_client_1\",\"expiration\":\"2014-09-10T22:49:44.090+0000\","
899  + "\"authenticationHolderId\":1,\"value\":\"eyJhbGciOiJub25lIn0.eyJqdGkiOiJmOTg4OWQyOS0xMTk1LTQ4ODEtODgwZC1lZjVlYzAwY2Y4NDIifQ.\"}," +
900  "{\"id\":2,\"clientId\":\"mocked_client_2\",\"expiration\":\"2015-01-07T18:31:50.079+0000\","
901  + "\"authenticationHolderId\":2,\"value\":\"eyJhbGciOiJub25lIn0.eyJqdGkiOiJlYmEyYjc3My0xNjAzLTRmNDAtOWQ3MS1hMGIxZDg1OWE2MDAifQ.\"}" +
902 
903  " ]" +
904  "}";
905  System.err.println(configJson);
906 
907  JsonReader reader = new JsonReader(new StringReader(configJson));
908  final Map<Long, OAuth2RefreshTokenEntity> fakeRefreshTokenTable = new HashMap<>();
909  final Map<Long, AuthenticationHolderEntity> fakeAuthHolderTable = new HashMap<>();
910  when(tokenRepository.saveRefreshToken(isA(OAuth2RefreshTokenEntity.class))).thenAnswer(new Answer<OAuth2RefreshTokenEntity>() {
911  Long id = 343L;
912  @Override
913  public OAuth2RefreshTokenEntity answer(InvocationOnMock invocation) throws Throwable {
914  OAuth2RefreshTokenEntity _token = (OAuth2RefreshTokenEntity) invocation.getArguments()[0];
915  if(_token.getId() == null) {
916  _token.setId(id++);
917  }
918  fakeRefreshTokenTable.put(_token.getId(), _token);
919  return _token;
920  }
921  });
922  when(tokenRepository.getRefreshTokenById(anyLong())).thenAnswer(new Answer<OAuth2RefreshTokenEntity>() {
923  @Override
924  public OAuth2RefreshTokenEntity answer(InvocationOnMock invocation) throws Throwable {
925  Long _id = (Long) invocation.getArguments()[0];
926  return fakeRefreshTokenTable.get(_id);
927  }
928  });
929  when(clientRepository.getClientByClientId(anyString())).thenAnswer(new Answer<ClientDetailsEntity>() {
930  @Override
931  public ClientDetailsEntity answer(InvocationOnMock invocation) throws Throwable {
932  String _clientId = (String) invocation.getArguments()[0];
933  ClientDetailsEntity _client = mock(ClientDetailsEntity.class);
934  when(_client.getClientId()).thenReturn(_clientId);
935  return _client;
936  }
937  });
938  when(authHolderRepository.save(isA(AuthenticationHolderEntity.class))).thenAnswer(new Answer<AuthenticationHolderEntity>() {
939  Long id = 356L;
940  @Override
941  public AuthenticationHolderEntity answer(InvocationOnMock invocation) throws Throwable {
942  AuthenticationHolderEntity _holder = (AuthenticationHolderEntity) invocation.getArguments()[0];
943  if(_holder.getId() == null) {
944  _holder.setId(id++);
945  }
946  fakeAuthHolderTable.put(_holder.getId(), _holder);
947  return _holder;
948  }
949  });
950  when(authHolderRepository.getById(anyLong())).thenAnswer(new Answer<AuthenticationHolderEntity>() {
951  @Override
952  public AuthenticationHolderEntity answer(InvocationOnMock invocation) throws Throwable {
953  Long _id = (Long) invocation.getArguments()[0];
954  return fakeAuthHolderTable.get(_id);
955  }
956  });
957  dataService.importData(reader);
958 
959  List<OAuth2RefreshTokenEntity> savedRefreshTokens = new ArrayList(fakeRefreshTokenTable.values()); //capturedRefreshTokens.getAllValues();
960  Collections.sort(savedRefreshTokens, new refreshTokenIdComparator());
961 
962  assertThat(savedRefreshTokens.get(0).getAuthenticationHolder().getId(), equalTo(356L));
963  assertThat(savedRefreshTokens.get(1).getAuthenticationHolder().getId(), equalTo(357L));
964  }
ClientDetailsEntity getClientByClientId(String clientId)
OAuth2RefreshTokenEntity saveRefreshToken(OAuth2RefreshTokenEntity refreshToken)
OAuth2ClientRepository clientRepository
Definition: TestMITREidDataService_1_1.java:94
MITREidDataService_1_1 dataService
Definition: TestMITREidDataService_1_1.java:126
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_1.java:104
AuthenticationHolderEntity save(AuthenticationHolderEntity a)
AuthenticationHolderRepository authHolderRepository
Definition: TestMITREidDataService_1_1.java:102
void importData(JsonReader reader)
Definition: MITREidDataService_1_1.java:131
DateFormatter formatter
Definition: TestMITREidDataService_1_1.java:127
OAuth2RefreshTokenEntity getRefreshTokenById(Long Id)

◆ testImportAccessTokens()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_1.testImportAccessTokens ( ) throws IOException, ParseException
inline
266  {
267  String expiration1 = "2014-09-10T22:49:44.090+0000";
268  Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
269 
270  ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
271  when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
272 
273  AuthenticationHolderEntity mockedAuthHolder1 = mock(AuthenticationHolderEntity.class);
274  when(mockedAuthHolder1.getId()).thenReturn(1L);
275 
276  OAuth2AccessTokenEntity token1 = new OAuth2AccessTokenEntity();
277  token1.setId(1L);
278  token1.setClient(mockedClient1);
279  token1.setExpiration(expirationDate1);
280  token1.setJwt(JWTParser.parse("eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE0MTI3ODk5NjgsInN1YiI6IjkwMzQyLkFTREZKV0ZBIiwiYXRfaGFzaCI6InptTmt1QmNRSmNYQktNaVpFODZqY0EiLCJhdWQiOlsiY2xpZW50Il0sImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo4MDgwXC9vcGVuaWQtY29ubmVjdC1zZXJ2ZXItd2ViYXBwXC8iLCJpYXQiOjE0MTI3ODkzNjh9.xkEJ9IMXpH7qybWXomfq9WOOlpGYnrvGPgey9UQ4GLzbQx7JC0XgJK83PmrmBZosvFPCmota7FzI_BtwoZLgAZfFiH6w3WIlxuogoH-TxmYbxEpTHoTsszZppkq9mNgOlArV4jrR9y3TPo4MovsH71dDhS_ck-CvAlJunHlqhs0"));
281  token1.setAuthenticationHolder(mockedAuthHolder1);
282  token1.setScope(ImmutableSet.of("id-token"));
283  token1.setTokenType("Bearer");
284 
285  String expiration2 = "2015-01-07T18:31:50.079+0000";
286  Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
287 
288  ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
289  when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
290 
291  AuthenticationHolderEntity mockedAuthHolder2 = mock(AuthenticationHolderEntity.class);
292  when(mockedAuthHolder2.getId()).thenReturn(2L);
293 
294  OAuth2RefreshTokenEntity mockRefreshToken2 = mock(OAuth2RefreshTokenEntity.class);
295  when(mockRefreshToken2.getId()).thenReturn(1L);
296 
297  OAuth2AccessTokenEntity token2 = new OAuth2AccessTokenEntity();
298  token2.setId(2L);
299  token2.setClient(mockedClient2);
300  token2.setExpiration(expirationDate2);
301  token2.setJwt(JWTParser.parse("eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE0MTI3OTI5NjgsImF1ZCI6WyJjbGllbnQiXSwiaXNzIjoiaHR0cDpcL1wvbG9jYWxob3N0OjgwODBcL29wZW5pZC1jb25uZWN0LXNlcnZlci13ZWJhcHBcLyIsImp0aSI6IjBmZGE5ZmRiLTYyYzItNGIzZS05OTdiLWU0M2VhMDUwMzNiOSIsImlhdCI6MTQxMjc4OTM2OH0.xgaVpRLYE5MzbgXfE0tZt823tjAm6Oh3_kdR1P2I9jRLR6gnTlBQFlYi3Y_0pWNnZSerbAE8Tn6SJHZ9k-curVG0-ByKichV7CNvgsE5X_2wpEaUzejvKf8eZ-BammRY-ie6yxSkAarcUGMvGGOLbkFcz5CtrBpZhfd75J49BIQ"));
302  token2.setAuthenticationHolder(mockedAuthHolder2);
303  token2.setRefreshToken(mockRefreshToken2);
304  token2.setScope(ImmutableSet.of("openid", "offline_access", "email", "profile"));
305  token2.setTokenType("Bearer");
306 
307  String configJson = "{" +
308  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
309  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
310  "\"" + MITREidDataService.CLIENTS + "\": [], " +
311  "\"" + MITREidDataService.GRANTS + "\": [], " +
312  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
313  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
314  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
315  "\"" + MITREidDataService.ACCESSTOKENS + "\": [" +
316 
317  "{\"id\":1,\"clientId\":\"mocked_client_1\",\"expiration\":\"2014-09-10T22:49:44.090+0000\","
318  + "\"refreshTokenId\":null,\"idTokenId\":null,\"scope\":[\"id-token\"],\"type\":\"Bearer\","
319  + "\"authenticationHolderId\":1,\"value\":\"eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE0MTI3ODk5NjgsInN1YiI6IjkwMzQyLkFTREZKV0ZBIiwiYXRfaGFzaCI6InptTmt1QmNRSmNYQktNaVpFODZqY0EiLCJhdWQiOlsiY2xpZW50Il0sImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo4MDgwXC9vcGVuaWQtY29ubmVjdC1zZXJ2ZXItd2ViYXBwXC8iLCJpYXQiOjE0MTI3ODkzNjh9.xkEJ9IMXpH7qybWXomfq9WOOlpGYnrvGPgey9UQ4GLzbQx7JC0XgJK83PmrmBZosvFPCmota7FzI_BtwoZLgAZfFiH6w3WIlxuogoH-TxmYbxEpTHoTsszZppkq9mNgOlArV4jrR9y3TPo4MovsH71dDhS_ck-CvAlJunHlqhs0\"}," +
320  "{\"id\":2,\"clientId\":\"mocked_client_2\",\"expiration\":\"2015-01-07T18:31:50.079+0000\","
321  + "\"refreshTokenId\":1,\"idTokenId\":1,\"scope\":[\"openid\",\"offline_access\",\"email\",\"profile\"],\"type\":\"Bearer\","
322  + "\"authenticationHolderId\":2,\"value\":\"eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE0MTI3OTI5NjgsImF1ZCI6WyJjbGllbnQiXSwiaXNzIjoiaHR0cDpcL1wvbG9jYWxob3N0OjgwODBcL29wZW5pZC1jb25uZWN0LXNlcnZlci13ZWJhcHBcLyIsImp0aSI6IjBmZGE5ZmRiLTYyYzItNGIzZS05OTdiLWU0M2VhMDUwMzNiOSIsImlhdCI6MTQxMjc4OTM2OH0.xgaVpRLYE5MzbgXfE0tZt823tjAm6Oh3_kdR1P2I9jRLR6gnTlBQFlYi3Y_0pWNnZSerbAE8Tn6SJHZ9k-curVG0-ByKichV7CNvgsE5X_2wpEaUzejvKf8eZ-BammRY-ie6yxSkAarcUGMvGGOLbkFcz5CtrBpZhfd75J49BIQ\"}" +
323 
324  " ]" +
325  "}";
326 
327 
328  System.err.println(configJson);
329 
330  JsonReader reader = new JsonReader(new StringReader(configJson));
331 
332  final Map<Long, OAuth2AccessTokenEntity> fakeDb = new HashMap<>();
333  when(tokenRepository.saveAccessToken(isA(OAuth2AccessTokenEntity.class))).thenAnswer(new Answer<OAuth2AccessTokenEntity>() {
334  Long id = 324L;
335  @Override
336  public OAuth2AccessTokenEntity answer(InvocationOnMock invocation) throws Throwable {
337  OAuth2AccessTokenEntity _token = (OAuth2AccessTokenEntity) invocation.getArguments()[0];
338  if(_token.getId() == null) {
339  _token.setId(id++);
340  }
341  fakeDb.put(_token.getId(), _token);
342  return _token;
343  }
344  });
345  when(tokenRepository.getAccessTokenById(anyLong())).thenAnswer(new Answer<OAuth2AccessTokenEntity>() {
346  @Override
347  public OAuth2AccessTokenEntity answer(InvocationOnMock invocation) throws Throwable {
348  Long _id = (Long) invocation.getArguments()[0];
349  return fakeDb.get(_id);
350  }
351  });
352  when(clientRepository.getClientByClientId(anyString())).thenAnswer(new Answer<ClientDetailsEntity>() {
353  @Override
354  public ClientDetailsEntity answer(InvocationOnMock invocation) throws Throwable {
355  String _clientId = (String) invocation.getArguments()[0];
356  ClientDetailsEntity _client = mock(ClientDetailsEntity.class);
357  when(_client.getClientId()).thenReturn(_clientId);
358  return _client;
359  }
360  });
361  when(authHolderRepository.getById(isNull(Long.class))).thenAnswer(new Answer<AuthenticationHolderEntity>() {
362  Long id = 133L;
363  @Override
364  public AuthenticationHolderEntity answer(InvocationOnMock invocation) throws Throwable {
365  AuthenticationHolderEntity _auth = mock(AuthenticationHolderEntity.class);
366  when(_auth.getId()).thenReturn(id);
367  id++;
368  return _auth;
369  }
370  });
371  dataService.importData(reader);
372  //2 times for token, 2 times to update client, 2 times to update authHolder, 1 times to update refresh token
373  verify(tokenRepository, times(7)).saveAccessToken(capturedAccessTokens.capture());
374 
375  List<OAuth2AccessTokenEntity> savedAccessTokens = new ArrayList(fakeDb.values()); //capturedAccessTokens.getAllValues();
376  Collections.sort(savedAccessTokens, new accessTokenIdComparator());
377 
378  assertThat(savedAccessTokens.size(), is(2));
379 
380  assertThat(savedAccessTokens.get(0).getClient().getClientId(), equalTo(token1.getClient().getClientId()));
381  assertThat(savedAccessTokens.get(0).getExpiration(), equalTo(token1.getExpiration()));
382  assertThat(savedAccessTokens.get(0).getValue(), equalTo(token1.getValue()));
383 
384  assertThat(savedAccessTokens.get(1).getClient().getClientId(), equalTo(token2.getClient().getClientId()));
385  assertThat(savedAccessTokens.get(1).getExpiration(), equalTo(token2.getExpiration()));
386  assertThat(savedAccessTokens.get(1).getValue(), equalTo(token2.getValue()));
387  }
OAuth2AccessTokenEntity saveAccessToken(OAuth2AccessTokenEntity token)
ClientDetailsEntity getClientByClientId(String clientId)
OAuth2AccessTokenEntity getAccessTokenById(Long id)
ArgumentCaptor< OAuth2AccessTokenEntity > capturedAccessTokens
Definition: TestMITREidDataService_1_1.java:111
OAuth2ClientRepository clientRepository
Definition: TestMITREidDataService_1_1.java:94
MITREidDataService_1_1 dataService
Definition: TestMITREidDataService_1_1.java:126
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_1.java:104
AuthenticationHolderRepository authHolderRepository
Definition: TestMITREidDataService_1_1.java:102
void importData(JsonReader reader)
Definition: MITREidDataService_1_1.java:131
DateFormatter formatter
Definition: TestMITREidDataService_1_1.java:127

◆ testImportAuthenticationHolders()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_1.testImportAuthenticationHolders ( ) throws IOException
inline
695  {
696  OAuth2Request req1 = new OAuth2Request(new HashMap<String, String>(), "client1", new ArrayList<GrantedAuthority>(),
697  true, new HashSet<String>(), new HashSet<String>(), "http://foo.com",
698  new HashSet<String>(), null);
699  Authentication mockAuth1 = mock(Authentication.class, withSettings().serializable());
700  OAuth2Authentication auth1 = new OAuth2Authentication(req1, mockAuth1);
701 
702  AuthenticationHolderEntity holder1 = new AuthenticationHolderEntity();
703  holder1.setId(1L);
704  holder1.setAuthentication(auth1);
705 
706  OAuth2Request req2 = new OAuth2Request(new HashMap<String, String>(), "client2", new ArrayList<GrantedAuthority>(),
707  true, new HashSet<String>(), new HashSet<String>(), "http://bar.com",
708  new HashSet<String>(), null);
709  Authentication mockAuth2 = mock(Authentication.class, withSettings().serializable());
710  OAuth2Authentication auth2 = new OAuth2Authentication(req2, mockAuth2);
711 
712  AuthenticationHolderEntity holder2 = new AuthenticationHolderEntity();
713  holder2.setId(2L);
714  holder2.setAuthentication(auth2);
715 
716  String configJson = "{" +
717  "\"" + MITREidDataService.CLIENTS + "\": [], " +
718  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
719  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
720  "\"" + MITREidDataService.GRANTS + "\": [], " +
721  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
722  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
723  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
724  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [" +
725 
726  "{\"id\":1,\"authentication\":{\"clientAuthorization\":{\"clientId\":\"client1\",\"redirectUri\":\"http://foo.com\"},"
727  + "\"userAuthentication\":null}}," +
728  "{\"id\":2,\"authentication\":{\"clientAuthorization\":{\"clientId\":\"client2\",\"redirectUri\":\"http://bar.com\"},"
729  + "\"userAuthentication\":null}}" +
730  " ]" +
731  "}";
732 
733  System.err.println(configJson);
734 
735  JsonReader reader = new JsonReader(new StringReader(configJson));
736 
737  final Map<Long, AuthenticationHolderEntity> fakeDb = new HashMap<>();
738  when(authHolderRepository.save(isA(AuthenticationHolderEntity.class))).thenAnswer(new Answer<AuthenticationHolderEntity>() {
739  Long id = 243L;
740  @Override
741  public AuthenticationHolderEntity answer(InvocationOnMock invocation) throws Throwable {
742  AuthenticationHolderEntity _site = (AuthenticationHolderEntity) invocation.getArguments()[0];
743  if(_site.getId() == null) {
744  _site.setId(id++);
745  }
746  fakeDb.put(_site.getId(), _site);
747  return _site;
748  }
749  });
750 
751  dataService.importData(reader);
752  verify(authHolderRepository, times(2)).save(capturedAuthHolders.capture());
753 
754  List<AuthenticationHolderEntity> savedAuthHolders = capturedAuthHolders.getAllValues();
755 
756  assertThat(savedAuthHolders.size(), is(2));
757  assertThat(savedAuthHolders.get(0).getAuthentication().getOAuth2Request().getClientId(), equalTo(holder1.getAuthentication().getOAuth2Request().getClientId()));
758  assertThat(savedAuthHolders.get(1).getAuthentication().getOAuth2Request().getClientId(), equalTo(holder2.getAuthentication().getOAuth2Request().getClientId()));
759  }
ArgumentCaptor< AuthenticationHolderEntity > capturedAuthHolders
Definition: TestMITREidDataService_1_1.java:121
MITREidDataService_1_1 dataService
Definition: TestMITREidDataService_1_1.java:126
AuthenticationHolderEntity save(AuthenticationHolderEntity a)
AuthenticationHolderRepository authHolderRepository
Definition: TestMITREidDataService_1_1.java:102
void importData(JsonReader reader)
Definition: MITREidDataService_1_1.java:131

◆ testImportBlacklistedSites()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_1.testImportBlacklistedSites ( ) throws IOException
inline
464  {
465  BlacklistedSite site1 = new BlacklistedSite();
466  site1.setId(1L);
467  site1.setUri("http://foo.com");
468 
469  BlacklistedSite site2 = new BlacklistedSite();
470  site2.setId(2L);
471  site2.setUri("http://bar.com");
472 
473  BlacklistedSite site3 = new BlacklistedSite();
474  site3.setId(3L);
475  site3.setUri("http://baz.com");
476 
477  String configJson = "{" +
478  "\"" + MITREidDataService.CLIENTS + "\": [], " +
479  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
480  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
481  "\"" + MITREidDataService.GRANTS + "\": [], " +
482  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
483  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
484  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
485  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [" +
486 
487  "{\"id\":1,\"uri\":\"http://foo.com\"}," +
488  "{\"id\":2,\"uri\":\"http://bar.com\"}," +
489  "{\"id\":3,\"uri\":\"http://baz.com\"}" +
490 
491  " ]" +
492  "}";
493 
494 
495  System.err.println(configJson);
496 
497  JsonReader reader = new JsonReader(new StringReader(configJson));
498 
499  dataService.importData(reader);
500  verify(blSiteRepository, times(3)).save(capturedBlacklistedSites.capture());
501 
502  List<BlacklistedSite> savedSites = capturedBlacklistedSites.getAllValues();
503 
504  assertThat(savedSites.size(), is(3));
505 
506  assertThat(savedSites.get(0).getUri(), equalTo(site1.getUri()));
507  assertThat(savedSites.get(1).getUri(), equalTo(site2.getUri()));
508  assertThat(savedSites.get(2).getUri(), equalTo(site3.getUri()));
509  }
ArgumentCaptor< BlacklistedSite > capturedBlacklistedSites
Definition: TestMITREidDataService_1_1.java:115
MITREidDataService_1_1 dataService
Definition: TestMITREidDataService_1_1.java:126
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_1.java:100
void importData(JsonReader reader)
Definition: MITREidDataService_1_1.java:131

◆ testImportClients()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_1.testImportClients ( ) throws IOException
inline
390  {
391  ClientDetailsEntity client1 = new ClientDetailsEntity();
392  client1.setId(1L);
393  client1.setAccessTokenValiditySeconds(3600);
394  client1.setClientId("client1");
395  client1.setClientSecret("clientsecret1");
396  client1.setRedirectUris(ImmutableSet.of("http://foo.com/"));
397  client1.setScope(ImmutableSet.of("foo", "bar", "baz", "dolphin"));
398  client1.setGrantTypes(ImmutableSet.of("implicit", "authorization_code", "urn:ietf:params:oauth:grant_type:redelegate", "refresh_token"));
399  client1.setAllowIntrospection(true);
400 
401  ClientDetailsEntity client2 = new ClientDetailsEntity();
402  client2.setId(2L);
403  client2.setAccessTokenValiditySeconds(3600);
404  client2.setClientId("client2");
405  client2.setClientSecret("clientsecret2");
406  client2.setRedirectUris(ImmutableSet.of("http://bar.baz.com/"));
407  client2.setScope(ImmutableSet.of("foo", "dolphin", "electric-wombat"));
408  client2.setGrantTypes(ImmutableSet.of("client_credentials", "urn:ietf:params:oauth:grant_type:redelegate"));
409  client2.setAllowIntrospection(false);
410 
411  String configJson = "{" +
412  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
413  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
414  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
415  "\"" + MITREidDataService.GRANTS + "\": [], " +
416  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
417  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
418  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
419  "\"" + MITREidDataService.CLIENTS + "\": [" +
420 
421  "{\"id\":1,\"accessTokenValiditySeconds\":3600,\"clientId\":\"client1\",\"secret\":\"clientsecret1\","
422  + "\"redirectUris\":[\"http://foo.com/\"],"
423  + "\"scope\":[\"foo\",\"bar\",\"baz\",\"dolphin\"],"
424  + "\"grantTypes\":[\"implicit\",\"authorization_code\",\"urn:ietf:params:oauth:grant_type:redelegate\",\"refresh_token\"],"
425  + "\"allowIntrospection\":true}," +
426  "{\"id\":2,\"accessTokenValiditySeconds\":3600,\"clientId\":\"client2\",\"secret\":\"clientsecret2\","
427  + "\"redirectUris\":[\"http://bar.baz.com/\"],"
428  + "\"scope\":[\"foo\",\"dolphin\",\"electric-wombat\"],"
429  + "\"grantTypes\":[\"client_credentials\",\"urn:ietf:params:oauth:grant_type:redelegate\"],"
430  + "\"allowIntrospection\":false}" +
431 
432  " ]" +
433  "}";
434 
435  System.err.println(configJson);
436 
437  JsonReader reader = new JsonReader(new StringReader(configJson));
438 
439  dataService.importData(reader);
440  verify(clientRepository, times(2)).saveClient(capturedClients.capture());
441 
442  List<ClientDetailsEntity> savedClients = capturedClients.getAllValues();
443 
444  assertThat(savedClients.size(), is(2));
445 
446  assertThat(savedClients.get(0).getAccessTokenValiditySeconds(), equalTo(client1.getAccessTokenValiditySeconds()));
447  assertThat(savedClients.get(0).getClientId(), equalTo(client1.getClientId()));
448  assertThat(savedClients.get(0).getClientSecret(), equalTo(client1.getClientSecret()));
449  assertThat(savedClients.get(0).getRedirectUris(), equalTo(client1.getRedirectUris()));
450  assertThat(savedClients.get(0).getScope(), equalTo(client1.getScope()));
451  assertThat(savedClients.get(0).getGrantTypes(), equalTo(client1.getGrantTypes()));
452  assertThat(savedClients.get(0).isAllowIntrospection(), equalTo(client1.isAllowIntrospection()));
453 
454  assertThat(savedClients.get(1).getAccessTokenValiditySeconds(), equalTo(client2.getAccessTokenValiditySeconds()));
455  assertThat(savedClients.get(1).getClientId(), equalTo(client2.getClientId()));
456  assertThat(savedClients.get(1).getClientSecret(), equalTo(client2.getClientSecret()));
457  assertThat(savedClients.get(1).getRedirectUris(), equalTo(client2.getRedirectUris()));
458  assertThat(savedClients.get(1).getScope(), equalTo(client2.getScope()));
459  assertThat(savedClients.get(1).getGrantTypes(), equalTo(client2.getGrantTypes()));
460  assertThat(savedClients.get(1).isAllowIntrospection(), equalTo(client2.isAllowIntrospection()));
461  }
ArgumentCaptor< ClientDetailsEntity > capturedClients
Definition: TestMITREidDataService_1_1.java:113
OAuth2ClientRepository clientRepository
Definition: TestMITREidDataService_1_1.java:94
MITREidDataService_1_1 dataService
Definition: TestMITREidDataService_1_1.java:126
void importData(JsonReader reader)
Definition: MITREidDataService_1_1.java:131

◆ testImportGrants()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_1.testImportGrants ( ) throws IOException, ParseException
inline
581  {
582  Date creationDate1 = formatter.parse("2014-09-10T22:49:44.090+0000", Locale.ENGLISH);
583  Date accessDate1 = formatter.parse("2014-09-10T23:49:44.090+0000", Locale.ENGLISH);
584 
585  OAuth2AccessTokenEntity mockToken1 = mock(OAuth2AccessTokenEntity.class);
586  when(mockToken1.getId()).thenReturn(1L);
587 
588  ApprovedSite site1 = new ApprovedSite();
589  site1.setId(1L);
590  site1.setClientId("foo");
591  site1.setCreationDate(creationDate1);
592  site1.setAccessDate(accessDate1);
593  site1.setUserId("user1");
594  site1.setAllowedScopes(ImmutableSet.of("openid", "phone"));
595  when(mockToken1.getApprovedSite()).thenReturn(site1);
596 
597  Date creationDate2 = formatter.parse("2014-09-11T18:49:44.090+0000", Locale.ENGLISH);
598  Date accessDate2 = formatter.parse("2014-09-11T20:49:44.090+0000", Locale.ENGLISH);
599  Date timeoutDate2 = formatter.parse("2014-10-01T20:49:44.090+0000", Locale.ENGLISH);
600 
601  ApprovedSite site2 = new ApprovedSite();
602  site2.setId(2L);
603  site2.setClientId("bar");
604  site2.setCreationDate(creationDate2);
605  site2.setAccessDate(accessDate2);
606  site2.setUserId("user2");
607  site2.setAllowedScopes(ImmutableSet.of("openid", "offline_access", "email", "profile"));
608  site2.setTimeoutDate(timeoutDate2);
609 
610  String configJson = "{" +
611  "\"" + MITREidDataService.CLIENTS + "\": [], " +
612  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
613  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
614  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
615  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
616  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
617  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
618  "\"" + MITREidDataService.GRANTS + "\": [" +
619 
620  "{\"id\":1,\"clientId\":\"foo\",\"creationDate\":\"2014-09-10T22:49:44.090+0000\",\"accessDate\":\"2014-09-10T23:49:44.090+0000\","
621  + "\"userId\":\"user1\",\"whitelistedSiteId\":null,\"allowedScopes\":[\"openid\",\"phone\"], \"whitelistedSiteId\":1,"
622  + "\"approvedAccessTokens\":[1]}," +
623  "{\"id\":2,\"clientId\":\"bar\",\"creationDate\":\"2014-09-11T18:49:44.090+0000\",\"accessDate\":\"2014-09-11T20:49:44.090+0000\","
624  + "\"timeoutDate\":\"2014-10-01T20:49:44.090+0000\",\"userId\":\"user2\","
625  + "\"allowedScopes\":[\"openid\",\"offline_access\",\"email\",\"profile\"]}" +
626 
627  " ]" +
628  "}";
629 
630  System.err.println(configJson);
631 
632  JsonReader reader = new JsonReader(new StringReader(configJson));
633 
634  final Map<Long, ApprovedSite> fakeDb = new HashMap<>();
635  when(approvedSiteRepository.save(isA(ApprovedSite.class))).thenAnswer(new Answer<ApprovedSite>() {
636  Long id = 364L;
637  @Override
638  public ApprovedSite answer(InvocationOnMock invocation) throws Throwable {
639  ApprovedSite _site = (ApprovedSite) invocation.getArguments()[0];
640  if(_site.getId() == null) {
641  _site.setId(id++);
642  }
643  fakeDb.put(_site.getId(), _site);
644  return _site;
645  }
646  });
647  when(approvedSiteRepository.getById(anyLong())).thenAnswer(new Answer<ApprovedSite>() {
648  @Override
649  public ApprovedSite answer(InvocationOnMock invocation) throws Throwable {
650  Long _id = (Long) invocation.getArguments()[0];
651  return fakeDb.get(_id);
652  }
653  });
654  when(wlSiteRepository.getById(isNull(Long.class))).thenAnswer(new Answer<WhitelistedSite>() {
655  Long id = 432L;
656  @Override
657  public WhitelistedSite answer(InvocationOnMock invocation) throws Throwable {
658  WhitelistedSite _site = mock(WhitelistedSite.class);
659  when(_site.getId()).thenReturn(id++);
660  return _site;
661  }
662  });
663  when(tokenRepository.getAccessTokenById(isNull(Long.class))).thenAnswer(new Answer<OAuth2AccessTokenEntity>() {
664  Long id = 245L;
665  @Override
666  public OAuth2AccessTokenEntity answer(InvocationOnMock invocation) throws Throwable {
667  OAuth2AccessTokenEntity _token = mock(OAuth2AccessTokenEntity.class);
668  when(_token.getId()).thenReturn(id++);
669  return _token;
670  }
671  });
672 
673  dataService.importData(reader);
674  //2 for sites, 1 for updating access token ref on #1
675  verify(approvedSiteRepository, times(3)).save(capturedApprovedSites.capture());
676 
677  List<ApprovedSite> savedSites = new ArrayList(fakeDb.values());
678 
679  assertThat(savedSites.size(), is(2));
680 
681  assertThat(savedSites.get(0).getClientId(), equalTo(site1.getClientId()));
682  assertThat(savedSites.get(0).getAccessDate(), equalTo(site1.getAccessDate()));
683  assertThat(savedSites.get(0).getCreationDate(), equalTo(site1.getCreationDate()));
684  assertThat(savedSites.get(0).getAllowedScopes(), equalTo(site1.getAllowedScopes()));
685  assertThat(savedSites.get(0).getTimeoutDate(), equalTo(site1.getTimeoutDate()));
686 
687  assertThat(savedSites.get(1).getClientId(), equalTo(site2.getClientId()));
688  assertThat(savedSites.get(1).getAccessDate(), equalTo(site2.getAccessDate()));
689  assertThat(savedSites.get(1).getCreationDate(), equalTo(site2.getCreationDate()));
690  assertThat(savedSites.get(1).getAllowedScopes(), equalTo(site2.getAllowedScopes()));
691  assertThat(savedSites.get(1).getTimeoutDate(), equalTo(site2.getTimeoutDate()));
692  }
OAuth2AccessTokenEntity getAccessTokenById(Long id)
ApprovedSite save(ApprovedSite approvedSite)
ApprovedSiteRepository approvedSiteRepository
Definition: TestMITREidDataService_1_1.java:96
MITREidDataService_1_1 dataService
Definition: TestMITREidDataService_1_1.java:126
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_1.java:104
WhitelistedSiteRepository wlSiteRepository
Definition: TestMITREidDataService_1_1.java:98
ArgumentCaptor< ApprovedSite > capturedApprovedSites
Definition: TestMITREidDataService_1_1.java:119
void importData(JsonReader reader)
Definition: MITREidDataService_1_1.java:131
DateFormatter formatter
Definition: TestMITREidDataService_1_1.java:127

◆ testImportRefreshTokens()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_1.testImportRefreshTokens ( ) throws IOException, ParseException
inline
147  {
148  String expiration1 = "2014-09-10T22:49:44.090+0000";
149  Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
150 
151  ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
152  when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
153 
154  AuthenticationHolderEntity mockedAuthHolder1 = mock(AuthenticationHolderEntity.class);
155  when(mockedAuthHolder1.getId()).thenReturn(1L);
156 
157  OAuth2RefreshTokenEntity token1 = new OAuth2RefreshTokenEntity();
158  token1.setId(1L);
159  token1.setClient(mockedClient1);
160  token1.setExpiration(expirationDate1);
161  token1.setJwt(JWTParser.parse("eyJhbGciOiJub25lIn0.eyJqdGkiOiJmOTg4OWQyOS0xMTk1LTQ4ODEtODgwZC1lZjVlYzAwY2Y4NDIifQ."));
162  token1.setAuthenticationHolder(mockedAuthHolder1);
163 
164  String expiration2 = "2015-01-07T18:31:50.079+0000";
165  Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
166 
167  ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
168  when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
169 
170  AuthenticationHolderEntity mockedAuthHolder2 = mock(AuthenticationHolderEntity.class);
171  when(mockedAuthHolder2.getId()).thenReturn(2L);
172 
173  OAuth2RefreshTokenEntity token2 = new OAuth2RefreshTokenEntity();
174  token2.setId(2L);
175  token2.setClient(mockedClient2);
176  token2.setExpiration(expirationDate2);
177  token2.setJwt(JWTParser.parse("eyJhbGciOiJub25lIn0.eyJqdGkiOiJlYmEyYjc3My0xNjAzLTRmNDAtOWQ3MS1hMGIxZDg1OWE2MDAifQ."));
178  token2.setAuthenticationHolder(mockedAuthHolder2);
179 
180  String configJson = "{" +
181  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
182  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
183  "\"" + MITREidDataService.CLIENTS + "\": [], " +
184  "\"" + MITREidDataService.GRANTS + "\": [], " +
185  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
186  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
187  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
188  "\"" + MITREidDataService.REFRESHTOKENS + "\": [" +
189 
190  "{\"id\":1,\"clientId\":\"mocked_client_1\",\"expiration\":\"2014-09-10T22:49:44.090+0000\","
191  + "\"authenticationHolderId\":1,\"value\":\"eyJhbGciOiJub25lIn0.eyJqdGkiOiJmOTg4OWQyOS0xMTk1LTQ4ODEtODgwZC1lZjVlYzAwY2Y4NDIifQ.\"}," +
192  "{\"id\":2,\"clientId\":\"mocked_client_2\",\"expiration\":\"2015-01-07T18:31:50.079+0000\","
193  + "\"authenticationHolderId\":2,\"value\":\"eyJhbGciOiJub25lIn0.eyJqdGkiOiJlYmEyYjc3My0xNjAzLTRmNDAtOWQ3MS1hMGIxZDg1OWE2MDAifQ.\"}" +
194 
195  " ]" +
196  "}";
197 
198  System.err.println(configJson);
199  JsonReader reader = new JsonReader(new StringReader(configJson));
200 
201  final Map<Long, OAuth2RefreshTokenEntity> fakeDb = new HashMap<>();
202  when(tokenRepository.saveRefreshToken(isA(OAuth2RefreshTokenEntity.class))).thenAnswer(new Answer<OAuth2RefreshTokenEntity>() {
203  Long id = 332L;
204  @Override
205  public OAuth2RefreshTokenEntity answer(InvocationOnMock invocation) throws Throwable {
206  OAuth2RefreshTokenEntity _token = (OAuth2RefreshTokenEntity) invocation.getArguments()[0];
207  if(_token.getId() == null) {
208  _token.setId(id++);
209  }
210  fakeDb.put(_token.getId(), _token);
211  return _token;
212  }
213  });
214  when(tokenRepository.getRefreshTokenById(anyLong())).thenAnswer(new Answer<OAuth2RefreshTokenEntity>() {
215  @Override
216  public OAuth2RefreshTokenEntity answer(InvocationOnMock invocation) throws Throwable {
217  Long _id = (Long) invocation.getArguments()[0];
218  return fakeDb.get(_id);
219  }
220  });
221  when(clientRepository.getClientByClientId(anyString())).thenAnswer(new Answer<ClientDetailsEntity>() {
222  @Override
223  public ClientDetailsEntity answer(InvocationOnMock invocation) throws Throwable {
224  String _clientId = (String) invocation.getArguments()[0];
225  ClientDetailsEntity _client = mock(ClientDetailsEntity.class);
226  when(_client.getClientId()).thenReturn(_clientId);
227  return _client;
228  }
229  });
230  when(authHolderRepository.getById(isNull(Long.class))).thenAnswer(new Answer<AuthenticationHolderEntity>() {
231  Long id = 131L;
232  @Override
233  public AuthenticationHolderEntity answer(InvocationOnMock invocation) throws Throwable {
234  AuthenticationHolderEntity _auth = mock(AuthenticationHolderEntity.class);
235  when(_auth.getId()).thenReturn(id);
236  id++;
237  return _auth;
238  }
239  });
240  dataService.importData(reader);
241  //2 times for token, 2 times to update client, 2 times to update authHolder
242  verify(tokenRepository, times(6)).saveRefreshToken(capturedRefreshTokens.capture());
243 
244  List<OAuth2RefreshTokenEntity> savedRefreshTokens = new ArrayList(fakeDb.values()); //capturedRefreshTokens.getAllValues();
245  Collections.sort(savedRefreshTokens, new refreshTokenIdComparator());
246 
247  assertThat(savedRefreshTokens.size(), is(2));
248 
249  assertThat(savedRefreshTokens.get(0).getClient().getClientId(), equalTo(token1.getClient().getClientId()));
250  assertThat(savedRefreshTokens.get(0).getExpiration(), equalTo(token1.getExpiration()));
251  assertThat(savedRefreshTokens.get(0).getValue(), equalTo(token1.getValue()));
252 
253  assertThat(savedRefreshTokens.get(1).getClient().getClientId(), equalTo(token2.getClient().getClientId()));
254  assertThat(savedRefreshTokens.get(1).getExpiration(), equalTo(token2.getExpiration()));
255  assertThat(savedRefreshTokens.get(1).getValue(), equalTo(token2.getValue()));
256  }
ClientDetailsEntity getClientByClientId(String clientId)
OAuth2RefreshTokenEntity saveRefreshToken(OAuth2RefreshTokenEntity refreshToken)
OAuth2ClientRepository clientRepository
Definition: TestMITREidDataService_1_1.java:94
MITREidDataService_1_1 dataService
Definition: TestMITREidDataService_1_1.java:126
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_1.java:104
AuthenticationHolderRepository authHolderRepository
Definition: TestMITREidDataService_1_1.java:102
void importData(JsonReader reader)
Definition: MITREidDataService_1_1.java:131
ArgumentCaptor< OAuth2RefreshTokenEntity > capturedRefreshTokens
Definition: TestMITREidDataService_1_1.java:109
DateFormatter formatter
Definition: TestMITREidDataService_1_1.java:127
OAuth2RefreshTokenEntity getRefreshTokenById(Long Id)

◆ testImportSystemScopes()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_1.testImportSystemScopes ( ) throws IOException
inline
762  {
763  SystemScope scope1 = new SystemScope();
764  scope1.setId(1L);
765  scope1.setValue("scope1");
766  scope1.setDescription("Scope 1");
767  scope1.setRestricted(true);
768  scope1.setDefaultScope(false);
769  scope1.setIcon("glass");
770 
771  SystemScope scope2 = new SystemScope();
772  scope2.setId(2L);
773  scope2.setValue("scope2");
774  scope2.setDescription("Scope 2");
775  scope2.setRestricted(false);
776  scope2.setDefaultScope(false);
777  scope2.setIcon("ball");
778 
779  SystemScope scope3 = new SystemScope();
780  scope3.setId(3L);
781  scope3.setValue("scope3");
782  scope3.setDescription("Scope 3");
783  scope3.setRestricted(false);
784  scope3.setDefaultScope(true);
785  scope3.setIcon("road");
786 
787  String configJson = "{" +
788  "\"" + MITREidDataService.CLIENTS + "\": [], " +
789  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
790  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
791  "\"" + MITREidDataService.GRANTS + "\": [], " +
792  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
793  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
794  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
795  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [" +
796 
797  "{\"id\":1,\"description\":\"Scope 1\",\"icon\":\"glass\",\"value\":\"scope1\",\"allowDynReg\":false,\"defaultScope\":false}," +
798  "{\"id\":2,\"description\":\"Scope 2\",\"icon\":\"ball\",\"value\":\"scope2\",\"allowDynReg\":true,\"defaultScope\":false}," +
799  "{\"id\":3,\"description\":\"Scope 3\",\"icon\":\"road\",\"value\":\"scope3\",\"allowDynReg\":true,\"defaultScope\":true}" +
800 
801  " ]" +
802  "}";
803 
804  System.err.println(configJson);
805 
806  JsonReader reader = new JsonReader(new StringReader(configJson));
807 
808  dataService.importData(reader);
809  verify(sysScopeRepository, times(3)).save(capturedScope.capture());
810 
811  List<SystemScope> savedScopes = capturedScope.getAllValues();
812 
813  assertThat(savedScopes.size(), is(3));
814  assertThat(savedScopes.get(0).getValue(), equalTo(scope1.getValue()));
815  assertThat(savedScopes.get(0).getDescription(), equalTo(scope1.getDescription()));
816  assertThat(savedScopes.get(0).getIcon(), equalTo(scope1.getIcon()));
817  assertThat(savedScopes.get(0).isDefaultScope(), equalTo(scope1.isDefaultScope()));
818  assertThat(savedScopes.get(0).isRestricted(), equalTo(scope1.isRestricted()));
819 
820  assertThat(savedScopes.get(1).getValue(), equalTo(scope2.getValue()));
821  assertThat(savedScopes.get(1).getDescription(), equalTo(scope2.getDescription()));
822  assertThat(savedScopes.get(1).getIcon(), equalTo(scope2.getIcon()));
823  assertThat(savedScopes.get(1).isDefaultScope(), equalTo(scope2.isDefaultScope()));
824  assertThat(savedScopes.get(1).isRestricted(), equalTo(scope2.isRestricted()));
825 
826  assertThat(savedScopes.get(2).getValue(), equalTo(scope3.getValue()));
827  assertThat(savedScopes.get(2).getDescription(), equalTo(scope3.getDescription()));
828  assertThat(savedScopes.get(2).getIcon(), equalTo(scope3.getIcon()));
829  assertThat(savedScopes.get(2).isDefaultScope(), equalTo(scope3.isDefaultScope()));
830  assertThat(savedScopes.get(2).isRestricted(), equalTo(scope3.isRestricted()));
831 
832  }
MITREidDataService_1_1 dataService
Definition: TestMITREidDataService_1_1.java:126
void importData(JsonReader reader)
Definition: MITREidDataService_1_1.java:131
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_1.java:106
ArgumentCaptor< SystemScope > capturedScope
Definition: TestMITREidDataService_1_1.java:123

◆ testImportWhitelistedSites()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_1.testImportWhitelistedSites ( ) throws IOException
inline
512  {
513  WhitelistedSite site1 = new WhitelistedSite();
514  site1.setId(1L);
515  site1.setClientId("foo");
516 
517  WhitelistedSite site2 = new WhitelistedSite();
518  site2.setId(2L);
519  site2.setClientId("bar");
520 
521  WhitelistedSite site3 = new WhitelistedSite();
522  site3.setId(3L);
523  site3.setClientId("baz");
524  //site3.setAllowedScopes(null);
525 
526  String configJson = "{" +
527  "\"" + MITREidDataService.CLIENTS + "\": [], " +
528  "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
529  "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
530  "\"" + MITREidDataService.GRANTS + "\": [], " +
531  "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
532  "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
533  "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
534  "\"" + MITREidDataService.WHITELISTEDSITES + "\": [" +
535 
536  "{\"id\":1,\"clientId\":\"foo\"}," +
537  "{\"id\":2,\"clientId\":\"bar\"}," +
538  "{\"id\":3,\"clientId\":\"baz\"}" +
539 
540  " ]" +
541  "}";
542 
543  System.err.println(configJson);
544 
545  JsonReader reader = new JsonReader(new StringReader(configJson));
546 
547  final Map<Long, WhitelistedSite> fakeDb = new HashMap<>();
548  when(wlSiteRepository.save(isA(WhitelistedSite.class))).thenAnswer(new Answer<WhitelistedSite>() {
549  Long id = 333L;
550  @Override
551  public WhitelistedSite answer(InvocationOnMock invocation) throws Throwable {
552  WhitelistedSite _site = (WhitelistedSite) invocation.getArguments()[0];
553  if(_site.getId() == null) {
554  _site.setId(id++);
555  }
556  fakeDb.put(_site.getId(), _site);
557  return _site;
558  }
559  });
560  when(wlSiteRepository.getById(anyLong())).thenAnswer(new Answer<WhitelistedSite>() {
561  @Override
562  public WhitelistedSite answer(InvocationOnMock invocation) throws Throwable {
563  Long _id = (Long) invocation.getArguments()[0];
564  return fakeDb.get(_id);
565  }
566  });
567 
568  dataService.importData(reader);
569  verify(wlSiteRepository, times(3)).save(capturedWhitelistedSites.capture());
570 
571  List<WhitelistedSite> savedSites = capturedWhitelistedSites.getAllValues();
572 
573  assertThat(savedSites.size(), is(3));
574 
575  assertThat(savedSites.get(0).getClientId(), equalTo(site1.getClientId()));
576  assertThat(savedSites.get(1).getClientId(), equalTo(site2.getClientId()));
577  assertThat(savedSites.get(2).getClientId(), equalTo(site3.getClientId()));
578  }
MITREidDataService_1_1 dataService
Definition: TestMITREidDataService_1_1.java:126
WhitelistedSiteRepository wlSiteRepository
Definition: TestMITREidDataService_1_1.java:98
WhitelistedSite save(WhitelistedSite whiteListedSite)
void importData(JsonReader reader)
Definition: MITREidDataService_1_1.java:131
ArgumentCaptor< WhitelistedSite > capturedWhitelistedSites
Definition: TestMITREidDataService_1_1.java:117

メンバ詳解

◆ approvedSiteRepository

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

◆ authHolderRepository

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

◆ blSiteRepository

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

◆ capturedAccessTokens

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

◆ capturedApprovedSites

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

◆ capturedAuthHolders

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

◆ capturedBlacklistedSites

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

◆ capturedClients

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

◆ capturedRefreshTokens

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

◆ capturedScope

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

◆ capturedWhitelistedSites

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

◆ clientRepository

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

◆ dataService

MITREidDataService_1_1 org.mitre.openid.connect.service.impl.TestMITREidDataService_1_1.dataService
private

◆ formatter

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

◆ sysScopeRepository

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

◆ tokenRepository

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

◆ wlSiteRepository

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

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