Skip to content

Commit e20934e

Browse files
authored
Merge pull request #88 from cip4/sec4
Sec4
2 parents 49134f7 + ea55d52 commit e20934e

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

src/main/java/org/cip4/jdfutility/server/JettyServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,9 @@ public MyResourceHandler(final String strip)
506506
/**
507507
* @return
508508
*/
509-
protected org.cip4.jdfutility.server.MyResourceHandler createResourceHandler()
509+
protected ResourceHandler createResourceHandler()
510510
{
511-
final org.cip4.jdfutility.server.MyResourceHandler resourceHandler = new org.cip4.jdfutility.server.MyResourceHandler(context, getHome());
511+
final ResourceHandler resourceHandler = new org.cip4.jdfutility.server.MyResourceHandler(context, getHome());
512512
resourceHandler.setResourceBase(".");
513513
resourceHandler.setDirAllowed(false);
514514
return resourceHandler;

src/main/java/org/cip4/jdfutility/server/MyResourceHandler.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737

3838
package org.cip4.jdfutility.server;
3939

40-
import java.io.File;
41-
import java.util.ArrayList;
4240
import java.util.Collection;
41+
import java.util.HashSet;
4342

4443
import org.cip4.jdflib.util.StringUtil;
4544
import org.eclipse.jetty.server.handler.ResourceHandler;
45+
import org.eclipse.jetty.util.resource.EmptyResource;
4646
import org.eclipse.jetty.util.resource.Resource;
4747

4848
/**
@@ -55,14 +55,14 @@ public class MyResourceHandler extends ResourceHandler
5555
{
5656

5757
private final String home;
58-
private final Collection<File> whiteList;
58+
private final Collection<String> whiteList;
5959

6060
public MyResourceHandler(final String strip, final String home)
6161
{
6262
super();
6363
this.strip = StringUtil.getNonEmpty(strip);
6464
this.home = home;
65-
whiteList = new ArrayList<>();
65+
whiteList = new HashSet<>();
6666
}
6767

6868
private final String strip;
@@ -84,9 +84,9 @@ public Resource getResource(String url)
8484
else if (!whiteList.isEmpty())
8585
{
8686
final String base = StringUtil.token(url, 0, "/");
87-
if (!whiteList.contains(new File(base)))
87+
if (!whiteList.contains(base.toLowerCase()))
8888
{
89-
return null;
89+
return EmptyResource.INSTANCE;
9090
}
9191
}
9292

@@ -105,7 +105,7 @@ else if (!whiteList.isEmpty())
105105
*/
106106
public void addBase(final String base)
107107
{
108-
whiteList.add(new File(base));
108+
whiteList.add(base.toLowerCase());
109109
}
110110

111111
@Override

src/test/java/org/cip4/jdfutility/server/JettyServerTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* The CIP4 Software License, Version 1.0
33
*
44
*
5-
* Copyright (c) 2001-2023 The International Cooperation for the Integration of Processes in Prepress, Press and Postpress (CIP4). All rights reserved.
5+
* Copyright (c) 2001-2024 The International Cooperation for the Integration of Processes in Prepress, Press and Postpress (CIP4). All rights reserved.
66
*
77
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
88
*
@@ -46,6 +46,7 @@
4646
import org.cip4.jdfutility.JDFUtilityTestBase;
4747
import org.cip4.jdfutility.exe.HTTPDump;
4848
import org.cip4.jdfutility.server.JettyServer.JettySSLData;
49+
import org.eclipse.jetty.util.resource.EmptyResource;
4950
import org.junit.jupiter.api.Test;
5051

5152
class JettyServerTest extends JDFUtilityTestBase
@@ -169,28 +170,23 @@ public synchronized void testIsRunning() throws InterruptedException
169170
@Test
170171
public void testResHandler() throws InterruptedException
171172
{
172-
final HTTPDump ns = new HTTPDump();
173-
ns.setPort(getPort());
174173
final MyResourceHandler rh = new MyResourceHandler("foo", "dummy");
175174
assertNull(rh.getResource("nix"));
176175
}
177176

178177
@Test
179178
public void testResHandlerWL() throws InterruptedException
180179
{
181-
final HTTPDump ns = new HTTPDump();
182-
ns.setPort(getPort());
183180
final MyResourceHandler rh = new MyResourceHandler("foo", "dummy");
184181
rh.addBase("boo");
185-
assertNull(rh.getResource("foo/nix"));
186-
assertNull(rh.getResource("foo/boo"));
182+
assertEquals(EmptyResource.INSTANCE, rh.getResource("/foo/nix"));
183+
assertEquals(EmptyResource.INSTANCE, rh.getResource("/foo/boo"));
184+
assertEquals(null, rh.getResource("/boo"));
187185
}
188186

189187
@Test
190188
public void testResHandlerString() throws InterruptedException
191189
{
192-
final HTTPDump ns = new HTTPDump();
193-
ns.setPort(getPort());
194190
final MyResourceHandler rh = new MyResourceHandler("foo", "bar");
195191
assertNotNull(rh.toString());
196192
}

0 commit comments

Comments
 (0)