mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Publishing:
- Finish support for posting status updates to Facebook git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29110 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -28,5 +28,6 @@
|
||||
<import resource="classpath*:alfresco/twitter-publishing-context.xml" />
|
||||
<import resource="classpath*:alfresco/slideshare-publishing-context.xml" />
|
||||
<import resource="classpath*:alfresco/flickr-publishing-context.xml" />
|
||||
<import resource="classpath*:alfresco/facebook-publishing-context.xml" />
|
||||
<import resource="classpath*:alfresco/domain/*-context.xml" />
|
||||
</beans>
|
||||
|
27
config/alfresco/facebook-publishing-context.xml
Normal file
27
config/alfresco/facebook-publishing-context.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
|
||||
|
||||
<beans>
|
||||
<bean parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
|
||||
<property name="models">
|
||||
<list>
|
||||
<value>alfresco/model/facebookPublishingModel.xml</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="facebookDeliveryChannelType" class="org.alfresco.repo.publishing.facebook.FacebookChannelType" parent="baseChannelType" >
|
||||
<property name="publishingHelper" ref="facebookPublishingHelper" />
|
||||
</bean>
|
||||
|
||||
<bean id="facebookPublishingHelper" class="org.alfresco.repo.publishing.facebook.FacebookPublishingHelper">
|
||||
<property name="nodeService" ref="NodeService" />
|
||||
<property name="connectionFactory">
|
||||
<bean class="org.springframework.social.facebook.connect.FacebookConnectionFactory">
|
||||
<constructor-arg value="172471752819337" />
|
||||
<constructor-arg value="663c15276462894fd3f0e94b41a4e2e1" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
@@ -32,22 +32,7 @@
|
||||
<aspect name="facebook:DeliveryChannelAspect">
|
||||
<title>Facebook Delivery Channel Aspect</title>
|
||||
<description>Applied to a node that represents a Facebook delivery channel</description>
|
||||
<parent>pub:UserPasswordDeliveryChannelAspect</parent>
|
||||
</aspect>
|
||||
|
||||
<aspect name="facebook:AssetAspect">
|
||||
<title>Facebook Asset</title>
|
||||
<description>Applied to a node that has been published to Facebook</description>
|
||||
<properties>
|
||||
<property name="facebook:assetId">
|
||||
<title>Facebook Asset Id</title>
|
||||
<type>d:text</type>
|
||||
</property>
|
||||
<property name="facebook:assetUrl">
|
||||
<title>Facebook Asset URL</title>
|
||||
<type>d:text</type>
|
||||
</property>
|
||||
</properties>
|
||||
<parent>pub:OAuth2DeliveryChannelAspect</parent>
|
||||
</aspect>
|
||||
</aspects>
|
||||
</model>
|
||||
|
@@ -321,6 +321,18 @@
|
||||
</properties>
|
||||
</aspect>
|
||||
|
||||
<aspect name="pub:OAuth2DeliveryChannelAspect">
|
||||
<title>OAuth2 Authenticated Delivery Channel</title>
|
||||
<description>Applied to delivery channels that use OAuth2</description>
|
||||
<properties>
|
||||
<property name="pub:oauth2Token">
|
||||
<title>The value of the OAuth2 token</title>
|
||||
<type>d:text</type>
|
||||
<multiple>false</multiple>
|
||||
</property>
|
||||
</properties>
|
||||
</aspect>
|
||||
|
||||
<aspect name="pub:UserPasswordDeliveryChannelAspect">
|
||||
<title>Username and Password Authenticated Delivery Channel</title>
|
||||
<description>Applied to delivery channels that use OAuth1</description>
|
||||
@@ -338,5 +350,19 @@
|
||||
</properties>
|
||||
</aspect>
|
||||
|
||||
<aspect name="pub:AssetAspect">
|
||||
<title>Published Asset</title>
|
||||
<description>Applied to a node that has been published to an external delivery service</description>
|
||||
<properties>
|
||||
<property name="pub:assetId">
|
||||
<title>Published Asset Id</title>
|
||||
<type>d:text</type>
|
||||
</property>
|
||||
<property name="pub:assetUrl">
|
||||
<title>Published Asset URL</title>
|
||||
<type>d:text</type>
|
||||
</property>
|
||||
</properties>
|
||||
</aspect>
|
||||
</aspects>
|
||||
</model>
|
||||
|
@@ -83,7 +83,7 @@ public class PublishingEventProcessor
|
||||
{
|
||||
publishEvent(channel, event);
|
||||
updateStatus(channel, environment, event.getStatusUpdate());
|
||||
String completedStatus = PublishingEvent.Status.COMPLETE.name();
|
||||
String completedStatus = PublishingEvent.Status.COMPLETED.name();
|
||||
nodeService.setProperty(eventNode, PublishingModel.PROP_PUBLISHING_EVENT_STATUS, completedStatus);
|
||||
}
|
||||
}
|
||||
|
@@ -45,6 +45,8 @@ public interface PublishingModel
|
||||
public static final QName ASPECT_CHANNEL_INFO= QName.createQName(NAMESPACE, "channelInfo");
|
||||
public static final QName ASPECT_PUBLISHED = QName.createQName(NAMESPACE, "published");
|
||||
public static final QName ASPECT_OAUTH1_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "OAuth1DeliveryChannelAspect");
|
||||
public static final QName ASPECT_OAUTH2_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "OAuth2DeliveryChannelAspect");
|
||||
public static final QName ASPECT_ASSET = QName.createQName(NAMESPACE, "AssetAspect");
|
||||
|
||||
public static final QName PROP_CHANNEL = QName.createQName(NAMESPACE, "channel");
|
||||
public static final QName PROP_CHANNEL_TYPE = QName.createQName(NAMESPACE, "channelType");
|
||||
@@ -66,6 +68,9 @@ public interface PublishingModel
|
||||
public static final QName PROP_OAUTH1_TOKEN_SECRET = QName.createQName(NAMESPACE, "oauth1TokenSecret");
|
||||
public static final QName PROP_CHANNEL_USERNAME = QName.createQName(NAMESPACE, "channelUsername");
|
||||
public static final QName PROP_CHANNEL_PASSWORD = QName.createQName(NAMESPACE, "channelPassword");
|
||||
public static final QName PROP_OAUTH2_TOKEN = QName.createQName(NAMESPACE, "oauth2Token");
|
||||
public static final QName PROP_ASSET_ID = QName.createQName(NAMESPACE, "assetId");
|
||||
public static final QName PROP_ASSET_URL = QName.createQName(NAMESPACE, "assetUrl");
|
||||
|
||||
|
||||
// Publishing Connection Properties
|
||||
|
@@ -20,6 +20,7 @@ package org.alfresco.repo.publishing.facebook;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -27,36 +28,33 @@ import org.alfresco.repo.publishing.AbstractChannelType;
|
||||
import org.alfresco.repo.publishing.PublishingModel;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.springframework.social.connect.Connection;
|
||||
import org.springframework.social.facebook.api.Facebook;
|
||||
import org.springframework.social.oauth1.AuthorizedRequestToken;
|
||||
import org.springframework.social.oauth1.OAuth1Operations;
|
||||
import org.springframework.social.oauth1.OAuth1Parameters;
|
||||
import org.springframework.social.oauth1.OAuthToken;
|
||||
import org.springframework.social.oauth2.AccessGrant;
|
||||
import org.springframework.social.oauth2.GrantType;
|
||||
import org.springframework.social.oauth2.OAuth2Operations;
|
||||
import org.springframework.social.oauth2.OAuth2Parameters;
|
||||
import org.springframework.social.twitter.api.Twitter;
|
||||
|
||||
public class FacebookChannelType extends AbstractChannelType
|
||||
{
|
||||
public final static String ID = "facebook";
|
||||
private NodeService nodeService;
|
||||
public final static String DEFAULT_REDIRECT_URI = "http://cognite.net";
|
||||
|
||||
private FacebookPublishingHelper publishingHelper;
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
private String redirectUri = DEFAULT_REDIRECT_URI;
|
||||
|
||||
public void setPublishingHelper(FacebookPublishingHelper facebookPublishingHelper)
|
||||
{
|
||||
this.publishingHelper = facebookPublishingHelper;
|
||||
}
|
||||
|
||||
public void setRedirectUri(String redirectUri)
|
||||
{
|
||||
this.redirectUri = redirectUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublish()
|
||||
{
|
||||
@@ -119,14 +117,9 @@ public class FacebookChannelType extends AbstractChannelType
|
||||
@Override
|
||||
public String getNodeUrl(NodeRef node)
|
||||
{
|
||||
String url = null;
|
||||
if (node != null && nodeService.exists(node) && nodeService.hasAspect(node, FacebookPublishingModel.ASPECT_ASSET))
|
||||
{
|
||||
url = (String)nodeService.getProperty(node, FacebookPublishingModel.PROP_ASSET_URL);
|
||||
}
|
||||
return url;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getAuthorisationUrl(Channel channel, String callbackUrl)
|
||||
{
|
||||
@@ -136,33 +129,42 @@ public class FacebookChannelType extends AbstractChannelType
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid channel type: " + channel.getChannelType().getId());
|
||||
}
|
||||
|
||||
|
||||
NodeRef channelRef = channel.getNodeRef();
|
||||
StringBuilder authStateBuilder = new StringBuilder(channelRef.getStoreRef().getProtocol()).append('.').append(
|
||||
channelRef.getStoreRef().getIdentifier()).append('.').append(channelRef.getId());
|
||||
OAuth2Operations oauthOperations = publishingHelper.getConnectionFactory().getOAuthOperations();
|
||||
return oauthOperations.buildAuthorizeUrl(GrantType.AUTHORIZATION_CODE, new OAuth2Parameters(callbackUrl));
|
||||
OAuth2Parameters params = new OAuth2Parameters(redirectUri,
|
||||
"publish_stream,offline_access,user_photos,user_videos", authStateBuilder.toString(), null);
|
||||
return oauthOperations.buildAuthorizeUrl(GrantType.IMPLICIT_GRANT, params);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean acceptAuthorisationCallback(Channel channel, Map<String, String[]> callbackHeaders,
|
||||
Map<String, String[]> callbackParams)
|
||||
{
|
||||
boolean authorised = false;
|
||||
//FIXME: BJR: 20110708: Write this.
|
||||
// String[] verifier = callbackParams.get("oauth_verifier");
|
||||
// if (verifier != null)
|
||||
// {
|
||||
// OAuth2Operations oauthOperations = publishingHelper.getConnectionFactory().getOAuthOperations();
|
||||
// NodeRef channelNodeRef = channel.getNodeRef();
|
||||
//
|
||||
// Map<QName, Serializable> props = nodeService.getProperties(channelNodeRef);
|
||||
// String tokenValue = (String) props.get(PublishingModel.PROP_OAUTH1_TOKEN_VALUE);
|
||||
// String tokenSecret = (String) props.get(PublishingModel.PROP_OAUTH1_TOKEN_SECRET);
|
||||
// OAuthToken token = new OAuthToken(tokenValue, tokenSecret);
|
||||
// OAuthToken accessToken = oauthOperations.exchangeForAccessToken(new AuthorizedRequestToken(token, verifier[0]), null);
|
||||
// nodeService.setProperty(channelNodeRef, PublishingModel.PROP_OAUTH1_TOKEN_VALUE, accessToken.getValue());
|
||||
// nodeService.setProperty(channelNodeRef, PublishingModel.PROP_OAUTH1_TOKEN_SECRET, accessToken.getSecret());
|
||||
//
|
||||
// authorised = true;
|
||||
// }
|
||||
|
||||
String accessToken = null;
|
||||
if (callbackParams.containsKey("access_token"))
|
||||
{
|
||||
//We have been given the access token directly.
|
||||
accessToken = callbackParams.get("access_token")[0];
|
||||
}
|
||||
else if (callbackParams.containsKey("code"))
|
||||
{
|
||||
//We have been passed an authorisation code that needs to be exchanged for a token
|
||||
OAuth2Operations oauthOps = publishingHelper.getConnectionFactory().getOAuthOperations();
|
||||
AccessGrant grant = oauthOps.exchangeForAccess(callbackParams.get("code")[0], redirectUri, null);
|
||||
accessToken = grant.getAccessToken();
|
||||
}
|
||||
if (accessToken != null)
|
||||
{
|
||||
Map<QName,Serializable> channelProps = new HashMap<QName, Serializable>();
|
||||
channelProps.put(PublishingModel.PROP_OAUTH2_TOKEN, accessToken);
|
||||
getChannelService().updateChannel(channel, channelProps);
|
||||
authorised = true;
|
||||
}
|
||||
return authorised;
|
||||
}
|
||||
}
|
||||
|
@@ -52,13 +52,12 @@ public class FacebookPublishingHelper
|
||||
if (nodeService.exists(channelNode)
|
||||
&& nodeService.hasAspect(channelNode, FacebookPublishingModel.ASPECT_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) nodeService.getProperty(channelNode, PublishingModel.PROP_OAUTH2_TOKEN);
|
||||
Boolean danceComplete = (Boolean) nodeService.getProperty(channelNode, PublishingModel.PROP_AUTHORISATION_COMPLETE);
|
||||
|
||||
if (danceComplete)
|
||||
{
|
||||
AccessGrant token = new AccessGrant(" ");
|
||||
AccessGrant token = new AccessGrant(tokenValue);
|
||||
connection = connectionFactory.createConnection(token);
|
||||
}
|
||||
}
|
||||
|
@@ -33,8 +33,4 @@ public interface FacebookPublishingModel
|
||||
public static final QName TYPE_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannel");
|
||||
|
||||
public static final QName ASPECT_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannelAspect");
|
||||
|
||||
public static final QName ASPECT_ASSET = QName.createQName(NAMESPACE, "AssetAspect");
|
||||
public static final QName PROP_ASSET_ID = QName.createQName(NAMESPACE, "assetId");
|
||||
public static final QName PROP_ASSET_URL = QName.createQName(NAMESPACE, "assetUrl");
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ import java.util.Date;
|
||||
*/
|
||||
public interface PublishingEvent
|
||||
{
|
||||
enum Status {SCHEDULED, IN_PROGRESS, CANCEL_REQUESTED, COMPLETE, FAILED}
|
||||
enum Status {SCHEDULED, IN_PROGRESS, CANCEL_REQUESTED, COMPLETED, FAILED}
|
||||
|
||||
String getId();
|
||||
|
||||
|
Reference in New Issue
Block a user