这个主题在社区(论坛,博客文章等)中已经出现了很多次,结论是应该做一个REST Post调用来分享和网址/service/modules/create-site
原因是某些冲浪特定的东西,如站点仪表板,是从共享端创建的。
但是,我一直在从不同的角度尝试这种方法,总是在响应中以HTTP 200结束,并且没有创建共享站点。相当令人沮丧。
我在Alfresco Enterprise 4.2.3.3上运行此操作(我怀疑我的问题是由于最近的更改)
为了将其拆分为易于复制的内容,我正在关注主题(http://www.ixxus.com/blog201203creating-alfresco-share-sites-javascript/)的Martin Bergljungs博客文章,首先使用curl:
使用以下内容创建包含登录凭据(login.txt)的文本文件(更改为适当的值):
username=admin&password=admin
使用json创建一个文本文件来创建一个站点(site_data.json)
{"visibility" : "PUBLIC","title" : "My Test Site","shortName" : "mytestsite",
"description" : "My Test Site created from command line", "sitePreset" : "site-dashboard"}
通过请求票证获取JSESSIONID:
curl -v -d @login.txt -H "Content-Type:application/x-www-form-urlencoded" http://localhost:8081/share/page/dologin
将生成的JSESSIONID值复制到以下curl调用中:
curl -v -d @site_data.json -H "Cookie:JSESSIONID=<insert your jsessionid>" -H "Content-Type:application/json" -H "Accept:application/json" http://localhost:8081/share/service/modules/create-site
卷曲输出:
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8081 (#0)
> POST /share/service/modules/create-site HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8081
> Cookie:JSESSIONID=5963B948684F562A278909AF466D2306
> Content-Type:application/json
> Accept:application/json
> Content-Length: 196
>
* upload completely sent off: 196 out of 196 bytes
< HTTP/1.1 200 OK
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Content-Language: en-US
< Content-Length: 0
< Date: Tue, 02 Dec 2014 13:57:02 GMT
<
* Connection #0 to host localhost left intact
后面的curl调用导致如上所示的HTTP 200,但是登录分享显示没有创建过任何网站:(
顺便说一句。我已禁用CSRF令牌过滤器。
更新: 我已经验证上述方法可以在Alfresco Enterprise 4.1.5上创建一个站点 我已经证实它在Alfresco社区4.2.e上也失败了 这被报告为错误:https://issues.alfresco.com/jira/browse/MNT-11706
更新:由于读者不清楚这个问题,我现在已经重新制定了
更新:
在Dave Websters回答之后,我一直在尝试使用以下步骤,仍然禁用CSRF令牌:
登录:
curl -v -d @login.txt -H "Content-Type:application/x-www-form-urlencoded" http://localhost:8081/share/page/dologin
响应:
POST / share / page / dologin HTTP / 1.1 User-Agent:curl / 7.35.0 主持人:localhost:8081 接受: / 内容类型:应用/ X WWW的窗体-urlencoded 内容长度:29
* upload completely sent off: 29 out of 29 bytes < HTTP/1.1 302 Found * Server Apache-Coyote/1.1 is not blacklisted < Server: Apache-Coyote/1.1 < X-Frame-Options: SAMEORIGIN < X-XSS-Protection: 1; mode=block < X-Content-Type-Options: nosniff < Set-Cookie: JSESSIONID=058A52486E4EB12F94D1F95302732616; Path=/share/; HttpOnly < Set-Cookie: alfLogin=1417618589; Expires=Wed, 10-Dec-2014 14:56:29 GMT; Path=/share < Set-Cookie: alfUsername3=admin; Expires=Wed, 10-Dec-2014 14:56:29 GMT; Path=/share < Location: http://localhost:8081/share < Content-Length: 0 < Date: Wed, 03 Dec 2014 14:56:29 GMT
取出cookie值并插入Daves代码(删除了csrf-stuff):
curl 'http://localhost:8081/share/service/modules/create-site' -H 'Cookie: JSESSIONID=058A52486E4EB12F94D1F95302732616; alfLogin=1417618589; alfUsername3=admin;' -H 'Origin: http://localhost:8081' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: */*' -H 'Referer: http://localhost:8081/share/page/site/erik/dashboard' -H 'X-Requested-With: application/json' -H 'Connection: keep-alive' --data-binary $'{"visibility":"PUBLIC","title":"erik'","shortName":"erik'","description":"This site is auto generated","sitePreset":"site-dashboard"}' --compressed
仍然没有生成共享站点,仍然是HTTP 200响应。日志中也没有错误。这让我疯狂:(
新更新(确实有效!):
我现在发现,在使用帖子调用create-site之前,您需要在进行登录呼叫后“触摸”共享webscript。我通过在两者之间发出get请求来做到这一点。这需要以某种方式来初始化共享会话。
答案 0 :(得分:2)
这是我用来以编程方式生成网站的curl命令。我手动插入JSESSIONID,LOGINCOOKIECONTENTS和CSRFTOKEN(两次)内容,但以编程方式获取它们应该可以正常工作。
curl 'http://localhost:8081/share/service/modules/create-site' -H 'Cookie: JSESSIONID={JSESSIONID}; alfLogin={LOGINCOOKIECONTENTS}; alfUsername3=admin; Alfresco-CSRFToken={CSRFTOKEN};' -H 'Origin: http://localhost:8081' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: */*' -H 'Referer: http://localhost:8081/share/page/site/auto-gen-0/dashboard' -H 'X-Requested-With: application/json' -H 'Connection: keep-alive' -H 'Alfresco-CSRFToken: {CSRFTOKEN}' --data-binary $'{"visibility":"PUBLIC","title":"auto-gen'$I'","shortName":"auto-gen-'$I'","description":"This site is auto generated","sitePreset":"site-dashboard"}' --compressed
预期的回应是:
{
"success": true
}