Commit bfc3e75fc9707aacee3970252ae0b3ae8fd928d4

Authored by vzikratyi
1 parent d5cfccc1

Unpacked Domain objects from ClientParams

... ... @@ -16,21 +16,17 @@
16 16 package org.thingsboard.server.controller;
17 17
18 18 import lombok.extern.slf4j.Slf4j;
19   -import org.springframework.beans.factory.annotation.Autowired;
20 19 import org.springframework.http.HttpStatus;
21 20 import org.springframework.security.access.prepost.PreAuthorize;
22 21 import org.springframework.web.bind.annotation.*;
23   -import org.thingsboard.server.common.data.Dashboard;
24 22 import org.thingsboard.server.common.data.EntityType;
25 23 import org.thingsboard.server.common.data.audit.ActionType;
26 24 import org.thingsboard.server.common.data.exception.ThingsboardException;
27   -import org.thingsboard.server.common.data.id.DashboardId;
28 25 import org.thingsboard.server.common.data.id.OAuth2ClientRegistrationId;
29 26 import org.thingsboard.server.common.data.id.OAuth2ClientRegistrationTemplateId;
30 27 import org.thingsboard.server.common.data.id.TenantId;
31 28 import org.thingsboard.server.common.data.oauth2.*;
32 29 import org.thingsboard.server.common.data.security.Authority;
33   -import org.thingsboard.server.dao.oauth2.OAuth2Service;
34 30 import org.thingsboard.server.queue.util.TbCoreComponent;
35 31 import org.thingsboard.server.service.security.permission.Operation;
36 32 import org.thingsboard.server.service.security.permission.Resource;
... ... @@ -61,14 +57,14 @@ public class OAuth2Controller extends BaseController {
61 57 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
62 58 @RequestMapping(value = "/oauth2/config", method = RequestMethod.GET, produces = "application/json")
63 59 @ResponseBody
64   - public OAuth2ClientsParams getCurrentClientsParams() throws ThingsboardException {
  60 + public List<OAuth2ClientsDomainParams> getCurrentClientsParams() throws ThingsboardException {
65 61 try {
66 62 Authority authority = getCurrentUser().getAuthority();
67 63 checkOAuth2ConfigPermissions(Operation.READ);
68 64 if (Authority.SYS_ADMIN.equals(authority)) {
69   - return oAuth2Service.findClientsParamsByTenantId(TenantId.SYS_TENANT_ID);
  65 + return oAuth2Service.findDomainsParamsByTenantId(TenantId.SYS_TENANT_ID);
70 66 } else if (Authority.TENANT_ADMIN.equals(authority)) {
71   - return oAuth2Service.findClientsParamsByTenantId(getCurrentUser().getTenantId());
  67 + return oAuth2Service.findDomainsParamsByTenantId(getCurrentUser().getTenantId());
72 68 } else {
73 69 throw new IllegalStateException("Authority " + authority + " cannot get client registrations.");
74 70 }
... ... @@ -80,7 +76,7 @@ public class OAuth2Controller extends BaseController {
80 76 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
81 77 @RequestMapping(value = "/oauth2/config", method = RequestMethod.POST)
82 78 @ResponseStatus(value = HttpStatus.OK)
83   - public OAuth2ClientsParams saveClientParams(@RequestBody OAuth2ClientsParams clientsParams) throws ThingsboardException {
  79 + public List<OAuth2ClientsDomainParams> saveClientParams(@RequestBody List<OAuth2ClientsDomainParams> domainsParams) throws ThingsboardException {
84 80 try {
85 81 TenantId tenantId;
86 82 Authority authority = getCurrentUser().getAuthority();
... ... @@ -91,13 +87,13 @@ public class OAuth2Controller extends BaseController {
91 87 } else {
92 88 throw new IllegalStateException("Authority " + authority + " cannot save client registrations.");
93 89 }
94   - List<ClientRegistrationDto> clientRegistrationDtos = clientsParams.getOAuth2DomainDtos().stream()
  90 + List<ClientRegistrationDto> clientRegistrationDtos = domainsParams.stream()
95 91 .flatMap(domainParams -> domainParams.getClientRegistrations().stream())
96 92 .collect(Collectors.toList());
97 93 for (ClientRegistrationDto clientRegistrationDto : clientRegistrationDtos) {
98 94 checkEntity(clientRegistrationDto.getId(), () -> tenantId, Resource.OAUTH2_CONFIGURATION);
99 95 }
100   - return oAuth2Service.saveClientsParams(tenantId, clientsParams);
  96 + return oAuth2Service.saveDomainsParams(tenantId, domainsParams);
101 97 } catch (Exception e) {
102 98 throw handleException(e);
103 99 }
... ...
... ... @@ -19,7 +19,7 @@ import org.thingsboard.server.common.data.id.OAuth2ClientRegistrationId;
19 19 import org.thingsboard.server.common.data.id.TenantId;
20 20 import org.thingsboard.server.common.data.oauth2.OAuth2ClientInfo;
21 21 import org.thingsboard.server.common.data.oauth2.OAuth2ClientRegistration;
22   -import org.thingsboard.server.common.data.oauth2.OAuth2ClientsParams;
  22 +import org.thingsboard.server.common.data.oauth2.OAuth2ClientsDomainParams;
23 23
24 24 import java.util.List;
25 25 import java.util.UUID;
... ... @@ -27,9 +27,9 @@ import java.util.UUID;
27 27 public interface OAuth2Service {
28 28 List<OAuth2ClientInfo> getOAuth2Clients(String domainName);
29 29
30   - OAuth2ClientsParams saveClientsParams(TenantId tenantId, OAuth2ClientsParams clientsParams);
  30 + List<OAuth2ClientsDomainParams> saveDomainsParams(TenantId tenantId, List<OAuth2ClientsDomainParams> domainsParams);
31 31
32   - OAuth2ClientsParams findClientsParamsByTenantId(TenantId tenantId);
  32 + List<OAuth2ClientsDomainParams> findDomainsParamsByTenantId(TenantId tenantId);
33 33
34 34 OAuth2ClientRegistration findClientRegistration(UUID id);
35 35
... ...
1   -/**
2   - * Copyright © 2016-2020 The Thingsboard Authors
3   - *
4   - * Licensed under the Apache License, Version 2.0 (the "License");
5   - * you may not use this file except in compliance with the License.
6   - * You may obtain a copy of the License at
7   - *
8   - * http://www.apache.org/licenses/LICENSE-2.0
9   - *
10   - * Unless required by applicable law or agreed to in writing, software
11   - * distributed under the License is distributed on an "AS IS" BASIS,
12   - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   - * See the License for the specific language governing permissions and
14   - * limitations under the License.
15   - */
16   -package org.thingsboard.server.common.data.oauth2;
17   -
18   -import lombok.*;
19   -import org.thingsboard.server.common.data.id.TenantId;
20   -
21   -import java.util.Collection;
22   -import java.util.List;
23   -import java.util.Objects;
24   -
25   -@EqualsAndHashCode
26   -@Data
27   -@ToString
28   -@Builder(toBuilder = true)
29   -@NoArgsConstructor
30   -@AllArgsConstructor
31   -public class OAuth2ClientsParams {
32   - private List<OAuth2ClientsDomainParams> oAuth2DomainDtos;
33   -}
\ No newline at end of file
... ... @@ -66,21 +66,21 @@ public class OAuth2ServiceImpl extends AbstractEntityService implements OAuth2Se
66 66
67 67 @Override
68 68 @Transactional
69   - public OAuth2ClientsParams saveClientsParams(TenantId tenantId, OAuth2ClientsParams clientsParams) {
70   - log.trace("Executing saveClientsParams [{}] [{}]", tenantId, clientsParams);
71   - clientParamsValidator.accept(tenantId, clientsParams);
72   - List<OAuth2ClientRegistration> inputClientRegistrations = OAuth2Utils.toClientRegistrations(tenantId, clientsParams);
  69 + public List<OAuth2ClientsDomainParams> saveDomainsParams(TenantId tenantId, List<OAuth2ClientsDomainParams> domainsParams) {
  70 + log.trace("Executing saveDomainsParams [{}] [{}]", tenantId, domainsParams);
  71 + clientParamsValidator.accept(tenantId, domainsParams);
  72 + List<OAuth2ClientRegistration> inputClientRegistrations = OAuth2Utils.toClientRegistrations(tenantId, domainsParams);
73 73 List<OAuth2ClientRegistration> savedClientRegistrations = inputClientRegistrations.stream()
74 74 .map(clientRegistration -> clientRegistrationDao.save(clientRegistration.getTenantId(), clientRegistration))
75 75 .collect(Collectors.toList());
76   - return OAuth2Utils.toOAuth2ClientsParams(savedClientRegistrations);
  76 + return OAuth2Utils.toDomainsParams(savedClientRegistrations);
77 77 }
78 78
79 79 @Override
80   - public OAuth2ClientsParams findClientsParamsByTenantId(TenantId tenantId) {
81   - log.trace("Executing findClientsParamsByTenantId [{}]", tenantId);
  80 + public List<OAuth2ClientsDomainParams> findDomainsParamsByTenantId(TenantId tenantId) {
  81 + log.trace("Executing findDomainsParamsByTenantId [{}]", tenantId);
82 82 validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
83   - return OAuth2Utils.toOAuth2ClientsParams(clientRegistrationDao.findByTenantId(tenantId.getId()));
  83 + return OAuth2Utils.toDomainsParams(clientRegistrationDao.findByTenantId(tenantId.getId()));
84 84 }
85 85
86 86 @Override
... ... @@ -135,12 +135,11 @@ public class OAuth2ServiceImpl extends AbstractEntityService implements OAuth2Se
135 135 }
136 136 }
137 137
138   - private final BiConsumer<TenantId, OAuth2ClientsParams> clientParamsValidator = (tenantId, clientsParams) -> {
139   - if (clientsParams == null || clientsParams.getOAuth2DomainDtos() == null
140   - || clientsParams.getOAuth2DomainDtos().isEmpty()) {
  138 + private final BiConsumer<TenantId, List<OAuth2ClientsDomainParams>> clientParamsValidator = (tenantId, domainsParams) -> {
  139 + if (domainsParams == null || domainsParams.isEmpty()) {
141 140 throw new DataValidationException("Domain params should be specified!");
142 141 }
143   - for (OAuth2ClientsDomainParams domainParams : clientsParams.getOAuth2DomainDtos()) {
  142 + for (OAuth2ClientsDomainParams domainParams : domainsParams) {
144 143 if (StringUtils.isEmpty(domainParams.getDomainName())) {
145 144 throw new DataValidationException("Domain name should be specified!");
146 145 }
... ...
... ... @@ -38,8 +38,8 @@ public class OAuth2Utils {
38 38 return client;
39 39 }
40 40
41   - public static List<OAuth2ClientRegistration> toClientRegistrations(TenantId tenantId, OAuth2ClientsParams clientsParams) {
42   - return clientsParams.getOAuth2DomainDtos().stream()
  41 + public static List<OAuth2ClientRegistration> toClientRegistrations(TenantId tenantId, List<OAuth2ClientsDomainParams> domainsParams) {
  42 + return domainsParams.stream()
43 43 .flatMap(domainParams -> domainParams.getClientRegistrations().stream()
44 44 .map(clientRegistrationDto -> OAuth2Utils.toClientRegistration(tenantId, domainParams.getDomainName(),
45 45 domainParams.getRedirectUriTemplate(), clientRegistrationDto)
... ... @@ -47,7 +47,7 @@ public class OAuth2Utils {
47 47 .collect(Collectors.toList());
48 48 }
49 49
50   - public static OAuth2ClientsParams toOAuth2ClientsParams(List<OAuth2ClientRegistration> clientRegistrations) {
  50 + public static List<OAuth2ClientsDomainParams> toDomainsParams(List<OAuth2ClientRegistration> clientRegistrations) {
51 51 Map<String, OAuth2ClientsDomainParams> domainParamsMap = new HashMap<>();
52 52 for (OAuth2ClientRegistration clientRegistration : clientRegistrations) {
53 53 String domainName = clientRegistration.getDomainName();
... ... @@ -57,7 +57,7 @@ public class OAuth2Utils {
57 57 domainParams.getClientRegistrations()
58 58 .add(toClientRegistrationDto(clientRegistration));
59 59 }
60   - return new OAuth2ClientsParams(new ArrayList<>(domainParamsMap.values()));
  60 + return new ArrayList<>(domainParamsMap.values());
61 61 }
62 62
63 63 public static ClientRegistrationDto toClientRegistrationDto(OAuth2ClientRegistration oAuth2ClientRegistration) {
... ...
... ... @@ -15,27 +15,21 @@
15 15 */
16 16 package org.thingsboard.server.dao.service;
17 17
18   -import org.apache.commons.lang3.tuple.Pair;
19 18 import org.junit.After;
20 19 import org.junit.Assert;
21 20 import org.junit.Before;
22 21 import org.junit.Test;
23 22 import org.springframework.beans.factory.annotation.Autowired;
24   -import org.thingsboard.server.common.data.DataConstants;
25 23 import org.thingsboard.server.common.data.Tenant;
26   -import org.thingsboard.server.common.data.id.OAuth2ClientRegistrationId;
27 24 import org.thingsboard.server.common.data.id.TenantId;
28 25 import org.thingsboard.server.common.data.oauth2.*;
29 26 import org.thingsboard.server.dao.attributes.AttributesService;
30   -import org.thingsboard.server.dao.exception.DataValidationException;
31 27 import org.thingsboard.server.dao.oauth2.OAuth2Service;
32 28 import org.thingsboard.server.dao.oauth2.OAuth2Utils;
33 29
34   -import javax.transaction.Transactional;
35 30 import java.io.IOException;
36 31 import java.util.*;
37 32 import java.util.stream.Collectors;
38   -import java.util.stream.Stream;
39 33
40 34 import static org.thingsboard.server.dao.oauth2.OAuth2Utils.ALLOW_OAUTH2_CONFIGURATION;
41 35 import static org.thingsboard.server.dao.oauth2.OAuth2Utils.toClientRegistrations;
... ... @@ -91,10 +85,10 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
91 85 @Test
92 86 public void testCreateNewSystemParams() {
93 87 OAuth2ClientRegistration clientRegistration = validClientRegistration(TenantId.SYS_TENANT_ID);
94   - OAuth2ClientsParams savedClientsParams = oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(clientRegistration)));
95   - Assert.assertNotNull(savedClientsParams);
  88 + List<OAuth2ClientsDomainParams> savedDomainsParams = oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toDomainsParams(Collections.singletonList(clientRegistration)));
  89 + Assert.assertNotNull(savedDomainsParams);
96 90
97   - List<OAuth2ClientRegistration> savedClientRegistrations = OAuth2Utils.toClientRegistrations(TenantId.SYS_TENANT_ID, savedClientsParams);
  91 + List<OAuth2ClientRegistration> savedClientRegistrations = OAuth2Utils.toClientRegistrations(TenantId.SYS_TENANT_ID, savedDomainsParams);
98 92 Assert.assertEquals(1, savedClientRegistrations.size());
99 93
100 94 OAuth2ClientRegistration savedClientRegistration = savedClientRegistrations.get(0);
... ... @@ -107,13 +101,13 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
107 101 @Test
108 102 public void testFindSystemParamsByTenant() {
109 103 OAuth2ClientRegistration clientRegistration = validClientRegistration(TenantId.SYS_TENANT_ID);
110   - oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(clientRegistration)));
  104 + oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toDomainsParams(Collections.singletonList(clientRegistration)));
111 105
112   - OAuth2ClientsParams foundClientsParams = oAuth2Service.findClientsParamsByTenantId(TenantId.SYS_TENANT_ID);
113   - Assert.assertEquals(1, foundClientsParams.getOAuth2DomainDtos().size());
  106 + List<OAuth2ClientsDomainParams> foundDomainsParams = oAuth2Service.findDomainsParamsByTenantId(TenantId.SYS_TENANT_ID);
  107 + Assert.assertEquals(1, foundDomainsParams.size());
114 108 Assert.assertEquals(1, oAuth2Service.findAllClientRegistrations().size());
115 109
116   - List<OAuth2ClientRegistration> foundClientRegistrations = OAuth2Utils.toClientRegistrations(TenantId.SYS_TENANT_ID, foundClientsParams);
  110 + List<OAuth2ClientRegistration> foundClientRegistrations = OAuth2Utils.toClientRegistrations(TenantId.SYS_TENANT_ID, foundDomainsParams);
117 111 OAuth2ClientRegistration foundClientRegistration = foundClientRegistrations.get(0);
118 112 Assert.assertNotNull(foundClientRegistration);
119 113 clientRegistration.setId(foundClientRegistration.getId());
... ... @@ -124,10 +118,10 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
124 118 @Test
125 119 public void testCreateNewTenantParams() {
126 120 OAuth2ClientRegistration clientRegistration = validClientRegistration(tenantId);
127   - OAuth2ClientsParams savedClientsParams = oAuth2Service.saveClientsParams(tenantId, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(clientRegistration)));
128   - Assert.assertNotNull(savedClientsParams);
  121 + List<OAuth2ClientsDomainParams> savedDomainsParams = oAuth2Service.saveDomainsParams(tenantId, OAuth2Utils.toDomainsParams(Collections.singletonList(clientRegistration)));
  122 + Assert.assertNotNull(savedDomainsParams);
129 123
130   - List<OAuth2ClientRegistration> savedClientRegistrations = OAuth2Utils.toClientRegistrations(tenantId, savedClientsParams);
  124 + List<OAuth2ClientRegistration> savedClientRegistrations = OAuth2Utils.toClientRegistrations(tenantId, savedDomainsParams);
131 125 Assert.assertEquals(1, savedClientRegistrations.size());
132 126
133 127 OAuth2ClientRegistration savedClientRegistration = savedClientRegistrations.get(0);
... ... @@ -142,13 +136,13 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
142 136 @Test
143 137 public void testFindTenantParams() {
144 138 OAuth2ClientRegistration clientRegistration = validClientRegistration(tenantId);
145   - oAuth2Service.saveClientsParams(tenantId, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(clientRegistration)));
  139 + oAuth2Service.saveDomainsParams(tenantId, OAuth2Utils.toDomainsParams(Collections.singletonList(clientRegistration)));
146 140
147   - OAuth2ClientsParams foundClientsParams = oAuth2Service.findClientsParamsByTenantId(tenantId);
148   - Assert.assertEquals(1, foundClientsParams.getOAuth2DomainDtos().size());
  141 + List<OAuth2ClientsDomainParams> foundDomainsParams = oAuth2Service.findDomainsParamsByTenantId(tenantId);
  142 + Assert.assertEquals(1, foundDomainsParams.size());
149 143 Assert.assertEquals(1, oAuth2Service.findAllClientRegistrations().size());
150 144
151   - List<OAuth2ClientRegistration> foundClientRegistrations = OAuth2Utils.toClientRegistrations(tenantId, foundClientsParams);
  145 + List<OAuth2ClientRegistration> foundClientRegistrations = OAuth2Utils.toClientRegistrations(tenantId, foundDomainsParams);
152 146 OAuth2ClientRegistration foundClientRegistration = foundClientRegistrations.get(0);
153 147
154 148 Assert.assertNotNull(foundClientRegistration);
... ... @@ -162,19 +156,19 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
162 156 OAuth2ClientRegistration tenantClientRegistration = validClientRegistration(tenantId);
163 157 OAuth2ClientRegistration sysAdminClientRegistration = validClientRegistration(TenantId.SYS_TENANT_ID);
164 158
165   - OAuth2ClientsParams savedTenantClientsParams = oAuth2Service.saveClientsParams(tenantId,
166   - OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(tenantClientRegistration)));
167   - OAuth2ClientsParams savedSysAdminClientsParams = oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID,
168   - OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(sysAdminClientRegistration)));
  159 + List<OAuth2ClientsDomainParams> savedTenantDomainsParams = oAuth2Service.saveDomainsParams(tenantId,
  160 + OAuth2Utils.toDomainsParams(Collections.singletonList(tenantClientRegistration)));
  161 + List<OAuth2ClientsDomainParams> savedSysAdminDomainsParams = oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID,
  162 + OAuth2Utils.toDomainsParams(Collections.singletonList(sysAdminClientRegistration)));
169 163
170 164 Assert.assertEquals(2, oAuth2Service.findAllClientRegistrations().size());
171 165
172   - Assert.assertEquals(savedTenantClientsParams, oAuth2Service.findClientsParamsByTenantId(tenantId));
173   - Assert.assertEquals(savedSysAdminClientsParams, oAuth2Service.findClientsParamsByTenantId(TenantId.SYS_TENANT_ID));
  166 + Assert.assertEquals(savedTenantDomainsParams, oAuth2Service.findDomainsParamsByTenantId(tenantId));
  167 + Assert.assertEquals(savedSysAdminDomainsParams, oAuth2Service.findDomainsParamsByTenantId(TenantId.SYS_TENANT_ID));
174 168
175   - OAuth2ClientRegistration savedTenantClientRegistration = toClientRegistrations(tenantId, savedTenantClientsParams).get(0);
  169 + OAuth2ClientRegistration savedTenantClientRegistration = toClientRegistrations(tenantId, savedTenantDomainsParams).get(0);
176 170 Assert.assertEquals(savedTenantClientRegistration, oAuth2Service.findClientRegistration(savedTenantClientRegistration.getUuidId()));
177   - OAuth2ClientRegistration savedSysAdminClientRegistration = toClientRegistrations(TenantId.SYS_TENANT_ID, savedSysAdminClientsParams).get(0);
  171 + OAuth2ClientRegistration savedSysAdminClientRegistration = toClientRegistrations(TenantId.SYS_TENANT_ID, savedSysAdminDomainsParams).get(0);
178 172 Assert.assertEquals(savedSysAdminClientRegistration, oAuth2Service.findClientRegistration(savedSysAdminClientRegistration.getUuidId()));
179 173 }
180 174
... ... @@ -184,8 +178,8 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
184 178 OAuth2ClientRegistration tenantClientRegistration = validClientRegistration(tenantId, testDomainName);
185 179 OAuth2ClientRegistration sysAdminClientRegistration = validClientRegistration(TenantId.SYS_TENANT_ID, testDomainName);
186 180
187   - oAuth2Service.saveClientsParams(tenantId, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(tenantClientRegistration)));
188   - oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(sysAdminClientRegistration)));
  181 + oAuth2Service.saveDomainsParams(tenantId, OAuth2Utils.toDomainsParams(Collections.singletonList(tenantClientRegistration)));
  182 + oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toDomainsParams(Collections.singletonList(sysAdminClientRegistration)));
189 183
190 184 List<OAuth2ClientInfo> oAuth2Clients = oAuth2Service.getOAuth2Clients(testDomainName);
191 185
... ... @@ -201,8 +195,8 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
201 195 String testDomainName = "test_domain";
202 196 OAuth2ClientRegistration tenantClientRegistration = validClientRegistration(tenantId, testDomainName);
203 197 OAuth2ClientRegistration sysAdminClientRegistration = validClientRegistration(TenantId.SYS_TENANT_ID, testDomainName);
204   - oAuth2Service.saveClientsParams(tenantId, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(tenantClientRegistration)));
205   - oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(sysAdminClientRegistration)));
  198 + oAuth2Service.saveDomainsParams(tenantId, OAuth2Utils.toDomainsParams(Collections.singletonList(tenantClientRegistration)));
  199 + oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toDomainsParams(Collections.singletonList(sysAdminClientRegistration)));
206 200 List<OAuth2ClientInfo> oAuth2Clients = oAuth2Service.getOAuth2Clients("random-domain");
207 201 Assert.assertTrue(oAuth2Clients.isEmpty());
208 202 }
... ... @@ -212,13 +206,13 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
212 206 OAuth2ClientRegistration tenantClientRegistration = validClientRegistration(tenantId);
213 207 OAuth2ClientRegistration sysAdminClientRegistration = validClientRegistration(TenantId.SYS_TENANT_ID);
214 208
215   - OAuth2ClientsParams savedTenantClientsParams = oAuth2Service.saveClientsParams(tenantId,
216   - OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(tenantClientRegistration)));
217   - OAuth2ClientsParams savedSysAdminClientsParams = oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID,
218   - OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(sysAdminClientRegistration)));
  209 + List<OAuth2ClientsDomainParams> savedTenantDomainsParams = oAuth2Service.saveDomainsParams(tenantId,
  210 + OAuth2Utils.toDomainsParams(Collections.singletonList(tenantClientRegistration)));
  211 + List<OAuth2ClientsDomainParams> savedSysAdminDomainsParams = oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID,
  212 + OAuth2Utils.toDomainsParams(Collections.singletonList(sysAdminClientRegistration)));
