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:
David Caruana
2007-05-31 18:03:17 +00:00
parent a02ac2a1d2
commit 770185b59b
29 changed files with 1112 additions and 39 deletions

View File

@@ -15,6 +15,8 @@ ok> user [<userName>]
Switch to specified <userName>. If <userName> is omitted, the currently
selected user is shown.
A ticket may be specified instead of username.
ok> quit | exit
Quit this Web Script server.
@@ -32,6 +34,27 @@ ok> get <path>
e.g. get /blog/category?c=Web20
ok> put <path>
Issue a HTTP PUT request to the Web Script located at <path>. The response
is dumped to the console.
<path> URL relative to /alfresco/service
ok> post <path>
Issue a HTTP POST request to the Web Script located at <path>. The response
is dumped to the console.
<path> URL relative to /alfresco/service
ok> delete <path>
Issue a HTTP DELETE request to the Web Script located at <path>. The response
is dumped to the console.
<path> URL relative to /alfresco/service
##
## end
##

View File

@@ -1,6 +1,5 @@
<webscript>
<shortname>Web Script Index</shortname>
<description>Retrieve an index of all Web Scripts</description>
<shortname>Web Scripts Documentation</shortname>
<description>Web Scripts Documentation</description>
<url format="html" template="/index" />
<url format="wiki" template="/index?format=wiki" />
</webscript>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Alfresco Web Scripts</title>
<title>Web Scripts Documentation</title>
<link rel="stylesheet" href="${url.context}/css/main.css" TYPE="text/css">
</head>
<body>
@@ -11,7 +11,7 @@
<table>
<tr>
<td><img src="${url.context}/images/logo/AlfrescoLogo32.png" alt="Alfresco" /></td>
<td><nobr><span class="mainTitle">Alfresco Web Scripts</span></nobr></td>
<td><nobr><span class="mainTitle">Web Scripts Documentation</span></nobr></td>
</tr>
<tr><td><td>Alfresco ${server.edition} v${server.version}
<tr><td><td>${webscripts?size} Web Scripts - <a href="http://wiki.alfresco.com/wiki/HTTP_API">Online documentation</a>. <input type="submit" name="submit" value="Refresh list of Web Scripts">
@@ -19,24 +19,34 @@
</form>
<br>
<br>
<#list webscripts as webscript>
<#assign desc = webscript.description>
<span class="mainSubTitle">${desc.shortName}</span>
<table>
<#list desc.URIs as uri>
<tr><td><a href="${url.serviceContext}${uri.URI}">${desc.method} ${url.serviceContext}${uri.URI}</a> => ${uri.format}<#if uri.format = desc.defaultFormat> (default)</#if>
</#list>
<tr><td>
</table>
<table>
<#if desc.description??><tr><td>Description:<td>${desc.description}<#else></#if>
<tr><td>Authentication:<td>${desc.requiredAuthentication}
<tr><td>Transaction:<td>${desc.requiredTransaction}
<tr><td>
<tr><td>Id:<td>${desc.id}
<tr><td>Description:<td><a href="${url.serviceContext}/description/${desc.id}">${desc.storePath}/${desc.descPath}</a>
<tr><td><a href="${url.serviceContext}/index/all">Browse all Web Scripts</a>
</table>
<br>
<#macro recurseuri uri>
<#if uri.scripts?size &gt; 0>
<tr><td><a href="${url.serviceContext}/index/uri${uri.path}">${uri.path}</a>
</#if>
<#list uri.children as childpath>
<@recurseuri uri=childpath/>
</#list>
</#macro>
<span class="mainSubTitle">Web Scripts by URL</span>
<table>
<@recurseuri uri=rooturl/>
</table>
<br>
<#macro recursepackage package>
<#if package.scripts?size &gt; 0>
<tr><td><a href="${url.serviceContext}/index/package${package.path}">${package.path}</a>
</#if>
<#list package.children as childpath>
<@recursepackage package=childpath/>
</#list>
</#macro>
<span class="mainSubTitle">Web Scripts by Package</span>
<table>
<@recursepackage package=rootpackage/>
</table>
</body>
</html>

View File

