diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml
index 5e456a6dfc..82433dfefa 100644
--- a/config/alfresco/web-scripts-application-context.xml
+++ b/config/alfresco/web-scripts-application-context.xml
@@ -1137,6 +1137,10 @@
class="org.alfresco.repo.web.scripts.publishing.ChannelsPostWebScript"
parent="webscript">
+
+
+
+
@@ -1144,14 +1148,21 @@
class="org.alfresco.repo.web.scripts.publishing.AuthCallbackWebScript"
parent="webscript">
+
+
+
+
+
executeImpl(WebScriptRequest req, Status status, Cache cache)
{
@@ -76,6 +84,16 @@ public class AuthCallbackWebScript extends DeclarativeWebScript
ChannelType.AuthStatus authStatus = channel.getChannelType().acceptAuthorisationCallback(channel, headers, params);
+ if (ChannelType.AuthStatus.RETRY.equals(authStatus))
+ {
+ String authoriseUrl = channel.getChannelType().getAuthorisationUrl(channel, channelAuthHelper.getAuthoriseCallbackUrl(channelNodeRef));
+ if (authoriseUrl == null)
+ {
+ authoriseUrl = channelAuthHelper.getDefaultAuthoriseUrl(channelNodeRef);
+ }
+ status.setCode(HttpServletResponse.SC_MOVED_TEMPORARILY);
+ status.setLocation(authoriseUrl);
+ }
Map model = new TreeMap();
model.put("authStatus", authStatus.name());
return model;
diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/AuthFormGetWebScript.java b/source/java/org/alfresco/repo/web/scripts/publishing/AuthFormGetWebScript.java
new file mode 100644
index 0000000000..ceeb74cf1b
--- /dev/null
+++ b/source/java/org/alfresco/repo/web/scripts/publishing/AuthFormGetWebScript.java
@@ -0,0 +1,68 @@
+/*
+ * 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 java.util.TreeMap;
+
+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 AuthFormGetWebScript extends DeclarativeWebScript
+{
+ private ChannelService channelService;
+
+ public void setChannelService(ChannelService channelService)
+ {
+ this.channelService = channelService;
+ }
+
+ @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");
+
+ NodeRef channelNodeRef = new NodeRef(channelNodeStoreProtocol, channelNodeStoreId, channelNodeUuid);
+ Channel channel = channelService.getChannelById(channelNodeRef.toString());
+ Map model = new TreeMap();
+
+ if (channel == null)
+ {
+ throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Channel not found - " + channelNodeRef);
+ }
+ else
+ {
+ model.put("channel", channel);
+ }
+ return model;
+ }
+}
diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java
new file mode 100644
index 0000000000..2a94243fb9
--- /dev/null
+++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java
@@ -0,0 +1,63 @@
+/*
+ * 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 org.alfresco.repo.admin.SysAdminParams;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.util.UrlUtil;
+
+public class ChannelAuthHelper
+{
+ private String basePath = "/proxy/alfresco/api/publishing/channels/";
+ private SysAdminParams sysAdminParams;
+
+ public void setSysAdminParams(SysAdminParams sysAdminParams)
+ {
+ this.sysAdminParams = sysAdminParams;
+ }
+
+ public void setBasePath(String basePath)
+ {
+ this.basePath = basePath;
+ }
+
+ public String getBaseChannelApiUrl(NodeRef channelId)
+ {
+ StringBuilder urlBuilder = new StringBuilder(UrlUtil.getShareUrl(sysAdminParams));
+ urlBuilder.append(basePath);
+ urlBuilder.append(channelId.getStoreRef().getProtocol());
+ urlBuilder.append('/');
+ urlBuilder.append(channelId.getStoreRef().getIdentifier());
+ urlBuilder.append('/');
+ urlBuilder.append(channelId.getId());
+ urlBuilder.append('/');
+
+ return urlBuilder.toString();
+ }
+
+ public String getDefaultAuthoriseUrl(NodeRef channelId)
+ {
+ return getBaseChannelApiUrl(channelId) + "authform";
+ }
+
+ public String getAuthoriseCallbackUrl(NodeRef channelId)
+ {
+ return getBaseChannelApiUrl(channelId) + "authcallback";
+ }
+}
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 131ae07b72..fdb65e9e48 100644
--- a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsPostWebScript.java
+++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsPostWebScript.java
@@ -22,11 +22,9 @@ 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.publishing.channels.ChannelService;
import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.util.UrlUtil;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
@@ -35,16 +33,16 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
public class ChannelsPostWebScript extends DeclarativeWebScript
{
private ChannelService channelService;
- private SysAdminParams sysAdminParams;
+ private ChannelAuthHelper channelAuthHelper;
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
- public void setSysAdminParams(SysAdminParams sysAdminParams)
+ public void setChannelAuthHelper(ChannelAuthHelper channelAuthHelper)
{
- this.sysAdminParams = sysAdminParams;
+ this.channelAuthHelper = channelAuthHelper;
}
@Override
@@ -56,17 +54,8 @@ public class ChannelsPostWebScript extends DeclarativeWebScript
Channel newChannel = channelService.createChannel(channelType, channelName, null);
NodeRef channelNodeRef = newChannel.getNodeRef();
- StringBuilder urlBuilder = new StringBuilder(UrlUtil.getShareUrl(sysAdminParams));
- urlBuilder.append("/proxy/alfresco/api/publishing/channels/");
- 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 callbackUrl = baseUrl + "authcallback";
+ String callbackUrl = channelAuthHelper.getAuthoriseCallbackUrl(channelNodeRef);
String authoriseUrl = channelService.getChannelType(channelType).getAuthorisationUrl(newChannel, callbackUrl);
if (authoriseUrl == null)
@@ -74,7 +63,7 @@ public class ChannelsPostWebScript extends DeclarativeWebScript
// 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";
+ authoriseUrl = channelAuthHelper.getDefaultAuthoriseUrl(channelNodeRef);
}
Map model = new TreeMap();