Merge with master
This commit is contained in:
		
						commit
						cd5434587f
					
				@ -31,9 +31,11 @@ import org.thingsboard.server.dao.customer.CustomerService;
 | 
			
		||||
import org.thingsboard.server.dao.oauth2.OAuth2User;
 | 
			
		||||
import org.thingsboard.server.dao.tenant.TenantService;
 | 
			
		||||
import org.thingsboard.server.dao.user.UserService;
 | 
			
		||||
import org.thingsboard.server.service.install.InstallScripts;
 | 
			
		||||
import org.thingsboard.server.service.security.model.SecurityUser;
 | 
			
		||||
import org.thingsboard.server.service.security.model.UserPrincipal;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.concurrent.locks.Lock;
 | 
			
		||||
@ -51,6 +53,9 @@ public abstract class AbstractOAuth2ClientMapper {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private CustomerService customerService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private InstallScripts installScripts;
 | 
			
		||||
 | 
			
		||||
    private final Lock userCreationLock = new ReentrantLock();
 | 
			
		||||
 | 
			
		||||
    protected SecurityUser getOrCreateSecurityUserFromOAuth2User(OAuth2User oauth2User, boolean allowUserCreation) {
 | 
			
		||||
@ -84,6 +89,9 @@ public abstract class AbstractOAuth2ClientMapper {
 | 
			
		||||
                    user.setLastName(oauth2User.getLastName());
 | 
			
		||||
                    user = userService.saveUser(user);
 | 
			
		||||
                }
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                log.error("Can't get or create security user from oauth2 user", e);
 | 
			
		||||
                throw new RuntimeException("Can't get or create security user from oauth2 user", e);
 | 
			
		||||
            } finally {
 | 
			
		||||
                userCreationLock.unlock();
 | 
			
		||||
            }
 | 
			
		||||
@ -98,13 +106,14 @@ public abstract class AbstractOAuth2ClientMapper {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private TenantId getTenantId(String tenantName) {
 | 
			
		||||
    private TenantId getTenantId(String tenantName) throws IOException {
 | 
			
		||||
        List<Tenant> tenants = tenantService.findTenants(new PageLink(1, 0, tenantName)).getData();
 | 
			
		||||
        Tenant tenant;
 | 
			
		||||
        if (tenants == null || tenants.isEmpty()) {
 | 
			
		||||
            tenant = new Tenant();
 | 
			
		||||
            tenant.setTitle(tenantName);
 | 
			
		||||
            tenant = tenantService.saveTenant(tenant);
 | 
			
		||||
            installScripts.createDefaultRuleChains(tenant.getId());
 | 
			
		||||
        } else {
 | 
			
		||||
            tenant = tenants.get(0);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										12
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								pom.xml
									
									
									
									
									
								
							@ -472,11 +472,23 @@
 | 
			
		||||
                <groupId>org.springframework.security</groupId>
 | 
			
		||||
                <artifactId>spring-security-oauth2-client</artifactId>
 | 
			
		||||
                <version>${spring-security.version}</version>
 | 
			
		||||
                <exclusions>
 | 
			
		||||
                    <exclusion>
 | 
			
		||||
                        <groupId>org.springframework</groupId>
 | 
			
		||||
                        <artifactId>spring-core</artifactId>
 | 
			
		||||
                    </exclusion>
 | 
			
		||||
                </exclusions>
 | 
			
		||||
            </dependency>
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>org.springframework.security</groupId>
 | 
			
		||||
                <artifactId>spring-security-oauth2-jose</artifactId>
 | 
			
		||||
                <version>${spring-security.version}</version>
 | 
			
		||||
                <exclusions>
 | 
			
		||||
                    <exclusion>
 | 
			
		||||
                        <groupId>org.springframework</groupId>
 | 
			
		||||
                        <artifactId>spring-core</artifactId>
 | 
			
		||||
                    </exclusion>
 | 
			
		||||
                </exclusions>
 | 
			
		||||
            </dependency>
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>org.springframework.boot</groupId>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user