mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Publishing: added authorisation framework for channel types. Migrated YouTube channel type onto it, and added Twitter and SlideShare channel types. Facebook is also added, but there is an issue with the way it authorises apps, so it isn't wired in yet.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28910 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Authorisation Callback</shortname>
|
||||||
|
<description><![CDATA[
|
||||||
|
Used to receive authorisation callbacks from publishing service providers
|
||||||
|
]]></description>
|
||||||
|
<description></description>
|
||||||
|
<url>/api/publishing/channel/{store_protocol}/{store_id}/{node_id}/authcallback</url>
|
||||||
|
<format default="json"/>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>public_api</lifecycle>
|
||||||
|
<args>
|
||||||
|
<arg>
|
||||||
|
<shortname>store_protocol</shortname>
|
||||||
|
<description>The protocol of the store in which the relevant publishing channel lives.</description>
|
||||||
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<shortname>store_id</shortname>
|
||||||
|
<description>The identifier of the store in which the relevant publishing channel lives.</description>
|
||||||
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<shortname>node_id</shortname>
|
||||||
|
<description>The identifier of the node that represents the relevant publishing channel.</description>
|
||||||
|
</arg>
|
||||||
|
</args>
|
||||||
|
</webscript>
|
@@ -0,0 +1,25 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Channel Authorisation Form</shortname>
|
||||||
|
<description><![CDATA[
|
||||||
|
Used to obtain a form to provide credentials to publish to a channel.
|
||||||
|
]]></description>
|
||||||
|
<url>/api/publishing/channel/{store_protocol}/{store_id}/{node_id}/authform</url>
|
||||||
|
<format default="html"/>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>public_api</lifecycle>
|
||||||
|
<args>
|
||||||
|
<arg>
|
||||||
|
<shortname>store_protocol</shortname>
|
||||||
|
<description>The protocol of the store in which the relevant publishing channel lives.</description>
|
||||||
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<shortname>store_id</shortname>
|
||||||
|
<description>The identifier of the store in which the relevant publishing channel lives.</description>
|
||||||
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<shortname>node_id</shortname>
|
||||||
|
<description>The identifier of the node that represents the relevant publishing channel.</description>
|
||||||
|
</arg>
|
||||||
|
</args>
|
||||||
|
</webscript>
|
@@ -0,0 +1,23 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<form id="loginform" action="#" method="post" accept-charset="UTF-8">
|
||||||
|
<fieldset>
|
||||||
|
<div style="padding-top:96px">
|
||||||
|
<label id="txt-username" for="username">User Name:</label>
|
||||||
|
</div>
|
||||||
|
<div style="padding-top:4px">
|
||||||
|
<input id="username" type="text" value="admin" style="width:200px" maxlength="255" name="username">
|
||||||
|
</div>
|
||||||
|
<div style="padding-top:12px">
|
||||||
|
<label id="txt-password" for="password">Password:</label>
|
||||||
|
</div>
|
||||||
|
<div style="padding-top:4px">
|
||||||
|
<input id="password" type="password" style="width:200px" maxlength="255" name="password">
|
||||||
|
</div>
|
||||||
|
<div style="padding-top:16px">
|
||||||
|
<input id="btn-login" class="login-button" type="submit" value="Login">
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
@@ -0,0 +1,25 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Channel Authorisation Form</shortname>
|
||||||
|
<description><![CDATA[
|
||||||
|
Used to post back credentials to publish to a channel.
|
||||||
|
]]></description>
|
||||||
|
<url>/api/publishing/channel/{store_protocol}/{store_id}/{node_id}/authform</url>
|
||||||
|
<format default="html"/>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>public_api</lifecycle>
|
||||||
|
<args>
|
||||||
|
<arg>
|
||||||
|
<shortname>store_protocol</shortname>
|
||||||
|
<description>The protocol of the store in which the relevant publishing channel lives.</description>
|
||||||
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<shortname>store_id</shortname>
|
||||||
|
<description>The identifier of the store in which the relevant publishing channel lives.</description>
|
||||||
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<shortname>node_id</shortname>
|
||||||
|
<description>The identifier of the node that represents the relevant publishing channel.</description>
|
||||||
|
</arg>
|
||||||
|
</args>
|
||||||
|
</webscript>
|
@@ -0,0 +1,48 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Authorisation status check for a new publishing channel</shortname>
|
||||||
|
<description><![CDATA[
|
||||||
|
Used to check whether a specified publishing channel has been authorised by the target
|
||||||
|
service provider. The returned "authStatus" value is one of:
|
||||||
|
<ul>
|
||||||
|
<li>PENDING - we haven't finished the necessary exchanges with the service provider yet.</li>
|
||||||
|
<li>REJECTED - our request to authorise the channel has been rejected. The channel creation has failed.</li>
|
||||||
|
<li>AUTHORISED - the channel has been authorised and is now ready to be used.</li>
|
||||||
|
</ul>
|
||||||
|
]]></description>
|
||||||
|
<description></description>
|
||||||
|
<url>/api/publishing/channel/{store_protocol}/{store_id}/{node_id}/authstatus</url>
|
||||||
|
<format default="json"/>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>public_api</lifecycle>
|
||||||
|
<args>
|
||||||
|
<arg>
|
||||||
|
<shortname>store_protocol</shortname>
|
||||||
|
<description>The protocol of the store in which the relevant publishing channel lives.</description>
|
||||||
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<shortname>store_id</shortname>
|
||||||
|
<description>The identifier of the store in which the relevant publishing channel lives.</description>
|
||||||
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<shortname>node_id</shortname>
|
||||||
|
<description>The identifier of the node that represents the relevant publishing channel.</description>
|
||||||
|
</arg>
|
||||||
|
</args>
|
||||||
|
<responses>
|
||||||
|
<response>
|
||||||
|
<format>json</format>
|
||||||
|
<type>
|
||||||
|
<![CDATA[
|
||||||
|
{
|
||||||
|
"data":
|
||||||
|
{
|
||||||
|
"channelId": string,
|
||||||
|
"authStatus": string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</type>
|
||||||
|
</response>
|
||||||
|
</responses>
|
||||||
|
</webscript>
|
@@ -0,0 +1,10 @@
|
|||||||
|
<#-- Response to a request to check the authorisation status of a publishing channel -->
|
||||||
|
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||||
|
{
|
||||||
|
"data":
|
||||||
|
{
|
||||||
|
"channelId" : "${channelId}",
|
||||||
|
"authStatus": "${authStatus}",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</#escape>
|
@@ -0,0 +1,57 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Create a publishing channel</shortname>
|
||||||
|
<description><![CDATA[
|
||||||
|
Create a new publishing channel using the supplied information.
|
||||||
|
<br />
|
||||||
|
<dl>
|
||||||
|
<dt>channelType</dt><dd>mandatory - the type of delivery channel to create</dd>
|
||||||
|
<dt>siteId</dt> <dd>mandatory - the Share site with which the new delivery channel is to be associated</dd>
|
||||||
|
<dt>channelName</dt> <dd>mandatory - the name of the new delivery channel</dd>
|
||||||
|
</dl>
|
||||||
|
Returns three pieces of informtation:
|
||||||
|
<br />
|
||||||
|
<dl>
|
||||||
|
<dt>channelId</dt><dd>the identifier of the new publishing channel</dd>
|
||||||
|
<dt>pollUrl</dt> <dd>The URL to poll to discover whether the channel has been authorised</dd>
|
||||||
|
<dt>authoriseUrl</dt> <dd>The URL to send the user to in order for them to authorise access to the channel</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
]]></description>
|
||||||
|
<description></description>
|
||||||
|
<url>/api/publishing/channel</url>
|
||||||
|
<format default="json"/>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>public_api</lifecycle>
|
||||||
|
<args>
|
||||||
|
<arg>
|
||||||
|
<shortname>siteId</shortname>
|
||||||
|
<description>The id of the site to create a delivery channel on.</description>
|
||||||
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<shortname>channelType</shortname>
|
||||||
|
<description>The identifier of the type of delivery channel to create.</description>
|
||||||
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<shortname>channelName</shortname>
|
||||||
|
<description>The name of the channel that is to be created.</description>
|
||||||
|
</arg>
|
||||||
|
</args>
|
||||||
|
<responses>
|
||||||
|
<response>
|
||||||
|
<format>json</format>
|
||||||
|
<type>
|
||||||
|
<![CDATA[
|
||||||
|
{
|
||||||
|
"data":
|
||||||
|
{
|
||||||
|
"channelId": string,
|
||||||
|
"pollUrl": string,
|
||||||
|
"authoriseUrl": string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</type>
|
||||||
|
</response>
|
||||||
|
</responses>
|
||||||
|
</webscript>
|
@@ -0,0 +1,11 @@
|
|||||||
|
<#-- Response to a request to create a publishing channel -->
|
||||||
|
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||||
|
{
|
||||||
|
"data":
|
||||||
|
{
|
||||||
|
"channelId" : "${channelId}",
|
||||||
|
"pollUrl": "${pollUrl}",
|
||||||
|
"authoriseUrl": "${authoriseUrl}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</#escape>
|
@@ -1118,6 +1118,33 @@
|
|||||||
<property name="defaultEnvironmentId" value="${publishing.default.environment}" />
|
<property name="defaultEnvironmentId" value="${publishing.default.environment}" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="webscript.org.alfresco.repository.publishing.channel.post"
|
||||||
|
class="org.alfresco.repo.web.scripts.publishing.ChannelPostWebScript"
|
||||||
|
parent="webscript">
|
||||||
|
<property name="channelService" ref="channelService" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="webscript.org.alfresco.repository.publishing.authcallback.get"
|
||||||
|
class="org.alfresco.repo.web.scripts.publishing.AuthCallbackWebScript"
|
||||||
|
parent="webscript">
|
||||||
|
<property name="nodeService" ref="NodeService" />
|
||||||
|
<property name="channelService" ref="channelService" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="webscript.org.alfresco.repository.publishing.authstatus.get"
|
||||||
|
class="org.alfresco.repo.web.scripts.publishing.AuthStatusGetWebScript"
|
||||||
|
parent="webscript">
|
||||||
|
<property name="nodeService" ref="NodeService" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="webscript.org.alfresco.repository.publishing.authform.post"
|
||||||
|
class="org.alfresco.repo.web.scripts.publishing.AuthCallbackWebScript"
|
||||||
|
parent="webscript">
|
||||||
|
<property name="nodeService" ref="NodeService" />
|
||||||
|
<property name="channelService" ref="channelService" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
<!-- Post Publishing Events Query web script -->
|
<!-- Post Publishing Events Query web script -->
|
||||||
<bean id="webscript.org.alfresco.repository.publishing.publishing-events-query.post"
|
<bean id="webscript.org.alfresco.repository.publishing.publishing-events-query.post"
|
||||||
class="org.alfresco.repo.web.scripts.publishing.PUblishingEventsQueryPost"
|
class="org.alfresco.repo.web.scripts.publishing.PUblishingEventsQueryPost"
|
||||||
@@ -1432,7 +1459,7 @@
|
|||||||
parent="webscript">
|
parent="webscript">
|
||||||
<property name="nodeLocatorService" ref="nodeLocatorService"/>
|
<property name="nodeLocatorService" ref="nodeLocatorService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- Google Doc API -->
|
<!-- Google Doc API -->
|
||||||
<bean id="webscript.org.alfresco.repository.googledocs.status.get"
|
<bean id="webscript.org.alfresco.repository.googledocs.status.get"
|
||||||
class="org.alfresco.repo.web.scripts.googledocs.Status"
|
class="org.alfresco.repo.web.scripts.googledocs.Status"
|
||||||
@@ -1478,4 +1505,4 @@
|
|||||||
parent="abstractCalendarWebScript">
|
parent="abstractCalendarWebScript">
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.repo.web.scripts.publishing;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import org.alfresco.repo.publishing.PublishingModel;
|
||||||
|
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||||
|
import org.alfresco.service.cmr.publishing.channels.ChannelService;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.springframework.extensions.webscripts.AbstractWebScript;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||||
|
|
||||||
|
public class AuthCallbackWebScript extends AbstractWebScript
|
||||||
|
{
|
||||||
|
private final static Log log = LogFactory.getLog(AuthCallbackWebScript.class);
|
||||||
|
private NodeService nodeService;
|
||||||
|
private ChannelService channelService;
|
||||||
|
|
||||||
|
public void setNodeService(NodeService nodeService)
|
||||||
|
{
|
||||||
|
this.nodeService = nodeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChannelService(ChannelService channelService)
|
||||||
|
{
|
||||||
|
this.channelService = channelService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
|
||||||
|
{
|
||||||
|
res.setContentType("text/html");
|
||||||
|
res.setContentEncoding("UTF-8");
|
||||||
|
|
||||||
|
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||||
|
Map<String,String[]> params = new TreeMap<String, String[]>();
|
||||||
|
Map<String,String[]> headers = new TreeMap<String, String[]>();
|
||||||
|
|
||||||
|
for (String paramName : req.getParameterNames())
|
||||||
|
{
|
||||||
|
params.put(paramName, req.getParameterValues(paramName));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String header : req.getHeaderNames())
|
||||||
|
{
|
||||||
|
headers.put(header, req.getHeaderValues(header));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (log.isDebugEnabled())
|
||||||
|
{
|
||||||
|
log.debug("templateVars = " + templateVars);
|
||||||
|
log.debug("params = " + params);
|
||||||
|
log.debug("headers = " + headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
String channelNodeUuid = templateVars.get("node_id");
|
||||||
|
String channelNodeStoreProtocol = templateVars.get("store_protocol");
|
||||||
|
String channelNodeStoreId = templateVars.get("store_id");
|
||||||
|
|
||||||
|
NodeRef channelNodeRef = new NodeRef(channelNodeStoreProtocol, channelNodeStoreId, channelNodeUuid);
|
||||||
|
Channel channel = channelService.getChannel(channelNodeRef.toString());
|
||||||
|
|
||||||
|
if (channel.getChannelType().acceptAuthorisationCallback(channel, headers, params))
|
||||||
|
{
|
||||||
|
nodeService.setProperty(channelNodeRef, PublishingModel.PROP_AUTHORISATION_COMPLETE, Boolean.TRUE);
|
||||||
|
res.getWriter().write("Authorisation granted!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Boolean authorised = (Boolean)nodeService.getProperty(channelNodeRef, PublishingModel.PROP_AUTHORISATION_COMPLETE);
|
||||||
|
if (authorised != null && !authorised)
|
||||||
|
{
|
||||||
|
//If we have not been granted access by the service provider then we
|
||||||
|
//simply delete this publishing channel
|
||||||
|
nodeService.deleteNode(channelNodeRef);
|
||||||
|
}
|
||||||
|
res.getWriter().write("Authorisation denied!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.repo.web.scripts.publishing;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import org.alfresco.repo.publishing.PublishingModel;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
|
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||||
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
|
||||||
|
public class AuthStatusGetWebScript extends DeclarativeWebScript
|
||||||
|
{
|
||||||
|
private NodeService nodeService;
|
||||||
|
|
||||||
|
public void setNodeService(NodeService nodeService)
|
||||||
|
{
|
||||||
|
this.nodeService = nodeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||||
|
{
|
||||||
|
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||||
|
String channelNodeUuid = templateVars.get("node_id");
|
||||||
|
String channelNodeStoreProtocol = templateVars.get("store_protocol");
|
||||||
|
String channelNodeStoreId = templateVars.get("store_id");
|
||||||
|
|
||||||
|
String authStatus = "REJECTED";
|
||||||
|
NodeRef channelNodeRef = new NodeRef(channelNodeStoreProtocol, channelNodeStoreId, channelNodeUuid);
|
||||||
|
if (nodeService.exists(channelNodeRef))
|
||||||
|
{
|
||||||
|
Boolean authComplete = (Boolean)nodeService.getProperty(channelNodeRef, PublishingModel.PROP_AUTHORISATION_COMPLETE);
|
||||||
|
if (authComplete)
|
||||||
|
{
|
||||||
|
authStatus = "AUTHORISED";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
authStatus = "PENDING";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map<String,Object> model = new TreeMap<String, Object>();
|
||||||
|
model.put("channelId", channelNodeRef.toString());
|
||||||
|
model.put("authStatus", authStatus);
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.repo.web.scripts.publishing;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||||
|
import org.alfresco.service.cmr.publishing.channels.ChannelService;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
|
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||||
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
|
||||||
|
public class ChannelPostWebScript extends DeclarativeWebScript
|
||||||
|
{
|
||||||
|
private ChannelService channelService;
|
||||||
|
|
||||||
|
public void setChannelService(ChannelService channelService)
|
||||||
|
{
|
||||||
|
this.channelService = channelService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||||
|
{
|
||||||
|
String channelType = req.getParameter("channelType");
|
||||||
|
String siteId = req.getParameter("siteId");
|
||||||
|
String channelName = req.getParameter("channelName");
|
||||||
|
|
||||||
|
Channel newChannel = channelService.createChannel(siteId, channelType, channelName, null);
|
||||||
|
|
||||||
|
NodeRef channelNodeRef = newChannel.getNodeRef();
|
||||||
|
StringBuilder urlBuilder = new StringBuilder(req.getServerPath());
|
||||||
|
urlBuilder.append(req.getServiceContextPath());
|
||||||
|
urlBuilder.append("/api/publishing/channel/");
|
||||||
|
urlBuilder.append(channelNodeRef.getStoreRef().getProtocol());
|
||||||
|
urlBuilder.append('/');
|
||||||
|
urlBuilder.append(channelNodeRef.getStoreRef().getIdentifier());
|
||||||
|
urlBuilder.append('/');
|
||||||
|
urlBuilder.append(channelNodeRef.getId());
|
||||||
|
urlBuilder.append('/');
|
||||||
|
|
||||||
|
String baseUrl = urlBuilder.toString();
|
||||||
|
String pollUrl = baseUrl + "authstatus";
|
||||||
|
String callbackUrl = baseUrl + "authcallback";
|
||||||
|
|
||||||
|
String authoriseUrl = channelService.getChannelType(channelType).getAuthorisationUrl(newChannel, callbackUrl);
|
||||||
|
if (authoriseUrl == null)
|
||||||
|
{
|
||||||
|
// If a channel type returns null as the authorise URL then we
|
||||||
|
// assume credentials are to be supplied to us directly. We'll point the
|
||||||
|
// user at our own credential-gathering form.
|
||||||
|
authoriseUrl = baseUrl + "authform";
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> model = new TreeMap<String, Object>();
|
||||||
|
model.put("pollUrl", pollUrl);
|
||||||
|
model.put("authoriseUrl", authoriseUrl);
|
||||||
|
model.put("channelId", channelNodeRef.toString());
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
@@ -299,12 +299,12 @@ public class PublishingRestApiTest extends BaseWebScriptTest
|
|||||||
// Check updateStatus is called correctly.
|
// Check updateStatus is called correctly.
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(statusUpdateChannelType)
|
verify(statusUpdateChannelType)
|
||||||
.updateStatus(captor.capture(), anyMap());
|
.updateStatus(any(Channel.class), captor.capture(), anyMap());
|
||||||
String actualStatusMessage = captor.getValue();
|
String actualStatusMessage = captor.getValue();
|
||||||
assertTrue(actualStatusMessage.startsWith(statusMessage));
|
assertTrue(actualStatusMessage.startsWith(statusMessage));
|
||||||
|
|
||||||
verify(statusUpdateChannelType, never()).publish(any(NodeRef.class), anyMap());
|
verify(statusUpdateChannelType, never()).publish(any(NodeRef.class), anyMap());
|
||||||
verify(publishAnyChannelType, never()).updateStatus(anyString(), anyMap());
|
verify(publishAnyChannelType, never()).updateStatus(any(Channel.class), anyString(), anyMap());
|
||||||
|
|
||||||
JSONObject status = json.optJSONObject(STATUS_UPDATE);
|
JSONObject status = json.optJSONObject(STATUS_UPDATE);
|
||||||
status.remove(NODE_REF);
|
status.remove(NODE_REF);
|
||||||
|
Reference in New Issue
Block a user