838 String expiration1 =
"2014-09-10T22:49:44.090+0000";
839 Date expirationDate1 =
formatter.parse(expiration1, Locale.ENGLISH);
841 ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
842 when(mockedClient1.getClientId()).thenReturn(
"mocked_client_1");
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);
850 AuthenticationHolderEntity holder1 =
new AuthenticationHolderEntity();
852 holder1.setAuthentication(auth1);
854 OAuth2RefreshTokenEntity token1 =
new OAuth2RefreshTokenEntity();
856 token1.setClient(mockedClient1);
857 token1.setExpiration(expirationDate1);
858 token1.setJwt(JWTParser.parse(
"eyJhbGciOiJub25lIn0.eyJqdGkiOiJmOTg4OWQyOS0xMTk1LTQ4ODEtODgwZC1lZjVlYzAwY2Y4NDIifQ."));
859 token1.setAuthenticationHolder(holder1);
861 String expiration2 =
"2015-01-07T18:31:50.079+0000";
862 Date expirationDate2 =
formatter.parse(expiration2, Locale.ENGLISH);
864 ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
865 when(mockedClient2.getClientId()).thenReturn(
"mocked_client_2");
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);
873 AuthenticationHolderEntity holder2 =
new AuthenticationHolderEntity();
875 holder2.setAuthentication(auth2);
877 OAuth2RefreshTokenEntity token2 =
new OAuth2RefreshTokenEntity();
879 token2.setClient(mockedClient2);
880 token2.setExpiration(expirationDate2);
881 token2.setJwt(JWTParser.parse(
"eyJhbGciOiJub25lIn0.eyJqdGkiOiJlYmEyYjc3My0xNjAzLTRmNDAtOWQ3MS1hMGIxZDg1OWE2MDAifQ."));
882 token2.setAuthenticationHolder(holder2);
884 String configJson =
"{" +
885 "\"" + MITREidDataService.SYSTEMSCOPES +
"\": [], " +
886 "\"" + MITREidDataService.ACCESSTOKENS +
"\": [], " +
887 "\"" + MITREidDataService.CLIENTS +
"\": [], " +
888 "\"" + MITREidDataService.GRANTS +
"\": [], " +
889 "\"" + MITREidDataService.WHITELISTEDSITES +
"\": [], " +
890 "\"" + MITREidDataService.BLACKLISTEDSITES +
"\": [], " +
891 "\"" + MITREidDataService.AUTHENTICATIONHOLDERS +
"\": [" +
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}}" +
898 "\"" + MITREidDataService.REFRESHTOKENS +
"\": [" +
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.\"}" +
909 JsonReader reader =
new JsonReader(
new StringReader(configJson));
910 final Map<Long, OAuth2RefreshTokenEntity> fakeRefreshTokenTable =
new HashMap<>();
911 final Map<Long, AuthenticationHolderEntity> fakeAuthHolderTable =
new HashMap<>();
915 public OAuth2RefreshTokenEntity answer(InvocationOnMock invocation)
throws Throwable {
916 OAuth2RefreshTokenEntity _token = (OAuth2RefreshTokenEntity) invocation.getArguments()[0];
917 if(_token.getId() == null) {
920 fakeRefreshTokenTable.put(_token.getId(), _token);
926 public OAuth2RefreshTokenEntity answer(InvocationOnMock invocation)
throws Throwable {
927 Long _id = (Long) invocation.getArguments()[0];
928 return fakeRefreshTokenTable.get(_id);
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);
940 when(
authHolderRepository.
save(isA(AuthenticationHolderEntity.class))).thenAnswer(
new Answer<AuthenticationHolderEntity>() {
943 public AuthenticationHolderEntity answer(InvocationOnMock invocation)
throws Throwable {
944 AuthenticationHolderEntity _holder = (AuthenticationHolderEntity) invocation.getArguments()[0];
945 if(_holder.getId() == null) {
948 fakeAuthHolderTable.put(_holder.getId(), _holder);
954 public AuthenticationHolderEntity answer(InvocationOnMock invocation)
throws Throwable {
955 Long _id = (Long) invocation.getArguments()[0];
956 return fakeAuthHolderTable.get(_id);
961 List<OAuth2RefreshTokenEntity> savedRefreshTokens =
new ArrayList(fakeRefreshTokenTable.values());
962 Collections.sort(savedRefreshTokens,
new refreshTokenIdComparator());
964 assertThat(savedRefreshTokens.get(0).getAuthenticationHolder().getId(), equalTo(356L));
965 assertThat(savedRefreshTokens.get(1).getAuthenticationHolder().getId(), equalTo(357L));
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)
AuthenticationHolderEntity getById(Long id)
OAuth2RefreshTokenEntity getRefreshTokenById(Long Id)