Fix ALF-10402: PUB: Access tokens are not being stored in encrypted properties

- NOTE: this fix means that any existing publishing channels in the repo will cease to work and will cause the publishing generally to have problems. If you have publishing channels in your repo then you must remove them following this fix. This can be done by either cleaning your repo out completely or deleting the node underneath "Data Dictionary/Publishing Root" (it has a UUID as its name).

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30646 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Brian Remmington
2011-09-20 13:49:36 +00:00
parent d8b5f09911
commit 10abd069bc
26 changed files with 419 additions and 204 deletions

View File

@@ -38,19 +38,27 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.benfante.jslideshare.SlideShareAPI;
import com.benfante.jslideshare.messages.Slideshow;
import com.benfante.jslideshare.messages.SlideshowInfo;
public class SlideSharePublishAction extends ActionExecuterAbstractBase
{
private final static Log log = LogFactory.getLog(SlideSharePublishAction.class);
private final static int STATUS_QUEUED = 0;
// private final static int STATUS_CONVERTING = 1;
private final static int STATUS_SUCCEEDED = 2;
private final static int STATUS_FAILED = 3;
private final static int STATUS_TIMED_OUT = 10;
public static final String NAME = "publish_slideshare";
private static final String ERROR_SLIDESHARE_CONVERSION_FAILED = "publish.slideshare.conversionFailed";
private static final String ERROR_SLIDESHARE_CONVERSION_TIMED_OUT = "publish.slideshare.conversionTimedOut";
private NodeService nodeService;
private ContentService contentService;
private TaggingService taggingService;
private SlideSharePublishingHelper slideShareHelper;
private long timeoutMilliseconds = 40L * 60L * 1000L; // 40 mins default
public void setSlideShareHelper(SlideSharePublishingHelper slideShareHelper)
{
this.slideShareHelper = slideShareHelper;
@@ -71,83 +79,136 @@ public class SlideSharePublishAction extends ActionExecuterAbstractBase
this.taggingService = taggingService;
}
public void setTimeoutMilliseconds(long timeoutMilliseconds)
{
this.timeoutMilliseconds = timeoutMilliseconds;
}
@Override
protected void executeImpl(Action action, NodeRef nodeRef)
{
Pair<String,String> usernamePassword = slideShareHelper.getSlideShareCredentialsForNode(nodeRef);
Pair<String, String> usernamePassword = slideShareHelper.getSlideShareCredentialsForNode(nodeRef);
if (usernamePassword == null)
{
throw new AlfrescoRuntimeException("publish.failed.no_credentials_found");
}
SlideShareAPI api = slideShareHelper.getSlideShareApi(usernamePassword.getFirst(), usernamePassword.getSecond());
SlideShareAPI api = slideShareHelper
.getSlideShareApi(usernamePassword.getFirst(), usernamePassword.getSecond());
ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
if (reader.exists())
{
File contentFile;
String mime = reader.getMimetype();
String extension = slideShareHelper.getAllowedMimeTypes().get(mime);
if (extension == null) extension = "";
if (extension == null)
extension = "";
boolean deleteContentFileOnCompletion = false;
//SlideShare seems to work entirely off file extension, so we always copy onto the
//file system and upload from there.
// SlideShare seems to work entirely off file extension, so we
// always copy onto the
// file system and upload from there.
File tempDir = TempFileProvider.getLongLifeTempDir("slideshare");
contentFile = TempFileProvider.createTempFile("slideshare", extension, tempDir);
reader.getContent(contentFile);
deleteContentFileOnCompletion = true;
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
String title = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
if (title == null || title.length() == 0)
try
{
title = name;
}
String description = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION);
if (description == null || description.length() == 0)
{
description = title;
}
List<String> tagList = taggingService.getTags(nodeRef);
StringBuilder tags = new StringBuilder();
for (String tag : tagList)
{
tags.append(tag);
tags.append(' ');
}
String assetId = api.uploadSlideshow(usernamePassword.getFirst(), usernamePassword.getSecond(), title,
contentFile, description, tags.toString(), false, false, false, false, false);
String url = null;
Slideshow slides = api.getSlideshow(assetId);
if (slides != null)
{
url = slides.getPermalink();
if (log.isInfoEnabled())
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
String title = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
if (title == null || title.length() == 0)
{
log.info("SlideShare has provided a URL for asset " + assetId + ": " + url);
title = name;
}
String description = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION);
if (description == null || description.length() == 0)
{
description = title;
}
List<String> tagList = taggingService.getTags(nodeRef);
StringBuilder tags = new StringBuilder();
for (String tag : tagList)
{
tags.append(tag);
tags.append(' ');
}
String assetId = api.uploadSlideshow(usernamePassword.getFirst(), usernamePassword.getSecond(), title,
contentFile, description, tags.toString(), false, false, false, false, false);
String url = null;
int status = STATUS_QUEUED;
boolean finished = false;
long timeoutTime = System.currentTimeMillis() + timeoutMilliseconds;
// Fetch the slideshow info every 5 seconds for 5 minutes...
while (!finished)
{
SlideshowInfo slideInfo = api.getSlideshowInfo(assetId, "");
if (slideInfo != null)
{
if (url == null)
{
url = slideInfo.getUrl();
if (log.isInfoEnabled())
{
log.info("SlideShare has provided a URL for asset " + assetId + ": " + url);
}
}
status = slideInfo.getStatus();
}
finished = (status == STATUS_FAILED || status == STATUS_SUCCEEDED);
if (!finished)
{
if (System.currentTimeMillis() < timeoutTime)
{
try
{
Thread.sleep(30000L);
}
catch (InterruptedException e)
{
}
}
else
{
status = STATUS_TIMED_OUT;
finished = true;
}
}
}
if (status == STATUS_SUCCEEDED)
{
if (log.isInfoEnabled())
{
log.info("File " + name + " has been published to SlideShare with id " + assetId + " at URL "
+ url);
}
nodeService.addAspect(nodeRef, SlideSharePublishingModel.ASPECT_ASSET, null);
nodeService.setProperty(nodeRef, PublishingModel.PROP_ASSET_ID, assetId);
nodeService.setProperty(nodeRef, PublishingModel.PROP_ASSET_URL, url);
}
else
{
throw new AlfrescoRuntimeException(status == STATUS_FAILED ? ERROR_SLIDESHARE_CONVERSION_FAILED
: ERROR_SLIDESHARE_CONVERSION_TIMED_OUT);
}
}
if (log.isInfoEnabled())
finally
{
log.info("File " + name + " has been published to SlideShare with id " + assetId + " at URL " + url);
}
nodeService.addAspect(nodeRef, SlideSharePublishingModel.ASPECT_ASSET, null);
nodeService.setProperty(nodeRef, PublishingModel.PROP_ASSET_ID, assetId);
nodeService.setProperty(nodeRef, PublishingModel.PROP_ASSET_URL, url);
if (deleteContentFileOnCompletion)
{
contentFile.delete();
if (deleteContentFileOnCompletion)
{
contentFile.delete();
}
}
}
}
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
{