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.oauth2.OAuth2User;
|
||||||
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.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;
|
||||||
@ -51,6 +53,9 @@ public abstract class AbstractOAuth2ClientMapper {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CustomerService customerService;
|
private CustomerService customerService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InstallScripts installScripts;
|
||||||
|
|
||||||
private final Lock userCreationLock = new ReentrantLock();
|
private final Lock userCreationLock = new ReentrantLock();
|
||||||
|
|
||||||
protected SecurityUser getOrCreateSecurityUserFromOAuth2User(OAuth2User oauth2User, boolean allowUserCreation) {
|
protected SecurityUser getOrCreateSecurityUserFromOAuth2User(OAuth2User oauth2User, boolean allowUserCreation) {
|
||||||
@ -84,6 +89,9 @@ public abstract class AbstractOAuth2ClientMapper {
|
|||||||
user.setLastName(oauth2User.getLastName());
|
user.setLastName(oauth2User.getLastName());
|
||||||
user = userService.saveUser(user);
|
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 {
|
} finally {
|
||||||
userCreationLock.unlock();
|
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();
|
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 = tenantService.saveTenant(tenant);
|
||||||
|
installScripts.createDefaultRuleChains(tenant.getId());
|
||||||
} else {
|
} else {
|
||||||
tenant = tenants.get(0);
|
tenant = tenants.get(0);
|
||||||
}
|
}
|
||||||
|
|||||||
12
pom.xml
12
pom.xml
@ -472,11 +472,23 @@
|
|||||||
<groupId>org.springframework.security</groupId>
|
<groupId>org.springframework.security</groupId>
|
||||||
<artifactId>spring-security-oauth2-client</artifactId>
|
<artifactId>spring-security-oauth2-client</artifactId>
|
||||||
<version>${spring-security.version}</version>
|
<version>${spring-security.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-core</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.security</groupId>
|
<groupId>org.springframework.security</groupId>
|
||||||
<artifactId>spring-security-oauth2-jose</artifactId>
|
<artifactId>spring-security-oauth2-jose</artifactId>
|
||||||
<version>${spring-security.version}</version>
|
<version>${spring-security.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-core</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user