Tridion UGC Anonymous Users saved to UGC Database with ID null

454 Views Asked by At

NOTE Exact same issue as Tridion UGC comment shows author as null

When posting comments from the presentation website users are saved with ID null. This causes the next comment to show as posted from the first user who commented and also has ID null.

The cd core log file shows that the AnonymousPostClaimProcessor is using the tracking id.

DEBUG ClaimStore - put: uri=taf:claim:contentdelivery:webservice:user, value=tridion_2151731a-97d2-4a90-800f-bee20074b970
TRACE ODataInputParser - Parsing following queryString: /Comments
TRACE BasePostClaimProcessor - User ID: tridion_2151731a-97d2-4a90-800f-bee20074b970, Request URI: /odata.svc/Comments
DEBUG PostAllowedByEveryoneClaimProcessor - Allowing user 'tridion_2151731a-97d2-4a90-800f-bee20074b970' to post on: /odata.svc/Comments
DEBUG ClaimStore - put: uri=taf:claim:contentdelivery:webservice:post:allowed, value=true
DEBUG ClaimStore - put: uri=taf:response:cookie:generation, value=true
DEBUG WebContext - setCurrentClaimStore: com.tridion.ambientdata.dotnet.DotNetClaimStore@74002515, thread: Thread-1
DEBUG ClaimStore - put: uri=taf:request:uri, value=/odata.svc/Comments
DEBUG ClaimStore - put: uri=taf:request:full_url, value=http://staging:8080/odata.svc/Comments
DEBUG ClaimStore - put: uri=taf:request:headers, value={content-type=[Ljava.lang.String;@3582c132, connection=[Ljava.lang.String;@1b59d510, host=[Ljava.lang.String;@26b31b77, accept=[Ljava.lang.String;@38d0357a, content-length=[Ljava.lang.String;@6d66f9b9}
DEBUG ClaimStore - put: uri=taf:request:cookies, value={}
DEBUG ClaimStore - put: uri=taf:request:parameters, value={CONTENT_TYPE=[Ljava.lang.String;@39518cc, $orderby=[Ljava.lang.String;@318efaea, QUERY_STRING=[Ljava.lang.String;@21fb3211, $filter=[Ljava.lang.String;@72940b84, $expand=[Ljava.lang.String;@558041e0, $top=[Ljava.lang.String;@576504fa, $skip=[Ljava.lang.String;@2929e5e9}
DEBUG ClaimStore - put: uri=taf:server:variables, value={REMOTE_USER=, PATH_TRANSLATED=C:\inetpub\staging_cd_webservices\odata.svc, SERVER_PORT=8080, SCRIPT_NAME=/odata.svc, REMOTE_ADDR=127.0.0.1, AUTH_TYPE=, SERVER_PROTOCOL=HTTP/1.1, REQUEST_METHOD=GET, DOCUMENT_ROOT=C:\inetpub\staging_cd_webservices, REMOTE_HOST=127.0.0.1, SERVER_NAME=staging, SECURE=false}
DEBUG ClaimStore - put: uri=taf:session:id, value=tridion_546acbc8-a478-45cd-80fa-5d93bc10481d
DEBUG ClaimStore - put: uri=taf:tracking:id, value=tridion_08092308-7e3b-47c7-9524-79497daee2e2
DEBUG ClaimStore - put: uri=taf:session:attributes, value={Tridion.ContentDelivery.AmbientData.ClaimStore=Tridion.ContentDelivery.AmbientData.ClaimStore}
DEBUG AllowAnonymousPostClaimProcessor - No external user specified, using tracking id.

My ugc ambient cartridge is configured as follows:

<ClaimProcessorDefinitions>
    <!-- Allows anonymous posts. Disable when using a login system. -->
    <ClaimProcessorDefinition Uri="taf:claimprocessor:webservice:ugc:anonymous"
                              ImplementationClass="com.tridion.ugc.odata.claimprocessor.AllowAnonymousPostClaimProcessor"
                              Description="Claim processor that allows an anonymous post.">
        <RequestStart>
            <OutputClaims>
                <ClaimDefinition Uri="taf:claim:contentdelivery:webservice:user"/>
            </OutputClaims>
        </RequestStart>
    </ClaimProcessorDefinition>
    <!-- Post allowed by everyone. -->
    <ClaimProcessorDefinition Uri="taf:claimprocessor:webservice:ugc:post"
                              ImplementationClass="com.tridion.ugc.odata.claimprocessor.PostAllowedByEveryoneClaimProcessor"
                              Description="Claim processor that allows a post.">
        <RequestStart>
            <InputClaims>
                <ClaimDefinition Uri="taf:claim:contentdelivery:webservice:user"/>
            </InputClaims>
            <OutputClaims>
                <ClaimDefinition Uri="taf:claim:contentdelivery:webservice:post:allowed"/>
            </OutputClaims>
        </RequestStart>
    </ClaimProcessorDefinition>
</ClaimProcessorDefinitions>

The ugc cartridge configuration for the cm ugc web service is the same, but does show the right ID.

It would be great when anyone can direct me to the right configuration files to verify.

EDIT 27/7

The ugc ambient cartridge configuration on the presentation cd ws is as follows, and has the AllowAnonymousPostClaimProcessor defined.

<?xml version="1.0" encoding="UTF-8"?>
<CartridgeDefinition Version="6.1" Uri="tcd:cartridge:ugc" Description="UGC cartridge."
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:noNamespaceSchemaLocation="schemas/cd_ambient_cartridge_conf.xsd">
    <ClaimDefinitions>
        <ClaimDefinition Uri="taf:claim:contentdelivery:webservice:post:allowed" Scope="REQUEST"
                         Description="A flag where a POST is allowed to the UGC OData entities."/>
        <ClaimDefinition Uri="taf:claim:contentdelivery:webservice:user" Scope="REQUEST"
                         Description="The user posting to the OData service."/>
        <ClaimDefinition Uri="taf:claim:tracking:internalcontactid" Scope="REQUEST"
                         Description="The Audience Manager internal contact id."/>
        <ClaimDefinition Uri="taf:claim:tracking:updatedcontact:xml" Scope="REQUEST"
                         Description="The Audience Manager updated contact xml."/>
    </ClaimDefinitions>

    <ClaimProcessorDefinitions>
        <!-- Allows anonymous posts. Disable when using a login system. -->
        <ClaimProcessorDefinition Uri="taf:claimprocessor:webservice:ugc:anonymous"
                                  ImplementationClass="com.tridion.ugc.odata.claimprocessor.AllowAnonymousPostClaimProcessor"
                                  Description="Claim processor that allows an anonymous post.">
            <RequestStart>
                <OutputClaims>
                    <ClaimDefinition Uri="taf:claim:contentdelivery:webservice:user"/>
                </OutputClaims>
            </RequestStart>
        </ClaimProcessorDefinition>

        <!-- Post allowed by owners. -->
        <!--
        <ClaimProcessorDefinition Uri="taf:claimprocessor:webservice:ugc:post"
                                  ImplementationClass="com.tridion.ugc.odata.claimprocessor.PostAllowedByOwnerClaimProcessor"
                                  Description="Claim processor that determines if a post is allowed by checking if the user is the owner.">
            <RequestStart>
                <InputClaims>
                    <ClaimDefinition Uri="taf:claim:contentdelivery:webservice:user"/>
                </InputClaims>
                <OutputClaims>
                    <ClaimDefinition Uri="taf:claim:contentdelivery:webservice:post:allowed"/>
                </OutputClaims>
            </RequestStart>
        </ClaimProcessorDefinition>
        -->

        <!-- Post allowed by everyone. -->
        <ClaimProcessorDefinition Uri="taf:claimprocessor:webservice:ugc:post"
                                  ImplementationClass="com.tridion.ugc.odata.claimprocessor.PostAllowedByEveryoneClaimProcessor"
                                  Description="Claim processor that allows a post.">
            <RequestStart>
                <InputClaims>
                    <ClaimDefinition Uri="taf:claim:contentdelivery:webservice:user"/>
                </InputClaims>
                <OutputClaims>
                    <ClaimDefinition Uri="taf:claim:contentdelivery:webservice:post:allowed"/>
                </OutputClaims>
            </RequestStart>
        </ClaimProcessorDefinition>
    </ClaimProcessorDefinitions>
</CartridgeDefinition>

And the POST log file as requested:

DEBUG ClaimStore - put: uri=taf:response:cookie:generation, value=true
DEBUG WebContext - setCurrentClaimStore: com.tridion.ambientdata.dotnet.DotNetClaimStore@29578426, thread: Thread-6
DEBUG ClaimStore - put: uri=taf:request:uri, value=/odata.svc/Comments
DEBUG ClaimStore - put: uri=taf:request:full_url, value=http://staging:8080/odata.svc/Comments
DEBUG ClaimStore - put: uri=taf:request:headers, value={expect=[Ljava.lang.String;@30a4effe, content-type=[Ljava.lang.String;@1c8825a5, host=[Ljava.lang.String;@2e5f8245, accept=[Ljava.lang.String;@6197cc, content-length=[Ljava.lang.String;@734d246}
DEBUG ClaimStore - put: uri=taf:request:cookies, value={}
DEBUG ClaimStore - put: uri=taf:request:parameters, value={CONTENT_TYPE=[Ljava.lang.String;@1cd8f55c, QUERY_STRING=[Ljava.lang.String;@67d479cf}
DEBUG ClaimStore - put: uri=taf:server:variables, value={REMOTE_USER=, PATH_TRANSLATED=C:\inetpub\staging_cd_webservices\odata.svc\Comments, SERVER_PORT=8080, SCRIPT_NAME=/odata.svc/Comments, REMOTE_ADDR=127.0.0.1, AUTH_TYPE=, SERVER_PROTOCOL=HTTP/1.1, REQUEST_METHOD=POST, DOCUMENT_ROOT=C:\inetpub\staging_cd_webservices, REMOTE_HOST=127.0.0.1, SERVER_NAME=staging, SECURE=false}
DEBUG ClaimStore - put: uri=taf:session:id, value=tridion_51f52143-1095-4585-9eb8-b01f95dff721
DEBUG ClaimStore - put: uri=taf:tracking:id, value=tridion_f409708f-4063-4eca-8c81-f140ba4a6568
DEBUG AllowAnonymousPostClaimProcessor - No external user specified, using tracking id.
DEBUG ClaimStore - put: uri=taf:claim:contentdelivery:webservice:user, value=tridion_f409708f-4063-4eca-8c81-f140ba4a6568
TRACE ODataInputParser - Parsing following queryString: /Comments
TRACE BasePostClaimProcessor - User ID: tridion_f409708f-4063-4eca-8c81-f140ba4a6568, Request URI: /odata.svc/Comments
DEBUG PostAllowedByEveryoneClaimProcessor - Allowing user 'tridion_f409708f-4063-4eca-8c81-f140ba4a6568' to post on: /odata.svc/Comments
DEBUG ClaimStore - put: uri=taf:claim:contentdelivery:webservice:post:allowed, value=true
DEBUG ClaimStore - put: uri=taf:response:cookie:generation, value=true
DEBUG WebContext - setCurrentClaimStore: com.tridion.ambientdata.dotnet.DotNetClaimStore@2e893a4a, thread: Thread-6
DEBUG ClaimStore - put: uri=taf:request:uri, value=/odata.svc/Comments
DEBUG ClaimStore - put: uri=taf:request:full_url, value=http://staging:8080/odata.svc/Comments
DEBUG ClaimStore - put: uri=taf:request:headers, value={expect=[Ljava.lang.String;@3351e824, content-type=[Ljava.lang.String;@465fadce, host=[Ljava.lang.String;@338bd37a, accept=[Ljava.lang.String;@20e90906, content-length=[Ljava.lang.String;@234f79cb}
DEBUG ClaimStore - put: uri=taf:request:cookies, value={ASP.NET_SessionId=wx00dumyccjnopshos2ucw4l}
DEBUG ClaimStore - put: uri=taf:request:parameters, value={CONTENT_TYPE=[Ljava.lang.String;@36c51089, QUERY_STRING=[Ljava.lang.String;@43c0ae76}
DEBUG ClaimStore - put: uri=taf:server:variables, value={REMOTE_USER=, PATH_TRANSLATED=C:\inetpub\staging_cd_webservices\odata.svc, SERVER_PORT=8080, SCRIPT_NAME=/odata.svc, REMOTE_ADDR=127.0.0.1, AUTH_TYPE=, SERVER_PROTOCOL=HTTP/1.1, REQUEST_METHOD=POST, DOCUMENT_ROOT=C:\inetpub\staging_cd_webservices, REMOTE_HOST=127.0.0.1, SERVER_NAME=staging, SECURE=false}
DEBUG ClaimStore - put: uri=taf:session:id, value=tridion_90269b03-0f48-4986-a607-ec04010a9161
DEBUG ClaimStore - put: uri=taf:tracking:id, value=tridion_9a97ffcb-7c38-41b6-95dd-8bd6d564a163
DEBUG ClaimStore - put: uri=taf:session:attributes, value={Tridion.ContentDelivery.AmbientData.ClaimStore=Tridion.ContentDelivery.AmbientData.ClaimStore}
DEBUG AllowAnonymousPostClaimProcessor - No external user specified, using tracking id.
DEBUG ClaimStore - put: uri=taf:claim:contentdelivery:webservice:user, value=tridion_9a97ffcb-7c38-41b6-95dd-8bd6d564a163
TRACE ODataInputParser - Parsing following queryString: /Comments
TRACE BasePostClaimProcessor - User ID: tridion_9a97ffcb-7c38-41b6-95dd-8bd6d564a163, Request URI: /odata.svc/Comments
DEBUG PostAllowedByEveryoneClaimProcessor - Allowing user 'tridion_9a97ffcb-7c38-41b6-95dd-8bd6d564a163' to post on: /odata.svc/Comments
DEBUG ClaimStore - put: uri=taf:claim:contentdelivery:webservice:post:allowed, value=true
DEBUG ODataService - ODATA.NET: Inserting entity on path: Comments
DEBUG WebContext - setCurrentClaimStore: com.tridion.ambientdata.dotnet.DotNetClaimStore@2e893a4a, thread: Thread-2
TRACE ODataInputParser - Parsing following queryString: Comments
DEBUG WritableCommentEntryService - Parsing comment: {d:{"Id":0,"ItemPublicationId":11,"ItemId":361,"ItemType":64,"CreationDate":"\/Date(1343385654263+60)\/","LastModifiedDate":"\/Date(1343385654263+60)\/","User":{"Id":null,"Name":"John Doe","EmailAddress":"[email protected]","ExternalId":null},"Content":"sdfsdfsdf","Moderator":null,"ModeratedDate":null,"Score":0,"Status":0}}.
DEBUG UGCConfigurationLoader - Attempt loading default storage configuration file
DEBUG WritableCommentEntryService - Storing comment: Comment [commentId=0, content=sdfsdfsdf, itemPublicationId=11, itemId=361, itemType=64, author=com.tridion.storage.ugc.UGCUser@2537e19e, creationDate=Fri Jul 27 11:40:54 BST 2012, lastModifiedDate=Fri Jul 27 11:40:54 BST 2012, moderatedDate=null, moderator=null, score=0, status=0].
DEBUG JPACommentDAO - Add comment to storage: Comment [commentId=0, content=sdfsdfsdf, itemPublicationId=11, itemId=361, itemType=64, author=com.tridion.storage.ugc.UGCUser@2537e19e, creationDate=Fri Jul 27 11:40:54 BST 2012, lastModifiedDate=Fri Jul 27 11:40:54 BST 2012, moderatedDate=null, moderator=null, score=0, status=0].
DEBUG JPAUserDAO - Searching for user with id null in storage.
TRACE JPABaseDAO - [ActionTimer] Query List Result time: 10275376 nanoseconds (10.275376 milliseconds)
DEBUG JPAUserDAO - User already in storage. No need to create new one.

You can see at some point that the User Id is null, already when the Comment Data is posted.

2

There are 2 best solutions below

1
On

Clean your browser cookies and then try again to post a comment on your UGC presentation site. This time fill in right data. The behavior you're seeing usually happens when you rate something first and UGC creates an Anonymous profile for you....after this is created, you can modify the generated username ('null') only programmatically. If this works for you...great...if not...some debugging steps are needed.

Your first step is to make sure you have ADF correctly set-up on your UGC presentation site. On the ADF on the presentation site you need to have enabled at least AllowAnonymousPostClaimProcessor. Enable TRACE logging to check if all are going all right on the UGC presentation site.

Second step (not before finishing with the first one, cleaning cookies and retrying) is to move on the UGC WS...enable the TRACE logging and check the request which is actually a POST and give us the logging.

Hope this helps.

P.S.: the logging you copy/pasted is from a GET request....not from the request which is actually making the POST....you can see this by looking at "REQUEST_METHOD=GET" from "uri=taf:server:variables" claim.

Cheers, Daniel.

0
On

put the validation with username client side and tridion side

below code should be in assembly(dll)

Tridion side :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Tridion.ContentDelivery.UGC.WebService;
using Tridion.ContentDelivery.UGC.Web.Model;
using Tridion.ContentDelivery.UGC.Web.Utilities;
using Tridion.ContentDelivery.AmbientData;
using System.Configuration;

namespace PresentationLayer
{
        public class UGCWordsSpamFilter : SpamFilter
    {
        // Collect a list of disallowed words

        IList<string> spamWords = new List<string>();

        public UGCWordsSpamFilter()
        {
            bool hasExcludes = true;
            int i = 1;
            while (hasExcludes)
            {
                string spamFilterWord = ConfigurationSettings.AppSettings["Comment.SpamFilter.Exclude" + i];
                if (!string.IsNullOrEmpty(spamFilterWord))
                {
                    spamWords.Add(spamFilterWord);
                }
                else
                {
                    hasExcludes = false;
                }
                i++;
            }
        }

        /// <summary>
        /// Validate a comment.
        /// </summary>
        /// <param name="claimStore">The Claim Store from the current request.</param>
        /// <param name="comment">The comment to validate.</param>
        /// <returns>A valid comment.</returns>
        /// <exception cref="SpamFilterException">If comment is regarded as spam.</exception>
        public Comment ValidateComment(ClaimStore claimStore, Comment comment)
        {
            string commentContent = comment.Content;
            string userName = comment.User.Name;
            string emailAddress = comment.User.EmailAddress;
            if (String.IsNullOrEmpty(commentContent))
            {
                throw new SpamFilterException("Comment cannot be empty.");
            }
            else if (String.IsNullOrEmpty(userName))
            {
                throw new SpamFilterException("Username cannot be empty.");
            }
            else if (String.IsNullOrEmpty(emailAddress))
            {
                throw new SpamFilterException("User email address cannot be empty.");
            }
            else if (!CheckEmail(emailAddress))
            {
                throw new SpamFilterException("User email address is wrong.");
            }
            else
            {
                foreach (string spamWord in spamWords)
                {
                    if (commentContent.Contains(spamWord))
                    {
                        throw new SpamFilterException("Comment rejected: contains the word '" + spamWord + "'");
                    }
                }
                // The comment contains none of the configured words, so it is acceptable.

                return comment;
            }
        }

        private bool CheckEmail(string emailAddress)
        {
            string strPattern = "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";
            if (Regex.IsMatch(emailAddress, strPattern))
            {
                return true;
            }
            return false;
        }

    }
}

Add some keys in web config
<add key="Comment.SpamFilter.Assembly" value="PresentationLayer" />
    <add key="Comment.SpamFilter.Implementation" value="PresentationLayer.UGCWordsSpamFilter" />
<add key="Comment.SpamFilter.Exclude1" value="poker" />