Browse Source

Unpacked Domain objects from ClientParams

pull/3557/head
vzikratyi 6 years ago
parent
commit
bfc3e75fc9
  1. 16
      application/src/main/java/org/thingsboard/server/controller/OAuth2Controller.java
  2. 6
      common/dao-api/src/main/java/org/thingsboard/server/dao/oauth2/OAuth2Service.java
  3. 33
      common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2ClientsParams.java
  4. 23
      dao/src/main/java/org/thingsboard/server/dao/oauth2/OAuth2ServiceImpl.java
  5. 8
      dao/src/main/java/org/thingsboard/server/dao/oauth2/OAuth2Utils.java
  6. 90
      dao/src/test/java/org/thingsboard/server/dao/service/BaseOAuth2ServiceTest.java

16
application/src/main/java/org/thingsboard/server/controller/OAuth2Controller.java

@ -16,21 +16,17 @@
package org.thingsboard.server.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.thingsboard.server.common.data.Dashboard;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.audit.ActionType;
import org.thingsboard.server.common.data.exception.ThingsboardException;
import org.thingsboard.server.common.data.id.DashboardId;
import org.thingsboard.server.common.data.id.OAuth2ClientRegistrationId;
import org.thingsboard.server.common.data.id.OAuth2ClientRegistrationTemplateId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.oauth2.*;
import org.thingsboard.server.common.data.security.Authority;
import org.thingsboard.server.dao.oauth2.OAuth2Service;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.security.permission.Operation;
import org.thingsboard.server.service.security.permission.Resource;
@ -61,14 +57,14 @@ public class OAuth2Controller extends BaseController {
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/oauth2/config", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public OAuth2ClientsParams getCurrentClientsParams() throws ThingsboardException {
public List<OAuth2ClientsDomainParams> getCurrentClientsParams() throws ThingsboardException {
try {
Authority authority = getCurrentUser().getAuthority();
checkOAuth2ConfigPermissions(Operation.READ);
if (Authority.SYS_ADMIN.equals(authority)) {
return oAuth2Service.findClientsParamsByTenantId(TenantId.SYS_TENANT_ID);
return oAuth2Service.findDomainsParamsByTenantId(TenantId.SYS_TENANT_ID);
} else if (Authority.TENANT_ADMIN.equals(authority)) {
return oAuth2Service.findClientsParamsByTenantId(getCurrentUser().getTenantId());
return oAuth2Service.findDomainsParamsByTenantId(getCurrentUser().getTenantId());
} else {
throw new IllegalStateException("Authority " + authority + " cannot get client registrations.");
}
@ -80,7 +76,7 @@ public class OAuth2Controller extends BaseController {
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/oauth2/config", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public OAuth2ClientsParams saveClientParams(@RequestBody OAuth2ClientsParams clientsParams) throws ThingsboardException {
public List<OAuth2ClientsDomainParams> saveClientParams(@RequestBody List<OAuth2ClientsDomainParams> domainsParams) throws ThingsboardException {
try {
TenantId tenantId;
Authority authority = getCurrentUser().getAuthority();
@ -91,13 +87,13 @@ public class OAuth2Controller extends BaseController {
} else {
throw new IllegalStateException("Authority " + authority + " cannot save client registrations.");
}
List<ClientRegistrationDto> clientRegistrationDtos = clientsParams.getOAuth2DomainDtos().stream()
List<ClientRegistrationDto> clientRegistrationDtos = domainsParams.stream()
.flatMap(domainParams -> domainParams.getClientRegistrations().stream())
.collect(Collectors.toList());
for (ClientRegistrationDto clientRegistrationDto : clientRegistrationDtos) {
checkEntity(clientRegistrationDto.getId(), () -> tenantId, Resource.OAUTH2_CONFIGURATION);
}
return oAuth2Service.saveClientsParams(tenantId, clientsParams);
return oAuth2Service.saveDomainsParams(tenantId, domainsParams);
} catch (Exception e) {
throw handleException(e);
}

6
common/dao-api/src/main/java/org/thingsboard/server/dao/oauth2/OAuth2Service.java

@ -19,7 +19,7 @@ import org.thingsboard.server.common.data.id.OAuth2ClientRegistrationId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.oauth2.OAuth2ClientInfo;
import org.thingsboard.server.common.data.oauth2.OAuth2ClientRegistration;
import org.thingsboard.server.common.data.oauth2.OAuth2ClientsParams;
import org.thingsboard.server.common.data.oauth2.OAuth2ClientsDomainParams;
import java.util.List;
import java.util.UUID;
@ -27,9 +27,9 @@ import java.util.UUID;
public interface OAuth2Service {
List<OAuth2ClientInfo> getOAuth2Clients(String domainName);
OAuth2ClientsParams saveClientsParams(TenantId tenantId, OAuth2ClientsParams clientsParams);
List<OAuth2ClientsDomainParams> saveDomainsParams(TenantId tenantId, List<OAuth2ClientsDomainParams> domainsParams);
OAuth2ClientsParams findClientsParamsByTenantId(TenantId tenantId);
List<OAuth2ClientsDomainParams> findDomainsParamsByTenantId(TenantId tenantId);
OAuth2ClientRegistration findClientRegistration(UUID id);

33
common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2ClientsParams.java

@ -1,33 +0,0 @@
/**
* Copyright © 2016-2020 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.oauth2;
import lombok.*;
import org.thingsboard.server.common.data.id.TenantId;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
@EqualsAndHashCode
@Data
@ToString
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class OAuth2ClientsParams {
private List<OAuth2ClientsDomainParams> oAuth2DomainDtos;
}

23
dao/src/main/java/org/thingsboard/server/dao/oauth2/OAuth2ServiceImpl.java

@ -66,21 +66,21 @@ public class OAuth2ServiceImpl extends AbstractEntityService implements OAuth2Se
@Override
@Transactional
public OAuth2ClientsParams saveClientsParams(TenantId tenantId, OAuth2ClientsParams clientsParams) {
log.trace("Executing saveClientsParams [{}] [{}]", tenantId, clientsParams);
clientParamsValidator.accept(tenantId, clientsParams);
List<OAuth2ClientRegistration> inputClientRegistrations = OAuth2Utils.toClientRegistrations(tenantId, clientsParams);
public List<OAuth2ClientsDomainParams> saveDomainsParams(TenantId tenantId, List<OAuth2ClientsDomainParams> domainsParams) {
log.trace("Executing saveDomainsParams [{}] [{}]", tenantId, domainsParams);
clientParamsValidator.accept(tenantId, domainsParams);
List<OAuth2ClientRegistration> inputClientRegistrations = OAuth2Utils.toClientRegistrations(tenantId, domainsParams);
List<OAuth2ClientRegistration> savedClientRegistrations = inputClientRegistrations.stream()
.map(clientRegistration -> clientRegistrationDao.save(clientRegistration.getTenantId(), clientRegistration))
.collect(Collectors.toList());
return OAuth2Utils.toOAuth2ClientsParams(savedClientRegistrations);
return OAuth2Utils.toDomainsParams(savedClientRegistrations);
}
@Override
public OAuth2ClientsParams findClientsParamsByTenantId(TenantId tenantId) {
log.trace("Executing findClientsParamsByTenantId [{}]", tenantId);
public List<OAuth2ClientsDomainParams> findDomainsParamsByTenantId(TenantId tenantId) {
log.trace("Executing findDomainsParamsByTenantId [{}]", tenantId);
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
return OAuth2Utils.toOAuth2ClientsParams(clientRegistrationDao.findByTenantId(tenantId.getId()));
return OAuth2Utils.toDomainsParams(clientRegistrationDao.findByTenantId(tenantId.getId()));
}
@Override
@ -135,12 +135,11 @@ public class OAuth2ServiceImpl extends AbstractEntityService implements OAuth2Se
}
}
private final BiConsumer<TenantId, OAuth2ClientsParams> clientParamsValidator = (tenantId, clientsParams) -> {
if (clientsParams == null || clientsParams.getOAuth2DomainDtos() == null
|| clientsParams.getOAuth2DomainDtos().isEmpty()) {
private final BiConsumer<TenantId, List<OAuth2ClientsDomainParams>> clientParamsValidator = (tenantId, domainsParams) -> {
if (domainsParams == null || domainsParams.isEmpty()) {
throw new DataValidationException("Domain params should be specified!");
}
for (OAuth2ClientsDomainParams domainParams : clientsParams.getOAuth2DomainDtos()) {
for (OAuth2ClientsDomainParams domainParams : domainsParams) {
if (StringUtils.isEmpty(domainParams.getDomainName())) {
throw new DataValidationException("Domain name should be specified!");
}

8
dao/src/main/java/org/thingsboard/server/dao/oauth2/OAuth2Utils.java

@ -38,8 +38,8 @@ public class OAuth2Utils {
return client;
}
public static List<OAuth2ClientRegistration> toClientRegistrations(TenantId tenantId, OAuth2ClientsParams clientsParams) {
return clientsParams.getOAuth2DomainDtos().stream()
public static List<OAuth2ClientRegistration> toClientRegistrations(TenantId tenantId, List<OAuth2ClientsDomainParams> domainsParams) {
return domainsParams.stream()
.flatMap(domainParams -> domainParams.getClientRegistrations().stream()
.map(clientRegistrationDto -> OAuth2Utils.toClientRegistration(tenantId, domainParams.getDomainName(),
domainParams.getRedirectUriTemplate(), clientRegistrationDto)
@ -47,7 +47,7 @@ public class OAuth2Utils {
.collect(Collectors.toList());
}
public static OAuth2ClientsParams toOAuth2ClientsParams(List<OAuth2ClientRegistration> clientRegistrations) {
public static List<OAuth2ClientsDomainParams> toDomainsParams(List<OAuth2ClientRegistration> clientRegistrations) {
Map<String, OAuth2ClientsDomainParams> domainParamsMap = new HashMap<>();
for (OAuth2ClientRegistration clientRegistration : clientRegistrations) {
String domainName = clientRegistration.getDomainName();
@ -57,7 +57,7 @@ public class OAuth2Utils {
domainParams.getClientRegistrations()
.add(toClientRegistrationDto(clientRegistration));
}
return new OAuth2ClientsParams(new ArrayList<>(domainParamsMap.values()));
return new ArrayList<>(domainParamsMap.values());
}
public static ClientRegistrationDto toClientRegistrationDto(OAuth2ClientRegistration oAuth2ClientRegistration) {

90
dao/src/test/java/org/thingsboard/server/dao/service/BaseOAuth2ServiceTest.java

@ -15,27 +15,21 @@
*/
package org.thingsboard.server.dao.service;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.DataConstants;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.id.OAuth2ClientRegistrationId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.oauth2.*;
import org.thingsboard.server.dao.attributes.AttributesService;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.oauth2.OAuth2Service;
import org.thingsboard.server.dao.oauth2.OAuth2Utils;
import javax.transaction.Transactional;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.thingsboard.server.dao.oauth2.OAuth2Utils.ALLOW_OAUTH2_CONFIGURATION;
import static org.thingsboard.server.dao.oauth2.OAuth2Utils.toClientRegistrations;
@ -91,10 +85,10 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
@Test
public void testCreateNewSystemParams() {
OAuth2ClientRegistration clientRegistration = validClientRegistration(TenantId.SYS_TENANT_ID);
OAuth2ClientsParams savedClientsParams = oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(clientRegistration)));
Assert.assertNotNull(savedClientsParams);
List<OAuth2ClientsDomainParams> savedDomainsParams = oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toDomainsParams(Collections.singletonList(clientRegistration)));
Assert.assertNotNull(savedDomainsParams);
List<OAuth2ClientRegistration> savedClientRegistrations = OAuth2Utils.toClientRegistrations(TenantId.SYS_TENANT_ID, savedClientsParams);
List<OAuth2ClientRegistration> savedClientRegistrations = OAuth2Utils.toClientRegistrations(TenantId.SYS_TENANT_ID, savedDomainsParams);
Assert.assertEquals(1, savedClientRegistrations.size());
OAuth2ClientRegistration savedClientRegistration = savedClientRegistrations.get(0);
@ -107,13 +101,13 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
@Test
public void testFindSystemParamsByTenant() {
OAuth2ClientRegistration clientRegistration = validClientRegistration(TenantId.SYS_TENANT_ID);
oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(clientRegistration)));
oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toDomainsParams(Collections.singletonList(clientRegistration)));
OAuth2ClientsParams foundClientsParams = oAuth2Service.findClientsParamsByTenantId(TenantId.SYS_TENANT_ID);
Assert.assertEquals(1, foundClientsParams.getOAuth2DomainDtos().size());
List<OAuth2ClientsDomainParams> foundDomainsParams = oAuth2Service.findDomainsParamsByTenantId(TenantId.SYS_TENANT_ID);
Assert.assertEquals(1, foundDomainsParams.size());
Assert.assertEquals(1, oAuth2Service.findAllClientRegistrations().size());
List<OAuth2ClientRegistration> foundClientRegistrations = OAuth2Utils.toClientRegistrations(TenantId.SYS_TENANT_ID, foundClientsParams);
List<OAuth2ClientRegistration> foundClientRegistrations = OAuth2Utils.toClientRegistrations(TenantId.SYS_TENANT_ID, foundDomainsParams);
OAuth2ClientRegistration foundClientRegistration = foundClientRegistrations.get(0);
Assert.assertNotNull(foundClientRegistration);
clientRegistration.setId(foundClientRegistration.getId());
@ -124,10 +118,10 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
@Test
public void testCreateNewTenantParams() {
OAuth2ClientRegistration clientRegistration = validClientRegistration(tenantId);
OAuth2ClientsParams savedClientsParams = oAuth2Service.saveClientsParams(tenantId, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(clientRegistration)));
Assert.assertNotNull(savedClientsParams);
List<OAuth2ClientsDomainParams> savedDomainsParams = oAuth2Service.saveDomainsParams(tenantId, OAuth2Utils.toDomainsParams(Collections.singletonList(clientRegistration)));
Assert.assertNotNull(savedDomainsParams);
List<OAuth2ClientRegistration> savedClientRegistrations = OAuth2Utils.toClientRegistrations(tenantId, savedClientsParams);
List<OAuth2ClientRegistration> savedClientRegistrations = OAuth2Utils.toClientRegistrations(tenantId, savedDomainsParams);
Assert.assertEquals(1, savedClientRegistrations.size());
OAuth2ClientRegistration savedClientRegistration = savedClientRegistrations.get(0);
@ -142,13 +136,13 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
@Test
public void testFindTenantParams() {
OAuth2ClientRegistration clientRegistration = validClientRegistration(tenantId);
oAuth2Service.saveClientsParams(tenantId, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(clientRegistration)));
oAuth2Service.saveDomainsParams(tenantId, OAuth2Utils.toDomainsParams(Collections.singletonList(clientRegistration)));
OAuth2ClientsParams foundClientsParams = oAuth2Service.findClientsParamsByTenantId(tenantId);
Assert.assertEquals(1, foundClientsParams.getOAuth2DomainDtos().size());
List<OAuth2ClientsDomainParams> foundDomainsParams = oAuth2Service.findDomainsParamsByTenantId(tenantId);
Assert.assertEquals(1, foundDomainsParams.size());
Assert.assertEquals(1, oAuth2Service.findAllClientRegistrations().size());
List<OAuth2ClientRegistration> foundClientRegistrations = OAuth2Utils.toClientRegistrations(tenantId, foundClientsParams);
List<OAuth2ClientRegistration> foundClientRegistrations = OAuth2Utils.toClientRegistrations(tenantId, foundDomainsParams);
OAuth2ClientRegistration foundClientRegistration = foundClientRegistrations.get(0);
Assert.assertNotNull(foundClientRegistration);
@ -162,19 +156,19 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
OAuth2ClientRegistration tenantClientRegistration = validClientRegistration(tenantId);
OAuth2ClientRegistration sysAdminClientRegistration = validClientRegistration(TenantId.SYS_TENANT_ID);
OAuth2ClientsParams savedTenantClientsParams = oAuth2Service.saveClientsParams(tenantId,
OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(tenantClientRegistration)));
OAuth2ClientsParams savedSysAdminClientsParams = oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID,
OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(sysAdminClientRegistration)));
List<OAuth2ClientsDomainParams> savedTenantDomainsParams = oAuth2Service.saveDomainsParams(tenantId,
OAuth2Utils.toDomainsParams(Collections.singletonList(tenantClientRegistration)));
List<OAuth2ClientsDomainParams> savedSysAdminDomainsParams = oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID,
OAuth2Utils.toDomainsParams(Collections.singletonList(sysAdminClientRegistration)));
Assert.assertEquals(2, oAuth2Service.findAllClientRegistrations().size());
Assert.assertEquals(savedTenantClientsParams, oAuth2Service.findClientsParamsByTenantId(tenantId));
Assert.assertEquals(savedSysAdminClientsParams, oAuth2Service.findClientsParamsByTenantId(TenantId.SYS_TENANT_ID));
Assert.assertEquals(savedTenantDomainsParams, oAuth2Service.findDomainsParamsByTenantId(tenantId));
Assert.assertEquals(savedSysAdminDomainsParams, oAuth2Service.findDomainsParamsByTenantId(TenantId.SYS_TENANT_ID));
OAuth2ClientRegistration savedTenantClientRegistration = toClientRegistrations(tenantId, savedTenantClientsParams).get(0);
OAuth2ClientRegistration savedTenantClientRegistration = toClientRegistrations(tenantId, savedTenantDomainsParams).get(0);
Assert.assertEquals(savedTenantClientRegistration, oAuth2Service.findClientRegistration(savedTenantClientRegistration.getUuidId()));
OAuth2ClientRegistration savedSysAdminClientRegistration = toClientRegistrations(TenantId.SYS_TENANT_ID, savedSysAdminClientsParams).get(0);
OAuth2ClientRegistration savedSysAdminClientRegistration = toClientRegistrations(TenantId.SYS_TENANT_ID, savedSysAdminDomainsParams).get(0);
Assert.assertEquals(savedSysAdminClientRegistration, oAuth2Service.findClientRegistration(savedSysAdminClientRegistration.getUuidId()));
}
@ -184,8 +178,8 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
OAuth2ClientRegistration tenantClientRegistration = validClientRegistration(tenantId, testDomainName);
OAuth2ClientRegistration sysAdminClientRegistration = validClientRegistration(TenantId.SYS_TENANT_ID, testDomainName);
oAuth2Service.saveClientsParams(tenantId, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(tenantClientRegistration)));
oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(sysAdminClientRegistration)));
oAuth2Service.saveDomainsParams(tenantId, OAuth2Utils.toDomainsParams(Collections.singletonList(tenantClientRegistration)));
oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toDomainsParams(Collections.singletonList(sysAdminClientRegistration)));
List<OAuth2ClientInfo> oAuth2Clients = oAuth2Service.getOAuth2Clients(testDomainName);
@ -201,8 +195,8 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
String testDomainName = "test_domain";
OAuth2ClientRegistration tenantClientRegistration = validClientRegistration(tenantId, testDomainName);
OAuth2ClientRegistration sysAdminClientRegistration = validClientRegistration(TenantId.SYS_TENANT_ID, testDomainName);
oAuth2Service.saveClientsParams(tenantId, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(tenantClientRegistration)));
oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(sysAdminClientRegistration)));
oAuth2Service.saveDomainsParams(tenantId, OAuth2Utils.toDomainsParams(Collections.singletonList(tenantClientRegistration)));
oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toDomainsParams(Collections.singletonList(sysAdminClientRegistration)));
List<OAuth2ClientInfo> oAuth2Clients = oAuth2Service.getOAuth2Clients("random-domain");
Assert.assertTrue(oAuth2Clients.isEmpty());
}
@ -212,13 +206,13 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
OAuth2ClientRegistration tenantClientRegistration = validClientRegistration(tenantId);
OAuth2ClientRegistration sysAdminClientRegistration = validClientRegistration(TenantId.SYS_TENANT_ID);
OAuth2ClientsParams savedTenantClientsParams = oAuth2Service.saveClientsParams(tenantId,
OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(tenantClientRegistration)));
OAuth2ClientsParams savedSysAdminClientsParams = oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID,
OAuth2Utils.toOAuth2ClientsParams(Collections.singletonList(sysAdminClientRegistration)));
List<OAuth2ClientsDomainParams> savedTenantDomainsParams = oAuth2Service.saveDomainsParams(tenantId,
OAuth2Utils.toDomainsParams(Collections.singletonList(tenantClientRegistration)));
List<OAuth2ClientsDomainParams> savedSysAdminDomainsParams = oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID,
OAuth2Utils.toDomainsParams(Collections.singletonList(sysAdminClientRegistration)));
OAuth2ClientRegistration savedTenantRegistration = toClientRegistrations(tenantId, savedTenantClientsParams).get(0);
OAuth2ClientRegistration savedSysAdminRegistration = toClientRegistrations(TenantId.SYS_TENANT_ID, savedSysAdminClientsParams).get(0);
OAuth2ClientRegistration savedTenantRegistration = toClientRegistrations(tenantId, savedTenantDomainsParams).get(0);
OAuth2ClientRegistration savedSysAdminRegistration = toClientRegistrations(TenantId.SYS_TENANT_ID, savedSysAdminDomainsParams).get(0);
oAuth2Service.deleteClientRegistrationById(tenantId, savedTenantRegistration.getId());
List<OAuth2ClientRegistration> foundRegistrations = oAuth2Service.findAllClientRegistrations();
@ -228,39 +222,39 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest {
@Test
public void testDeleteTenantOAuth2ClientRegistrations() {
oAuth2Service.saveClientsParams(tenantId, OAuth2Utils.toOAuth2ClientsParams(Arrays.asList(
oAuth2Service.saveDomainsParams(tenantId, OAuth2Utils.toDomainsParams(Arrays.asList(
validClientRegistration(tenantId, "domain"),
validClientRegistration(tenantId, "domain"),
validClientRegistration(tenantId, "domain")
)));
Assert.assertEquals(3, oAuth2Service.findAllClientRegistrations().size());
Assert.assertEquals(1, oAuth2Service.findClientsParamsByTenantId(tenantId).getOAuth2DomainDtos().size());
Assert.assertEquals(1, oAuth2Service.findDomainsParamsByTenantId(tenantId).size());
oAuth2Service.deleteClientRegistrationsByTenantId(tenantId);
Assert.assertEquals(0, oAuth2Service.findAllClientRegistrations().size());
Assert.assertEquals(0, oAuth2Service.findClientsParamsByTenantId(tenantId).getOAuth2DomainDtos().size());
Assert.assertEquals(0, oAuth2Service.findDomainsParamsByTenantId(tenantId).size());
}
@Test
public void testDeleteTenantDomainOAuth2ClientRegistrations() {
oAuth2Service.saveClientsParams(tenantId, OAuth2Utils.toOAuth2ClientsParams(Arrays.asList(
oAuth2Service.saveDomainsParams(tenantId, OAuth2Utils.toDomainsParams(Arrays.asList(
validClientRegistration(tenantId, "domain1"),
validClientRegistration(tenantId, "domain1"),
validClientRegistration(tenantId, "domain2")
)));
oAuth2Service.saveClientsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toOAuth2ClientsParams(Arrays.asList(
oAuth2Service.saveDomainsParams(TenantId.SYS_TENANT_ID, OAuth2Utils.toDomainsParams(Arrays.asList(
validClientRegistration(TenantId.SYS_TENANT_ID, "domain2")
)));
Assert.assertEquals(4, oAuth2Service.findAllClientRegistrations().size());
OAuth2ClientsParams tenantClientsParams = oAuth2Service.findClientsParamsByTenantId(tenantId);
List<OAuth2ClientRegistration> tenantClientRegistrations = toClientRegistrations(tenantId, tenantClientsParams);
Assert.assertEquals(2, tenantClientsParams.getOAuth2DomainDtos().size());
List<OAuth2ClientsDomainParams> tenantDomainsParams = oAuth2Service.findDomainsParamsByTenantId(tenantId);
List<OAuth2ClientRegistration> tenantClientRegistrations = toClientRegistrations(tenantId, tenantDomainsParams);
Assert.assertEquals(2, tenantDomainsParams.size());
Assert.assertEquals(3, tenantClientRegistrations.size());
oAuth2Service.deleteClientRegistrationsByDomain(tenantId, "domain1");
Assert.assertEquals(2, oAuth2Service.findAllClientRegistrations().size());
Assert.assertEquals(1, oAuth2Service.findClientsParamsByTenantId(tenantId).getOAuth2DomainDtos().size());
Assert.assertEquals(1, toClientRegistrations(tenantId, oAuth2Service.findClientsParamsByTenantId(tenantId)).size());
Assert.assertEquals(1, oAuth2Service.findDomainsParamsByTenantId(tenantId).size());
Assert.assertEquals(1, toClientRegistrations(tenantId, oAuth2Service.findDomainsParamsByTenantId(tenantId)).size());
}
private void updateTenantAllowOAuth2Setting(Boolean allowOAuth2) throws IOException {

Loading…
Cancel
Save