mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Publishing:
- On channel authorisation, if a retry is permitted the webscript now does a browser redirect back to the authorisation URL - The controller for the authform.get webscript now places the relevant Channel object into the model for use by the template git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29350 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1137,6 +1137,10 @@
|
||||
class="org.alfresco.repo.web.scripts.publishing.ChannelsPostWebScript"
|
||||
parent="webscript">
|
||||
<property name="channelService" ref="channelService" />
|
||||
<property name="channelAuthHelper" ref="channelAuthHelper" />
|
||||
</bean>
|
||||
|
||||
<bean id="channelAuthHelper" class="org.alfresco.repo.web.scripts.publishing.ChannelAuthHelper">
|
||||
<property name="sysAdminParams" ref="sysAdminParams" />
|
||||
</bean>
|
||||
|
||||
@@ -1144,14 +1148,21 @@
|
||||
class="org.alfresco.repo.web.scripts.publishing.AuthCallbackWebScript"
|
||||
parent="webscript">
|
||||
<property name="channelService" ref="channelService" />
|
||||
<property name="channelAuthHelper" ref="channelAuthHelper" />
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.publishing.authform.post"
|
||||
class="org.alfresco.repo.web.scripts.publishing.AuthCallbackWebScript"
|
||||
parent="webscript">
|
||||
<property name="channelService" ref="channelService" />
|
||||
<property name="channelAuthHelper" ref="channelAuthHelper" />
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.publishing.authform.get"
|
||||
class="org.alfresco.repo.web.scripts.publishing.AuthFormGetWebScript"
|
||||
parent="webscript">
|
||||
<property name="channelService" ref="channelService" />
|
||||
</bean>
|
||||
|
||||
<!-- Get Publishing Events For Node web script -->
|
||||
<bean id="webscript.org.alfresco.repository.publishing.publishing-events.get"
|
||||
|
@@ -22,6 +22,8 @@ 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.publishing.channels.ChannelType;
|
||||
@@ -37,12 +39,18 @@ public class AuthCallbackWebScript extends DeclarativeWebScript
|
||||
{
|
||||
private final static Log log = LogFactory.getLog(AuthCallbackWebScript.class);
|
||||
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)
|
||||
{
|
||||
@@ -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<String,Object> model = new TreeMap<String, Object>();
|
||||
model.put("authStatus", authStatus.name());
|
||||
return model;
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<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");
|
||||
|
||||
NodeRef channelNodeRef = new NodeRef(channelNodeStoreProtocol, channelNodeStoreId, channelNodeUuid);
|
||||
Channel channel = channelService.getChannelById(channelNodeRef.toString());
|
||||
Map<String,Object> model = new TreeMap<String, Object>();
|
||||
|
||||
if (channel == null)
|
||||
{
|
||||
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Channel not found - " + channelNodeRef);
|
||||
}
|
||||
else
|
||||
{
|
||||
model.put("channel", channel);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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";
|
||||
}
|
||||
}
|
@@ -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<String, Object> model = new TreeMap<String, Object>();
|
||||
|
Reference in New Issue
Block a user