Commit 92c9bc0ae569e01cdfc47cf70085ef9953a2be3d
1 parent
549ab8ad
Improve oauth mapper - create default rule chains for tenant
Showing
1 changed file
with
10 additions
and
1 deletions
... | ... | @@ -31,9 +31,11 @@ import org.thingsboard.server.dao.customer.CustomerService; |
31 | 31 | import org.thingsboard.server.dao.oauth2.OAuth2User; |
32 | 32 | import org.thingsboard.server.dao.tenant.TenantService; |
33 | 33 | import org.thingsboard.server.dao.user.UserService; |
34 | +import org.thingsboard.server.service.install.InstallScripts; | |
34 | 35 | import org.thingsboard.server.service.security.model.SecurityUser; |
35 | 36 | import org.thingsboard.server.service.security.model.UserPrincipal; |
36 | 37 | |
38 | +import java.io.IOException; | |
37 | 39 | import java.util.List; |
38 | 40 | import java.util.Optional; |
39 | 41 | import java.util.concurrent.locks.Lock; |
... | ... | @@ -51,6 +53,9 @@ public abstract class AbstractOAuth2ClientMapper { |
51 | 53 | @Autowired |
52 | 54 | private CustomerService customerService; |
53 | 55 | |
56 | + @Autowired | |
57 | + private InstallScripts installScripts; | |
58 | + | |
54 | 59 | private final Lock userCreationLock = new ReentrantLock(); |
55 | 60 | |
56 | 61 | protected SecurityUser getOrCreateSecurityUserFromOAuth2User(OAuth2User oauth2User, boolean allowUserCreation) { |
... | ... | @@ -84,6 +89,9 @@ public abstract class AbstractOAuth2ClientMapper { |
84 | 89 | user.setLastName(oauth2User.getLastName()); |
85 | 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 | 95 | } finally { |
88 | 96 | userCreationLock.unlock(); |
89 | 97 | } |
... | ... | @@ -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 | 110 | List<Tenant> tenants = tenantService.findTenants(new TextPageLink(1, tenantName)).getData(); |
103 | 111 | Tenant tenant; |
104 | 112 | if (tenants == null || tenants.isEmpty()) { |
105 | 113 | tenant = new Tenant(); |
106 | 114 | tenant.setTitle(tenantName); |
107 | 115 | tenant = tenantService.saveTenant(tenant); |
116 | + installScripts.createDefaultRuleChains(tenant.getId()); | |
108 | 117 | } else { |
109 | 118 | tenant = tenants.get(0); |
110 | 119 | } | ... | ... |