Improve oauth mapper - create default rule chains for tenant
This commit is contained in:
parent
549ab8addf
commit
92c9bc0ae5
@ -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 TextPageLink(1, tenantName)).getData();
|
List<Tenant> tenants = tenantService.findTenants(new TextPageLink(1, 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);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user