diff --git a/config/alfresco/content-publishing-context.xml b/config/alfresco/content-publishing-context.xml index 06b8c6771a..42899cad52 100644 --- a/config/alfresco/content-publishing-context.xml +++ b/config/alfresco/content-publishing-context.xml @@ -49,11 +49,13 @@ + + diff --git a/config/alfresco/facebook-publishing-context.xml b/config/alfresco/facebook-publishing-context.xml index 207fb6ce02..04e5758ba8 100644 --- a/config/alfresco/facebook-publishing-context.xml +++ b/config/alfresco/facebook-publishing-context.xml @@ -17,6 +17,7 @@ + diff --git a/config/alfresco/flickr-publishing-context.xml b/config/alfresco/flickr-publishing-context.xml index 91c8a5e9e0..a99c9e1d00 100644 --- a/config/alfresco/flickr-publishing-context.xml +++ b/config/alfresco/flickr-publishing-context.xml @@ -19,6 +19,7 @@ + diff --git a/config/alfresco/model/publishingModel.xml b/config/alfresco/model/publishingModel.xml index 6007873759..e934aa1d8b 100644 --- a/config/alfresco/model/publishingModel.xml +++ b/config/alfresco/model/publishingModel.xml @@ -299,12 +299,12 @@ The value of the OAuth1 token - d:text + d:encrypted false The secret of the OAuth1 token - d:text + d:encrypted false @@ -316,7 +316,7 @@ The value of the OAuth2 token - d:text + d:encrypted false @@ -328,12 +328,12 @@ The authenticated channel username - d:text + d:encrypted false The authenticated channel password - d:text + d:encrypted false diff --git a/config/alfresco/slideshare-publishing-context.xml b/config/alfresco/slideshare-publishing-context.xml index 09fac7ada5..d4f79d04d0 100644 --- a/config/alfresco/slideshare-publishing-context.xml +++ b/config/alfresco/slideshare-publishing-context.xml @@ -13,6 +13,7 @@ + @@ -28,6 +29,12 @@ + + + + + + diff --git a/config/alfresco/youtube-publishing-context.xml b/config/alfresco/youtube-publishing-context.xml index e6a613747c..8f049155fe 100644 --- a/config/alfresco/youtube-publishing-context.xml +++ b/config/alfresco/youtube-publishing-context.xml @@ -12,6 +12,7 @@ + diff --git a/config/test/alfresco/TestPresentation2.ppt b/config/test/alfresco/TestPresentation2.ppt new file mode 100644 index 0000000000..b04340a211 Binary files /dev/null and b/config/test/alfresco/TestPresentation2.ppt differ diff --git a/config/test/alfresco/TestPresentation3.odp b/config/test/alfresco/TestPresentation3.odp new file mode 100644 index 0000000000..76eb259fb7 Binary files /dev/null and b/config/test/alfresco/TestPresentation3.odp differ diff --git a/config/test/alfresco/TestPresentation4.pdf b/config/test/alfresco/TestPresentation4.pdf new file mode 100644 index 0000000000..ee70772800 Binary files /dev/null and b/config/test/alfresco/TestPresentation4.pdf differ diff --git a/config/test/alfresco/test-web-publishing-context.xml b/config/test/alfresco/test-web-publishing-context.xml index 99669390f2..cf1ba175aa 100644 --- a/config/test/alfresco/test-web-publishing-context.xml +++ b/config/test/alfresco/test-web-publishing-context.xml @@ -100,6 +100,10 @@ + + + + diff --git a/source/java/org/alfresco/repo/node/encryption/MetadataEncryptor.java b/source/java/org/alfresco/repo/node/encryption/MetadataEncryptor.java index fee3f26e09..3ad9eb81f4 100644 --- a/source/java/org/alfresco/repo/node/encryption/MetadataEncryptor.java +++ b/source/java/org/alfresco/repo/node/encryption/MetadataEncryptor.java @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2005-2011 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.node.encryption; import java.io.Serializable; @@ -12,7 +30,6 @@ import javax.crypto.SealedObject; import org.alfresco.encryption.FallbackEncryptor; import org.alfresco.encryption.KeyProvider; import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.security.authentication.AuthenticationException; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DictionaryService; @@ -53,21 +70,8 @@ public class MetadataEncryptor this.encryptor = encryptor; } - /** - * @throws AuthenticationException if the thread is not running as 'system' - */ - private final void checkAuthentication() - { - if (!AuthenticationUtil.isRunAsUserTheSystemUser()) - { - throw new AuthenticationException("Metadata decryption can only be done by the system user."); - } - } - /** * Encrypt a properties if the data definition (model-specific) requires it. - *

- * This method has no specific authentication requirements. * * @param propertyQName the property qualified name * @param inbound the property to encrypt @@ -91,8 +95,6 @@ public class MetadataEncryptor /** * Decrypt a property if the data definition (model-specific) requires it. - *

- * This method can only be called by the 'system' user. * * @param propertyQName the property qualified name * @param inbound the property to decrypt @@ -124,8 +126,6 @@ public class MetadataEncryptor /** * Encrypt properties if their data definition (model-specific) requires it. * The values provided can be mixed; values will be encrypted only if required. - *

- * This method has no specific authentication requirements. * * @param inbound the properties to encrypt * @return a new map of values if some encryption occured @@ -170,8 +170,6 @@ public class MetadataEncryptor /** * Decrypt properties if they are decryptable. The values provided can be mixed; * encrypted values will be sought out and decrypted. - *

- * This method can only be called by the 'system' user. * * @param inbound the properties to decrypt * @return a new map of values if some decryption occured @@ -179,8 +177,6 @@ public class MetadataEncryptor */ public Map decrypt(Map inbound) { - checkAuthentication(); - Set encryptedProperties = new HashSet(5); for (Map.Entry entry : inbound.entrySet()) { diff --git a/source/java/org/alfresco/repo/publishing/AbstractChannelType.java b/source/java/org/alfresco/repo/publishing/AbstractChannelType.java index 56f00e2703..175f3c8180 100644 --- a/source/java/org/alfresco/repo/publishing/AbstractChannelType.java +++ b/source/java/org/alfresco/repo/publishing/AbstractChannelType.java @@ -23,6 +23,7 @@ import java.io.Serializable; import java.util.HashMap; import java.util.Map; +import org.alfresco.repo.node.encryption.MetadataEncryptor; import org.alfresco.service.cmr.publishing.channels.Channel; import org.alfresco.service.cmr.publishing.channels.ChannelService; import org.alfresco.service.cmr.publishing.channels.ChannelType; @@ -38,6 +39,7 @@ import org.springframework.core.io.Resource; public abstract class AbstractChannelType implements ChannelType { private ChannelService channelService; + private MetadataEncryptor encryptor; public void setChannelService(ChannelService channelService) { @@ -50,6 +52,16 @@ public abstract class AbstractChannelType implements ChannelType return channelService; } + public void setEncryptor(MetadataEncryptor encryptor) + { + this.encryptor = encryptor; + } + + protected MetadataEncryptor getEncryptor() + { + return encryptor; + } + /** * {@inheritDoc} */ diff --git a/source/java/org/alfresco/repo/publishing/AbstractOAuth1ChannelType.java b/source/java/org/alfresco/repo/publishing/AbstractOAuth1ChannelType.java index e4c2e67d22..6cfbcaaa4e 100644 --- a/source/java/org/alfresco/repo/publishing/AbstractOAuth1ChannelType.java +++ b/source/java/org/alfresco/repo/publishing/AbstractOAuth1ChannelType.java @@ -58,8 +58,10 @@ public abstract class AbstractOAuth1ChannelType extends AbstractChannelType if (nodeService.exists(channelNode) && nodeService.hasAspect(channelNode, PublishingModel.ASPECT_OAUTH1_DELIVERY_CHANNEL)) { - String tokenValue = (String) nodeService.getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_VALUE); - String tokenSecret = (String) nodeService.getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_SECRET); + String tokenValue = (String) getEncryptor().decrypt(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, nodeService + .getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_VALUE)); + String tokenSecret = (String) getEncryptor().decrypt(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, nodeService + .getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_SECRET)); Boolean danceComplete = (Boolean) nodeService.getProperty(channelNode, PublishingModel.PROP_AUTHORISATION_COMPLETE); if (danceComplete) @@ -90,8 +92,10 @@ public abstract class AbstractOAuth1ChannelType extends AbstractChannelType OAuthToken requestToken = oauthOperations.fetchRequestToken(callbackUrl, null); NodeRef channelNodeRef = channel.getNodeRef(); - nodeService.setProperty(channelNodeRef, PublishingModel.PROP_OAUTH1_TOKEN_SECRET, requestToken.getSecret()); - nodeService.setProperty(channelNodeRef, PublishingModel.PROP_OAUTH1_TOKEN_VALUE, requestToken.getValue()); + nodeService.setProperty(channelNodeRef, PublishingModel.PROP_OAUTH1_TOKEN_SECRET, + getEncryptor().encrypt(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, requestToken.getSecret())); + nodeService.setProperty(channelNodeRef, PublishingModel.PROP_OAUTH1_TOKEN_VALUE, + getEncryptor().encrypt(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, requestToken.getValue())); return oauthOperations.buildAuthorizeUrl(requestToken.getValue(), getOAuth1Parameters(callbackUrl)); } @@ -108,14 +112,17 @@ public abstract class AbstractOAuth1ChannelType extends AbstractChannelType NodeRef channelNodeRef = channel.getNodeRef(); Map currentProps = nodeService.getProperties(channelNodeRef); - String tokenValue = (String) currentProps.get(PublishingModel.PROP_OAUTH1_TOKEN_VALUE); - String tokenSecret = (String) currentProps.get(PublishingModel.PROP_OAUTH1_TOKEN_SECRET); + String tokenValue = (String) getEncryptor().decrypt(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, currentProps + .get(PublishingModel.PROP_OAUTH1_TOKEN_VALUE)); + String tokenSecret = (String) getEncryptor().decrypt(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, currentProps + .get(PublishingModel.PROP_OAUTH1_TOKEN_SECRET)); OAuthToken token = new OAuthToken(tokenValue, tokenSecret); OAuthToken accessToken = oauthOperations.exchangeForAccessToken(new AuthorizedRequestToken(token, verifier[0]), null); Map newProps = new HashMap(); newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, accessToken.getValue()); newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, accessToken.getSecret()); + newProps = getEncryptor().encrypt(newProps); getChannelService().updateChannel(channel, newProps); authorised = AuthStatus.AUTHORISED; } diff --git a/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java b/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java index e9db7e9db2..c64d49e547 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java +++ b/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.TreeMap; import org.alfresco.model.ContentModel; +import org.alfresco.repo.node.encryption.MetadataEncryptor; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.publishing.channels.Channel; import org.alfresco.service.cmr.publishing.channels.ChannelService; @@ -57,6 +58,7 @@ public class ChannelServiceImpl implements ChannelService private DictionaryService dictionaryService; private ChannelHelper channelHelper; private PublishingRootObject rootObject; + private MetadataEncryptor encryptor; /** * @param nodeService @@ -92,6 +94,11 @@ public class ChannelServiceImpl implements ChannelService this.channelHelper = channelHelper; } + public void setEncryptor(MetadataEncryptor encryptor) + { + this.encryptor = encryptor; + } + /** * {@inheritDoc} */ @@ -126,7 +133,7 @@ public class ChannelServiceImpl implements ChannelService String message = "Channel Type: " + channelTypeId + " does not exist!"; throw new IllegalArgumentException(message); } - HashMap actualProps = new HashMap(); + Map actualProps = new HashMap(); if (properties != null) { actualProps.putAll(properties); @@ -134,6 +141,7 @@ public class ChannelServiceImpl implements ChannelService actualProps.put(ContentModel.PROP_NAME, name); actualProps.put(PROP_CHANNEL_TYPE_ID, channelType.getId()); actualProps.put(PublishingModel.PROP_AUTHORISATION_COMPLETE, Boolean.FALSE); + actualProps = encryptor.encrypt(actualProps); NodeRef channelNode = channelHelper.createChannelNode(channelContainer, channelType, name, actualProps); return channelHelper.buildChannelObject(channelNode, this); } diff --git a/source/java/org/alfresco/repo/publishing/facebook/FacebookChannelType.java b/source/java/org/alfresco/repo/publishing/facebook/FacebookChannelType.java index b4e73cf14e..07e106ff57 100644 --- a/source/java/org/alfresco/repo/publishing/facebook/FacebookChannelType.java +++ b/source/java/org/alfresco/repo/publishing/facebook/FacebookChannelType.java @@ -165,6 +165,7 @@ public class FacebookChannelType extends AbstractChannelType { Map channelProps = new HashMap(); channelProps.put(PublishingModel.PROP_OAUTH2_TOKEN, accessToken); + channelProps = getEncryptor().encrypt(channelProps); getChannelService().updateChannel(channel, channelProps); authorised = AuthStatus.AUTHORISED; } diff --git a/source/java/org/alfresco/repo/publishing/facebook/FacebookPublishingHelper.java b/source/java/org/alfresco/repo/publishing/facebook/FacebookPublishingHelper.java index a588330867..f12813e29c 100644 --- a/source/java/org/alfresco/repo/publishing/facebook/FacebookPublishingHelper.java +++ b/source/java/org/alfresco/repo/publishing/facebook/FacebookPublishingHelper.java @@ -18,6 +18,7 @@ */ package org.alfresco.repo.publishing.facebook; +import org.alfresco.repo.node.encryption.MetadataEncryptor; import org.alfresco.repo.publishing.PublishingModel; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; @@ -34,6 +35,7 @@ public class FacebookPublishingHelper { private NodeService nodeService; private FacebookConnectionFactory connectionFactory; + private MetadataEncryptor encryptor; public void setNodeService(NodeService nodeService) { @@ -50,13 +52,19 @@ public class FacebookPublishingHelper return connectionFactory; } + public void setEncryptor(MetadataEncryptor encryptor) + { + this.encryptor = encryptor; + } + public Connection getFacebookConnectionForChannel(NodeRef channelNode) { Connection connection = null; if (nodeService.exists(channelNode) && nodeService.hasAspect(channelNode, FacebookPublishingModel.ASPECT_DELIVERY_CHANNEL)) { - String tokenValue = (String) nodeService.getProperty(channelNode, PublishingModel.PROP_OAUTH2_TOKEN); + String tokenValue = (String) encryptor.decrypt(PublishingModel.PROP_OAUTH2_TOKEN, nodeService.getProperty( + channelNode, PublishingModel.PROP_OAUTH2_TOKEN)); Boolean danceComplete = (Boolean) nodeService.getProperty(channelNode, PublishingModel.PROP_AUTHORISATION_COMPLETE); if (danceComplete) diff --git a/source/java/org/alfresco/repo/publishing/flickr/FlickrPublishingHelper.java b/source/java/org/alfresco/repo/publishing/flickr/FlickrPublishingHelper.java index f7aa070b1a..63dcc3cc54 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/FlickrPublishingHelper.java +++ b/source/java/org/alfresco/repo/publishing/flickr/FlickrPublishingHelper.java @@ -18,6 +18,7 @@ */ package org.alfresco.repo.publishing.flickr; +import org.alfresco.repo.node.encryption.MetadataEncryptor; import org.alfresco.repo.publishing.PublishingModel; import org.alfresco.repo.publishing.flickr.springsocial.api.Flickr; import org.alfresco.repo.publishing.flickr.springsocial.connect.FlickrConnectionFactory; @@ -30,6 +31,7 @@ public class FlickrPublishingHelper { private NodeService nodeService; private FlickrConnectionFactory connectionFactory; + private MetadataEncryptor encryptor; public void setNodeService(NodeService nodeService) { @@ -41,6 +43,11 @@ public class FlickrPublishingHelper this.connectionFactory = connectionFactory; } + public void setEncryptor(MetadataEncryptor encryptor) + { + this.encryptor = encryptor; + } + public FlickrConnectionFactory getConnectionFactory() { return connectionFactory; @@ -53,8 +60,10 @@ public class FlickrPublishingHelper if (nodeService.exists(channelNode) && nodeService.hasAspect(channelNode, PublishingModel.ASPECT_OAUTH1_DELIVERY_CHANNEL)) { - String tokenValue = (String) nodeService.getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_VALUE); - String tokenSecret = (String) nodeService.getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_SECRET); + String tokenValue = (String) encryptor.decrypt(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, nodeService + .getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_VALUE)); + String tokenSecret = (String) encryptor.decrypt(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, nodeService + .getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_SECRET)); Boolean danceComplete = (Boolean) nodeService.getProperty(channelNode, PublishingModel.PROP_AUTHORISATION_COMPLETE); if (danceComplete) diff --git a/source/java/org/alfresco/repo/publishing/linkedin/LinkedInPublishingHelper.java b/source/java/org/alfresco/repo/publishing/linkedin/LinkedInPublishingHelper.java deleted file mode 100644 index fce749bc5e..0000000000 --- a/source/java/org/alfresco/repo/publishing/linkedin/LinkedInPublishingHelper.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2005-2011 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.publishing.linkedin; - -import org.alfresco.repo.publishing.PublishingModel; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.springframework.social.connect.Connection; -import org.springframework.social.oauth1.OAuthToken; -import org.springframework.social.twitter.api.Twitter; -import org.springframework.social.twitter.connect.TwitterConnectionFactory; - -public class LinkedInPublishingHelper -{ - private NodeService nodeService; - private TwitterConnectionFactory connectionFactory; - - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } - - public void setConnectionFactory(TwitterConnectionFactory connectionFactory) - { - this.connectionFactory = connectionFactory; - } - - public TwitterConnectionFactory getConnectionFactory() - { - return connectionFactory; - } - - public Connection getTwitterConnectionForChannel(NodeRef channelNode) - { - Connection connection = null; - if (nodeService.exists(channelNode) - && nodeService.hasAspect(channelNode, PublishingModel.ASPECT_OAUTH1_DELIVERY_CHANNEL)) - { - String tokenValue = (String) nodeService.getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_VALUE); - String tokenSecret = (String) nodeService.getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_SECRET); - Boolean danceComplete = (Boolean) nodeService.getProperty(channelNode, PublishingModel.PROP_AUTHORISATION_COMPLETE); - - if (danceComplete) - { - OAuthToken token = new OAuthToken(tokenValue, tokenSecret); - connection = connectionFactory.createConnection(token); - } - } - return connection; - } - -} diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareApi.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareApi.java new file mode 100644 index 0000000000..832730b4c8 --- /dev/null +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareApi.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2005-2011 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.publishing.slideshare; + +import com.benfante.jslideshare.SlideShareAPI; +import com.benfante.jslideshare.SlideShareErrorException; +import com.benfante.jslideshare.SlideShareException; + +public interface SlideShareApi extends SlideShareAPI +{ + String deleteSlideshow(String username, String password, String id) throws SlideShareException, + SlideShareErrorException; +} diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareApiImpl.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareApiImpl.java index 264c8a8404..422a9902b7 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareApiImpl.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareApiImpl.java @@ -30,7 +30,6 @@ import org.apache.commons.logging.LogFactory; import com.benfante.jslideshare.DocumentParser; import com.benfante.jslideshare.DocumentParserResult; -import com.benfante.jslideshare.SlideShareAPI; import com.benfante.jslideshare.SlideShareConnector; import com.benfante.jslideshare.SlideShareErrorException; import com.benfante.jslideshare.SlideShareException; @@ -40,7 +39,7 @@ import com.benfante.jslideshare.messages.SlideshowInfo; import com.benfante.jslideshare.messages.Tag; import com.benfante.jslideshare.messages.User; -public class SlideShareApiImpl implements SlideShareAPI +public class SlideShareApiImpl implements SlideShareApi { private static final Log logger = LogFactory.getLog(SlideShareApiImpl.class); @@ -57,12 +56,12 @@ public class SlideShareApiImpl implements SlideShareAPI static { DEFAULT_API_URLS.put(URL_GET_SLIDESHOW, "http://www.slideshare.net/api/2/get_slideshow"); - DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_INFO, "https://www.slideshare.net/api/2/get_slideshow_info"); - DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_BY_USER, "https://www.slideshare.net/api/2/get_slideshow_by_user"); - DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_BY_TAG, "https://www.slideshare.net/api/2/get_slideshow_by_tag"); - DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_BY_GROUP, "https://www.slideshare.net/api/2/get_slideshow_from_group"); + DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_INFO, "http://www.slideshare.net/api/2/get_slideshow"); + DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_BY_USER, "http://www.slideshare.net/api/2/get_slideshow_by_user"); + DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_BY_TAG, "http://www.slideshare.net/api/2/get_slideshow_by_tag"); + DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_BY_GROUP, "http://www.slideshare.net/api/2/get_slideshow_from_group"); DEFAULT_API_URLS.put(URL_UPLOAD_SLIDESHOW, "http://www.slideshare.net/api/2/upload_slideshow"); - DEFAULT_API_URLS.put(URL_DELETE_SLIDESHOW, "https://www.slideshare.net/api/2/delete_slideshow"); + DEFAULT_API_URLS.put(URL_DELETE_SLIDESHOW, "http://www.slideshare.net/api/2/delete_slideshow"); } private Map apiUrls = new TreeMap(DEFAULT_API_URLS); @@ -200,7 +199,7 @@ public class SlideShareApiImpl implements SlideShareAPI addParameter(parameters, "username", username); addParameter(parameters, "password", password); addParameter(parameters, "slideshow_id", id); - return sendGetMessage(URL_DELETE_SLIDESHOW, parameters).getSlideShowId(); + return sendMessage(URL_DELETE_SLIDESHOW, parameters).getSlideShowId(); } private Map addParameter(Map parameters, String name, String value) diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareChannelType.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareChannelType.java index 378ab6e96c..12c93a50b9 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareChannelType.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareChannelType.java @@ -70,7 +70,7 @@ public class SlideShareChannelType extends AbstractChannelType @Override public boolean canUnpublish() { - return false; + return true; } @Override @@ -107,7 +107,8 @@ public class SlideShareChannelType extends AbstractChannelType @Override public void unpublish(NodeRef nodeToUnpublish, Map properties) { - throw new UnsupportedOperationException(); + Action unpublishAction = actionService.createAction(SlideShareUnpublishAction.NAME); + actionService.executeAction(unpublishAction, nodeToUnpublish); } @Override diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishAction.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishAction.java index 2524d1e45b..70f239572f 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishAction.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishAction.java @@ -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 usernamePassword = slideShareHelper.getSlideShareCredentialsForNode(nodeRef); + Pair 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 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 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 paramList) { diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingHelper.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingHelper.java index f0283688e8..e4a24b2b4b 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingHelper.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingHelper.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.TreeMap; import org.alfresco.repo.content.MimetypeMap; +import org.alfresco.repo.node.encryption.MetadataEncryptor; import org.alfresco.repo.publishing.PublishingModel; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; @@ -53,6 +54,7 @@ public class SlideSharePublishingHelper private Map allowedMimeTypes = Collections.unmodifiableMap(DEFAULT_MIME_TYPES); private NodeService nodeService; private SlideShareConnector slideshareConnector; + private MetadataEncryptor encryptor; public void setNodeService(NodeService nodeService) { @@ -74,6 +76,11 @@ public class SlideSharePublishingHelper this.allowedMimeTypes = Collections.unmodifiableMap(allowedMimeTypes); } + public void setEncryptor(MetadataEncryptor encryptor) + { + this.encryptor = encryptor; + } + public SlideShareAPI getSlideShareApi() { return createApiObject(); @@ -92,8 +99,10 @@ public class SlideSharePublishingHelper NodeRef parent = nodeService.getPrimaryParent(publishNode).getParentRef(); if (nodeService.hasAspect(parent, SlideSharePublishingModel.ASPECT_DELIVERY_CHANNEL)) { - String username = (String) nodeService.getProperty(parent, PublishingModel.PROP_CHANNEL_USERNAME); - String password = (String) nodeService.getProperty(parent, PublishingModel.PROP_CHANNEL_PASSWORD); + String username = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_USERNAME, nodeService + .getProperty(parent, PublishingModel.PROP_CHANNEL_USERNAME)); + String password = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_PASSWORD, nodeService + .getProperty(parent, PublishingModel.PROP_CHANNEL_PASSWORD)); if (username != null && password != null) { result = new Pair(username, password); @@ -103,7 +112,7 @@ public class SlideSharePublishingHelper return result; } - public SlideShareAPI getSlideShareApi(String username, String password) + public SlideShareApi getSlideShareApi(String username, String password) { SlideShareApiImpl api = createApiObject(); api.setUsername(username); diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java index 10ebdfbcbc..0bc043fd42 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java @@ -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 testFiles = new TreeMap(); + protected Map testNodeMap = new HashMap(); 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() + final List nodes = transactionHelper.doInTransaction(new RetryingTransactionCallback>() { - public NodeRef execute() throws Throwable + public List execute() throws Throwable { + List createdTestNodes = new ArrayList(); Map props = new HashMap(); + // 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 vidProps = new HashMap(); - 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 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 props = new HashMap(); + 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 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 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; } }); diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareUnpublishAction.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareUnpublishAction.java new file mode 100644 index 0000000000..ee3569d18f --- /dev/null +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareUnpublishAction.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2005-2011 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.publishing.slideshare; + +import java.util.List; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; +import org.alfresco.repo.publishing.PublishingModel; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ParameterDefinition; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.util.Pair; + +public class SlideShareUnpublishAction extends ActionExecuterAbstractBase +{ + public static final String NAME = "unpublish_slideshare"; + + private NodeService nodeService; + private SlideSharePublishingHelper slideShareHelper; + + public void setSlideShareHelper(SlideSharePublishingHelper slideShareHelper) + { + this.slideShareHelper = slideShareHelper; + } + + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + @Override + protected void executeImpl(Action action, NodeRef nodeRef) + { + if (nodeService.hasAspect(nodeRef, SlideSharePublishingModel.ASPECT_ASSET)) + { + String assetId = (String) nodeService.getProperty(nodeRef, PublishingModel.PROP_ASSET_ID); + if (assetId != null) + { + Pair usernamePassword = slideShareHelper.getSlideShareCredentialsForNode(nodeRef); + if (usernamePassword == null) + { + throw new AlfrescoRuntimeException("publish.failed.no_credentials_found"); + } + SlideShareApi api = slideShareHelper.getSlideShareApi( + usernamePassword.getFirst(), usernamePassword.getSecond()); + + api.deleteSlideshow(usernamePassword.getFirst(), usernamePassword.getSecond(), assetId); + nodeService.removeAspect(nodeRef, SlideSharePublishingModel.ASPECT_ASSET); + nodeService.removeAspect(nodeRef, PublishingModel.ASPECT_ASSET); + } + } + } + + @Override + protected void addParameterDefinitions(List paramList) + { + } +} diff --git a/source/java/org/alfresco/repo/publishing/youtube/YouTubePublishingHelper.java b/source/java/org/alfresco/repo/publishing/youtube/YouTubePublishingHelper.java index 3645582035..223dd8de23 100644 --- a/source/java/org/alfresco/repo/publishing/youtube/YouTubePublishingHelper.java +++ b/source/java/org/alfresco/repo/publishing/youtube/YouTubePublishingHelper.java @@ -18,6 +18,7 @@ */ package org.alfresco.repo.publishing.youtube; +import org.alfresco.repo.node.encryption.MetadataEncryptor; import org.alfresco.repo.publishing.PublishingModel; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; @@ -30,12 +31,17 @@ public class YouTubePublishingHelper { private static final Log log = LogFactory.getLog(YouTubePublishingHelper.class); private NodeService nodeService; + private MetadataEncryptor encryptor; public void setNodeService(NodeService nodeService) { this.nodeService = nodeService; } + public void setEncryptor(MetadataEncryptor encryptor) + { + this.encryptor = encryptor; + } public YouTubeService getYouTubeServiceForNode(NodeRef publishNode) { @@ -45,8 +51,10 @@ public class YouTubePublishingHelper NodeRef parent = nodeService.getPrimaryParent(publishNode).getParentRef(); if (nodeService.hasAspect(parent, YouTubePublishingModel.ASPECT_DELIVERY_CHANNEL)) { - String youtubeUsername = (String) nodeService.getProperty(parent, PublishingModel.PROP_CHANNEL_USERNAME); - String youtubePassword = (String) nodeService.getProperty(parent, PublishingModel.PROP_CHANNEL_PASSWORD); + String youtubeUsername = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_USERNAME, nodeService + .getProperty(parent, PublishingModel.PROP_CHANNEL_USERNAME)); + String youtubePassword = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_PASSWORD, nodeService + .getProperty(parent, PublishingModel.PROP_CHANNEL_PASSWORD)); service = new YouTubeService("Alfresco", "AI39si78RHlniONCtnu9o8eBfwZToBAp2ZbbURm5eoJjj4gZi0LcxjDqJTzD35oYokmtFXbCo5ojofbimGnMlRbmNrh7-M7ZCw"); try