@@ -0,0 +1,6 @@
<webscript>
<shortname>All Web Scripts Index</shortname>
<description>Retrieve an index of all Web Scripts</description>
<url format="html" template="/index/all" />
<url format="mediawiki" template="/index/all.mediawiki" />
</webscript>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Index of All Web Scripts</title>
<link rel="stylesheet" href="${url.context}/css/main.css" TYPE="text/css">
</head>
<body>
<table>
<tr>
<td><img src="${url.context}/images/logo/AlfrescoLogo32.png" alt="Alfresco" /></td>
<td><nobr><span class="mainTitle">Index of All Web Scripts</span></nobr></td>
</tr>
<tr><td><td>Alfresco ${server.edition} v${server.version}
<tr><td><td>${webscripts?size} Web Scripts
</table>
<br>
<table>
<tr><td><a href="${url.serviceContext}/index">Back to Web Scripts Home</a>
</table>
<br>
<#macro recursepackage package>
<#if package.scripts?size &gt; 0>
<span class="mainSubTitle">Package: <a href="${url.serviceContext}/index/package${package.path}">${package.path}</a></span><br><br>
<#list package.scripts as webscript>
<#assign desc = webscript.description>
<span class="mainSubTitle">${desc.shortName}</span>
<table>
<#list desc.URIs as uri>
<tr><td><a href="${url.serviceContext}${uri.URI}">${desc.method} ${url.serviceContext}${uri.URI}</a> => ${uri.format}<#if uri.format = desc.defaultFormat> (default)</#if>
</#list>
<tr><td>
</table>
<table>
<#if desc.description??><tr><td>Description:<td>${desc.description}<#else></#if>
<tr><td>Authentication:<td>${desc.requiredAuthentication}
<tr><td>Transaction:<td>${desc.requiredTransaction}
<tr><td>Format Style:<td>${desc.formatStyle}
<tr><td>
<tr><td>Id:<td>${desc.id}
<tr><td>Description:<td><a href="${url.serviceContext}/description/${desc.id}">${desc.storePath}/${desc.descPath}</a>
</table>
<br>
</#list>
</#if>
<#list package.children as childpath>
<@recursepackage package=childpath/>
</#list>
</#macro>
<@recursepackage package=rootpackage/>
</body>
</html>

View File

@@ -12,13 +12,18 @@ This page provides reference documentation for the Alfresco [[HTTP API]].
Generated on ${date?datetime} from
GET <nowiki>http://</nowiki><host>:<port>/alfresco/service/index?format=wiki
GET <nowiki>http://</nowiki><host>:<port>/alfresco/service/indexall.mediawiki
= API Reference =
<#list webscripts as webscript>
The following reference provides a list of all available Web Scripts organised by Web Script package.
<#macro recursepackage package>
<#if package.scripts?size &gt; 0>
== Package: ${package.path} ==
<#list package.scripts as webscript>
<#assign desc = webscript.description>
== ${desc.shortName} ==
=== ${desc.shortName} ===
<#if desc.description??><#if desc.description?ends_with(".")>${desc.description}<#else>${desc.description}.</#if><#else></#if>
@@ -29,9 +34,16 @@ Generated on ${date?datetime} from
Requirements:
* Authentication: ${desc.requiredAuthentication}
* Transaction: ${desc.requiredTransaction}
* Format Style: ${desc.formatStyle}
Definition:
* Id: ${desc.id}
* Store: ${desc.storePath}/${desc.descPath}
* Description: ${desc.storePath}/${desc.descPath}
</#list>
</#if>
<#list package.children as childpath>
<@recursepackage package=childpath/>
</#list>
</#macro>
<@recursepackage package=rootpackage/>

View File

