Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-17941

UserReferenceConverter cannot perform a two-ways conversion UserReference <-> String

    XMLWordPrintable

Details

    • Unit
    • Unknown
    • N/A
    • N/A

    Description

      The UserReferenceConverter relies on the default UserReference#toString method when performing the conversion to String, but the DocumentUserReference#toString implementation doesn't rely on a serializer. So when trying to convert back the computed String to a UserReference it creates a wrong reference.

      Here's a small groovy script to reproduce the bug in a wiki:

      {{groovy}}
      import org.xwiki.user.UserReference;
      import org.xwiki.user.UserReferenceResolver;
      import org.xwiki.component.util.DefaultParameterizedType;
      import javax.inject.Inject;
      import javax.inject.Named;
      import org.xwiki.properties.converter.Converter;
      import org.xwiki.model.reference.DocumentReference;
      
      // Get UserReferenceResolver for the test
      def resolverType = new DefaultParameterizedType(null, UserReferenceResolver.class, DocumentReference.class);
      def userReferenceResolver = services.component.getInstance(resolverType, "document");
      
      // Get a UserReferenceConverter
      def converterType = new DefaultParameterizedType(null, Converter.class, UserReference.class);
      def userReferenceConverter = services.component.getInstance(converterType);
      
      // Resolve first the UserReference for Admin user.
      def adminUser = new DocumentReference("xwiki", "XWiki", "Admin");
      def userReference = userReferenceResolver.resolve(adminUser);
      
      println "Original user reference: " + userReference;
      
      // Convert the reference toString (same as what's done in SolrUtils)
      def convertedReference = userReferenceConverter.convert(String.class, userReference);
      println "Converted reference in string: " + convertedReference;
      
      // Convert back the "serialized" String reference to UserReference
      def resolvedBackReference = userReferenceConverter.convert(UserReference.class, convertedReference);
      println "Obtained user reference: " + resolvedBackReference;
      
      // Check if both references are equals
      def areReferenceEquals = userReference.equals(resolvedBackReference);
      println "Obtained reference is equal to the original reference: " + areReferenceEquals;
      {{/groovy}}
      

      Attachments

        Issue Links

          Activity

            People

              surli Simon Urli
              surli Simon Urli
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: