|
@@ -31,9 +31,11 @@ import org.thingsboard.server.dao.customer.CustomerService; |
|
@@ -31,9 +31,11 @@ import org.thingsboard.server.dao.customer.CustomerService; |
31
|
import org.thingsboard.server.dao.oauth2.OAuth2User;
|
31
|
import org.thingsboard.server.dao.oauth2.OAuth2User;
|
32
|
import org.thingsboard.server.dao.tenant.TenantService;
|
32
|
import org.thingsboard.server.dao.tenant.TenantService;
|
33
|
import org.thingsboard.server.dao.user.UserService;
|
33
|
import org.thingsboard.server.dao.user.UserService;
|
|
|
34
|
+import org.thingsboard.server.service.install.InstallScripts;
|
34
|
import org.thingsboard.server.service.security.model.SecurityUser;
|
35
|
import org.thingsboard.server.service.security.model.SecurityUser;
|
35
|
import org.thingsboard.server.service.security.model.UserPrincipal;
|
36
|
import org.thingsboard.server.service.security.model.UserPrincipal;
|
36
|
|
37
|
|
|
|
38
|
+import java.io.IOException;
|
37
|
import java.util.List;
|
39
|
import java.util.List;
|
38
|
import java.util.Optional;
|
40
|
import java.util.Optional;
|
39
|
import java.util.concurrent.locks.Lock;
|
41
|
import java.util.concurrent.locks.Lock;
|
|
@@ -51,6 +53,9 @@ public abstract class AbstractOAuth2ClientMapper { |
|
@@ -51,6 +53,9 @@ public abstract class AbstractOAuth2ClientMapper { |
51
|
@Autowired
|
53
|
@Autowired
|
52
|
private CustomerService customerService;
|
54
|
private CustomerService customerService;
|
53
|
|
55
|
|
|
|
56
|
+ @Autowired
|
|
|
57
|
+ private InstallScripts installScripts;
|
|
|
58
|
+
|
54
|
private final Lock userCreationLock = new ReentrantLock();
|
59
|
private final Lock userCreationLock = new ReentrantLock();
|
55
|
|
60
|
|
56
|
protected SecurityUser getOrCreateSecurityUserFromOAuth2User(OAuth2User oauth2User, boolean allowUserCreation) {
|
61
|
protected SecurityUser getOrCreateSecurityUserFromOAuth2User(OAuth2User oauth2User, boolean allowUserCreation) {
|
|
@@ -84,6 +89,9 @@ public abstract class AbstractOAuth2ClientMapper { |
|
@@ -84,6 +89,9 @@ public abstract class AbstractOAuth2ClientMapper { |
84
|
user.setLastName(oauth2User.getLastName());
|
89
|
user.setLastName(oauth2User.getLastName());
|
85
|
user = userService.saveUser(user);
|
90
|
user = userService.saveUser(user);
|
86
|
}
|
91
|
}
|
|
|
92
|
+ } catch (Exception e) {
|
|
|
93
|
+ log.error("Can't get or create security user from oauth2 user", e);
|
|
|
94
|
+ throw new RuntimeException("Can't get or create security user from oauth2 user", e);
|
87
|
} finally {
|
95
|
} finally {
|
88
|
userCreationLock.unlock();
|
96
|
userCreationLock.unlock();
|
89
|
}
|
97
|
}
|
|
@@ -98,13 +106,14 @@ public abstract class AbstractOAuth2ClientMapper { |
|
@@ -98,13 +106,14 @@ public abstract class AbstractOAuth2ClientMapper { |
98
|
}
|
106
|
}
|
99
|
}
|
107
|
}
|
100
|
|
108
|
|
101
|
- private TenantId getTenantId(String tenantName) {
|
109
|
+ private TenantId getTenantId(String tenantName) throws IOException {
|
102
|
List<Tenant> tenants = tenantService.findTenants(new PageLink(1, 0, tenantName)).getData();
|
110
|
List<Tenant> tenants = tenantService.findTenants(new PageLink(1, 0, tenantName)).getData();
|
103
|
Tenant tenant;
|
111
|
Tenant tenant;
|
104
|
if (tenants == null || tenants.isEmpty()) {
|
112
|
if (tenants == null || tenants.isEmpty()) {
|
105
|
tenant = new Tenant();
|
113
|
tenant = new Tenant();
|
106
|
tenant.setTitle(tenantName);
|
114
|
tenant.setTitle(tenantName);
|
107
|
tenant = tenantService.saveTenant(tenant);
|
115
|
tenant = tenantService.saveTenant(tenant);
|
|
|
116
|
+ installScripts.createDefaultRuleChains(tenant.getId());
|
108
|
} else {
|
117
|
} else {
|
109
|
tenant = tenants.get(0);
|
118
|
tenant = tenants.get(0);
|
110
|
}
|
119
|
}
|