注意与Tridion UGC comment shows author as null
完全相同的问题从演示网站发布评论时,用户ID保存为null。这会导致下一个评论显示为从评论的第一个用户发布,并且ID为null。
cd core日志文件显示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为空。
答案 0 :(得分: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" />
答案 1 :(得分:3)
清理浏览器Cookie,然后再次尝试在您的UGC演示网站上发表评论。 这次填写正确的数据。你看到的行为通常发生在你首先评价某些东西并且UGC为你创建一个匿名的个人资料时....在创建之后,你可以只通过编程方式修改生成的用户名('null')。如果这适合你...很棒......如果不是......需要一些调试步骤。
您的第一步是确保在UGC演示网站上正确设置ADF。在演示站点上的ADF上,您需要至少启用AllowAnonymousPostClaimProcessor。启用TRACE日志记录以检查UGC演示站点上是否所有内容都正常。
第二步(不是在完成第一步之前,清除cookie并重试)是继续使用UGC WS ...启用TRACE日志记录并检查实际上是POST的请求并给我们记录。
希望这有帮助。
PS:您复制/粘贴的日志记录来自GET请求....而不是来自实际进行POST的请求....您可以通过查看“uQU =”中的“REQUEST_METHOD = GET”来看到这一点taf:server:变量“claim。
干杯, 丹尼尔。