diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.get.desc.xml new file mode 100644 index 0000000000..529acbb349 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.get.desc.xml @@ -0,0 +1,56 @@ + + Reauthorise the specified publishing channel + + Response status may be: +
+
200
The body of the response contains the necessary information to continue the reauthorisation process
+
400
invalid data received from caller
+
404
the specified channel cannot be found
+
+ Returns three pieces of informtation: +
+
+
channelId
the identifier of the publishing channel
+
authoriseUrl
The URL to send the user to in order for them to authorise access to the channel
+
authCallbackUrl
The URL to return the channel authorisation details to
+
+ ]]>
+ /api/publishing/channels/{store_protocol}/{store_id}/{node_id}/reauthorise + + user + required + public_api + + + store_protocol + The protocol of the store in which the relevant publishing channel lives. + + + store_id + The identifier of the store in which the relevant publishing channel lives. + + + node_id + The identifier of the node that represents the relevant publishing channel. + + + + + json + + + + + +
\ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.get.json.ftl new file mode 100644 index 0000000000..685717eabd --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.get.json.ftl @@ -0,0 +1,6 @@ +<#-- Response to a request to create a publishing channel --> +<#import "publishing.lib.ftl" as publishLib /> +{ + "data": + <@publishLib.channelAuthJSON /> +} diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.post.desc.xml new file mode 100644 index 0000000000..529acbb349 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.post.desc.xml @@ -0,0 +1,56 @@ + + Reauthorise the specified publishing channel + + Response status may be: +
+
200
The body of the response contains the necessary information to continue the reauthorisation process
+
400
invalid data received from caller
+
404
the specified channel cannot be found
+
+ Returns three pieces of informtation: +
+
+
channelId
the identifier of the publishing channel
+
authoriseUrl
The URL to send the user to in order for them to authorise access to the channel
+
authCallbackUrl
The URL to return the channel authorisation details to
+
+ ]]>
+ /api/publishing/channels/{store_protocol}/{store_id}/{node_id}/reauthorise + + user + required + public_api + + + store_protocol + The protocol of the store in which the relevant publishing channel lives. + + + store_id + The identifier of the store in which the relevant publishing channel lives. + + + node_id + The identifier of the node that represents the relevant publishing channel. + + + + + json + + + + + +
\ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.post.json.ftl new file mode 100644 index 0000000000..685717eabd --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.post.json.ftl @@ -0,0 +1,6 @@ +<#-- Response to a request to create a publishing channel --> +<#import "publishing.lib.ftl" as publishLib /> +{ + "data": + <@publishLib.channelAuthJSON /> +} diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.desc.xml index 945da2d805..51244895ff 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.desc.xml @@ -47,7 +47,6 @@ "data": { "channelId": string, - "pollUrl": string, "authoriseUrl": string "authCallbackUrl": string } diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.json.ftl index ae16ba8c9c..685717eabd 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.json.ftl @@ -1,11 +1,6 @@ <#-- Response to a request to create a publishing channel --> -<#escape x as jsonUtils.encodeJSONString(x)> +<#import "publishing.lib.ftl" as publishLib /> { "data": - { - "channelId" : "${channelId}", - "authoriseUrl": "${authoriseUrl}", - "authCallbackUrl": "${authCallbackUrl}" - } + <@publishLib.channelAuthJSON /> } - diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing.lib.ftl index b614326793..526a927d82 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing.lib.ftl @@ -138,3 +138,15 @@ "timeZone": "${calendar.timeZone}" } + +<#-- Renders a calendar. --> +<#macro channelAuthJSON> +<#escape x as jsonUtils.encodeJSONString(x)> + { + "channelId" : "${channelId}", + "authoriseUrl": "${authoriseUrl}", + "authCallbackUrl": "${authCallbackUrl}" + } + + + \ No newline at end of file diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 82433dfefa..755f78142f 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1185,6 +1185,20 @@ + + + + + + + + + + diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java index 2a94243fb9..62144075ca 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java @@ -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 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 model = new TreeMap(); + model.put("authoriseUrl", authoriseUrl); + model.put("channelId", channel.getId()); + model.put("authCallbackUrl", callbackUrl); + return model; + } } diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelReauthWebScript.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelReauthWebScript.java new file mode 100644 index 0000000000..5569a69350 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelReauthWebScript.java @@ -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 . + */ + +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 executeImpl(WebScriptRequest req, Status status, Cache cache) + { + Map 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); + } +} diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsPostWebScript.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsPostWebScript.java index fdb65e9e48..ec7789c240 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsPostWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsPostWebScript.java @@ -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 model = new TreeMap(); - model.put("authoriseUrl", authoriseUrl); - model.put("channelId", newChannel.getId()); - model.put("authCallbackUrl", callbackUrl); - - return model; + return channelAuthHelper.buildAuthorisationModel(newChannel); } }