219 213
220   - OAuth2ClientRegistration savedTenantRegistration = toClientRegistrations(tenantId, savedTenantClientsParams).get(0);
221   - OAuth2ClientRegistration savedSysAdminRegistration = toClientRegistrations(TenantId.SYS_TENANT_ID, savedSysAdminClientsParams).get(0);
  214 + OAuth2ClientRegistration savedTenantRegistration = toClientRegistrations(tenantId, savedTenantDomainsParams).get(0);
  215 + OAuth2ClientRegistration savedSysAdminRegistration = toClientRegistrations(TenantId.SYS_TENANT_ID, savedSysAdminDomainsParams).get(0);
222 216
223 217 oAuth2Service.deleteClientRegistrationById(tenantId, savedTenantRegistration.getId());
224 218 List<OAuth2ClientRegistration> foundRegistrations = oAuth2Service.findAllClientRegistrations();
... ... @@ -228,39 +222,39 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
228 222
229 223 @Test
230 224 public void testDeleteTenantOAuth2ClientRegistrations() {
231   - oAuth2Service.saveClientsParams(tenantId, OAuth2Utils.toOAuth2ClientsParams(Arrays.asList(
  225 + oAuth2Service.saveDomainsParams(tenantId, OAuth2Utils.toDomainsParams(Arrays.asList(
232 226 validClientRegistration(tenantId, "domain"),
233 227 validClientRegistration(tenantId, "domain"),
234 228 validClientRegistration(tenantId, "domain")
235 229 )));
236 230 Assert.assertEquals(3, oAuth2Service.findAllClientRegistrations().size());
237   - Assert.assertEquals(1, oAuth2Service.findClientsParamsByTenantId(tenantId).getOAuth2DomainDtos().size());
  231 + Assert.assertEquals(1, oAuth2Service.findDomainsParamsByTenantId(tenantId).size());
238 232
239 233 oAuth2Service.deleteClientRegistrationsByTenantId(tenantId);
240 234 Assert.assertEquals(0, oAuth2Service.findAllClientRegistrations().size());
241   - Assert.assertEquals(0, oAuth2Service.findClientsParamsByTenantId(tenantId).getOAuth2DomainDtos().size());
  235 + Assert.assertEquals(0, oAuth2Service.findDomainsParamsByTenantId(tenantId).size());
242 236 }
243 237
244 238 @Test
245 239 public void testDeleteTenantDomainOAuth2ClientRegistrations() {
246   - oAuth2Service.saveClientsParams(tenantId, OAuth2Utils.toOAuth2ClientsParams(Arrays.asList(
  240 + oAuth2Service.saveDomainsParams(tenantId, OAuth2Utils.toDomainsParams(Arrays.asList(
247 241 validClientRegistration(tenantId, "domain1"),
248 242 validClientRegistration(tenantId, "domain1"),
249 243 validClientRegistration(tenantId, "domain2")
250 244 )));
251   - oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toOAuth2ClientsParams(Arrays.asList(
  245 + oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toDomainsParams(Arrays.asList(
252 246 validClientRegistration(TenantId.SYS_TENANT_ID, "domain2")
253 247 )));
254 248 Assert.assertEquals(4, oAuth2Service.findAllClientRegistrations().size());
255   - OAuth2ClientsParams tenantClientsParams = oAuth2Service.findClientsParamsByTenantId(tenantId);
256   - List<OAuth2ClientRegistration> tenantClientRegistrations = toClientRegistrations(tenantId, tenantClientsParams);
257   - Assert.assertEquals(2, tenantClientsParams.getOAuth2DomainDtos().size());
  249 + List<OAuth2ClientsDomainParams> tenantDomainsParams = oAuth2Service.findDomainsParamsByTenantId(tenantId);
  250 + List<OAuth2ClientRegistration> tenantClientRegistrations = toClientRegistrations(tenantId, tenantDomainsParams);
  251 + Assert.assertEquals(2, tenantDomainsParams.size());
258 252 Assert.assertEquals(3, tenantClientRegistrations.size());
259 253
260 254 oAuth2Service.deleteClientRegistrationsByDomain(tenantId, "domain1");
261 255 Assert.assertEquals(2, oAuth2Service.findAllClientRegistrations().size());
262   - Assert.assertEquals(1, oAuth2Service.findClientsParamsByTenantId(tenantId).getOAuth2DomainDtos().size());
263   - Assert.assertEquals(1, toClientRegistrations(tenantId, oAuth2Service.findClientsParamsByTenantId(tenantId)).size());
  256 + Assert.assertEquals(1, oAuth2Service.findDomainsParamsByTenantId(tenantId).size());
  257 + Assert.assertEquals(1, toClientRegistrations(tenantId, oAuth2Service.findDomainsParamsByTenantId(tenantId)).size());
264 258 }
265 259
266 260 private void updateTenantAllowOAuth2Setting(Boolean allowOAuth2) throws IOException {
... ...