Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

Check warning on line 22 in accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/ui/AcToolUiService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'java.io.OutputStream'.

See more on https://sonarcloud.io/project/issues?id=Netcentric_accesscontroltool&issues=AZ_HWZZtdbV-jUphA1Z8&open=AZ_HWZZtdbV-jUphA1Z8&pullRequest=904
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -103,6 +103,9 @@

private static final int MAX_LINE_WIDTH = 180; // max line width for log output in characters

private static final java.util.Set<String> ALLOWED_RESOURCES = java.util.Collections.unmodifiableSet(
new java.util.HashSet<>(java.util.Arrays.asList("actooluiservice.js")));

@Reference(policyOption = ReferencePolicyOption.GREEDY)
private ConfigDumpService dumpService;

Expand Down Expand Up @@ -152,7 +155,7 @@
* @throws ServletException
* @throws IOException
*/
protected void doGet(HttpServletRequest req, HttpServletResponse resp, String basePath, boolean isTouchUi)

Check failure on line 158 in accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/ui/AcToolUiService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=Netcentric_accesscontroltool&issues=AZ_HWZZtdbV-jUphA1Z7&open=AZ_HWZZtdbV-jUphA1Z7&pullRequest=904
throws ServletException, IOException {

if (req.getRequestURI().startsWith(basePath)) {
Expand All @@ -172,6 +175,11 @@
// either spool resource
String resourcePath = req.getRequestURI().substring(basePath.length());
if (resourcePath.startsWith("/res/")) {
String resourceName = resourcePath.substring(resourcePath.lastIndexOf('/') + 1);
if (!ALLOWED_RESOURCES.contains(resourceName)) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
// check for a resource, fail if none
if (!spoolResource(req, resourcePath, resp)) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
Expand Down Expand Up @@ -244,12 +252,7 @@
response.setStatus( HttpServletResponse.SC_OK);

// spool the actual contents
final OutputStream out = response.getOutputStream();
final byte[] buf = new byte[2048];
int rd;
while ( ( rd = ins.read( buf ) ) >= 0 ) {
out.write( buf, 0, rd );
}
ins.transferTo(response.getOutputStream());
}
return true;
}
Expand Down
Loading