@ -20,7 +20,6 @@ import lombok.Getter;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.context.ApplicationEventPublisher ;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken ;
import org.springframework.security.core.userdetails.UsernameNotFoundException ;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder ;
@ -37,7 +36,6 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.oauth2.OAuth2Client ;
import org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig ;
import org.thingsboard.server.common.data.page.PageData ;
import org.thingsboard.server.common.data.page.PageDataIterable ;
import org.thingsboard.server.common.data.page.PageLink ;
import org.thingsboard.server.common.data.security.Authority ;
import org.thingsboard.server.common.data.security.UserCredentials ;
@ -49,7 +47,6 @@ import org.thingsboard.server.dao.tenant.TenantService;
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.install.InstallScripts ;
import org.thingsboard.server.service.security.model.SecurityUser ;
import org.thingsboard.server.service.security.model.UserPrincipal ;
@ -80,18 +77,12 @@ public abstract class AbstractOAuth2ClientMapper {
@Autowired
private DashboardService dashboardService ;
@Autowired
private InstallScripts installScripts ;
@Autowired
private TbUserService tbUserService ;
@Autowired
protected TbTenantProfileCache tenantProfileCache ;
@Autowired
private ApplicationEventPublisher eventPublisher ;
@Value ( "${edges.enabled}" )
@Getter
private boolean edgesEnabled ;
@ -121,8 +112,7 @@ public abstract class AbstractOAuth2ClientMapper {
} else {
user . setAuthority ( Authority . CUSTOMER_USER ) ;
}
TenantId tenantId = oauth2User . getTenantId ( ) ! = null ?
oauth2User . getTenantId ( ) : getTenantId ( oauth2User . getTenantName ( ) ) ;
TenantId tenantId = oauth2User . getTenantId ( ) ! = null ? oauth2User . getTenantId ( ) : getTenantId ( oauth2User . getTenantName ( ) ) ;
user . setTenantId ( tenantId ) ;
CustomerId customerId = oauth2User . getCustomerId ( ) ! = null ?
oauth2User . getCustomerId ( ) : getCustomerId ( user . getTenantId ( ) , oauth2User . getCustomerName ( ) ) ;
@ -174,15 +164,13 @@ public abstract class AbstractOAuth2ClientMapper {
}
}
private TenantId getTenantId ( String tenantName ) throws Exception {
PageDataIterable < Tenant > tenantIterator = new PageDataIterable < > ( tenantService : : findTenants , 1024 ) ;
for ( Tenant tenant : tenantIterator ) {
if ( tenant . getTitle ( ) . equals ( tenantName ) ) {
return tenant . getId ( ) ;
}
private TenantId getTenantId ( String name ) throws Exception {
Tenant tenant = tenantService . findTenantByName ( name ) ;
if ( tenant ! = null ) {
return tenant . getId ( ) ;
}
Tenant tenant = new Tenant ( ) ;
tenant . setTitle ( te nantN ame) ;
tenant = new Tenant ( ) ;
tenant . setTitle ( name ) ;
tenant = tbTenantService . save ( tenant ) ;
return tenant . getId ( ) ;
}