mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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<QName, Serializable> decrypt(Map<QName, Serializable> inbound)
|
||||
{
|
||||
checkAuthentication();
|
||||
|
||||
Set<QName> encryptedProperties = new HashSet<QName>(5);
|
||||
for (Map.Entry<QName, Serializable> entry : inbound.entrySet())
|
||||
{
|
||||
|
@@ -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}
|
||||
*/
|
||||
|
@@ -58,8 +58,10 @@ public abstract class AbstractOAuth1ChannelType<A> 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<A> 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<A> extends AbstractChannelType
|
||||
NodeRef channelNodeRef = channel.getNodeRef();
|
||||
|
||||
Map<QName, Serializable> 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<QName, Serializable> newProps = new HashMap<QName, Serializable>();
|
||||
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;
|
||||
}
|
||||
|
@@ -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<QName, Serializable> actualProps = new HashMap<QName, Serializable>();
|
||||
Map<QName, Serializable> actualProps = new HashMap<QName, Serializable>();
|
||||
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);
|
||||
}
|
||||
|
@@ -165,6 +165,7 @@ public class FacebookChannelType extends AbstractChannelType
|
||||
{
|
||||
Map<QName,Serializable> channelProps = new HashMap<QName, Serializable>();
|
||||
channelProps.put(PublishingModel.PROP_OAUTH2_TOKEN, accessToken);
|
||||
channelProps = getEncryptor().encrypt(channelProps);
|
||||
getChannelService().updateChannel(channel, channelProps);
|
||||
authorised = AuthStatus.AUTHORISED;
|
||||
}
|
||||
|
@@ -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<Facebook> getFacebookConnectionForChannel(NodeRef channelNode)
|
||||
{
|
||||
Connection<Facebook> 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)
|
||||
|
@@ -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)
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<Twitter> getTwitterConnectionForChannel(NodeRef channelNode)
|
||||
{
|
||||
Connection<Twitter> 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;
|
||||
}
|
||||
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
@@ -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<String, String> apiUrls = new TreeMap<String, String>(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<String, String> addParameter(Map<String, String> parameters, String name, String value)
|
||||
|
@@ -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<QName, Serializable> properties)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
Action unpublishAction = actionService.createAction(SlideShareUnpublishAction.NAME);
|
||||
actionService.executeAction(unpublishAction, nodeToUnpublish);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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<String, String> 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<String, String>(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);
|
||||
|
@@ -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;
|
||||
}
|
||||
});
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<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());
|
||||
|
||||
api.deleteSlideshow(usernamePassword.getFirst(), usernamePassword.getSecond(), assetId);
|
||||
nodeService.removeAspect(nodeRef, SlideSharePublishingModel.ASPECT_ASSET);
|
||||
nodeService.removeAspect(nodeRef, PublishingModel.ASPECT_ASSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
|
||||
{
|
||||
}
|
||||
}
|
@@ -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
|
||||
|
Reference in New Issue
Block a user