@@ -0,0 +1,5 @@
<webscript>
<shortname>Web Script Package Index</shortname>
<description>Provide an index of Web Scripts for the specified Web Script package</description>
<url format="html" template="/index/package/{package}" />
</webscript>

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Index of Web Scripts Package '${package.path}'</title>
<link rel="stylesheet" href="${url.context}/css/main.css" TYPE="text/css">
</head>
<body>
<table>
<tr>
<td><img src="${url.context}/images/logo/AlfrescoLogo32.png" alt="Alfresco" /></td>
<td><nobr><span class="mainTitle">Index of Web Scripts Package '${package.path}'</span></nobr></td>
</tr>
<tr><td><td>Alfresco ${server.edition} v${server.version}
<tr><td><td>${package.scripts?size} Web Scripts
</table>
<br>
<table>
<tr><td><a href="${url.serviceContext}/index">Back to Web Scripts Home</a>
<#if package.parent?exists>
<tr><td><a href="${url.serviceContext}/index/package${package.parent.path}">Up to ${package.parent.path}</a>
</#if>
</table>
<br>
<#if package.children?size &gt; 0>
<table>
<@recurseuri package=package/>
</table>
<br>
</#if>
<#macro recurseuri package>
<#list package.children as childpath>
<#if childpath.scripts?size &gt; 0>
<tr><td><a href="${url.serviceContext}/index/package${childpath.path}">${childpath.path}</a>
</#if>
<@recurseuri package=childpath/>
</#list>
</#macro>
<#list package.scripts as webscript>
<#assign desc = webscript.description>
<span class="mainSubTitle">${desc.shortName}</span>
<table>
<#list desc.URIs as uri>
<tr><td><a href="${url.serviceContext}${uri.URI}">${desc.method} ${url.serviceContext}${uri.URI}</a> => ${uri.format}<#if uri.format = desc.defaultFormat> (default)</#if>
</#list>
<tr><td>
</table>
<table>
<#if desc.description??><tr><td>Description:<td>${desc.description}<#else></#if>
<tr><td>Authentication:<td>${desc.requiredAuthentication}
<tr><td>Transaction:<td>${desc.requiredTransaction}
<tr><td>Format Style:<td>${desc.formatStyle}
<tr><td>
<tr><td>Id:<td>${desc.id}
<tr><td>Description:<td><a href="${url.serviceContext}/description/${desc.id}">${desc.storePath}/${desc.descPath}</a>
</table>
<br>
</#list>
</body>
</html>

View File

@@ -0,0 +1,6 @@
<webscript>
<shortname>Web Script URI Index</shortname>
<description>Provide an index of Web Scripts for the specified Web Script URI</description>
<url format="html" template="/index/uri/{uri}" />
<format>argument</format>
</webscript>

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Index of Web Scripts URI '${uri.path}'</title>
<link rel="stylesheet" href="${url.context}/css/main.css" TYPE="text/css">
</head>
<body>
<table>
<tr>
<td><img src="${url.context}/images/logo/AlfrescoLogo32.png" alt="Alfresco" /></td>
<td><nobr><span class="mainTitle">Index of Web Scripts URI '${uri.path}'</span></nobr></td>
</tr>
<tr><td><td>Alfresco ${server.edition} v${server.version}
<tr><td><td>${uri.scripts?size} Web Scripts
</table>
<br>
<table>
<tr><td><a href="${url.serviceContext}/index">Back to Web Scripts Home</a>
<#if uri.parent?exists>
<tr><td><a href="${url.serviceContext}/index/uri${uri.parent.path}">Up to ${uri.parent.path}</a>
</#if>
</table>
<br>
<#if uri.children?size &gt; 0>
<table>
<@recurseuri uri=uri/>
</table>
<br>
</#if>
<#macro recurseuri uri>
<#list uri.children as childpath>
<#if childpath.scripts?size &gt; 0>
<tr><td><a href="${url.serviceContext}/index/uri${childpath.path}">${childpath.path}</a>
</#if>
<@recurseuri uri=childpath/>
</#list>
</#macro>
<#list uri.scripts as webscript>
<#assign desc = webscript.description>
<span class="mainSubTitle">${desc.shortName}</span>
<table>
<#list desc.URIs as uri>
<tr><td><a href="${url.serviceContext}${uri.URI}">${desc.method} ${url.serviceContext}${uri.URI}</a> => ${uri.format}<#if uri.format = desc.defaultFormat> (default)</#if>
</#list>
<tr><td>
</table>
<table>
<#if desc.description??><tr><td>Description:<td>${desc.description}<#else></#if>
<tr><td>Authentication:<td>${desc.requiredAuthentication}
<tr><td>Transaction:<td>${desc.requiredTransaction}
<tr><td>Format Style:<td>${desc.formatStyle}
<tr><td>
<tr><td>Id:<td>${desc.id}
<tr><td>Description:<td><a href="${url.serviceContext}/description/${desc.id}">${desc.storePath}/${desc.descPath}</a>
</table>
<br>
</#list>
</body>
</html>

