1

注意与Tridion UGC 评论完全相同的问题将作者显示为空

当发布来自演示网站的评论时,用户的 ID 为 null。这会导致下一条评论显示为来自第一个发表评论并且 ID 为 null 的用户。

cd 核心日志文件显示AnonymousPostClaimProcessor正在使用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.

我的ugc环境墨盒配置如下:

<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>

cm ugc Web 服务的 ugc 墨盒配置是相同的,但会显示正确的 ID。

如果任何人都可以指导我到正确的配置文件进行验证,那就太好了。

编辑 27/7

演示文稿 cd ws 上的 ugc 环境墨盒配置如下,并定义了 AllowAnonymousPostClaimProcessor。

<?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>

以及请求的 POST 日志文件:

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":"bla@bla.com","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.

您可以在某些时候看到用户 ID 为空,在发布评论数据时已经如此。

4

2 回答 2

5

使用用户名客户端和 tridion 端进行验证

下面的代码应该在程序集(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" />
于 2012-08-22T02:27:33.140 回答
3

清理您的浏览器 cookie,然后再次尝试在您的 UGC 演示网站上发表评论。这次填写正确的数据。您看到的行为通常发生在您首先对某事物进行评分并且 UGC 为您创建匿名配置文件时......创建此配置文件后,您只能以编程方式修改生成的用户名('null')。如果这对你有用......很好......如果不是......需要一些调试步骤。

第一步是确保在 UGC 演示站点上正确设置了 ADF。在演示站点上的 ADF 上,您至少需要启用 AllowAnonymousPostClaimProcessor。启用 TRACE 日志记录以检查 UGC 演示站点上是否一切正常。

第二步(不是在完成第一步,清理 cookie 并重试之前)是继续 UGC WS...启用 TRACE 日志记录并检查实际上是 POST 的请求并给我们日志记录。

希望这可以帮助。

PS:您复制/粘贴的日志记录来自 GET 请求....而不是来自实际发出 POST 的请求....您可以通过查看“uri=taf:server”中的“REQUEST_METHOD=GET”来看到这一点:variables”声明。

干杯,丹尼尔。

于 2012-07-27T09:34:07.413 回答