mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
126434 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 121906 jvonka: Nodes (File/Folder) API - hopefully fix CMIS test fallout (from noAuth changes) RA-750, RA-755 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126780 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -65,6 +65,12 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
|||||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author steveglover
|
||||||
|
* @author janv
|
||||||
|
* @since PublicApi1.0
|
||||||
|
*/
|
||||||
public class PublicApiDeclarativeRegistry extends DeclarativeRegistry
|
public class PublicApiDeclarativeRegistry extends DeclarativeRegistry
|
||||||
{
|
{
|
||||||
private WebScript getNetworksWebScript;
|
private WebScript getNetworksWebScript;
|
||||||
@@ -99,277 +105,283 @@ public class PublicApiDeclarativeRegistry extends DeclarativeRegistry
|
|||||||
*/
|
*/
|
||||||
public Match findWebScript(String method, String uri)
|
public Match findWebScript(String method, String uri)
|
||||||
{
|
{
|
||||||
if(method.equalsIgnoreCase("get") && uri.equals(PublicApiTenantWebScriptServletRequest.NETWORKS_PATH))
|
Match match = null;
|
||||||
{
|
|
||||||
Map<String, String> templateVars = new HashMap<String, String>();
|
|
||||||
templateVars.put("apiScope", "public");
|
|
||||||
templateVars.put("apiVersion", "1");
|
|
||||||
templateVars.put("apiName", "networks");
|
|
||||||
Match match = new Match("", templateVars, "", getNetworksWebScript);
|
|
||||||
return match;
|
|
||||||
}
|
|
||||||
else if(method.equalsIgnoreCase("get") && uri.equals(PublicApiTenantWebScriptServletRequest.NETWORK_PATH))
|
|
||||||
{
|
|
||||||
Map<String, String> templateVars = new HashMap<String, String>();
|
|
||||||
templateVars.put("apiScope", "public");
|
|
||||||
templateVars.put("apiVersion", "1");
|
|
||||||
templateVars.put("apiName", "network");
|
|
||||||
Match match = new Match("", templateVars, "", getNetworkWebScript);
|
|
||||||
return match;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Match match = super.findWebScript(method, uri);
|
|
||||||
|
|
||||||
HttpMethod httpMethod = HttpMethod.valueOf(method);
|
HttpMethod httpMethod = HttpMethod.valueOf(method);
|
||||||
|
if (httpMethod.equals(HttpMethod.GET))
|
||||||
if (httpMethod.equals(HttpMethod.GET))
|
{
|
||||||
|
if (uri.equals(PublicApiTenantWebScriptServletRequest.NETWORKS_PATH))
|
||||||
|
{
|
||||||
|
Map<String, String> templateVars = new HashMap<String, String>();
|
||||||
|
templateVars.put("apiScope", "public");
|
||||||
|
templateVars.put("apiVersion", "1");
|
||||||
|
templateVars.put("apiName", "networks");
|
||||||
|
match = new Match("", templateVars, "", getNetworksWebScript);
|
||||||
|
}
|
||||||
|
else if (uri.equals(PublicApiTenantWebScriptServletRequest.NETWORK_PATH))
|
||||||
|
{
|
||||||
|
Map<String, String> templateVars = new HashMap<String, String>();
|
||||||
|
templateVars.put("apiScope", "public");
|
||||||
|
templateVars.put("apiVersion", "1");
|
||||||
|
templateVars.put("apiName", "network");
|
||||||
|
match = new Match("", templateVars, "", getNetworkWebScript);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// TODO - review (experimental)
|
// TODO - review (experimental)
|
||||||
|
match = super.findWebScript(method, uri);
|
||||||
|
|
||||||
// noAuth currently only exposed for GET
|
|
||||||
Map<String, String> templateVars = match.getTemplateVars();
|
Map<String, String> templateVars = match.getTemplateVars();
|
||||||
Api api = determineApi(templateVars);
|
|
||||||
|
|
||||||
// TODO can we avoid locating resource more than once ?
|
if (templateVars.get("apiName") != null)
|
||||||
ResourceWithMetadata rwm = locator.locateResource(api, templateVars, HttpMethod.valueOf(method));
|
|
||||||
|
|
||||||
Class resAction = null;
|
|
||||||
|
|
||||||
switch (rwm.getMetaData().getType())
|
|
||||||
{
|
{
|
||||||
case ENTITY:
|
// NOTE: noAuth currently only exposed for GET
|
||||||
// TODO check params for entity id (for now - assume there is)
|
Api api = determineApi(templateVars);
|
||||||
if (EntityResourceAction.ReadById.class.isAssignableFrom(rwm.getResource().getClass()))
|
|
||||||
{
|
|
||||||
resAction = EntityResourceAction.ReadById.class;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PROPERTY:
|
|
||||||
// TODO check params for entity id (for now - assume there is)
|
|
||||||
if (BinaryResourceAction.Read.class.isAssignableFrom(rwm.getResource().getClass()))
|
|
||||||
{
|
|
||||||
resAction = BinaryResourceAction.Read.class;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean noAuth = (resAction != null && rwm.getMetaData().isNoAuth(resAction));
|
// TODO can we avoid locating resource more than once ?
|
||||||
|
ResourceWithMetadata rwm = locator.locateResource(api, templateVars, HttpMethod.valueOf(method));
|
||||||
|
|
||||||
if (noAuth)
|
Class resAction = null;
|
||||||
{
|
|
||||||
final WebScript webScript = match.getWebScript();
|
|
||||||
|
|
||||||
// hack ! - is there a better way (to dynamically override "requiredAuthentication") or handle noAuth check earlier ?
|
switch (rwm.getMetaData().getType())
|
||||||
WebScript noAuthWebScriptWrapper = new WebScript()
|
|
||||||
{
|
{
|
||||||
@Override
|
case ENTITY:
|
||||||
public void init(Container container, Description description)
|
// TODO check params for entity id (for now - assume there is)
|
||||||
{
|
if (EntityResourceAction.ReadById.class.isAssignableFrom(rwm.getResource().getClass()))
|
||||||
webScript.init(container, description);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Description getDescription()
|
|
||||||
{
|
|
||||||
final Description d = webScript.getDescription();
|
|
||||||
return new Description()
|
|
||||||
{
|
{
|
||||||
@Override
|
resAction = EntityResourceAction.ReadById.class;
|
||||||
public String getStorePath()
|
}
|
||||||
{
|
break;
|
||||||
return d.getStorePath();
|
case PROPERTY:
|
||||||
}
|
// TODO check params for entity id (for now - assume there is)
|
||||||
|
if (BinaryResourceAction.Read.class.isAssignableFrom(rwm.getResource().getClass()))
|
||||||
|
{
|
||||||
|
resAction = BinaryResourceAction.Read.class;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
final boolean noAuth = (resAction != null && rwm.getMetaData().isNoAuth(resAction));
|
||||||
public String getScriptPath()
|
|
||||||
{
|
|
||||||
return d.getScriptPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (noAuth)
|
||||||
public Path getPackage()
|
{
|
||||||
{
|
final WebScript webScript = match.getWebScript();
|
||||||
return d.getPackage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// TODO is there a better way (to dynamically override "requiredAuthentication") or handle noAuth check earlier ?
|
||||||
public String getDescPath()
|
WebScript noAuthWebScriptWrapper = new WebScript()
|
||||||
{
|
|
||||||
return d.getDescPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputStream getDescDocument() throws IOException
|
|
||||||
{
|
|
||||||
return d.getDescDocument();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKind()
|
|
||||||
{
|
|
||||||
return d.getKind();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getFamilys()
|
|
||||||
{
|
|
||||||
return d.getFamilys();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RequiredAuthentication getRequiredAuthentication()
|
|
||||||
{
|
|
||||||
return RequiredAuthentication.none;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRunAs()
|
|
||||||
{
|
|
||||||
return d.getRunAs();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RequiredTransaction getRequiredTransaction()
|
|
||||||
{
|
|
||||||
return d.getRequiredTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RequiredTransactionParameters getRequiredTransactionParameters()
|
|
||||||
{
|
|
||||||
return d.getRequiredTransactionParameters();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RequiredCache getRequiredCache()
|
|
||||||
{
|
|
||||||
return d.getRequiredCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMethod()
|
|
||||||
{
|
|
||||||
return d.getMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getURIs()
|
|
||||||
{
|
|
||||||
return d.getURIs();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FormatStyle getFormatStyle()
|
|
||||||
{
|
|
||||||
return d.getFormatStyle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDefaultFormat()
|
|
||||||
{
|
|
||||||
return d.getDefaultFormat();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NegotiatedFormat[] getNegotiatedFormats()
|
|
||||||
{
|
|
||||||
return d.getNegotiatedFormats();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Serializable> getExtensions()
|
|
||||||
{
|
|
||||||
return d.getExtensions();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Lifecycle getLifecycle()
|
|
||||||
{
|
|
||||||
return d.getLifecycle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getMultipartProcessing()
|
|
||||||
{
|
|
||||||
return d.getMultipartProcessing();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMultipartProcessing(boolean b)
|
|
||||||
{
|
|
||||||
d.setMultipartProcessing(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArgumentTypeDescription[] getArguments()
|
|
||||||
{
|
|
||||||
return d.getArguments();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeDescription[] getRequestTypes()
|
|
||||||
{
|
|
||||||
return d.getRequestTypes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeDescription[] getResponseTypes()
|
|
||||||
{
|
|
||||||
return d.getResponseTypes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId()
|
|
||||||
{
|
|
||||||
return d.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getShortName()
|
|
||||||
{
|
|
||||||
return d.getShortName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription()
|
|
||||||
{
|
|
||||||
return d.getDescription();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceBundle getResources()
|
|
||||||
{
|
{
|
||||||
return webScript.getResources();
|
@Override
|
||||||
}
|
public void init(Container container, Description description)
|
||||||
|
{
|
||||||
|
webScript.init(container, description);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(WebScriptRequest webScriptRequest, WebScriptResponse webScriptResponse) throws IOException
|
public Description getDescription()
|
||||||
{
|
{
|
||||||
webScript.execute(webScriptRequest, webScriptResponse);
|
final Description d = webScript.getDescription();
|
||||||
}
|
return new Description()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getStorePath()
|
||||||
|
{
|
||||||
|
return d.getStorePath();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setURLModelFactory(URLModelFactory urlModelFactory)
|
public String getScriptPath()
|
||||||
{
|
{
|
||||||
webScript.setURLModelFactory(urlModelFactory);
|
return d.getScriptPath();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
match = new Match(match.getTemplate(), match.getTemplateVars(), match.getPath(), noAuthWebScriptWrapper);
|
@Override
|
||||||
|
public Path getPackage()
|
||||||
|
{
|
||||||
|
return d.getPackage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescPath()
|
||||||
|
{
|
||||||
|
return d.getDescPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getDescDocument() throws IOException
|
||||||
|
{
|
||||||
|
return d.getDescDocument();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKind()
|
||||||
|
{
|
||||||
|
return d.getKind();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getFamilys()
|
||||||
|
{
|
||||||
|
return d.getFamilys();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RequiredAuthentication getRequiredAuthentication()
|
||||||
|
{
|
||||||
|
return RequiredAuthentication.none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRunAs()
|
||||||
|
{
|
||||||
|
return d.getRunAs();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RequiredTransaction getRequiredTransaction()
|
||||||
|
{
|
||||||
|
return d.getRequiredTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RequiredTransactionParameters getRequiredTransactionParameters()
|
||||||
|
{
|
||||||
|
return d.getRequiredTransactionParameters();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RequiredCache getRequiredCache()
|
||||||
|
{
|
||||||
|
return d.getRequiredCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMethod()
|
||||||
|
{
|
||||||
|
return d.getMethod();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getURIs()
|
||||||
|
{
|
||||||
|
return d.getURIs();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FormatStyle getFormatStyle()
|
||||||
|
{
|
||||||
|
return d.getFormatStyle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultFormat()
|
||||||
|
{
|
||||||
|
return d.getDefaultFormat();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NegotiatedFormat[] getNegotiatedFormats()
|
||||||
|
{
|
||||||
|
return d.getNegotiatedFormats();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Serializable> getExtensions()
|
||||||
|
{
|
||||||
|
return d.getExtensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Lifecycle getLifecycle()
|
||||||
|
{
|
||||||
|
return d.getLifecycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getMultipartProcessing()
|
||||||
|
{
|
||||||
|
return d.getMultipartProcessing();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMultipartProcessing(boolean b)
|
||||||
|
{
|
||||||
|
d.setMultipartProcessing(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArgumentTypeDescription[] getArguments()
|
||||||
|
{
|
||||||
|
return d.getArguments();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TypeDescription[] getRequestTypes()
|
||||||
|
{
|
||||||
|
return d.getRequestTypes();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TypeDescription[] getResponseTypes()
|
||||||
|
{
|
||||||
|
return d.getResponseTypes();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId()
|
||||||
|
{
|
||||||
|
return d.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getShortName()
|
||||||
|
{
|
||||||
|
return d.getShortName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription()
|
||||||
|
{
|
||||||
|
return d.getDescription();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceBundle getResources()
|
||||||
|
{
|
||||||
|
return webScript.getResources();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(WebScriptRequest webScriptRequest, WebScriptResponse webScriptResponse) throws IOException
|
||||||
|
{
|
||||||
|
webScript.execute(webScriptRequest, webScriptResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setURLModelFactory(URLModelFactory urlModelFactory)
|
||||||
|
{
|
||||||
|
webScript.setURLModelFactory(urlModelFactory);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// override match with noAuth
|
||||||
|
match = new Match(match.getTemplate(), match.getTemplateVars(), match.getPath(), noAuthWebScriptWrapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
match = super.findWebScript(method, uri);
|
||||||
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// note: same as ApiWebscript
|
// note: same as ApiWebscript (apiName must not be null)
|
||||||
private Api determineApi(Map<String, String> templateVars)
|
private Api determineApi(Map<String, String> templateVars)
|
||||||
{
|
{
|
||||||
String apiScope = templateVars.get("apiScope");
|
String apiScope = templateVars.get("apiScope");
|
||||||
|
Reference in New Issue
Block a user