Publishing:

- Added reauthorisation API for publishing channels
- Refactored OAuth1 channels to share common functionality (Twitter and Flickr)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29362 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Brian Remmington
2011-07-26 15:42:57 +00:00
parent a3b541a7a2
commit 89e8369e38
11 changed files with 250 additions and 29 deletions

View File

@@ -18,7 +18,11 @@
*/
package org.alfresco.repo.web.scripts.publishing;
import java.util.Map;
import java.util.TreeMap;
import org.alfresco.repo.admin.SysAdminParams;
import org.alfresco.service.cmr.publishing.channels.Channel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.UrlUtil;
@@ -60,4 +64,23 @@ public class ChannelAuthHelper
{
return getBaseChannelApiUrl(channelId) + "authcallback";
}
public Map<String, Object> buildAuthorisationModel(Channel channel)
{
String callbackUrl = getAuthoriseCallbackUrl(channel.getNodeRef());
String authoriseUrl = channel.getChannelType().getAuthorisationUrl(channel, 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 = getDefaultAuthoriseUrl(channel.getNodeRef());
}
Map<String, Object> model = new TreeMap<String, Object>();
model.put("authoriseUrl", authoriseUrl);
model.put("channelId", channel.getId());
model.put("authCallbackUrl", callbackUrl);
return model;
}
}

View File

@@ -0,0 +1,74 @@
/*
* 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 javax.servlet.http.HttpServletResponse;
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.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
public class ChannelReauthWebScript extends DeclarativeWebScript
{
private ChannelService channelService;
private ChannelAuthHelper channelAuthHelper;
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
public void setChannelAuthHelper(ChannelAuthHelper channelAuthHelper)
{
this.channelAuthHelper = channelAuthHelper;
}
@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");
if (channelNodeStoreId == null || channelNodeStoreProtocol == null || channelNodeUuid == null)
{
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Missing parameter(s)");
}
NodeRef channelNodeRef = new NodeRef(channelNodeStoreProtocol, channelNodeStoreId, channelNodeUuid);
Channel channel = channelService.getChannelById(channelNodeRef.toString());
if (channel == null)
{
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Channel not found");
}
return channelAuthHelper.buildAuthorisationModel(channel);
}
}

View File

@@ -20,11 +20,9 @@
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;
@@ -53,24 +51,6 @@ public class ChannelsPostWebScript extends DeclarativeWebScript
Channel newChannel = channelService.createChannel(channelType, channelName, null);
NodeRef channelNodeRef = newChannel.getNodeRef();
String callbackUrl = channelAuthHelper.getAuthoriseCallbackUrl(channelNodeRef);
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 = channelAuthHelper.getDefaultAuthoriseUrl(channelNodeRef);
}
Map<String, Object> model = new TreeMap<String, Object>();
model.put("authoriseUrl", authoriseUrl);
model.put("channelId", newChannel.getId());
model.put("authCallbackUrl", callbackUrl);
return model;
return channelAuthHelper.buildAuthorisationModel(newChannel);
}
}