Download presentation
Presentation is loading. Please wait.
Published byBuck Baldwin Modified over 8 years ago
1
#SummitNow CORS 6 Nov 2013 / 14 Nov 2013 Jared Ottley / Alfresco Software
2
#SummitNow CORS 6 Nov 2013 / 14 Nov 2013 Jared Ottley / Alfresco Software
3
#SummitNow What is CORS? Cross-Origin Resource Sharing Cross Domain AJAX Calls Implemented in Browser and Server 3
4
#SummitNow What Browsers Support CORS? 4.0+3.5 + 12.0+4.0+Partial 8 & 9 10+ 4
5
#SummitNow How Does CORS Work? Nothing to implement in your javascript. The Browser & the Server do the heavy lifting. 5
6
#SummitNow How Does CORS Work? 6 Browser OPTIONS API Request
7
#SummitNow Example Code $.ajax ({ type: ”HTTP METHOD”, url: “Place to go to”, dataType: 'json’, async: false, data: '{}', beforeSend: function (xhr){ xhr.setRequestHeader('Authorization', setAuthTokenHere() }, success: function (response){ //do something }, failure: function (response) { //do something } }); 7
8
#SummitNow What About the Server Side? Alfresco does not ship with CORS support. Alfresco uses CORS as part of “Alfresco for Salesforce” to talk to Alfresco Cloud. 8
9
#SummitNow How to Enable CORS in Alfresco Add the following jars to WEB-INF/lib cors-filter java-property-utils Both can be found at http://software.dzhuvinov.com/cors-filter.html http://software.dzhuvinov.com/cors-filter.html 9
10
#SummitNow How to Enable CORS in Alfresco Modify WEB-INF/web.xml CORS com.thetransactioncompany.cors.CORSFilter CORS /service/* 10
11
#SummitNow How to Enable CORS in Alfresco What services will be called by your app? CORS /service/* /cmisatom/* /cmisbrowser/* 11
12
#SummitNow How to Enable CORS in Alfresco 12 Browser OPTIONS API Request Authentication
13
#SummitNow Filter can be placed anywhere in web.xml However… Filter mapping MUST be before authentication filters How to Enable CORS in Alfresco 13
14
#SummitNow How to Enable CORS in Alfresco Place after Global Localization Filter but before CMIS security context cleaning filter. This is true for 4.2…but may not be true for other versions of Alfresco. By rule BEFORE any security/authentication filters 14
15
#SummitNow Filter Configuration By default the CORS Filter will apply a "public access" CORS policy, allowing all cross-site requests through (including credentials/cookies). Leaving the CORS Filter at this setting would actually be fine for most situations as CORS is not about adding server security; its primary intent is to protect the browser - the legitimate JavaScript apps running in it and the user's confidential data, such as cookies. 15
16
#SummitNow Filter Configuration (cont.) cors.configurationFile properties file Setting the location using System Property (-D) init-param Or Individual init-param 16
17
#SummitNow Filter Configuration (cont.) Do not change the following defaults: cors.allowGenericHttpRequests {true|false} defaults to true cors.supportsCredentials {true|false} defaults to true. cors.maxAge {int} defaults to -1 (unspecified) How long should pre-flight requests be cached. Recommended value is 3600 (1 hour) 17
18
#SummitNow Filter Configuration (cont.) cors.allowOrigin {"*"|origin-list} defaults to * Which calling domains are allowed? ex: http://alfresco.com https://www.alfresco.com Returns 403 if the domain is not allowed 18
19
#SummitNow Filter Configuration (cont.) cors.allowSubdomains {true|false} defaults to false Your application may run in a hosted service where the subdomain is dynamically assigned ex. salesforce.com ex. https:na14.salesforce.com 19
20
#SummitNow Filter Configuration (cont.) cors.supportedMethods {method-list} defaults to "GET, POST, HEAD, OPTIONS” cors.supportedHeaders {"*"|header-list} defaults to * origin, authorization, accept 20
21
#SummitNow Filter Configuration (cont.) cors.exposedHeaders {header-list} defaults to empty list Response headers limited to: Cache- Control, Content-Language, Content- Type, Expires, Last-Modified Pragma Add additional headers to be exposed 21
22
#SummitNow Demo 22
23
#SummitNow CORS Resources http://software.dzhuvinov.com/cors-filter.html https://bitbucket.org/thetransactioncompany/cors-filter http://www.w3.org/TR/cors/ http://en.wikipedia.org/wiki/Cross-origin_resource_sharing 23
24
#SummitNow CORS Resources http://software.dzhuvinov.com/cors-filter.html https://bitbucket.org/thetransactioncompany/cors-filter http://www.w3.org/TR/cors/ http://en.wikipedia.org/wiki/Cross-origin_resource_sharing 24
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.