Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-132241

Trying to create a new user via API with a longer than allowed firstName produces a nonfriendly error message in the logs


    • 3


      Reproducing steps

      1. Start Liferay and go to Control Panel > Server Administration > Script
      2. Use the following Groovy script to create a new user via API with a very long firstName (longer than 75 characters).
        import com.liferay.portal.kernel.service.UserLocalServiceUtil;
        import com.liferay.portal.kernel.util.LocaleUtil;
        import com.liferay.portal.kernel.service.ServiceContext;
        import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
        import com.liferay.portal.kernel.model.User;
        ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
        long companyId = serviceContext.getCompanyId();
        User defaultUser = UserLocalServiceUtil.getDefaultUser(companyId);
        String firstName = "veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongfirstname";
        UserLocalServiceUtil.addUser(defaultUser.getUserId(), companyId, false, "1234", "1234", true, null, "[email protected]", 0, null, LocaleUtil.getDefault(), firstName, null, "user01", -1, -1, true, 1, 1, 1977, "", new long[0], new long[0], new long[0], new long[0], false, serviceContext);

        Observed: There's an error in the log produced by the database indicating that one of the fields is too long for the existing constraint (VARCHAR(75)).

        2021-05-14 10:49:43.044 ERROR [http-nio-8080-exec-4][JDBCExceptionReporter:234] Batch entry 0 insert into User_ (mvccVersion, ctCollectionId, uuid_, externalReferenceCode, companyId, createDate, modifiedDate, defaultUser, contactId, password_, passwordEncrypted, passwordReset, passwordModifiedDate, digest, reminderQueryQuestion, reminderQueryAnswer, graceLoginCount, screenName, emailAddress, facebookId, googleUserId, ldapServerId, openId, portraitId, languageId, timeZoneId, greeting, comments, firstName, middleName, lastName, jobTitle, loginDate, loginIP, lastLoginDate, lastLoginIP, lastFailedLoginDate, failedLoginAttempts, lockout, lockoutDate, agreedToTermsOfUse, emailAddressVerified, status, userId) values (0, 0, '9b91320b-fa07-c0b8-922c-31e573e7c49d', NULL, 20103, '2021-05-14 10:49:43.024+00', '2021-05-14 10:49:43.024+00', 'FALSE', 39458, '{PBKDF2WITHHMACSHA1}AAAAoAAB9ABJkHqzYtguDbRCwEbRsJghz5wgsW5ISD9FE/+l', 'TRUE', 'TRUE', NULL, '9ad14b9978803512de35c5abf7eae246,99d3f5b2f43f6c71b0db76450253223f,2d871374e4c9045618155eaca32c0e75', NULL, NULL, 0, 'user01', '[email protected]', 0, NULL, -1, NULL, 0, 'en_US', 'UTC', 'Welcome v user01!', NULL, 'veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongfirstname', NULL, 'user01', NULL, NULL, NULL, NULL, NULL, NULL, 0, 'FALSE', NULL, 'FALSE', 'FALSE', 2, 39457) was aborted: ERROR: value too long for type character varying(75)  Call getNextException to see other errors in the batch.
        2021-05-14 10:49:43.046 ERROR [http-nio-8080-exec-4][JDBCExceptionReporter:234] ERROR: value too long for type character varying(75)

        Expected: There's a friendly error message generated by Liferay explaining that the argument firstName is longer than the maximum number of characters allowed.

      Note: Using the UI only 75 characters can be input in the corresponding field due to the attribute maxlength="75" of the <input> tag.




            support-lep@liferay.com SE Support
            ricardo.couso Ricardo Couso
            Kiyoshi Lee Kiyoshi Lee
            0 Vote for this issue
            1 Start watching this issue


              10 weeks, 2 days ago


                Version Package