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

非公開メンバ関数

Set< String > jsonArrayToStringSet (JsonArray a)
 

非公開変数類

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

静的非公開変数類

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

詳解

関数詳解

◆ jsonArrayToStringSet()

Set<String> org.mitre.openid.connect.service.impl.TestMITREidDataService_1_2.jsonArrayToStringSet ( JsonArray  a)
inlineprivate
968  {
969  Set<String> s = new HashSet<>();
970  for (JsonElement jsonElement : a) {
971  s.add(jsonElement.getAsString());
972  }
973  return s;
974  }

◆ prepare()

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

◆ testFixRefreshTokenAuthHolderReferencesOnImport()

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

◆ testImportAccessTokens()

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

◆ testImportAuthenticationHolders()

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

◆ testImportBlacklistedSites()

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

◆ testImportClients()

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

◆ testImportGrants()

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

◆ testImportRefreshTokens()

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

◆ testImportSystemScopes()

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

◆ testImportWhitelistedSites()

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

メンバ詳解

◆ approvedSiteRepository

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

◆ authHolderRepository

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

◆ blSiteRepository

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

◆ capturedAccessTokens

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

◆ capturedApprovedSites

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

◆ capturedAuthHolders

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

◆ capturedBlacklistedSites

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

◆ capturedClients

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

◆ capturedRefreshTokens

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

◆ capturedScope

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

◆ capturedWhitelistedSites

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

◆ clientRepository

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

◆ dataService

MITREidDataService_1_2 org.mitre.openid.connect.service.impl.TestMITREidDataService_1_2.dataService
private

◆ formatter

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

◆ logger

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

◆ sysScopeRepository

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

◆ tokenRepository

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

◆ wlSiteRepository

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

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