|
|
@ -38,7 +38,6 @@ import org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig; |
|
|
import org.thingsboard.server.common.data.oauth2.OAuth2Registration; |
|
|
import org.thingsboard.server.common.data.oauth2.OAuth2Registration; |
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; |
|
|
|
|
|
import org.thingsboard.server.common.data.security.Authority; |
|
|
import org.thingsboard.server.common.data.security.Authority; |
|
|
import org.thingsboard.server.common.data.security.UserCredentials; |
|
|
import org.thingsboard.server.common.data.security.UserCredentials; |
|
|
import org.thingsboard.server.dao.customer.CustomerService; |
|
|
import org.thingsboard.server.dao.customer.CustomerService; |
|
|
@ -47,12 +46,12 @@ import org.thingsboard.server.dao.oauth2.OAuth2User; |
|
|
import org.thingsboard.server.dao.tenant.TbTenantProfileCache; |
|
|
import org.thingsboard.server.dao.tenant.TbTenantProfileCache; |
|
|
import org.thingsboard.server.dao.tenant.TenantService; |
|
|
import org.thingsboard.server.dao.tenant.TenantService; |
|
|
import org.thingsboard.server.dao.user.UserService; |
|
|
import org.thingsboard.server.dao.user.UserService; |
|
|
|
|
|
import org.thingsboard.server.service.entitiy.tenant.TbTenantService; |
|
|
import org.thingsboard.server.service.entitiy.user.TbUserService; |
|
|
import org.thingsboard.server.service.entitiy.user.TbUserService; |
|
|
import org.thingsboard.server.service.install.InstallScripts; |
|
|
import org.thingsboard.server.service.install.InstallScripts; |
|
|
import org.thingsboard.server.service.security.model.SecurityUser; |
|
|
import org.thingsboard.server.service.security.model.SecurityUser; |
|
|
import org.thingsboard.server.service.security.model.UserPrincipal; |
|
|
import org.thingsboard.server.service.security.model.UserPrincipal; |
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Optional; |
|
|
import java.util.Optional; |
|
|
import java.util.concurrent.locks.Lock; |
|
|
import java.util.concurrent.locks.Lock; |
|
|
@ -71,6 +70,9 @@ public abstract class AbstractOAuth2ClientMapper { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private TenantService tenantService; |
|
|
private TenantService tenantService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private TbTenantService tbTenantService; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private CustomerService customerService; |
|
|
private CustomerService customerService; |
|
|
|
|
|
|
|
|
@ -92,7 +94,7 @@ public abstract class AbstractOAuth2ClientMapper { |
|
|
@Value("${edges.enabled}") |
|
|
@Value("${edges.enabled}") |
|
|
@Getter |
|
|
@Getter |
|
|
private boolean edgesEnabled; |
|
|
private boolean edgesEnabled; |
|
|
|
|
|
|
|
|
private final Lock userCreationLock = new ReentrantLock(); |
|
|
private final Lock userCreationLock = new ReentrantLock(); |
|
|
|
|
|
|
|
|
protected SecurityUser getOrCreateSecurityUserFromOAuth2User(OAuth2User oauth2User, OAuth2Registration registration) { |
|
|
protected SecurityUser getOrCreateSecurityUserFromOAuth2User(OAuth2User oauth2User, OAuth2Registration registration) { |
|
|
@ -171,19 +173,13 @@ public abstract class AbstractOAuth2ClientMapper { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private TenantId getTenantId(String tenantName) throws IOException { |
|
|
private TenantId getTenantId(String tenantName) throws Exception { |
|
|
List<Tenant> tenants = tenantService.findTenants(new PageLink(1, 0, tenantName)).getData(); |
|
|
List<Tenant> tenants = tenantService.findTenants(new PageLink(1, 0, tenantName)).getData(); |
|
|
Tenant tenant; |
|
|
Tenant tenant; |
|
|
if (tenants == null || tenants.isEmpty()) { |
|
|
if (tenants == null || tenants.isEmpty()) { |
|
|
tenant = new Tenant(); |
|
|
tenant = new Tenant(); |
|
|
tenant.setTitle(tenantName); |
|
|
tenant.setTitle(tenantName); |
|
|
tenant = tenantService.saveTenant(tenant); |
|
|
tenant = tbTenantService.save(tenant); |
|
|
installScripts.createDefaultRuleChains(tenant.getId()); |
|
|
|
|
|
installScripts.createDefaultEdgeRuleChains(tenant.getId()); |
|
|
|
|
|
tenantProfileCache.evict(tenant.getId()); |
|
|
|
|
|
tbClusterService.onTenantChange(tenant, null); |
|
|
|
|
|
tbClusterService.broadcastEntityStateChangeEvent(tenant.getId(), tenant.getId(), |
|
|
|
|
|
ComponentLifecycleEvent.CREATED); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
tenant = tenants.get(0); |
|
|
tenant = tenants.get(0); |
|
|
} |
|
|
} |
|
|
|