834 String expiration1 =
"2014-09-10T22:49:44.090+0000";
835 Date expirationDate1 =
formatter.parse(expiration1, Locale.ENGLISH);
837 ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
838 when(mockedClient1.getClientId()).thenReturn(
"mocked_client_1");
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);
846 AuthenticationHolderEntity holder1 =
new AuthenticationHolderEntity();
848 holder1.setAuthentication(auth1);
850 OAuth2RefreshTokenEntity token1 =
new OAuth2RefreshTokenEntity();
852 token1.setClient(mockedClient1);
853 token1.setExpiration(expirationDate1);
854 token1.setJwt(JWTParser.parse(
"eyJhbGciOiJub25lIn0.eyJqdGkiOiJmOTg4OWQyOS0xMTk1LTQ4ODEtODgwZC1lZjVlYzAwY2Y4NDIifQ."));
855 token1.setAuthenticationHolder(holder1);
857 String expiration2 =
"2015-01-07T18:31:50.079+0000";
858 Date expirationDate2 =
formatter.parse(expiration2, Locale.ENGLISH);
860 ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
861 when(mockedClient2.getClientId()).thenReturn(
"mocked_client_2");
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);
869 AuthenticationHolderEntity holder2 =
new AuthenticationHolderEntity();
871 holder2.setAuthentication(auth2);
873 OAuth2RefreshTokenEntity token2 =
new OAuth2RefreshTokenEntity();
875 token2.setClient(mockedClient2);
876 token2.setExpiration(expirationDate2);
877 token2.setJwt(JWTParser.parse(
"eyJhbGciOiJub25lIn0.eyJqdGkiOiJlYmEyYjc3My0xNjAzLTRmNDAtOWQ3MS1hMGIxZDg1OWE2MDAifQ."));
878 token2.setAuthenticationHolder(holder2);
880 String configJson =
"{" +
881 "\"" + MITREidDataService.SYSTEMSCOPES +
"\": [], " +
882 "\"" + MITREidDataService.ACCESSTOKENS +
"\": [], " +
883 "\"" + MITREidDataService.CLIENTS +
"\": [], " +
884 "\"" + MITREidDataService.GRANTS +
"\": [], " +
885 "\"" + MITREidDataService.WHITELISTEDSITES +
"\": [], " +
886 "\"" + MITREidDataService.BLACKLISTEDSITES +
"\": [], " +
887 "\"" + MITREidDataService.AUTHENTICATIONHOLDERS +
"\": [" +
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}}" +
894 "\"" + MITREidDataService.REFRESHTOKENS +
"\": [" +
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.\"}" +
903 System.err.println(configJson);
905 JsonReader reader =
new JsonReader(
new StringReader(configJson));
906 final Map<Long, OAuth2RefreshTokenEntity> fakeRefreshTokenTable =
new HashMap<>();
907 final Map<Long, AuthenticationHolderEntity> fakeAuthHolderTable =
new HashMap<>();
911 public OAuth2RefreshTokenEntity answer(InvocationOnMock invocation)
throws Throwable {
912 OAuth2RefreshTokenEntity _token = (OAuth2RefreshTokenEntity) invocation.getArguments()[0];
913 if(_token.getId() == null) {
916 fakeRefreshTokenTable.put(_token.getId(), _token);
922 public OAuth2RefreshTokenEntity answer(InvocationOnMock invocation)
throws Throwable {
923 Long _id = (Long) invocation.getArguments()[0];
924 return fakeRefreshTokenTable.get(_id);
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);
936 when(
authHolderRepository.
save(isA(AuthenticationHolderEntity.class))).thenAnswer(
new Answer<AuthenticationHolderEntity>() {
939 public AuthenticationHolderEntity answer(InvocationOnMock invocation)
throws Throwable {
940 AuthenticationHolderEntity _holder = (AuthenticationHolderEntity) invocation.getArguments()[0];
941 if(_holder.getId() == null) {
944 fakeAuthHolderTable.put(_holder.getId(), _holder);
950 public AuthenticationHolderEntity answer(InvocationOnMock invocation)
throws Throwable {
951 Long _id = (Long) invocation.getArguments()[0];
952 return fakeAuthHolderTable.get(_id);
957 List<OAuth2RefreshTokenEntity> savedRefreshTokens =
new ArrayList(fakeRefreshTokenTable.values());
958 Collections.sort(savedRefreshTokens,
new refreshTokenIdComparator());
960 assertThat(savedRefreshTokens.get(0).getAuthenticationHolder().getId(), equalTo(356L));
961 assertThat(savedRefreshTokens.get(1).getAuthenticationHolder().getId(), equalTo(357L));
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)
AuthenticationHolderEntity getById(Long id)
OAuth2ClientRepository clientRepository
Definition: TestMITREidDataService_1_0.java:95
OAuth2RefreshTokenEntity getRefreshTokenById(Long Id)