diff --git a/config/alfresco/social-publishing-context.xml b/config/alfresco/social-publishing-context.xml index efbbd18944..25c756fcea 100644 --- a/config/alfresco/social-publishing-context.xml +++ b/config/alfresco/social-publishing-context.xml @@ -3,14 +3,6 @@ - - - - - - - - @@ -23,10 +15,4 @@ - - - - - - diff --git a/source/java/org/alfresco/repo/publishing/authorization/NodeBasedConnectionRepository.java b/source/java/org/alfresco/repo/publishing/authorization/NodeBasedConnectionRepository.java deleted file mode 100644 index 3d20a0eea6..0000000000 --- a/source/java/org/alfresco/repo/publishing/authorization/NodeBasedConnectionRepository.java +++ /dev/null @@ -1,250 +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.authorization; - -import static org.alfresco.repo.publishing.PublishingModel.PROP_ACCESS_SECRET; -import static org.alfresco.repo.publishing.PublishingModel.PROP_ACCESS_TOKEN; -import static org.alfresco.repo.publishing.PublishingModel.PROP_ACCOUNT_ID; -import static org.alfresco.repo.publishing.PublishingModel.PROP_PROVIDER_ACCOUNT_ID; -import static org.alfresco.repo.publishing.PublishingModel.PROP_PROVIDER_ID; -import static org.alfresco.repo.publishing.PublishingModel.PROP_REFRESH_TOKEN; -import static org.alfresco.repo.publishing.PublishingModel.TYPE_PUBLISHING_CONNECTION; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.model.Repository; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.namespace.QName; -import org.springframework.social.connect.Connection; -import org.springframework.social.connect.ConnectionRepository; -import org.springframework.social.oauth1.OAuthToken; -import org.springframework.social.twitter.api.TwitterApi; -import org.springframework.social.twitter.connect.TwitterConnectionFactory; - -/** - * A node-backed Social Connection Repository, that stores the - * credentials and auth tokens in the Data Dictionary. - * - * @author Nick Burch - * @author Nick Smith - */ -public class NodeBasedConnectionRepository -{ - /** - * Serial version UID - */ - private static final long serialVersionUID = 3258131523636186548L; - - /** Reference to the auth store space node */ - private static final StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); - protected static final NodeRef SOCIAL_PUBLISHING_AUTHORISATION_ROOT_NODE_REF = - new NodeRef(SPACES_STORE, "social_publishing_authorisation_space"); - - private NodeService nodeService; - private SearchService searchService; - private Repository repositoryHelper; - - // TODO Replace this with doing it properly... - private NodeRef authRootNode; - - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } - - public void setSearchService(SearchService searchService) - { - this.searchService = searchService; - } - - public void setRepositoryHelper(Repository repositoryHelper) - { - this.repositoryHelper = repositoryHelper; - } - - private void findAuthRootNode() { - if(authRootNode != null) return; - - // TODO Replace this with doing it properly... - AuthenticationUtil.runAs(new RunAsWork() - { - @Override - public Void doWork() throws Exception - { - if(! nodeService.exists(SOCIAL_PUBLISHING_AUTHORISATION_ROOT_NODE_REF)) - { - NodeRef dataDictionary = nodeService.getChildByName( - repositoryHelper.getCompanyHome(), - ContentModel.ASSOC_CONTAINS, - "dictionary" - ); - authRootNode = nodeService.getChildByName( - dataDictionary, - ContentModel.ASSOC_CONTAINS, - SOCIAL_PUBLISHING_AUTHORISATION_ROOT_NODE_REF.getId() - ); - if(authRootNode == null) - { - authRootNode = nodeService.createNode( - dataDictionary, - ContentModel.ASSOC_CONTAINS, - QName.createQName("{}"+SOCIAL_PUBLISHING_AUTHORISATION_ROOT_NODE_REF.getId()), - ContentModel.TYPE_FOLDER - ).getChildRef(); - } - } - else - { - authRootNode = SOCIAL_PUBLISHING_AUTHORISATION_ROOT_NODE_REF; - } - return null; - } - }, AuthenticationUtil.getAdminUserName()); - } - - private NodeRef findProvider(final String providerId, boolean autoCreate) - { - NodeRef node = nodeService.getChildByName( - authRootNode, ContentModel.ASSOC_CONTAINS, providerId - ); - if(autoCreate && node == null) - { - node = AuthenticationUtil.runAs(new RunAsWork() - { - @Override - public NodeRef doWork() throws Exception - { - return nodeService.createNode( - authRootNode, ContentModel.ASSOC_CONTAINS, - QName.createQName("{}" + providerId), - ContentModel.TYPE_FOLDER - ).getChildRef(); - } - } , AuthenticationUtil.getAdminUserName() - ); - } - return node; - } - - private NodeRef findAccount(Serializable accountId, String providerId) - { - findAuthRootNode(); - NodeRef folder = findProvider(providerId, false); - if(folder == null) - { - return null; - } - - NodeRef account = nodeService.getChildByName( - folder, ContentModel.ASSOC_CONTAINS, accountId.toString() - ); - return account; - } - - private Connection buildConnection(NodeRef node) - { -// Map props = nodeService.getProperties(node); -// return new Connection( -// (long)-1, -// (String)props.get(PROP_ACCESS_TOKEN), -// (String)props.get(PROP_ACCESS_SECRET), -// (String)props.get(PROP_REFRESH_TOKEN), -// (String)props.get(PROP_PROVIDER_ACCOUNT_ID) -// ); - return null; - } - - public boolean isConnected(Serializable accountId, String providerId) - { - NodeRef account = findAccount(accountId, providerId); - return (account != null); - } - - public Serializable findAccountIdByConnectionAccessToken(String providerId, - String accessToken) { - // TODO Auto-generated method stub - return null; - } - - public List findAccountIdsForProviderAccountIds( - String providerId, List providerAccountIds) { - // TODO Auto-generated method stub - return null; - } - - public List> findConnections(Serializable accountId, - String providerId) { - NodeRef account = findAccount(accountId, providerId); - if(account == null) - { - return Collections.emptyList(); - } - - List> connections = new ArrayList>(); - connections.add( buildConnection(account) ); - return connections; - } - - public void removeConnection(Serializable accountId, String providerId, - Long connectionId) - { - NodeRef account = findAccount(accountId, providerId); - if(account != null) - { - nodeService.deleteNode(account); - } - } - - public Connection saveConnection(Serializable accountId, String providerId, - Connection connection) - { -// Map args = new HashMap(); -// args.put(ContentModel.PROP_NAME, accountId); -// args.put(PROP_ACCOUNT_ID, accountId); -// args.put(PROP_PROVIDER_ID, providerId); -// args.put(PROP_PROVIDER_ACCOUNT_ID, connection.getProviderAccountId()); -// args.put(PROP_ACCESS_TOKEN, connection.getAccessToken()); -// args.put(PROP_ACCESS_SECRET, connection.getSecret()); -// args.put(PROP_REFRESH_TOKEN, connection.getRefreshToken()); -// -// findAuthRootNode(); -// NodeRef folder = findProvider(providerId, true); -// NodeRef node = nodeService.createNode( -// folder, ContentModel.ASSOC_CONTAINS, -// QName.createQName("{}" + accountId.toString()), -// TYPE_PUBLISHING_CONNECTION, -// args -// ).getChildRef(); -// -// return buildConnection(node); - return null; - } -} diff --git a/source/java/org/alfresco/repo/publishing/authorization/NodeBasedConnectionRepository2.java b/source/java/org/alfresco/repo/publishing/authorization/NodeBasedConnectionRepository2.java deleted file mode 100644 index 70cc47efae..0000000000 --- a/source/java/org/alfresco/repo/publishing/authorization/NodeBasedConnectionRepository2.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright (C) 2005-2010 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.authorization; - -import static org.alfresco.model.ContentModel.ASSOC_CONTAINS; -import static org.alfresco.repo.publishing.PublishingModel.TYPE_PUBLISHING_CONNECTION; -import java.util.Collections; -import java.util.List; - -import org.alfresco.repo.model.Repository; -import org.alfresco.service.cmr.model.FileFolderService; -import org.alfresco.service.cmr.model.FileInfo; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.util.collections.CollectionUtils; -import org.alfresco.util.collections.Function; -import org.springframework.social.connect.Connection; -import org.springframework.social.connect.ConnectionKey; -import org.springframework.social.connect.ConnectionRepository; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; - -/** - * @author Nick Smith - * @since 4.0 - * - */ -public class NodeBasedConnectionRepository2 implements ConnectionRepository -{ - /** - * Serial version UID - */ - private static final long serialVersionUID = 3258131523636186548L; - - /** Reference to the auth store space node */ - private static final StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); - protected static final NodeRef SOCIAL_PUBLISHING_AUTHORISATION_ROOT_NODE_REF = - new NodeRef(SPACES_STORE, "social_publishing_authorisation_space"); - - private NodeService nodeService; - private FileFolderService fileFolderService; - private SearchService searchService; - private Repository repositoryHelper; - - // TODO Replace this with doing it properly... - private NodeRef authRootNode; - - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } - - /** - * @param fileFolderService the fileFolderService to set - */ - public void setFileFolderService(FileFolderService fileFolderService) - { - this.fileFolderService = fileFolderService; - } - - public void setSearchService(SearchService searchService) - { - this.searchService = searchService; - } - - public void setRepositoryHelper(Repository repositoryHelper) - { - this.repositoryHelper = repositoryHelper; - } - - /** - * {@inheritDoc} - */ - public MultiValueMap> findConnections() - { - MultiValueMap> results = new LinkedMultiValueMap>(); - for (String providerId : getAllProviderIds()) - { - List> connections = findConnectionsToProvider(providerId); - if(connections!=null && connections.isEmpty() == false) - { - results.put(providerId, connections); - } - } - return results; - } - - /** - * {@inheritDoc} - */ - public List> findConnectionsToProvider(String providerId) - { - NodeRef providerNode = getProviderNode(providerId); - List connectionNodes = nodeService.getChildAssocs(providerNode, Collections.singleton(TYPE_PUBLISHING_CONNECTION)); - return convertConnections(connectionNodes); - } - - /** - * {@inheritDoc} - */ - @Override - public MultiValueMap> findConnectionsForUsers(MultiValueMap providerUserIds) - { - // TODO Auto-generated method stub - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public Connection findConnection(ConnectionKey connectionKey) - { - // TODO Auto-generated method stub - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public Connection findPrimaryConnectionToApi(Class apiType) - { - // TODO Auto-generated method stub - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public Connection findConnectionToApiForUser(Class apiType, String providerUserId) - { - // TODO Auto-generated method stub - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public List> findConnectionsToApi(Class apiType) - { - // TODO Auto-generated method stub - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public void addConnection(Connection connection) - { - // TODO Auto-generated method stub - - } - - /** - * {@inheritDoc} - */ - @Override - public void updateConnection(Connection connection) - { - // TODO Auto-generated method stub - - } - - /** - * {@inheritDoc} - */ - @Override - public void removeConnectionsToProvider(String providerId) - { - // TODO Auto-generated method stub - - } - - /** - * {@inheritDoc} - */ - public void removeConnection(ConnectionKey connectionKey) - { - // TODO Auto-generated method stub - - } - - private List getAllProviderIds() - { - return CollectionUtils.transform(fileFolderService.listFolders(getAuthentiactionRoot()), new Function() - { - public String apply(FileInfo value) - { - return value.getName(); - } - }); - } - - private NodeRef getProviderNode(String providerId) - { - return nodeService.getChildByName(getAuthentiactionRoot(), ASSOC_CONTAINS, providerId); - } - - private NodeRef getAuthentiactionRoot() - { - //TODO - return null; - } - - private List> convertConnections(List connectionNodes) - { - //TODO - return null; - } - - -}