From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-04-20 15:03:06
|
Revision: 498 http://sword-app.svn.sourceforge.net/sword-app/?rev=498&view=rev Author: richard-jones Date: 2012-04-20 15:02:55 +0000 (Fri, 20 Apr 2012) Log Message: ----------- Add clean up operation to deposit operations All deposit operations which take a Deposit object now run a cleanup on the deposit object to remove any temp files that are created Modified Paths: -------------- JavaServer2.0/trunk/src/main/java/org/swordapp/server/CollectionAPI.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/ContainerAPI.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/MediaResourceAPI.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/CollectionAPI.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/CollectionAPI.java 2012-04-20 10:41:40 UTC (rev 497) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/CollectionAPI.java 2012-04-20 15:02:55 UTC (rev 498) @@ -122,6 +122,7 @@ } } + Deposit deposit = null; try { // the first thing to do is determine what the deposit type is: @@ -134,7 +135,7 @@ String slug = req.getHeader("Slug"); boolean inProgress = this.getInProgress(req); - Deposit deposit = new Deposit(); + deposit = new Deposit(); deposit.setInProgress(inProgress); deposit.setSlug(slug); DepositReceipt receipt = null; @@ -213,6 +214,11 @@ // need to throw a 403 Forbidden resp.sendError(403); } + finally + { + // get rid of any temp files used + this.cleanup(deposit); + } } protected void addGenerator(DepositReceipt doc, SwordConfiguration config) { Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/ContainerAPI.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/ContainerAPI.java 2012-04-20 10:41:40 UTC (rev 497) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/ContainerAPI.java 2012-04-20 15:02:55 UTC (rev 498) @@ -179,6 +179,7 @@ } } + Deposit deposit = null; try { // the first thing to do is determine what the deposit type is: @@ -189,7 +190,7 @@ // get the In-Progress header boolean inProgress = this.getInProgress(req); - Deposit deposit = new Deposit(); + deposit = new Deposit(); deposit.setInProgress(inProgress); String iri = this.getFullUrl(req); DepositReceipt receipt; @@ -277,6 +278,11 @@ // need to throw a 403 Forbidden resp.sendError(403); } + finally + { + // get rid of any temp files used + this.cleanup(deposit); + } } public void post(HttpServletRequest req, HttpServletResponse resp) @@ -304,6 +310,7 @@ } } + Deposit deposit = null; try { // the first thing to do is determine what the deposit type is: @@ -321,7 +328,7 @@ boolean inProgress = this.getInProgress(req); String iri = this.getFullUrl(req); - Deposit deposit = new Deposit(); + deposit = new Deposit(); deposit.setInProgress(inProgress); DepositReceipt receipt; @@ -400,6 +407,11 @@ // need to throw a 403 Forbidden resp.sendError(403); } + finally + { + // get rid of any temp files used + this.cleanup(deposit); + } } public void delete(HttpServletRequest req, HttpServletResponse resp) Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/MediaResourceAPI.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/MediaResourceAPI.java 2012-04-20 10:41:40 UTC (rev 497) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/MediaResourceAPI.java 2012-04-20 15:02:55 UTC (rev 498) @@ -156,10 +156,12 @@ } } + Deposit deposit = null; + try { String editMediaIRI = this.getFullUrl(req); - Deposit deposit = new Deposit(); + deposit = new Deposit(); // add the properties from the binary deposit this.addDepositPropertiesFromBinary(deposit, req); @@ -186,6 +188,11 @@ // need to throw a 403 Forbidden resp.sendError(403); } + finally + { + // get rid of any temp files used + this.cleanup(deposit); + } } public void post(HttpServletRequest req, HttpServletResponse resp) @@ -213,6 +220,7 @@ } } + Deposit deposit = null; try { // the first thing to do is determine what the deposit type is: @@ -220,7 +228,7 @@ boolean isMultipart = contentType.startsWith("multipart/related"); String uri = this.getFullUrl(req); - Deposit deposit = new Deposit(); + deposit = new Deposit(); if (isMultipart) { @@ -275,6 +283,11 @@ // need to throw a 403 Forbidden resp.sendError(403); } + finally + { + // get rid of any temp files used + this.cleanup(deposit); + } } public void delete(HttpServletRequest req, HttpServletResponse resp) Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java 2012-04-20 10:41:40 UTC (rev 497) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java 2012-04-20 15:02:55 UTC (rev 498) @@ -257,6 +257,22 @@ } } + protected void cleanup(Deposit deposit) + { + if (deposit == null) + { + return; + } + + File tmp = deposit.getFile(); + if (tmp == null) + { + return; + } + + tmp.delete(); + } + protected Element getGenerator(SwordConfiguration config) { String generatorUri = config.generator(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-04-21 13:52:34
|
Revision: 499 http://sword-app.svn.sourceforge.net/sword-app/?rev=499&view=rev Author: richard-jones Date: 2012-04-21 13:52:27 +0000 (Sat, 21 Apr 2012) Log Message: ----------- File cleanup enhancements Previously, in the case of an error, file cleanup wasn't successful. This update adds calls to the cleanup operation in more places, enhances the cleanup process, and fixes a bug in the SwordAPIEndpoint which caused the cleanup not to function correctly Modified Paths: -------------- JavaServer2.0/trunk/src/main/java/org/swordapp/server/CollectionAPI.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/ContainerAPI.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/MediaResourceAPI.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/CollectionAPI.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/CollectionAPI.java 2012-04-20 15:02:55 UTC (rev 498) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/CollectionAPI.java 2012-04-21 13:52:27 UTC (rev 499) @@ -198,6 +198,9 @@ } catch (SwordError se) { + // get rid of any temp files used + this.cleanup(deposit); + this.swordError(req, resp, se); } catch (SwordServerException e) @@ -210,6 +213,9 @@ } catch (SwordAuthException e) { + // get rid of any temp files used + this.cleanup(deposit); + // authentication actually failed at the server end; not a SwordError, but // need to throw a 403 Forbidden resp.sendError(403); Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/ContainerAPI.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/ContainerAPI.java 2012-04-20 15:02:55 UTC (rev 498) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/ContainerAPI.java 2012-04-21 13:52:27 UTC (rev 499) @@ -262,6 +262,9 @@ } catch (SwordError se) { + // get rid of any temp files used + this.cleanup(deposit); + this.swordError(req, resp, se); } catch (SwordServerException e) @@ -274,6 +277,9 @@ } catch (SwordAuthException e) { + // get rid of any temp files used + this.cleanup(deposit); + // authentication actually failed at the server end; not a SwordError, but // need to throw a 403 Forbidden resp.sendError(403); @@ -391,6 +397,9 @@ } catch (SwordError se) { + // get rid of any temp files used + this.cleanup(deposit); + this.swordError(req, resp, se); } catch (SwordServerException e) @@ -403,6 +412,9 @@ } catch (SwordAuthException e) { + // get rid of any temp files used + this.cleanup(deposit); + // authentication actually failed at the server end; not a SwordError, but // need to throw a 403 Forbidden resp.sendError(403); Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/MediaResourceAPI.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/MediaResourceAPI.java 2012-04-20 15:02:55 UTC (rev 498) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/MediaResourceAPI.java 2012-04-21 13:52:27 UTC (rev 499) @@ -176,6 +176,9 @@ } catch (SwordError se) { + // get rid of any temp files used + this.cleanup(deposit); + this.swordError(req, resp, se); } catch (SwordServerException e) @@ -184,6 +187,9 @@ } catch (SwordAuthException e) { + // get rid of any temp files used + this.cleanup(deposit); + // authentication actually failed at the server end; not a SwordError, but // need to throw a 403 Forbidden resp.sendError(403); @@ -270,8 +276,10 @@ } catch (SwordError se) { + // get rid of any temp files used + this.cleanup(deposit); + this.swordError(req, resp, se); - return; } catch (SwordServerException e) { @@ -279,6 +287,9 @@ } catch (SwordAuthException e) { + // get rid of any temp files used + this.cleanup(deposit); + // authentication actually failed at the server end; not a SwordError, but // need to throw a 403 Forbidden resp.sendError(403); Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java 2012-04-20 15:02:55 UTC (rev 498) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java 2012-04-21 13:52:27 UTC (rev 499) @@ -161,7 +161,10 @@ // Check the size is OK File file = new File(filename); - long fLength = file.length() / 1024; // in kilobytes + // Set the file to be deposited + deposit.setFile(file); + + long fLength = file.length() / 1024; // in kilobytes if ((config.getMaxUploadSize() != -1) && (fLength > config.getMaxUploadSize())) { String msg = "The uploaded file exceeded the maximum file size this server will accept (the file is " + @@ -184,11 +187,6 @@ String msg = "The received MD5 checksum for the deposited file did not match the checksum sent by the deposit client"; throw new SwordError(UriRegistry.ERROR_CHECKSUM_MISMATCH, msg); } - else - { - // Set the file to be deposited - deposit.setFile(file); - } log.debug("Package temporarily stored as: " + filename); } catch (NoSuchAlgorithmException e) @@ -271,6 +269,7 @@ } tmp.delete(); + deposit.setFile(null); } protected Element getGenerator(SwordConfiguration config) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-04-26 16:17:30
|
Revision: 504 http://sword-app.svn.sourceforge.net/sword-app/?rev=504&view=rev Author: richard-jones Date: 2012-04-26 16:17:19 +0000 (Thu, 26 Apr 2012) Log Message: ----------- add support for 404 Previously this library did not expressly support 404 responses (although it was possible with a workaround). This patch: * allows implementers to throw a sworderror with just a the status code as an argument * allows errors which have only status code arguments to be returned to the client with an empty body (rather than the server's 404 page or a sword error document) Modified Paths: -------------- JavaServer2.0/trunk/src/main/java/org/swordapp/server/ErrorDocument.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordError.java Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/ErrorDocument.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/ErrorDocument.java 2012-04-25 13:39:56 UTC (rev 503) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/ErrorDocument.java 2012-04-26 16:17:19 UTC (rev 504) @@ -16,7 +16,7 @@ public class ErrorDocument { - private String errorUri; + private String errorUri = null; private Map<String, Integer> errorCodes = new HashMap<String, Integer>(); private String summary = null; private String verboseDescription = null; @@ -66,7 +66,7 @@ return this.status; } - if (this.errorCodes.containsKey(errorUri)) + if (errorUri != null && this.errorCodes.containsKey(errorUri)) { return this.errorCodes.get(errorUri); } Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java 2012-04-25 13:39:56 UTC (rev 503) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java 2012-04-26 16:17:19 UTC (rev 504) @@ -347,10 +347,10 @@ { try { - if (!this.config.returnErrorBody()) + if (!this.config.returnErrorBody() || !e.hasBody()) { ErrorDocument doc = new ErrorDocument(e.getErrorUri(), e.getStatus()); - resp.sendError(doc.getStatus()); + resp.setStatus(doc.getStatus()); return; } Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordError.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordError.java 2012-04-25 13:39:56 UTC (rev 503) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordError.java 2012-04-26 16:17:19 UTC (rev 504) @@ -7,12 +7,20 @@ { private String errorUri; private int status = -1; + private boolean hasBody = true; public SwordError() { super(); } + public SwordError(int status) + { + super(); + this.status = status; + this.hasBody = false; + } + public SwordError(String errorUri) { super(errorUri); @@ -74,4 +82,9 @@ { return status; } + + public boolean hasBody() + { + return hasBody; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-04-27 12:45:05
|
Revision: 505 http://sword-app.svn.sourceforge.net/sword-app/?rev=505&view=rev Author: richard-jones Date: 2012-04-27 12:44:54 +0000 (Fri, 27 Apr 2012) Log Message: ----------- Improved Statement support * Namespace prefixes in ORE formatted statement are now more sensible (i.e. "sword" and "ore" not "j.0", "j.1") * Author in atom feed is always set (fixes bug which didn't catch the empty string) Modified Paths: -------------- JavaServer2.0/trunk/src/main/java/org/swordapp/server/AtomStatement.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/OREStatement.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/UriRegistry.java Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/AtomStatement.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/AtomStatement.java 2012-04-26 16:17:19 UTC (rev 504) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/AtomStatement.java 2012-04-27 12:44:54 UTC (rev 505) @@ -23,7 +23,7 @@ public AtomStatement(String feedUri, String author, String title, String updated) { this.contentType = "application/atom+xml;type=feed"; - this.author = author != null ? author : "Unknown"; + this.author = (author != null && !"".equals(author)) ? author : "Unknown"; this.feedUri = feedUri; this.title = title != null ? title : "Untitled"; this.updated = updated; Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/OREStatement.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/OREStatement.java 2012-04-26 16:17:19 UTC (rev 504) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/OREStatement.java 2012-04-27 12:44:54 UTC (rev 505) @@ -31,10 +31,16 @@ // create the default model (in memory) to start with Model model = ModelFactory.createDefaultModel(); + // set up some sensible namespaces for the prefixes + model.setNsPrefix(UriRegistry.ORE_PREFIX, UriRegistry.ORE_NAMESPACE); + model.setNsPrefix(UriRegistry.SWORD_PREFIX, UriRegistry.SWORD_TERMS_NAMESPACE); + // create the resource map in the model Resource rem = model.createResource(this.remUri); rem.addProperty(RDF.type, model.createResource(UriRegistry.ORE_NAMESPACE + "ResourceMap")); + + // create the aggregation Resource agg = model.createResource(this.aggUri); agg.addProperty(RDF.type, model.createResource(UriRegistry.ORE_NAMESPACE + "Aggregation")); Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/UriRegistry.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/UriRegistry.java 2012-04-26 16:17:19 UTC (rev 504) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/UriRegistry.java 2012-04-27 12:44:54 UTC (rev 505) @@ -4,6 +4,13 @@ public class UriRegistry { + // Namespace prefixes + public static String SWORD_PREFIX = "sword"; + public static String ORE_PREFIX = "ore"; + public static String APP_PREFIX = "app"; + public static String DC_PREFIX = "dcterms"; + public static String ATOM_PREFIX = "atom"; + // Namespaces public static String SWORD_TERMS_NAMESPACE = "http://purl.org/net/sword/terms/"; public static String APP_NAMESPACE = "http://www.w3.org/2007/app"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-04-27 16:37:09
|
Revision: 506 http://sword-app.svn.sourceforge.net/sword-app/?rev=506&view=rev Author: richard-jones Date: 2012-04-27 16:37:03 +0000 (Fri, 27 Apr 2012) Log Message: ----------- Error handling improvements * add default title to error documents * support configurable alternate urls to error documents * max upload size now expects bytes not kilobytes Modified Paths: -------------- JavaServer2.0/trunk/src/main/java/org/swordapp/server/ErrorDocument.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordConfiguration.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordConfigurationDefault.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordError.java Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/ErrorDocument.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/ErrorDocument.java 2012-04-27 12:44:54 UTC (rev 505) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/ErrorDocument.java 2012-04-27 16:37:03 UTC (rev 506) @@ -85,6 +85,7 @@ // write some boiler-plate text into the document Element title = new Element("atom:title", UriRegistry.ATOM_NAMESPACE); + title.appendChild("ERROR"); Element updates = new Element("atom:updated", UriRegistry.ATOM_NAMESPACE); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); updates.appendChild(sdf.format(new Date())); @@ -118,6 +119,20 @@ error.appendChild(vd); } + String alternate = config.getAlternateUrl(); + String altContentType = config.getAlternateUrlContentType(); + if (alternate != null && !"".equals(alternate)) + { + Element altLink = new Element("atom:link", UriRegistry.ATOM_NAMESPACE); + altLink.addAttribute(new Attribute("rel", "alternate")); + if (altContentType != null && !"".equals(altContentType)) + { + altLink.addAttribute(new Attribute("type", altContentType)); + } + altLink.addAttribute(new Attribute("href", alternate)); + error.appendChild(altLink); + } + try { // now get it written out Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java 2012-04-27 12:44:54 UTC (rev 505) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java 2012-04-27 16:37:03 UTC (rev 506) @@ -164,12 +164,12 @@ // Set the file to be deposited deposit.setFile(file); - long fLength = file.length() / 1024; // in kilobytes + long fLength = file.length(); // in bytes if ((config.getMaxUploadSize() != -1) && (fLength > config.getMaxUploadSize())) { String msg = "The uploaded file exceeded the maximum file size this server will accept (the file is " + - fLength + "kB but the server will only accept files as large as " + - config.getMaxUploadSize() + "kB)"; + fLength + " bytes but the server will only accept files as large as " + + config.getMaxUploadSize() + " bytes)"; throw new SwordError(UriRegistry.ERROR_MAX_UPLOAD_SIZE_EXCEEDED, msg); } Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordConfiguration.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordConfiguration.java 2012-04-27 12:44:54 UTC (rev 505) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordConfiguration.java 2012-04-27 16:37:03 UTC (rev 506) @@ -21,4 +21,8 @@ String getTempDirectory(); int getMaxUploadSize(); + + String getAlternateUrl(); + + String getAlternateUrlContentType(); } Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordConfigurationDefault.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordConfigurationDefault.java 2012-04-27 12:44:54 UTC (rev 505) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordConfigurationDefault.java 2012-04-27 16:37:03 UTC (rev 506) @@ -51,4 +51,14 @@ { return -1; } + + public String getAlternateUrl() + { + return null; + } + + public String getAlternateUrlContentType() + { + return null; + } } Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordError.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordError.java 2012-04-27 12:44:54 UTC (rev 505) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordError.java 2012-04-27 16:37:03 UTC (rev 506) @@ -1,8 +1,5 @@ package org.swordapp.server; -import java.util.HashMap; -import java.util.Map; - public class SwordError extends Exception { private String errorUri; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-04-29 17:05:13
|
Revision: 507 http://sword-app.svn.sourceforge.net/sword-app/?rev=507&view=rev Author: richard-jones Date: 2012-04-29 17:05:07 +0000 (Sun, 29 Apr 2012) Log Message: ----------- allow for unauthenticated GET requests on media resource Modified Paths: -------------- JavaServer2.0/trunk/src/main/java/org/swordapp/server/MediaResourceAPI.java JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/MediaResourceAPI.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/MediaResourceAPI.java 2012-04-27 16:37:03 UTC (rev 506) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/MediaResourceAPI.java 2012-04-29 17:05:07 UTC (rev 507) @@ -40,7 +40,7 @@ AuthCredentials auth = null; try { - auth = this.getAuthCredentials(req); + auth = this.getAuthCredentials(req, true); } catch (SwordAuthException e) { Modified: JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java =================================================================== --- JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java 2012-04-27 16:37:03 UTC (rev 506) +++ JavaServer2.0/trunk/src/main/java/org/swordapp/server/SwordAPIEndpoint.java 2012-04-29 17:05:07 UTC (rev 507) @@ -35,35 +35,40 @@ this.config = config; } - protected AuthCredentials getAuthCredentials(HttpServletRequest request) + protected AuthCredentials getAuthCredentials(HttpServletRequest request) + throws SwordAuthException + { + return this.getAuthCredentials(request, false); + } + + protected AuthCredentials getAuthCredentials(HttpServletRequest request, boolean allowUnauthenticated) throws SwordAuthException { + // is the user authenticating? + String authHeader = request.getHeader("Authorization"); + // is there an On-Behalf-Of header? String obo = request.getHeader("On-Behalf-Of"); - // is authentication required + // which authentication scheme do we recognise (should only be Basic) String authType = this.config.getAuthType(); - boolean authRequired = "Basic".equals(authType); + boolean isBasic = "Basic".equals(authType); - // is the user authenticating? - String authHeader = request.getHeader("Authorization"); + if (isBasic && (authHeader == null || "".equals(authHeader))) + { + if (!allowUnauthenticated) + { + throw new SwordAuthException(true); + } + else + { + log.debug("No Authentication Credentials supplied"); + return new AuthCredentials(null, null, obo); + } + } - // are we meant to authenticate, but haven't been given anything? - if (authRequired && (authHeader == null || "".equals(authHeader))) - { - throw new SwordAuthException(true); - } - - // by this stage we are either meant to authenticate and have been given credentials or - // we don't need to authenticate. Either way we just fill in the AuthCredentials + // decode the auth header and populate the authcredentials object for return String[] userPass = this.decodeAuthHeader(authHeader); - - if (userPass == null) - { - log.debug("No Authentication Credentials supplied"); - return new AuthCredentials(null, null, obo); - } - AuthCredentials auth = new AuthCredentials(userPass[0], userPass[1], obo); return auth; } @@ -85,7 +90,7 @@ if (!"Basic".equalsIgnoreCase(authBits[0].trim())) { log.warn("Authentication method not supported: " + authBits[0]); - return null; + throw new SwordAuthException("Authentication method not supported: " + authBits[0]); } // get the username and password out of the base64 encoded Basic auth string This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |