/** * Returns the tenant id of the logged user if any, {@code null} otherwise. */ protected String getCurrentTenantId() { NuxeoPrincipal principal = ClientLoginModule.getCurrentPrincipal(); return principal != null ? principal.getTenantId() : null; }
/** * Check that the user that initiated the registration is in the same tenant than the user it creates. * * @param registrationDoc * @param configuration * @return * @since 10.2 */ private boolean isSameTenant(DocumentModel registrationDoc, UserRegistrationConfiguration configuration) { NuxeoPrincipal originatingPrincipal = getOriginatingPrincipal(registrationDoc); if (originatingPrincipal == null) { // Should never occur, but just in case. return registrationDoc.getPropertyValue(configuration.getUserInfoTenantIdField()) == null; } if (originatingPrincipal.isAdministrator()) { return true; } return Objects.equals(registrationDoc.getPropertyValue(configuration.getUserInfoTenantIdField()), originatingPrincipal.getTenantId()); }
private DocumentModel wrapToUserRegistration(UserAdapter newUserAdapter) { UserInvitationService userRegistrationService = Framework.getService(UserInvitationService.class); DocumentModel newUserRegistration = userRegistrationService.getUserRegistrationModel(null); // Map the values from the object filled in the form newUserRegistration.setPropertyValue(userRegistrationService.getConfiguration().getUserInfoUsernameField(), newUserAdapter.getName()); newUserRegistration.setPropertyValue(userRegistrationService.getConfiguration().getUserInfoFirstnameField(), newUserAdapter.getFirstName()); newUserRegistration.setPropertyValue(userRegistrationService.getConfiguration().getUserInfoLastnameField(), newUserAdapter.getLastName()); newUserRegistration.setPropertyValue(userRegistrationService.getConfiguration().getUserInfoEmailField(), newUserAdapter.getEmail()); newUserRegistration.setPropertyValue(userRegistrationService.getConfiguration().getUserInfoGroupsField(), newUserAdapter.getGroups().toArray()); newUserRegistration.setPropertyValue(userRegistrationService.getConfiguration().getUserInfoCompanyField(), newUserAdapter.getCompany()); String tenantId = newUserAdapter.getTenantId(); if (StringUtils.isBlank(tenantId)) { tenantId = currentUser.getTenantId(); } newUserRegistration.setPropertyValue(userRegistrationService.getConfiguration().getUserInfoTenantIdField(), tenantId); return newUserRegistration; }