mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Web Scripts:
- improved generated documentation (indexed by web script url & package) - addition of ticket management web scripts - addition of put, post & delete support to Web Script test server git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5820 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -83,7 +83,13 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
|
||||
// NOTE: The map is sorted by url (descending order)
|
||||
private Map<String, WebScript> webscriptsByURL = new TreeMap<String, WebScript>(Collections.reverseOrder());
|
||||
|
||||
// map of web script packages by path
|
||||
private Map<String, Path> packageByPath = new TreeMap<String, Path>();
|
||||
|
||||
// map of web script uris by path
|
||||
private Map<String, Path> uriByPath = new TreeMap<String, Path>();
|
||||
|
||||
|
||||
//
|
||||
// Initialisation
|
||||
//
|
||||
@@ -180,6 +186,10 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
|
||||
// clear currently registered services
|
||||
webscriptsById.clear();
|
||||
webscriptsByURL.clear();
|
||||
packageByPath.clear();
|
||||
packageByPath.put("/", new Path("/"));
|
||||
uriByPath.clear();
|
||||
uriByPath.put("/", new Path("/"));
|
||||
|
||||
// register services
|
||||
for (WebScriptStore apiStore : storage.getStores())
|
||||
@@ -287,6 +297,10 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
|
||||
logger.debug("Registered Web Script URL '" + uriIdx + "'");
|
||||
}
|
||||
}
|
||||
|
||||
// build path indexes to web script
|
||||
registerPackage(serviceImpl);
|
||||
registerURIs(serviceImpl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,6 +308,63 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
|
||||
logger.debug("Registered " + webscriptsById.size() + " Web Scripts; " + webscriptsByURL.size() + " URLs");
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a Web Script Package
|
||||
*
|
||||
* @param script
|
||||
*/
|
||||
private void registerPackage(WebScript script)
|
||||
{
|
||||
WebScriptDescription desc = script.getDescription();
|
||||
Path path = packageByPath.get("/");
|
||||
String[] parts = desc.getScriptPath().split("/");
|
||||
for (String part : parts)
|
||||
{
|
||||
Path subpath = packageByPath.get(Path.concatPath(path.getPath(), part));
|
||||
if (subpath == null)
|
||||
{
|
||||
subpath = path.createChildPath(part);
|
||||
packageByPath.put(subpath.getPath(), subpath);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Registered Web Script package " + subpath.getPath());
|
||||
}
|
||||
path = subpath;
|
||||
}
|
||||
path.addScript(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a Web Script URI
|
||||
*
|
||||
* @param script
|
||||
*/
|
||||
private void registerURIs(WebScript script)
|
||||
{
|
||||
WebScriptDescription desc = script.getDescription();
|
||||
for (URI uri : desc.getURIs())
|
||||
{
|
||||
Path path = uriByPath.get("/");
|
||||
String[] parts = uri.getURI().split("/");
|
||||
for (String part : parts)
|
||||
{
|
||||
if (part.indexOf("?") != -1)
|
||||
{
|
||||
part = part.substring(0, part.indexOf("?"));
|
||||
}
|
||||
Path subpath = uriByPath.get(Path.concatPath(path.getPath(), part));
|
||||
if (subpath == null)
|
||||
{
|
||||
subpath = path.createChildPath(part);
|
||||
uriByPath.put(subpath.getPath(), subpath);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Registered Web Script URI " + subpath.getPath());
|
||||
}
|
||||
path = subpath;
|
||||
}
|
||||
path.addScript(script);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an Web Script Description
|
||||
*
|
||||
@@ -461,6 +532,22 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptRegistry#getPackage(java.lang.String)
|
||||
*/
|
||||
public WebScriptPath getPackage(String scriptPackage)
|
||||
{
|
||||
return packageByPath.get(scriptPackage);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptRegistry#getUri(java.lang.String)
|
||||
*/
|
||||
public WebScriptPath getUri(String scriptUri)
|
||||
{
|
||||
return uriByPath.get(scriptUri);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptRegistry#getWebScripts()
|
||||
*/
|
||||
@@ -576,5 +663,5 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
|
||||
return service;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
149
source/java/org/alfresco/web/scripts/Path.java
Normal file
149
source/java/org/alfresco/web/scripts/Path.java
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* 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.web.scripts;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
/**
|
||||
* Basic implementation of a Web Script Path
|
||||
*
|
||||
* Used for package & url trees.
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class Path implements WebScriptPath
|
||||
{
|
||||
private String path;
|
||||
private Path parent = null;
|
||||
private Map<String, Path> children = new TreeMap<String, Path>();
|
||||
private Map<String, WebScript> scripts = new TreeMap<String, WebScript>();
|
||||
|
||||
|
||||
/**
|
||||
* Helper to concatenate paths
|
||||
*
|
||||
* @param path1
|
||||
* @param path2
|
||||
* @return concatenated path
|
||||
*/
|
||||
public static String concatPath(String path1, String path2)
|
||||
{
|
||||
return path1.equals("/") ? path1 + path2 : path1 + "/" + path2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
public Path(String path)
|
||||
{
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Child Path
|
||||
*
|
||||
* @param path child path name
|
||||
* @return child path
|
||||
*/
|
||||
public Path createChildPath(String path)
|
||||
{
|
||||
Path child = new Path(concatPath(this.path, path));
|
||||
child.parent = this;
|
||||
children.put(child.path, child);
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* Associate Web Script with Path
|
||||
*
|
||||
* @param script
|
||||
*/
|
||||
public void addScript(WebScript script)
|
||||
{
|
||||
scripts.put(script.getDescription().getId(), script);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptPath#getChildren()
|
||||
*/
|
||||
public WebScriptPath[] getChildren()
|
||||
{
|
||||
WebScriptPath[] childrenArray = new WebScriptPath[children.size()];
|
||||
return children.values().toArray(childrenArray);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptPath#getScripts()
|
||||
*/
|
||||
public WebScript[] getScripts()
|
||||
{
|
||||
WebScript[] scriptsArray = new WebScript[scripts.size()];
|
||||
return scripts.values().toArray(scriptsArray);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptPath#getName()
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
String name = "";
|
||||
int i = path.lastIndexOf("/");
|
||||
if (i != -1 && i != (path.length() -1))
|
||||
{
|
||||
name = path.substring(i + 1);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptPath#getParent()
|
||||
*/
|
||||
public WebScriptPath getParent()
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptPath#getPath()
|
||||
*/
|
||||
public String getPath()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
@@ -35,8 +35,11 @@ import java.io.StringWriter;
|
||||
|
||||
import org.alfresco.config.Config;
|
||||
import org.alfresco.config.ConfigService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.transaction.TransactionUtil;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.web.config.ServerConfigElement;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -55,6 +58,7 @@ import org.springframework.mock.web.MockHttpServletResponse;
|
||||
public class TestWebScriptServer
|
||||
{
|
||||
// dependencies
|
||||
protected AuthenticationService authenticationService;
|
||||
protected TransactionService transactionService;
|
||||
protected DeclarativeWebScriptRegistry registry;
|
||||
protected ConfigService configService;
|
||||
@@ -105,6 +109,13 @@ public class TestWebScriptServer
|
||||
this.configService = configService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authenticationService
|
||||
*/
|
||||
public void setAuthenticationService(AuthenticationService authenticationService)
|
||||
{
|
||||
this.authenticationService = authenticationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Messages resource bundle
|
||||
@@ -184,7 +195,7 @@ public class TestWebScriptServer
|
||||
public MockHttpServletResponse submitRequest(String method, String uri)
|
||||
throws IOException
|
||||
{
|
||||
MockHttpServletRequest req = createRequest("get", uri);
|
||||
MockHttpServletRequest req = createRequest(method, uri);
|
||||
MockHttpServletResponse res = new MockHttpServletResponse();
|
||||
|
||||
WebScriptRuntime runtime = new WebScriptServletRuntime(registry, transactionService, null, req, res, serverConfig);
|
||||
@@ -211,7 +222,7 @@ public class TestWebScriptServer
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// execute command in context of currently selected user
|
||||
long startms = System.currentTimeMillis();
|
||||
System.out.print(interpretCommand(line));
|
||||
@@ -234,6 +245,33 @@ public class TestWebScriptServer
|
||||
private String interpretCommand(final String line)
|
||||
throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
if (username.startsWith("TICKET_"))
|
||||
{
|
||||
try
|
||||
{
|
||||
TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Throwable
|
||||
{
|
||||
authenticationService.validate(username);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return executeCommand(line);
|
||||
}
|
||||
finally
|
||||
{
|
||||
authenticationService.clearCurrentSecurityContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(AuthenticationException e)
|
||||
{
|
||||
executeCommand("user admin");
|
||||
}
|
||||
|
||||
// execute command in context of currently selected user
|
||||
return AuthenticationUtil.runAs(new RunAsWork<String>()
|
||||
{
|
||||
@@ -310,7 +348,10 @@ public class TestWebScriptServer
|
||||
out.println("using user " + username);
|
||||
}
|
||||
|
||||
else if (command[0].equals("get"))
|
||||
else if (command[0].equals("get") ||
|
||||
command[0].equals("put") ||
|
||||
command[0].equals("post") ||
|
||||
command[0].equals("delete"))
|
||||
{
|
||||
if (command.length < 2)
|
||||
{
|
||||
@@ -318,11 +359,11 @@ public class TestWebScriptServer
|
||||
}
|
||||
|
||||
String uri = command[1];
|
||||
MockHttpServletResponse res = submitRequest("get", uri);
|
||||
MockHttpServletResponse res = submitRequest(command[0], uri);
|
||||
bout.write(res.getContentAsByteArray());
|
||||
out.println();
|
||||
}
|
||||
|
||||
|
||||
else if (command[0].equals("reset"))
|
||||
{
|
||||
registry.reset();
|
||||
@@ -349,7 +390,7 @@ public class TestWebScriptServer
|
||||
*/
|
||||
private MockHttpServletRequest createRequest(String method, String uri)
|
||||
{
|
||||
MockHttpServletRequest req = new MockHttpServletRequest("get", uri);
|
||||
MockHttpServletRequest req = new MockHttpServletRequest(method, uri);
|
||||
|
||||
// set parameters
|
||||
int iArgIndex = uri.indexOf('?');
|
||||
|
70
source/java/org/alfresco/web/scripts/WebScriptPath.java
Normal file
70
source/java/org/alfresco/web/scripts/WebScriptPath.java
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.web.scripts;
|
||||
|
||||
|
||||
/**
|
||||
* Web Script Path
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public interface WebScriptPath
|
||||
{
|
||||
/**
|
||||
* Gets the full path
|
||||
*
|
||||
* @return path
|
||||
*/
|
||||
public String getPath();
|
||||
|
||||
/**
|
||||
* Gets the name of the path (last path segment)
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Gets the parent path
|
||||
*
|
||||
* @return path
|
||||
*/
|
||||
public WebScriptPath getParent();
|
||||
|
||||
/**
|
||||
* Gets the child paths
|
||||
*
|
||||
* @return child paths
|
||||
*/
|
||||
public WebScriptPath[] getChildren();
|
||||
|
||||
/**
|
||||
* Gets Web Scripts associated with this path
|
||||
*
|
||||
* @return web scripts
|
||||
*/
|
||||
public WebScript[] getScripts();
|
||||
|
||||
}
|
@@ -38,6 +38,22 @@ import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
*/
|
||||
public interface WebScriptRegistry
|
||||
{
|
||||
/**
|
||||
* Gets a Web Script Package
|
||||
*
|
||||
* @param packagePath
|
||||
* @return web script path representing package
|
||||
*/
|
||||
public WebScriptPath getPackage(String packagePath);
|
||||
|
||||
/**
|
||||
* Gets a Web Script URL
|
||||
*
|
||||
* @param uriPath
|
||||
* @return web script path representing uri
|
||||
*/
|
||||
public WebScriptPath getUri(String uriPath);
|
||||
|
||||
/**
|
||||
* Gets all Web Scripts
|
||||
*
|
||||
|
@@ -33,7 +33,7 @@ import org.alfresco.web.scripts.WebScriptResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the list of available Web Scripts
|
||||
* Index of all Web Scripts
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
@@ -48,6 +48,8 @@ public class Index extends DeclarativeWebScript
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>(7, 1.0f);
|
||||
model.put("webscripts", getWebScriptRegistry().getWebScripts());
|
||||
model.put("rooturl", getWebScriptRegistry().getUri("/"));
|
||||
model.put("rootpackage", getWebScriptRegistry().getPackage("/"));
|
||||
return model;
|
||||
}
|
||||
|
||||
|
74
source/java/org/alfresco/web/scripts/bean/IndexPackage.java
Normal file
74
source/java/org/alfresco/web/scripts/bean/IndexPackage.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.web.scripts.bean;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.web.scripts.DeclarativeWebScript;
|
||||
import org.alfresco.web.scripts.WebScriptException;
|
||||
import org.alfresco.web.scripts.WebScriptPath;
|
||||
import org.alfresco.web.scripts.WebScriptRequest;
|
||||
import org.alfresco.web.scripts.WebScriptResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Index of a Web Script Package
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class IndexPackage extends DeclarativeWebScript
|
||||
{
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
|
||||
*/
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptResponse res)
|
||||
{
|
||||
// extract web script package
|
||||
String packagePath = req.getExtensionPath();
|
||||
if (packagePath == null || packagePath.length() == 0)
|
||||
{
|
||||
packagePath = "/";
|
||||
}
|
||||
if (!packagePath.startsWith("/"))
|
||||
{
|
||||
packagePath = "/" + packagePath;
|
||||
}
|
||||
|
||||
// locate web script package
|
||||
WebScriptPath path = getWebScriptRegistry().getPackage(packagePath);
|
||||
if (path == null)
|
||||
{
|
||||
throw new WebScriptException("Web Script Package '" + packagePath + "' not found");
|
||||
}
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>(7, 1.0f);
|
||||
model.put("package", path);
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
74
source/java/org/alfresco/web/scripts/bean/IndexURI.java
Normal file
74
source/java/org/alfresco/web/scripts/bean/IndexURI.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.web.scripts.bean;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.web.scripts.DeclarativeWebScript;
|
||||
import org.alfresco.web.scripts.WebScriptException;
|
||||
import org.alfresco.web.scripts.WebScriptPath;
|
||||
import org.alfresco.web.scripts.WebScriptRequest;
|
||||
import org.alfresco.web.scripts.WebScriptResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Index of a Web Script URI
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class IndexURI extends DeclarativeWebScript
|
||||
{
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
|
||||
*/
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptResponse res)
|
||||
{
|
||||
// extract web script package
|
||||
String uriPath = req.getExtensionPath();
|
||||
if (uriPath == null || uriPath.length() == 0)
|
||||
{
|
||||
uriPath = "/";
|
||||
}
|
||||
if (!uriPath.startsWith("/"))
|
||||
{
|
||||
uriPath = "/" + uriPath;
|
||||
}
|
||||
|
||||
// locate web script package
|
||||
WebScriptPath path = getWebScriptRegistry().getUri(uriPath);
|
||||
if (path == null)
|
||||
{
|
||||
throw new WebScriptException("Web Script URI '" + uriPath + "' not found");
|
||||
}
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>(7, 1.0f);
|
||||
model.put("uri", path);
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
86
source/java/org/alfresco/web/scripts/bean/Login.java
Normal file
86
source/java/org/alfresco/web/scripts/bean/Login.java
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.web.scripts.bean;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.web.scripts.DeclarativeWebScript;
|
||||
import org.alfresco.web.scripts.WebScriptException;
|
||||
import org.alfresco.web.scripts.WebScriptRequest;
|
||||
import org.alfresco.web.scripts.WebScriptResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Login and establish a ticket
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class Login extends DeclarativeWebScript
|
||||
{
|
||||
// dependencies
|
||||
private AuthenticationService authenticationService;
|
||||
|
||||
/**
|
||||
* @param authenticationService
|
||||
*/
|
||||
public void setAuthenticationService(AuthenticationService authenticationService)
|
||||
{
|
||||
this.authenticationService = authenticationService;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
|
||||
*/
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptResponse res)
|
||||
{
|
||||
// extract username and password
|
||||
String username = req.getParameter("u");
|
||||
if (username == null || username.length() == 0)
|
||||
{
|
||||
throw new WebScriptException("Username has not been specified");
|
||||
}
|
||||
String password = req.getParameter("pw");
|
||||
|
||||
// get ticket
|
||||
authenticationService.authenticate(username, password == null ? null : password.toCharArray());
|
||||
|
||||
// add ticket to model for javascript and template access
|
||||
try
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>(7, 1.0f);
|
||||
model.put("ticket", authenticationService.getCurrentTicket());
|
||||
return model;
|
||||
}
|
||||
finally
|
||||
{
|
||||
authenticationService.clearCurrentSecurityContext();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
92
source/java/org/alfresco/web/scripts/bean/LoginTicket.java
Normal file
92
source/java/org/alfresco/web/scripts/bean/LoginTicket.java
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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.web.scripts.bean;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.TicketComponent;
|
||||
import org.alfresco.web.scripts.DeclarativeWebScript;
|
||||
import org.alfresco.web.scripts.WebScriptException;
|
||||
import org.alfresco.web.scripts.WebScriptRequest;
|
||||
import org.alfresco.web.scripts.WebScriptResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Login Ticket
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class LoginTicket extends DeclarativeWebScript
|
||||
{
|
||||
// dependencies
|
||||
private TicketComponent ticketComponent;
|
||||
|
||||
/**
|
||||
* @param ticketComponent
|
||||
*/
|
||||
public void setTicketComponent(TicketComponent ticketComponent)
|
||||
{
|
||||
this.ticketComponent = ticketComponent;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
|
||||
*/
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptResponse res)
|
||||
{
|
||||
// retrieve ticket from request and current ticket
|
||||
String ticket = req.getExtensionPath();
|
||||
if (ticket == null && ticket.length() == 0)
|
||||
{
|
||||
throw new WebScriptException("Ticket not specified");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String ticketUser = ticketComponent.validateTicket(ticket);
|
||||
|
||||
// do not go any further if tickets are different
|
||||
if (!AuthenticationUtil.getCurrentUserName().equals(ticketUser))
|
||||
{
|
||||
// TODO: 404 error
|
||||
throw new WebScriptException("Ticket not found");
|
||||
}
|
||||
}
|
||||
catch(AuthenticationException e)
|
||||
{
|
||||
throw new WebScriptException("Ticket not found");
|
||||
}
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>(7, 1.0f);
|
||||
model.put("ticket", ticket);
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
105
source/java/org/alfresco/web/scripts/bean/LoginTicketDelete.java
Normal file
105
source/java/org/alfresco/web/scripts/bean/LoginTicketDelete.java
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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.web.scripts.bean;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.TicketComponent;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.web.scripts.DeclarativeWebScript;
|
||||
import org.alfresco.web.scripts.WebScriptException;
|
||||
import org.alfresco.web.scripts.WebScriptRequest;
|
||||
import org.alfresco.web.scripts.WebScriptResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Delete Login Ticket
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class LoginTicketDelete extends DeclarativeWebScript
|
||||
{
|
||||
// dependencies
|
||||
private AuthenticationService authenticationService;
|
||||
private TicketComponent ticketComponent;
|
||||
|
||||
/**
|
||||
* @param ticketComponent
|
||||
*/
|
||||
public void setTicketComponent(TicketComponent ticketComponent)
|
||||
{
|
||||
this.ticketComponent = ticketComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authenticationService
|
||||
*/
|
||||
public void setAuthenticationService(AuthenticationService authenticationService)
|
||||
{
|
||||
this.authenticationService = authenticationService;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
|
||||
*/
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptResponse res)
|
||||
{
|
||||
// retrieve ticket from request and current ticket
|
||||
String ticket = req.getExtensionPath();
|
||||
if (ticket == null && ticket.length() == 0)
|
||||
{
|
||||
throw new WebScriptException("Ticket not specified");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String ticketUser = ticketComponent.validateTicket(ticket);
|
||||
|
||||
// do not go any further if tickets are different
|
||||
if (!AuthenticationUtil.getCurrentUserName().equals(ticketUser))
|
||||
{
|
||||
// TODO: 404 error
|
||||
throw new WebScriptException("Ticket not found");
|
||||
}
|
||||
}
|
||||
catch(AuthenticationException e)
|
||||
{
|
||||
throw new WebScriptException("Ticket not found");
|
||||
}
|
||||
|
||||
// delete the ticket
|
||||
authenticationService.invalidateTicket(ticket);
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>(7, 1.0f);
|
||||
model.put("ticket", ticket);
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user