mitreid-connect
クラス | 公開メンバ関数 | 非公開変数類 | 全メンバ一覧
org.mitre.openid.connect.service.impl.TestMITREidDataService_1_0 クラス
org.mitre.openid.connect.service.impl.TestMITREidDataService_1_0 連携図
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_0 dataService
 
DateFormatter formatter
 

詳解

関数詳解

◆ prepare()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_0.prepare ( )
inline
132  {
133  formatter = new DateFormatter();
134  formatter.setIso(ISO.DATE_TIME);
136  }
DateFormatter formatter
Definition: TestMITREidDataService_1_0.java:129
AuthenticationHolderRepository authHolderRepository
Definition: TestMITREidDataService_1_0.java:103
ApprovedSiteRepository approvedSiteRepository
Definition: TestMITREidDataService_1_0.java:97
OAuth2TokenRepository tokenRepository
Definition: TestMITREidDataService_1_0.java:105
SystemScopeRepository sysScopeRepository
Definition: TestMITREidDataService_1_0.java:107
OAuth2ClientRepository clientRepository
Definition: TestMITREidDataService_1_0.java:95
WhitelistedSiteRepository wlSiteRepository
Definition: TestMITREidDataService_1_0.java:99
BlacklistedSiteRepository blSiteRepository
Definition: TestMITREidDataService_1_0.java:101

◆ testExportDisabled()

void org.mitre.openid.connect.service.impl.TestMITREidDataService_1_0.testExportDisabled ( ) throws IOException
inline
965  {
966  JsonWriter writer = new JsonWriter(new StringWriter());
967  dataService.exportData(writer);
968  }
void exportData(JsonWriter writer)
Definition: MITREidDataService_1_0.java:121
MITREidDataService_1_0 dataService
Definition: TestMITREidDataService_1_0.java:127

◆ testFixRefreshTokenAuthHolderReferencesOnImport()

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

◆ testImportAccessTokens()

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

◆ testImportAuthenticationHolders()

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

◆ testImportBlacklistedSites()

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

◆ testImportClients()

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

◆ testImportGrants()

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

◆ testImportRefreshTokens()

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

◆ testImportSystemScopes()

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

◆ testImportWhitelistedSites()

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

メンバ詳解

◆ approvedSiteRepository

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

◆ authHolderRepository

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

◆ blSiteRepository

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

◆ capturedAccessTokens

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

◆ capturedApprovedSites

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

◆ capturedAuthHolders

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

◆ capturedBlacklistedSites

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

◆ capturedClients

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

◆ capturedRefreshTokens

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

◆ capturedScope

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

◆ capturedWhitelistedSites

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

◆ clientRepository

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

◆ dataService

MITREidDataService_1_0 org.mitre.openid.connect.service.impl.TestMITREidDataService_1_0.dataService
private

◆ formatter

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

◆ sysScopeRepository

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

◆ tokenRepository

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

◆ wlSiteRepository

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

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