Skip to content

Commit

Permalink
Remove security manager support and other deprecated items.
Browse files Browse the repository at this point in the history
Addressed some compile warnings, yet many still remain.

Signed-off-by: Arjan Tijms <[email protected]>
  • Loading branch information
arjantijms committed Aug 20, 2024
1 parent 64ce5d1 commit 17f21c8
Show file tree
Hide file tree
Showing 43 changed files with 437 additions and 906 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<version>3.13.0</version>
<configuration>
<release>17</release>
<compilerArgument>-Xlint:unchecked</compilerArgument>
<compilerArgument>-Xlint:all</compilerArgument>
</configuration>
</plugin>

Expand Down
7 changes: 1 addition & 6 deletions src/main/java/org/glassfish/wasp/Constants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
Expand Down Expand Up @@ -187,11 +187,6 @@ public class Constants {
// other modules, and therefore requires special caution whenever it is changed.
public static final String JSP_ERROR_HANDLED = "org.glassfish.jsp.error_handled";

/**
* Has security been turned on?
*/
public static final boolean IS_SECURITY_ENABLED = System.getSecurityManager() != null;

/**
* The name of the JSP engine. Used for X-Powered-By identification in the response header
*/
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/org/glassfish/wasp/JspC.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*
* Copyright (c) 2022, 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright 2004 The Apache Software Foundation
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +18,9 @@

package org.glassfish.wasp;

// START GlassFish 750
import jakarta.servlet.jsp.tagext.TagLibraryInfo;

import java.io.BufferedReader;
import java.io.CharArrayWriter;
import java.io.File;
Expand Down Expand Up @@ -59,9 +61,6 @@
import org.glassfish.wasp.servlet.JspCServletContext;
import org.glassfish.wasp.xmlparser.ParserUtils;

// START GlassFish 750
import jakarta.servlet.jsp.tagext.TagLibraryInfo;


/**
* Shell for the jspc compiler. Handles all options associated with the command line and creates compilation contexts
Expand Down Expand Up @@ -217,8 +216,6 @@ public class JspC implements Options {

private HashMap<String, WaspException> jspErrors = new HashMap<>();

private static String myJavaVersion = System.getProperty("java.specification.version");

private boolean ignoreJspFragmentErrors = false;
private Set<String> dependents = new HashSet<>();

Expand Down Expand Up @@ -550,7 +547,7 @@ public File getScratchDir() {
return scratchDir;
}

public Class getJspCompilerPlugin() {
public Class<?> getJspCompilerPlugin() {
// we don't compile, so this is meaningless
return null;
}
Expand Down Expand Up @@ -1388,7 +1385,7 @@ private void initClassLoader(JspCompilationContext clctxt) throws IOException {
String path = tokenizer.nextToken();
try {
File libFile = new File(path);
urls.add(libFile.toURL());
urls.add(libFile.toURI().toURL());
} catch (IOException ioe) {
// Failing a toCanonicalPath on a file that
// exists() should be a JVM regression test,
Expand All @@ -1403,7 +1400,7 @@ private void initClassLoader(JspCompilationContext clctxt) throws IOException {
try {
if (classes.exists()) {
classPath = classPath + File.pathSeparator + classes.getCanonicalPath();
urls.add(classes.getCanonicalFile().toURL());
urls.add(classes.getCanonicalFile().toURI().toURL());
}
} catch (IOException ioe) {
// failing a toCanonicalPath on a file that
Expand All @@ -1428,7 +1425,7 @@ private void initClassLoader(JspCompilationContext clctxt) throws IOException {
try {
File libFile = new File(lib, libs[i]);
classPath = classPath + File.pathSeparator + libFile.getCanonicalPath();
urls.add(libFile.getCanonicalFile().toURL());
urls.add(libFile.getCanonicalFile().toURI().toURL());
} catch (IOException ioe) {
// failing a toCanonicalPath on a file that
// exists() should be a JVM regression test,
Expand All @@ -1440,7 +1437,7 @@ private void initClassLoader(JspCompilationContext clctxt) throws IOException {
}

// What is this ??
urls.add(new File(clctxt.getRealPath("/")).getCanonicalFile().toURL());
urls.add(new File(clctxt.getRealPath("/")).getCanonicalFile().toURI().toURL());

URL urlsA[] = new URL[urls.size()];
urls.toArray(urlsA);
Expand Down Expand Up @@ -1519,7 +1516,7 @@ private ClassLoader initSystemClassLoader() throws IOException {
ArrayList<URL> urls = new ArrayList<>();
StringTokenizer tokenizer = new StringTokenizer(sysClassPath, File.pathSeparator);
while (tokenizer.hasMoreTokens()) {
urls.add(new File(tokenizer.nextToken()).toURL());
urls.add(new File(tokenizer.nextToken()).toURI().toURL());
}

if (urls.size() == 0) {
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/glassfish/wasp/JspCompilationContext.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2024 Contributors to Eclipse Foundation.
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
Expand All @@ -17,6 +18,9 @@

package org.glassfish.wasp;

import jakarta.servlet.ServletContext;
import jakarta.servlet.jsp.tagext.TagInfo;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
Expand All @@ -32,11 +36,8 @@
import org.glassfish.wasp.compiler.Localizer;
import org.glassfish.wasp.compiler.ServletWriter;
import org.glassfish.wasp.compiler.TagLibraryInfoImpl;
import org.glassfish.wasp.servlet.WaspLoader;
import org.glassfish.wasp.servlet.JspServletWrapper;

import jakarta.servlet.ServletContext;
import jakarta.servlet.jsp.tagext.TagInfo;
import org.glassfish.wasp.servlet.WaspLoader;

/**
* A place holder for various things that are used through out the JSP engine. This is a per-request/per-context data
Expand Down Expand Up @@ -602,7 +603,7 @@ public Class<?> load() throws WaspException, ClassNotFoundException {
}

public ClassLoader getJspLoader() {
return new WaspLoader(new URL[] { baseUrl }, getClassLoader(), rctxt.getPermissionCollection(), rctxt.getCodeSource(), rctxt.getBytecodes());
return new WaspLoader(new URL[] { baseUrl }, getClassLoader(), rctxt.getBytecodes());
}

public void makeOutputDir(String outdir) {
Expand Down Expand Up @@ -631,7 +632,7 @@ private void createOutputDir() {
// Append servlet or tag handler path to scratch dir
File f = new File(options.getScratchDir(), path);
makeOutputDir(f.getPath() + File.separator);
baseUrl = options.getScratchDir().toURL();
baseUrl = options.getScratchDir().toURI().toURL();
} catch (Exception e) {
throw new IllegalStateException("No output directory: " + e.getMessage());
}
Expand Down
40 changes: 10 additions & 30 deletions src/main/java/org/glassfish/wasp/compiler/JspDocumentParser.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2024 Contributors to Eclipse Foundation.
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
Expand All @@ -17,26 +18,24 @@

package org.glassfish.wasp.compiler;

import jakarta.servlet.jsp.tagext.TagFileInfo;
import jakarta.servlet.jsp.tagext.TagInfo;
import jakarta.servlet.jsp.tagext.TagLibraryInfo;

import java.io.CharArrayWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.security.AccessController;
// START GlassFish 750
import java.util.Iterator;
import java.util.List;
// START GlassFish 750
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.JarFile;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.glassfish.wasp.Constants;
import org.glassfish.wasp.WaspException;
import org.glassfish.wasp.JspCompilationContext;
import org.glassfish.wasp.security.PrivilegedGetTccl;
import org.glassfish.wasp.security.PrivilegedSetTccl;
import org.glassfish.wasp.WaspException;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
Expand All @@ -47,10 +46,6 @@
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.DefaultHandler;

import jakarta.servlet.jsp.tagext.TagFileInfo;
import jakarta.servlet.jsp.tagext.TagInfo;
import jakarta.servlet.jsp.tagext.TagLibraryInfo;

/**
* Class implementing a parser for a JSP document, that is, a JSP page in XML syntax.
*
Expand Down Expand Up @@ -996,20 +991,10 @@ private void checkPrefix(String uri, String qName) {
*/
private static SAXParser getSAXParser(boolean validating, JspDocumentParser jspDocParser) throws Exception {

ClassLoader original;
if (Constants.IS_SECURITY_ENABLED) {
PrivilegedGetTccl pa = new PrivilegedGetTccl();
original = AccessController.doPrivileged(pa);
} else {
original = Thread.currentThread().getContextClassLoader();
}
ClassLoader original = Thread.currentThread().getContextClassLoader();

try {
if (Constants.IS_SECURITY_ENABLED) {
PrivilegedSetTccl pa = new PrivilegedSetTccl(JspDocumentParser.class.getClassLoader());
AccessController.doPrivileged(pa);
} else {
Thread.currentThread().setContextClassLoader(JspDocumentParser.class.getClassLoader());
}
Thread.currentThread().setContextClassLoader(JspDocumentParser.class.getClassLoader());

SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
Expand All @@ -1026,12 +1011,7 @@ private static SAXParser getSAXParser(boolean validating, JspDocumentParser jspD

return saxParser;
} finally {
if (Constants.IS_SECURITY_ENABLED) {
PrivilegedSetTccl pa = new PrivilegedSetTccl(original);
AccessController.doPrivileged(pa);
} else {
Thread.currentThread().setContextClassLoader(original);
}
Thread.currentThread().setContextClassLoader(original);
}
}

Expand Down
Loading

0 comments on commit 17f21c8

Please sign in to comment.