View File

@@ -0,0 +1,7 @@
<webscript>
<shortname>Login</shortname>
<description>Establish a ticket</description>
<url format="xml" template="/login?u={username}&amp;pw={password?}"/>
<authentication>none</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<ticket>${ticket}</ticket>

View File

@@ -0,0 +1,7 @@
<webscript>
<shortname>Delete Login Ticket</shortname>
<description>Delete Login Ticket</description>
<url format="xml" template="/login/ticket/{ticket}"/>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<ticket>${ticket}</ticket>

View File

@@ -0,0 +1,7 @@
<webscript>
<shortname>Login Ticket</shortname>
<description>Login Ticket</description>
<url format="xml" template="/login/ticket/{ticket}"/>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<ticket>${ticket}</ticket>

View File

@@ -9,6 +9,7 @@
<bean id="webscripts.test" class="org.alfresco.web.scripts.TestWebScriptServer">
<property name="registry" ref="webscripts.registry" />
<property name="authenticationService" ref="authenticationService" />
<property name="transactionService" ref="transactionComponent" />
<property name="configService" ref="webClientConfigService" />
<property name="messages">

View File

@@ -157,7 +157,7 @@
</bean>
<!-- Scripted API Service -->
<bean id="webscript_default" parent="webscript" class="org.alfresco.web.scripts.DeclarativeWebScript" singleton="false" />
<bean id="webscript_default" parent="webscript" class="org.alfresco.web.scripts.DeclarativeWebScript" singleton="false"/>
<!-- -->
@@ -165,11 +165,26 @@
<!-- -->
<!-- List of available Web APIs -->
<bean id="webscript.org.alfresco.index.get" class="org.alfresco.web.scripts.bean.Index" parent="webscript" />
<bean id="webscript.org.alfresco.index.get" class="org.alfresco.web.scripts.bean.Index" parent="webscript" singleton="false"/>
<alias name="webscript.org.alfresco.index.get" alias="webscript.org.alfresco.indexall.get"/>
<bean id="webscript.org.alfresco.indexuri.get" class="org.alfresco.web.scripts.bean.IndexURI" parent="webscript" />
<bean id="webscript.org.alfresco.indexpackage.get" class="org.alfresco.web.scripts.bean.IndexPackage" parent="webscript" />
<!-- Maintain list of available Web APIs -->
<bean id="webscript.org.alfresco.index.post" class="org.alfresco.web.scripts.bean.IndexUpdate" parent="webscript" />
<!-- Authentication APIs -->
<bean id="webscript.org.alfresco.repository.login.get" class="org.alfresco.web.scripts.bean.Login" parent="webscript">
<property name="authenticationService" ref="authenticationService" />
</bean>
<bean id="webscript.org.alfresco.repository.loginticket.get" class="org.alfresco.web.scripts.bean.LoginTicket" parent="webscript">
<property name="ticketComponent" ref="ticketComponent" />
</bean>
<bean id="webscript.org.alfresco.repository.loginticket.delete" class="org.alfresco.web.scripts.bean.LoginTicketDelete" parent="webscript">
<property name="authenticationService" ref="authenticationService" />
<property name="ticketComponent" ref="ticketComponent" />
</bean>
<!-- Retrieve Web Script Description Document -->
<bean id="webscript.org.alfresco.scriptdescription.get" class="org.alfresco.web.scripts.bean.ServiceDescription" parent="webscript" />

View File

@@ -83,6 +83,12 @@ 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()
*/

View 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;
}
}

View File

@@ -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);
@@ -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,7 +359,7 @@ public class TestWebScriptServer
}
String uri = command[1];
MockHttpServletResponse res = submitRequest("get", uri);
MockHttpServletResponse res = submitRequest(command[0], uri);
bout.write(res.getContentAsByteArray());
out.println();
}
@@ -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('?');

View 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();
}

View File

@@ -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
*

View File

@@ -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;
}

View 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;
}
}

View 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;
}
}

View 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();
}
}
}

View 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;
}
}

View 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;
}
}