Changeset 218


Ignore:
Timestamp:
03/08/10 16:25:36 (14 years ago)
Author:
oschonef
Message:
  • (try to) handle requests to methods which require authentication more gracefully if URIs contain dangling slashes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/rest/VirtualCollectionRegistryRestService.java

    r217 r218  
    5757                Principal principal = security.getUserPrincipal();
    5858                if (principal == null) {
    59                         throw new NullPointerException("princial == null");
     59                        String path = uriInfo.getPath();
     60                        if (path.endsWith("/")) {
     61                                /*
     62                                 * fix bad client request and remove tailing slash
     63                                 */
     64                                path = path.substring(0, path.length() - 1);
     65                                URI uri = uriInfo.getBaseUriBuilder().path(path).build();
     66                                return Response.temporaryRedirect(uri).build();
     67                        }
     68                        /*
     69                         * should never happen, because servlet container should
     70                         * supply a valid principal
     71                         */
     72                        throw new AssertionError("prinicial == null");
    6073                }
    6174                try {
     
    162175                Principal principal = security.getUserPrincipal();
    163176                if (principal == null) {
    164                         throw new NullPointerException("princial == null");
     177                        String path = uriInfo.getPath();
     178                        if (path.endsWith("/")) {
     179                                /*
     180                                 * fix bad client request and remove tailing slash
     181                                 */
     182                                path = path.substring(0, path.length() - 1);
     183                                URI uri = uriInfo.getBaseUriBuilder().path(path).build();
     184                                return Response.seeOther(uri).build();
     185                        }
     186                        /*
     187                         * should never happen, because servlet container should
     188                         * supply a valid principal
     189                         */
     190                        throw new AssertionError("prinicial == null");
    165191                }
    166192                final VirtualCollectionList vcs =
Note: See TracChangeset for help on using the changeset viewer.