CMDBuild Forum

Error applying patch 3.4.0-01ba_scrub_auth_data whilst trying to go from 3.3.2 to 3.3.3

Hello. We’re getting an error trying to update our CMDBuild installation from 3.3.2 to 3.3.3, and we can not figure it out. Anyone have any tips?

org.cmdbuild.dao.DaoException: error processing patch = Patch{version=3.4.0-01ba_scrub_auth_data, category=core, applied=false}, caused by: org.cmdbuild.dao.DaoException: error processing patch =< core-3.4.0-01ba_scrub_auth_data (scrub auth data) >, caused by: org.springframework.dao.DataIntegrityViolationException: StatementCallback; SQL [
SET SESSION cmdbuild.ignore_tenant_policies = ‘true’;
SET SESSION cmdbuild.user_tenants = ‘{}’;

DO $$ BEGIN RAISE NOTICE ‘apply cmdbuild patch %’, ‘core-3.4.0-01ba_scrub_auth_data’; END $$ LANGUAGE PLPGSQL;

– scrub auth data

DO $$ DECLARE
_record record;
_payload jsonb;
_key varchar;
BEGIN
FOR _record IN SELECT * FROM “_Request” WHERE “Path” ~ ‘^/?services/rest/v./(sessions|users(/.+)?|)/?$’ AND “Method” ~ ‘POST|PUT’ AND _cm3_utils_is_not_blank(“Payload”) AND “Payload” ~ ‘[{].+[}]’ LOOP**
_payload = _record.“Payload”::jsonb;
FOR _key IN SELECT k FROM jsonb_object_keys(_payload) k WHERE k ~ ‘^(password|oldpassword|confirmpassword)$’ LOOP*
_payload = _payload || jsonb_build_object(_key, ‘password_removed’);
END LOOP;
UPDATE “_Request” SET “Payload” = _payload WHERE “Id” = _record.“Id”;
END LOOP;
END $$ LANGUAGE PLPGSQL;

UPDATE "Request" SET “Payload” = regexp_replace(“Payload”, ‘(<[^<>][^a-z]Password[^a-z][^<>]>)([^<>]*)’, '\1___password_removed__’, ‘i’)
WHERE “Path” ~ ‘/?services/soap/Private/?’ AND “Method” ~ ‘POST’ AND _cm3_utils_is_not_blank(“Payload”) AND “Payload” ~* ‘<[^<>][^a-z]Password[^a-z][^<>]>[^<>]*<’;**

– patch to strip auth
– CREATE FUNCTION _cm3_aux_strip_auth() RETURNS TRIGGER AS $$ BEGIN
– IF NEW.“Path” ~ ‘/?services/rest/v./sessions/?’ AND NEW.“Method” ~ ‘POST’ AND cm3_utils_is_not_blank(NEW.“Payload”) AND NEW.“Payload” ~ ‘[{].+[}]’ AND cm3_utils_is_not_blank((NEW.“Payload”::jsonb)->>‘password’) THEN**
– NEW.“Payload” = (NEW.“Payload”::jsonb || jsonb_build_object(‘password’, ‘password_removed’))::varchar;
– END IF;
– IF NEW.“Path” ~ ‘/?services/soap/Private/?’ AND NEW.“Method” ~ ‘POST’ AND cm3_utils_is_not_blank(NEW.“Payload”) AND NEW.“Payload” ~* ‘<[^<>][^a-z]Password[^a-z][^<>]>[^<>]<’ THEN**
**-- NEW.“Payload” = regexp_replace(NEW.“Payload”, '(<[^<>]
[^a-z]Password[^a-z][^<>]>)([^<>])’, '\1___password_removed
’, ‘i’);**
– END IF;
– RETURN NEW;
– END $$ LANGUAGE PLPGSQL;

– CREATE TRIGGER _cm3_aux_strip_auth BEFORE INSERT OR UPDATE ON "_Request"
– FOR EACH ROW EXECUTE PROCEDURE _cm3_aux_strip_auth();

DROP TRIGGER IF EXISTS _cm3_aux_strip_auth ON “_Request”;
DROP FUNCTION IF EXISTS _cm3_aux_strip_auth();

DO $$ BEGIN RAISE NOTICE ‘applied cmdbuild patch %’, ‘core-3.4.0-01ba_scrub_auth_data’; END $$ LANGUAGE PLPGSQL;

]; ERROR: invalid input syntax for type json
Detail: Token “username” is invalid.
username…
Where: JSON data, line 1: {
PL/pgSQL function inline_code_block line 7 at assignment; nested exception is org.postgresql.util.PSQLException: ERROR: invalid input syntax for type json
Detail: Token “username” is invalid.
Where: JSON data, line 1: {
username…
PL/pgSQL function inline_code_block line 7 at assignment, caused by: org.postgresql.util.PSQLException: ERROR: invalid input syntax for type json
Detail: Token “username” is invalid.
Where: JSON data, line 1: {
username…
PL/pgSQL function inline_code_block line 7 at assignment

Hi LSVestvold,

I’m having the same error when updating from 3.3 → 3.4 and trying to apply patches, were you able to resolve it?