mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged DEV/TEMPORARY to HEAD
17804: Branch for SpringSurf integration 2 to RemoteAPI - from HEAD r17789 17808: Part 3 of SpringSurf integration - RemoteAPI, Web-Client, Mobile and DOD5015 java code refactored to use SpringSurf Webscripts libraries, removed dependancies on existing WebScriptFramework project. 17812: Removed web-framework and webscript-framework projects. Updated build scripts to use SpringSurf dependencies for remote API and client projects and also removal of wf and wsf projects from builds. 17818: Various Spring app context and config changes to integration SpringSurf at the RemoteAPI and Web-Client project level. - Build scripts fixed up - Temporary web.xml changes until spring mvc dispatcher is hooked into /service urls - The server starts up! No nothing else works yet, you know how this goes... 17819: Fix to incremental-webclient-tomcat-exploded build target to work on first deploy to a clean tomcat (affects HEAD also, not SpringSurf related). 17872: Refactor Web-Client web.xml to use Spring WebScripts Dispatcher Servlet - servlet is configured to use the existing Spring application context instance as loaded by the ContextLoaderListener Share web.xml TODOs for JBoss app-server support (currently missing from SpringSurf extraction) 17892: Upgraded Repository Spring dependant libraries to 3.0.0 release. Upgraded to latest SpringSurf release (also running against Spring 3.0.0) Various related fixes. 17893: Additional Spring3.0.0 migration fixes and libraries. 17899: Integrated another SpringSurf bug fix - to correctly add ClassPathStore instances to SearchPath objects. 17901: Fixes to handling of merging of models returned from the new Script Processors. Share now works against a Repository that is running SpringSurf WebScripts and Spring 3.0.0. 17904: Latest SpringSurf libraries after latest changes. TODO: - NTLM filter needs moving to Share (not present in SpringSurf) - MessagesWebScript - community tracking image needs adding to Share specific version (not present in SpringSurf) - feedController - for rss feed service urls - needs testing - Clustering config overrides - no longer work in SpringSurf, needs a rethink - Mobile project is not working - PHP module project - JBossEnabledWebApplicationContext required for Share - currently missing from SpringSurf git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@17906 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.facebook;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.extensions.config.ServerProperties;
|
||||
import org.springframework.extensions.webscripts.Match;
|
||||
import org.springframework.extensions.webscripts.RuntimeContainer;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.servlet.ServletAuthenticatorFactory;
|
||||
import org.springframework.extensions.webscripts.servlet.WebScriptServletRuntime;
|
||||
|
||||
|
||||
/**
|
||||
* Runtime to support requests from Facebook
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class FacebookAPIRuntime extends WebScriptServletRuntime
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param container
|
||||
* @param authFactory
|
||||
* @param req
|
||||
* @param res
|
||||
* @param serverProperties
|
||||
*/
|
||||
public FacebookAPIRuntime(RuntimeContainer container, ServletAuthenticatorFactory authFactory, HttpServletRequest req, HttpServletResponse res, ServerProperties serverProperties)
|
||||
{
|
||||
super(container, authFactory, req, res, serverProperties);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.servlet.WebScriptServletRuntime#createRequest(org.alfresco.web.scripts.Match)
|
||||
*/
|
||||
@Override
|
||||
protected WebScriptRequest createRequest(Match match)
|
||||
{
|
||||
servletReq = new FacebookServletRequest(this, req, match, serverProperties, getScriptUrl());
|
||||
return servletReq;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.servlet.WebScriptServletRuntime#getScriptParameters()
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getScriptParameters()
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.putAll(super.getScriptParameters());
|
||||
model.put("facebook", new FacebookModel((FacebookServletRequest)servletReq));
|
||||
return model;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.AbstractRuntime#getTemplateParameters()
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getTemplateParameters()
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.putAll(super.getTemplateParameters());
|
||||
model.put("facebook", new FacebookModel((FacebookServletRequest)servletReq));
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.facebook;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.webscripts.servlet.WebScriptServlet;
|
||||
|
||||
|
||||
/**
|
||||
* Web Script API entry point (with Facebook authentication)
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class FacebookAPIServlet extends WebScriptServlet
|
||||
{
|
||||
private static final long serialVersionUID = 4209892938069597860L;
|
||||
|
||||
// Logger
|
||||
private static final Log logger = LogFactory.getLog(FacebookAPIServlet.class);
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
|
||||
* javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
@Override
|
||||
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Processing facebook api request (" + req.getMethod() + ") " + req.getRequestURL() + (req.getQueryString() != null ? "?" + req.getQueryString() : ""));
|
||||
|
||||
FacebookAPIRuntime runtime = new FacebookAPIRuntime(container, authenticatorFactory, req, res, serverProperties);
|
||||
runtime.executeScript();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.facebook;
|
||||
|
||||
|
||||
/**
|
||||
* Facebook Application
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class FacebookAppModel
|
||||
{
|
||||
String appId;
|
||||
String apiKey;
|
||||
String secretKey;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param apiKey
|
||||
*/
|
||||
public FacebookAppModel(String apiKey)
|
||||
{
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return application apiKey
|
||||
*/
|
||||
public String getApiKey()
|
||||
{
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return application secret
|
||||
*/
|
||||
public String getSecret()
|
||||
{
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param secretKey application secret
|
||||
*/
|
||||
public void setSecret(String secretKey)
|
||||
{
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return application id
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param appId application id
|
||||
*/
|
||||
public void setId(String appId)
|
||||
{
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
}
|
@@ -27,15 +27,14 @@ package org.alfresco.repo.web.scripts.facebook;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.web.scripts.Authenticator;
|
||||
import org.alfresco.web.scripts.WebScriptException;
|
||||
import org.alfresco.web.scripts.Description.RequiredAuthentication;
|
||||
import org.alfresco.web.scripts.facebook.FacebookServletRequest;
|
||||
import org.alfresco.web.scripts.servlet.ServletAuthenticatorFactory;
|
||||
import org.alfresco.web.scripts.servlet.WebScriptServletRequest;
|
||||
import org.alfresco.web.scripts.servlet.WebScriptServletResponse;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.webscripts.Authenticator;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.Description.RequiredAuthentication;
|
||||
import org.springframework.extensions.webscripts.servlet.ServletAuthenticatorFactory;
|
||||
import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest;
|
||||
import org.springframework.extensions.webscripts.servlet.WebScriptServletResponse;
|
||||
|
||||
/**
|
||||
* Web Script Authenticator that supports Facebook authentication
|
||||
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.facebook;
|
||||
|
||||
/**
|
||||
* Facebook Error.
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class FacebookError extends RuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = -7338963365877285084L;
|
||||
|
||||
private int code = -1;
|
||||
|
||||
public FacebookError(String msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public FacebookError(int code, String msg)
|
||||
{
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.facebook;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import com.facebook.api.FacebookException;
|
||||
import com.facebook.api.FacebookRestClient;
|
||||
|
||||
|
||||
/**
|
||||
* Facebook Javascript API
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class FacebookModel
|
||||
{
|
||||
// Logger
|
||||
private static final Log logger = LogFactory.getLog(FacebookModel.class);
|
||||
|
||||
private FacebookServletRequest req;
|
||||
private FacebookRestClient client;
|
||||
private String[] friends;
|
||||
private String[] appFriends;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param req
|
||||
*/
|
||||
public FacebookModel(FacebookServletRequest req)
|
||||
{
|
||||
this.req = req;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the facebook rest client
|
||||
*/
|
||||
private FacebookRestClient getClient()
|
||||
{
|
||||
if (client == null)
|
||||
{
|
||||
String apiKey = req.getApiKey();
|
||||
String secretKey = req.getSecretKey();
|
||||
String sessionKey = req.getSessionKey();
|
||||
if (sessionKey == null)
|
||||
{
|
||||
client = new FacebookRestClient(apiKey, secretKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
client = new FacebookRestClient(apiKey, secretKey, sessionKey);
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
client.setDebug(true);
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all friends of the logged in facebook user
|
||||
*/
|
||||
public String[] getFriends()
|
||||
{
|
||||
if (friends == null)
|
||||
{
|
||||
friends = req.getFriends();
|
||||
if (friends == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Document response = getClient().friends_get();
|
||||
NodeList uids = response.getElementsByTagName("uid");
|
||||
String[] uidsArray = new String[uids.getLength()];
|
||||
for (int i = 0; i < uids.getLength(); i++)
|
||||
{
|
||||
uidsArray[i] = uids.item(i).getTextContent();
|
||||
}
|
||||
friends = uidsArray;
|
||||
}
|
||||
catch(FacebookException e)
|
||||
{
|
||||
throw new FacebookError(e.getCode(), e.getMessage());
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new FacebookError(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return friends;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return friends who are users of the current application
|
||||
*/
|
||||
public String[] getAppFriends()
|
||||
{
|
||||
if (appFriends == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Document response = getClient().friends_getAppUsers();
|
||||
NodeList uids = response.getElementsByTagName("uid");
|
||||
String[] uidsArray = new String[uids.getLength()];
|
||||
for (int i = 0; i < uids.getLength(); i++)
|
||||
{
|
||||
uidsArray[i] = uids.item(i).getTextContent();
|
||||
}
|
||||
appFriends = uidsArray;
|
||||
}
|
||||
catch(FacebookException e)
|
||||
{
|
||||
throw new FacebookError(e.getCode(), e.getMessage());
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new FacebookError(e.getMessage());
|
||||
}
|
||||
}
|
||||
return appFriends;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post User Action
|
||||
*
|
||||
* For details see:
|
||||
* http://wiki.developers.facebook.com/index.php/Feed.publishActionOfUser
|
||||
*
|
||||
* @param title
|
||||
* @param body
|
||||
* @return
|
||||
*/
|
||||
public int postUserAction(String title, String body)
|
||||
{
|
||||
try
|
||||
{
|
||||
Document response = getClient().feed_publishActionOfUser(title, body);
|
||||
int status = Integer.parseInt(response.getDocumentElement().getTextContent());
|
||||
return status;
|
||||
}
|
||||
catch (FacebookException e)
|
||||
{
|
||||
if (logger.isErrorEnabled())
|
||||
logger.error("Failed to post user action [title=" + title + ", body=" + body + "] due to " + e.toString());
|
||||
throw new FacebookError(e.getCode(), e.getMessage());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
if (logger.isErrorEnabled())
|
||||
logger.error("Failed to post user action [title=" + title + ", body=" + body + "] due to " + e.toString());
|
||||
throw new FacebookError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return user id of logged in facebook user
|
||||
*/
|
||||
public String getUser()
|
||||
{
|
||||
return req.getUserId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return application id of current application
|
||||
*/
|
||||
public String getAppId()
|
||||
{
|
||||
return req.getAppId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return session key of current facebook session
|
||||
*/
|
||||
public String getSessionKey()
|
||||
{
|
||||
return req.getSessionKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return application api key
|
||||
*/
|
||||
public String getApiKey()
|
||||
{
|
||||
return req.getApiKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return application secret key
|
||||
*/
|
||||
public String getSecret()
|
||||
{
|
||||
return req.getSecretKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return facebook canvas path (as entered into 'Create Application' dialog)
|
||||
*/
|
||||
public String getCanvasPath()
|
||||
{
|
||||
return req.getCanvasPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return facebook canvas url (http://apps.facebook.com/canvasPath)
|
||||
*/
|
||||
public String getCanvasURL()
|
||||
{
|
||||
return "http://apps.facebook.com/" + getCanvasPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return facebook page url (http://apps.facebook.com/canvasPath/page)
|
||||
*/
|
||||
public String getPageURL()
|
||||
{
|
||||
return "http://apps.facebook.com" + req.getPagePath();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.facebook;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.webscripts.Container;
|
||||
import org.springframework.extensions.webscripts.ScriptContent;
|
||||
import org.springframework.extensions.webscripts.ScriptProcessor;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
||||
|
||||
/**
|
||||
* Facebook Service
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class FacebookService
|
||||
{
|
||||
// Logger
|
||||
private static final Log logger = LogFactory.getLog(FacebookService.class);
|
||||
|
||||
// Facebook Application Cache
|
||||
private Map<String, FacebookAppModel> apps = new HashMap<String, FacebookAppModel>();
|
||||
private ReentrantReadWriteLock appsLock = new ReentrantReadWriteLock();
|
||||
|
||||
// Component dependencies
|
||||
private Container container;
|
||||
|
||||
|
||||
/**
|
||||
* @param registry Web Script Registry
|
||||
*/
|
||||
public void setContainer(Container container)
|
||||
{
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the application model for the given application api key
|
||||
*
|
||||
* @param apiKey api key
|
||||
* @return application model
|
||||
*/
|
||||
FacebookAppModel getAppModel(String apiKey)
|
||||
{
|
||||
FacebookAppModel facebookApp = null;
|
||||
appsLock.readLock().lock();
|
||||
|
||||
try
|
||||
{
|
||||
facebookApp = apps.get(apiKey);
|
||||
if (facebookApp == null)
|
||||
{
|
||||
// Upgrade read lock to write lock
|
||||
appsLock.readLock().unlock();
|
||||
appsLock.writeLock().lock();
|
||||
|
||||
try
|
||||
{
|
||||
// Check again
|
||||
facebookApp = apps.get(apiKey);
|
||||
if (facebookApp == null)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Initialising Facebook Application '" + apiKey + "'");
|
||||
|
||||
// Locate app initialisation script in web script store
|
||||
String appPath = "com/facebook/_apps/app." + apiKey + ".js";
|
||||
String validScriptPath = container.getScriptProcessorRegistry().findValidScriptPath(appPath);
|
||||
if (validScriptPath == null)
|
||||
{
|
||||
throw new WebScriptException("Unable to locate application initialisation script '" + appPath + "'");
|
||||
}
|
||||
ScriptProcessor scriptProcessor = container.getScriptProcessorRegistry().getScriptProcessor(validScriptPath);
|
||||
ScriptContent appScript = scriptProcessor.findScript(validScriptPath);
|
||||
if (appScript == null)
|
||||
{
|
||||
throw new WebScriptException("Unable to locate application initialisation script '" + appPath + "'");
|
||||
}
|
||||
|
||||
// Execute app initialisation script
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
FacebookAppModel app = new FacebookAppModel(apiKey);
|
||||
model.put("app", app);
|
||||
scriptProcessor.executeScript(appScript, model);
|
||||
|
||||
// Validate initialisation
|
||||
if (app.getSecret() == null)
|
||||
{
|
||||
throw new WebScriptException("Secret key for application '" + apiKey + "' has not been specified.");
|
||||
}
|
||||
if (app.getApiKey() == null)
|
||||
{
|
||||
throw new WebScriptException("Application Id for application '" + apiKey + "' has not been specified.");
|
||||
}
|
||||
|
||||
apps.put(apiKey, app);
|
||||
facebookApp = app;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Downgrade lock to read
|
||||
appsLock.readLock().lock();
|
||||
appsLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
return facebookApp;
|
||||
}
|
||||
finally
|
||||
{
|
||||
appsLock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets currently known Facebook Applications
|
||||
*
|
||||
* @return map (name, application) of known applications
|
||||
*/
|
||||
public Map<String, FacebookAppModel> getAppModels()
|
||||
{
|
||||
return apps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset Facebook Service
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
appsLock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
apps.clear();
|
||||
}
|
||||
finally
|
||||
{
|
||||
appsLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.facebook;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
|
||||
/**
|
||||
* Facebook Canvas Page Requests
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class FacebookServlet extends FacebookAPIServlet
|
||||
{
|
||||
private static final long serialVersionUID = 2276870692940598426L;
|
||||
|
||||
// Logger
|
||||
private static final Log logger = LogFactory.getLog(FacebookServlet.class);
|
||||
|
||||
// Component Dependencies
|
||||
protected FacebookService facebookService;
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
@Override
|
||||
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Processing facebook canvas (" + req.getMethod() + ") " + req.getRequestURL() + (req.getQueryString() != null ? "?" + req.getQueryString() : ""));
|
||||
|
||||
FacebookServletRuntime runtime = new FacebookServletRuntime(container, authenticatorFactory, req, res, serverProperties, facebookService);
|
||||
runtime.executeScript();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptServlet#initServlet(org.springframework.context.ApplicationContext)
|
||||
*/
|
||||
@Override
|
||||
protected void initServlet(ApplicationContext context)
|
||||
{
|
||||
facebookService = (FacebookService)context.getBean("facebook.service");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.facebook;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.extensions.config.ServerProperties;
|
||||
import org.springframework.extensions.webscripts.Match;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest;
|
||||
import org.springframework.extensions.webscripts.Runtime;
|
||||
|
||||
/**
|
||||
* Facebook Servlet Request
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class FacebookServletRequest extends WebScriptServletRequest
|
||||
{
|
||||
private String appId;
|
||||
private String secretKey;
|
||||
private String pathInfo;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param serverConfig
|
||||
* @param req
|
||||
* @param serviceMatch
|
||||
*/
|
||||
public FacebookServletRequest(Runtime container, HttpServletRequest req, Match serviceMatch, ServerProperties serverProperties, String pathInfo)
|
||||
{
|
||||
super(container, req, serviceMatch, serverProperties);
|
||||
this.pathInfo = pathInfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param secretKey application secret
|
||||
*/
|
||||
/*package*/ void setSecretKey(String secretKey)
|
||||
{
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param appId application id
|
||||
*/
|
||||
/*package*/ void setAppId(String appId)
|
||||
{
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return application api key
|
||||
*/
|
||||
public String getApiKey()
|
||||
{
|
||||
return getParameter("fb_sig_api_key");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Facebook user id
|
||||
*/
|
||||
public String getUserId()
|
||||
{
|
||||
return getParameter("fb_sig_user");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return session key
|
||||
*/
|
||||
public String getSessionKey()
|
||||
{
|
||||
return getParameter("fb_sig_session_key");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true => within Facebook canvas
|
||||
*/
|
||||
public boolean isInCanvas()
|
||||
{
|
||||
String canvas = getParameter("fb_sig_api_key");
|
||||
return (canvas == null || canvas.equals("1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return application secret
|
||||
*/
|
||||
public String getSecretKey()
|
||||
{
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return application id
|
||||
*/
|
||||
public String getAppId()
|
||||
{
|
||||
return appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return application canvas path
|
||||
*/
|
||||
public String getCanvasPath()
|
||||
{
|
||||
String pathInfo = getPathInfo();
|
||||
String[] pathSegments = pathInfo.split("/");
|
||||
if (pathSegments.length < 3)
|
||||
{
|
||||
throw new WebScriptException("Cannot establish Facebook Canvas Page URL from request " + getURL());
|
||||
}
|
||||
return pathSegments[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return application page path
|
||||
*/
|
||||
public String getPagePath()
|
||||
{
|
||||
String pagePath = getPathInfo();
|
||||
if (pagePath.startsWith("/facebook"))
|
||||
{
|
||||
pagePath = pathInfo.substring("/facebook".length());
|
||||
}
|
||||
return pagePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return friends of authenticated Facebook user
|
||||
*/
|
||||
public String[] getFriends()
|
||||
{
|
||||
String[] friends;
|
||||
String friendsStr = getParameter("fb_sig_friends");
|
||||
friends = (friendsStr == null) ? new String[0] : friendsStr.split(",");
|
||||
return friends;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.servlet.WebScriptServletRequest#getPathInfo()
|
||||
*/
|
||||
@Override
|
||||
public String getPathInfo()
|
||||
{
|
||||
return pathInfo;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.facebook;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.config.ServerProperties;
|
||||
import org.springframework.extensions.webscripts.Match;
|
||||
import org.springframework.extensions.webscripts.RuntimeContainer;
|
||||
import org.springframework.extensions.webscripts.StatusTemplate;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||
import org.springframework.extensions.webscripts.servlet.ServletAuthenticatorFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Facebook Canvas Page Servlet.
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class FacebookServletRuntime extends FacebookAPIRuntime
|
||||
{
|
||||
// Logger
|
||||
private static final Log logger = LogFactory.getLog(FacebookServletRuntime.class);
|
||||
|
||||
// Component dependencies
|
||||
protected FacebookService facebookService;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param container
|
||||
* @param authFactory
|
||||
* @param req
|
||||
* @param res
|
||||
* @param serverProperties
|
||||
* @param facebookService
|
||||
*/
|
||||
public FacebookServletRuntime(RuntimeContainer container, ServletAuthenticatorFactory authFactory, HttpServletRequest req, HttpServletResponse res,
|
||||
ServerProperties serverProperties, FacebookService facebookService)
|
||||
{
|
||||
super(container, authFactory, req, res, serverProperties);
|
||||
this.facebookService = facebookService;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptRuntime#createRequest(org.alfresco.web.scripts.WebScriptMatch)
|
||||
*/
|
||||
@Override
|
||||
protected WebScriptRequest createRequest(Match match)
|
||||
{
|
||||
FacebookServletRequest fbreq = new FacebookServletRequest(this, req, match, serverProperties, getScriptUrl());
|
||||
|
||||
if (match != null)
|
||||
{
|
||||
FacebookAppModel appModel = facebookService.getAppModel(fbreq.getApiKey());
|
||||
fbreq.setSecretKey(appModel.getSecret());
|
||||
fbreq.setAppId(appModel.getId());
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Facebook request [apiKey=" + fbreq.getApiKey() + ", user=" + fbreq.getUserId() + ", session=" + fbreq.getSessionKey() + ", secret=" + fbreq.getSecretKey() + "]");
|
||||
|
||||
servletReq = fbreq;
|
||||
return servletReq;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptServletRuntime#getScriptUrl()
|
||||
*/
|
||||
@Override
|
||||
protected String getScriptUrl()
|
||||
{
|
||||
return "/facebook" + super.getScriptUrl();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptRuntime#getStatusCodeTemplate(int)
|
||||
*/
|
||||
@Override
|
||||
protected StatusTemplate getStatusCodeTemplate(int statusCode)
|
||||
{
|
||||
return new StatusTemplate("/fbml." + statusCode + ".ftl", WebScriptResponse.HTML_FORMAT);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptRuntime#getStatusTemplate()
|
||||
*/
|
||||
@Override
|
||||
protected StatusTemplate getStatusTemplate()
|
||||
{
|
||||
return new StatusTemplate("/fbml.status.ftl", WebScriptResponse.HTML_FORMAT);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user