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

@@ -19,9 +19,13 @@
package org.alfresco.repo.publishing.slideshare;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
@@ -37,6 +41,7 @@ import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.publishing.channels.Channel;
import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -65,15 +70,17 @@ public class SlideShareTest extends BaseSpringTest
protected PublishingQueueImpl queue;
protected Environment environment;
protected NodeRef docLib;
protected Map<String, String> testFiles = new TreeMap<String, String>();
protected Map<NodeRef, String> testNodeMap = new HashMap<NodeRef, String>();
private ChannelService channelService;
private RetryingTransactionHelper transactionHelper;
public void onSetUp() throws Exception
{
serviceRegistry = (ServiceRegistry) getApplicationContext().getBean("ServiceRegistry");
channelService = (ChannelService) getApplicationContext().getBean("channelService");
channelService = (ChannelService) getApplicationContext().getBean("channelService");
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
siteService = serviceRegistry.getSiteService();
fileFolderService = serviceRegistry.getFileFolderService();
@@ -84,8 +91,13 @@ public class SlideShareTest extends BaseSpringTest
siteService.createSite("test", siteId, "Site created by publishing test", "Site created by publishing test",
SiteVisibility.PUBLIC);
docLib = siteService.createContainer(siteId, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
testFiles.put("test/alfresco/TestPresentation.pptx", MimetypeMap.MIMETYPE_OPENXML_PRESENTATION);
testFiles.put("test/alfresco/TestPresentation2.ppt", MimetypeMap.MIMETYPE_PPT);
testFiles.put("test/alfresco/TestPresentation3.odp", MimetypeMap.MIMETYPE_OPENDOCUMENT_PRESENTATION);
testFiles.put("test/alfresco/TestPresentation4.pdf", MimetypeMap.MIMETYPE_PDF);
}
public void onTearDown()
{
siteService.deleteSite(siteId);
@@ -93,33 +105,54 @@ public class SlideShareTest extends BaseSpringTest
public void testBlank()
{
}
//Note that this test isn't normally run, as it requires valid YouTube credentials.
//To run it, remove the initial 'x' from the method name and set the appropriate YouTube credentials where the
//text "YOUR_USER_NAME" and "YOUR_PASSWORD" appear.
// Note that this test isn't normally run, as it requires valid YouTube
// credentials.
// To run it, remove the initial 'x' from the method name and set the
// appropriate YouTube credentials where the
// text "YOUR_USER_NAME" and "YOUR_PASSWORD" appear.
public void xtestSlideSharePublishAndUnpublishActions() throws Exception
{
final NodeRef node = transactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
final List<NodeRef> nodes = transactionHelper.doInTransaction(new RetryingTransactionCallback<List<NodeRef>>()
{
public NodeRef execute() throws Throwable
public List<NodeRef> execute() throws Throwable
{
List<NodeRef> createdTestNodes = new ArrayList<NodeRef>();
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
// props.put(PublishingModel.PROP_CHANNEL_USERNAME,
// "YOUR_USER_NAME");
// props.put(PublishingModel.PROP_CHANNEL_PASSWORD,
// "YOUR_PASSWORD");
props.put(PublishingModel.PROP_CHANNEL_USERNAME, "YOUR_USER_NAME");
props.put(PublishingModel.PROP_CHANNEL_PASSWORD, "YOUR_PASSWORD");
Channel channel = channelService.createChannel(SlideShareChannelType.ID, "SlideShareChannel", props);
Channel channel = channelService.createChannel(SlideShareChannelType.ID, GUID.generate(), props);
NodeRef channelNode = channel.getNodeRef();
Resource file = new ClassPathResource("test/alfresco/TestPresentation.pptx");
Map<QName, Serializable> vidProps = new HashMap<QName, Serializable>();
vidProps.put(ContentModel.PROP_NAME, "Test Presentation");
NodeRef node = nodeService.createNode(channelNode, ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "testPresentation"),
ContentModel.TYPE_CONTENT, vidProps).getChildRef();
for (Map.Entry<String, String> testFileInfoEntry : testFiles.entrySet())
{
NodeRef nodeRef = createTestNode(channelNode, testFileInfoEntry.getKey(), testFileInfoEntry
.getValue());
createdTestNodes.add(nodeRef);
testNodeMap.put(nodeRef, testFileInfoEntry.getKey());
}
return createdTestNodes;
}
private NodeRef createTestNode(NodeRef parent, String fileLocation, String mimeType)
throws ContentIOException, IOException
{
Resource file = new ClassPathResource(fileLocation);
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(ContentModel.PROP_NAME, "Presentation " + GUID.generate());
NodeRef node = nodeService.createNode(parent, ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, GUID.generate()),
ContentModel.TYPE_CONTENT, props).getChildRef();
ContentService contentService = serviceRegistry.getContentService();
ContentWriter writer = contentService.getWriter(node, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_OPENXML_PRESENTATION);
writer.setMimetype(mimeType);
writer.putContent(file.getFile());
return node;
}
@@ -129,22 +162,29 @@ public class SlideShareTest extends BaseSpringTest
{
public NodeRef execute() throws Throwable
{
ActionService actionService = serviceRegistry.getActionService();
Action publishAction = actionService.createAction(SlideSharePublishAction.NAME);
actionService.executeAction(publishAction, node);
Map<QName, Serializable> props = nodeService.getProperties(node);
Assert.assertTrue(nodeService.hasAspect(node, SlideSharePublishingModel.ASPECT_ASSET));
Assert.assertNotNull(props.get(PublishingModel.PROP_ASSET_ID));
// Assert.assertNotNull(props.get(SlideSharePublishingModel.PROP_ASSET_URL));
for (NodeRef node : nodes)
{
ActionService actionService = serviceRegistry.getActionService();
Action publishAction = actionService.createAction(SlideSharePublishAction.NAME);
actionService.executeAction(publishAction, node);
Map<QName, Serializable> props = nodeService.getProperties(node);
Assert.assertTrue(nodeService.hasAspect(node, SlideSharePublishingModel.ASPECT_ASSET));
Assert.assertNotNull(props.get(PublishingModel.PROP_ASSET_ID));
Assert.assertNotNull(props.get(PublishingModel.PROP_ASSET_URL));
System.out.println("SlideShare id: " + props.get(PublishingModel.PROP_ASSET_ID));
// Action unpublishAction = actionService.createAction(SlideShareUnpublishAction.NAME);
// actionService.executeAction(unpublishAction, node);
// props = nodeService.getProperties(node);
// Assert.assertFalse(nodeService.hasAspect(node, SlideSharePublishingModel.ASPECT_ASSET));
// Assert.assertNull(props.get(SlideSharePublishingModel.PROP_ASSET_ID));
// Assert.assertNull(props.get(SlideSharePublishingModel.PROP_ASSET_URL));
System.out.println("Test file: " + testNodeMap.get(node));
System.out.println("SlideShare id: " + props.get(PublishingModel.PROP_ASSET_ID));
System.out.println("SlideShare URL: " + props.get(PublishingModel.PROP_ASSET_URL));
}
// Action unpublishAction =
// actionService.createAction(SlideShareUnpublishAction.NAME);
// actionService.executeAction(unpublishAction, node);
// props = nodeService.getProperties(node);
// Assert.assertFalse(nodeService.hasAspect(node,
// SlideSharePublishingModel.ASPECT_ASSET));
// Assert.assertNull(props.get(SlideSharePublishingModel.PROP_ASSET_ID));
// Assert.assertNull(props.get(SlideSharePublishingModel.PROP_ASSET_URL));
return null;
}
});
@@ -153,7 +193,10 @@ public class SlideShareTest extends BaseSpringTest
{
public NodeRef execute() throws Throwable
{
nodeService.deleteNode(node);
for (NodeRef node : nodes)
{
nodeService.deleteNode(node);
}
return null;
}
});