8346045: Cleanup of security library tests calling Security Manager APIs

Reviewed-by: rriggs
This commit is contained in:
Sean Mullan 2025-01-14 15:21:06 +00:00
parent 56c780078f
commit a49f8332ed
6 changed files with 14 additions and 85 deletions

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6648816
* @summary REGRESSION: setting -Djava.security.debug=failure result in NPE
* in ACC
* @run main/othervm -Djava.security.debug=failure FailureDebugOption
*/
import java.security.ProtectionDomain;
import java.security.AccessController;
import java.security.AccessControlException;
import java.security.BasicPermission;
public class FailureDebugOption {
public static void main (String argv[]) throws Exception {
try {
AccessController.checkPermission(
new BasicPermission("no such permission"){});
} catch (NullPointerException npe) {
throw new Exception("Unexpected NullPointerException for security" +
" debug option, -Djava.security.debug=failure");
} catch (AccessControlException ace) {
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -30,11 +30,7 @@
* The test passes if it returns.
* The test fails if an exception is thrown.
*/
import java.security.cert.CertPathParameters;
import java.security.cert.CertPathBuilderResult;
import java.security.cert.CertPathBuilderSpi;
import java.security.Provider;
import java.security.AccessController;
import java.security.cert.CertPathBuilder;
import java.security.NoSuchAlgorithmException;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -37,7 +37,6 @@ import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPairGenerator;
import java.security.NoSuchProviderException;
import java.security.Policy;
import java.security.Provider;
import java.security.ProviderException;
import java.security.SecureRandom;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -32,15 +32,12 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Locale;
public class CertChainUnclosed {
public static void main(String[] args) throws Exception {
String os = AccessController.doPrivileged(
(PrivilegedAction<String>)() -> System.getProperty("os.name"));
String os = System.getProperty("os.name");
if (!os.toUpperCase(Locale.US).contains("WINDOWS")) {
System.out.println("Not Windows. Skip test.");
return;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -49,9 +49,7 @@ public class AVAEqualsHashCode {
byte[] ba = deros.toByteArray();
DerValue dv = new DerValue(ba);
GetAVAConstructor a = new GetAVAConstructor();
java.security.AccessController.doPrivileged(a);
Constructor c = a.getCons();
Constructor c = getAVAConstructor();
Object[] objs = new Object[2];
objs[0] = oid;
@ -72,16 +70,10 @@ public class AVAEqualsHashCode {
else
throw new Exception("FAILED equals()/hashCode() contract");
}
}
class GetAVAConstructor implements java.security.PrivilegedExceptionAction {
private Class avaClass = null;
private Constructor avaCons = null;
public Object run() throws Exception {
static Constructor getAVAConstructor() throws Exception {
try {
avaClass = Class.forName("sun.security.x509.AVA");
Class avaClass = Class.forName("sun.security.x509.AVA");
Constructor[] cons = avaClass.getDeclaredConstructors();
int i;
@ -90,22 +82,16 @@ class GetAVAConstructor implements java.security.PrivilegedExceptionAction {
if (parms.length == 2) {
if (parms[0].getName().equalsIgnoreCase("sun.security.util.ObjectIdentifier") &&
parms[1].getName().equalsIgnoreCase("sun.security.util.DerValue")) {
avaCons = cons[i];
Constructor avaCons = cons[i];
avaCons.setAccessible(true);
break;
return avaCons;
}
}
}
return null;
} catch (Exception e) {
System.out.println("Caught unexpected exception " + e);
throw e;
}
return avaCons;
}
public Constructor getCons(){
return avaCons;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -48,8 +48,7 @@ public class SimpleSSLContext {
}
private SimpleSSLContext(Supplier<String> protocols) throws IOException {
final String proto = protocols.get();
String proto = protocols.get();
String paths = System.getProperty("test.src.path");
StringTokenizer st = new StringTokenizer(paths, File.pathSeparator);
while (st.hasMoreTokens()) {
@ -58,6 +57,7 @@ public class SimpleSSLContext {
if (f.exists()) {
try (FileInputStream fis = new FileInputStream(f)) {
init(fis, proto);
break;
}
}
}