This commit is contained in:
Lana Steuck 2015-07-23 15:27:58 -07:00
commit 101f981a23
44 changed files with 1012 additions and 1366 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2015, 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
@ -61,7 +61,6 @@ class InvokerBytecodeGenerator {
private static final String LFN_SIG = "L" + LFN + ";";
private static final String LL_SIG = "(L" + OBJ + ";)L" + OBJ + ";";
private static final String LLV_SIG = "(L" + OBJ + ";L" + OBJ + ";)V";
private static final String CLL_SIG = "(L" + CLS + ";L" + OBJ + ";)L" + OBJ + ";";
/** Name of its super class*/
private static final String superName = OBJ;
@ -571,7 +570,7 @@ class InvokerBytecodeGenerator {
mv.visitLdcInsn(constantPlaceholder(cls));
mv.visitTypeInsn(Opcodes.CHECKCAST, CLS);
mv.visitInsn(Opcodes.SWAP);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, MHI, "castReference", CLL_SIG, false);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CLS, "cast", LL_SIG, false);
if (Object[].class.isAssignableFrom(cls))
mv.visitTypeInsn(Opcodes.CHECKCAST, OBJARY);
else if (PROFILE_LEVEL > 0)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2015, 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
@ -219,7 +219,7 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
if (convSpec == null) continue;
MethodHandle fn;
if (convSpec instanceof Class) {
fn = Lazy.MH_castReference.bindTo(convSpec);
fn = Lazy.MH_cast.bindTo(convSpec);
} else {
fn = (MethodHandle) convSpec;
}
@ -239,7 +239,7 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
if (convSpec == void.class)
fn = null;
else
fn = Lazy.MH_castReference.bindTo(convSpec);
fn = Lazy.MH_cast.bindTo(convSpec);
} else {
fn = (MethodHandle) convSpec;
}
@ -302,7 +302,7 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
Name conv;
if (convSpec instanceof Class) {
Class<?> convClass = (Class<?>) convSpec;
conv = new Name(Lazy.MH_castReference, convClass, names[INARG_BASE + i]);
conv = new Name(Lazy.MH_cast, convClass, names[INARG_BASE + i]);
} else {
MethodHandle fn = (MethodHandle) convSpec;
conv = new Name(fn, names[INARG_BASE + i]);
@ -326,7 +326,7 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
conv = new Name(LambdaForm.constantZero(BasicType.basicType(srcType.returnType())));
} else if (convSpec instanceof Class) {
Class<?> convClass = (Class<?>) convSpec;
conv = new Name(Lazy.MH_castReference, convClass, names[OUT_CALL]);
conv = new Name(Lazy.MH_cast, convClass, names[OUT_CALL]);
} else {
MethodHandle fn = (MethodHandle) convSpec;
if (fn.type().parameterCount() == 0)
@ -343,25 +343,6 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
return SimpleMethodHandle.make(srcType, form);
}
/**
* Identity function, with reference cast.
* @param t an arbitrary reference type
* @param x an arbitrary reference value
* @return the same value x
*/
@ForceInline
@SuppressWarnings("unchecked")
static <T,U> T castReference(Class<? extends T> t, U x) {
// inlined Class.cast because we can't ForceInline it
if (x != null && !t.isInstance(x))
throw newClassCastException(t, x);
return (T) x;
}
private static ClassCastException newClassCastException(Class<?> t, Object obj) {
return new ClassCastException("Cannot cast " + obj.getClass().getName() + " to " + t.getName());
}
static Object[] computeValueConversions(MethodType srcType, MethodType dstType,
boolean strict, boolean monobox) {
final int INARG_COUNT = srcType.parameterCount();
@ -591,6 +572,7 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
*/
static class Lazy {
private static final Class<?> MHI = MethodHandleImpl.class;
private static final Class<?> CLS = Class.class;
private static final MethodHandle[] ARRAYS;
private static final MethodHandle[] FILL_ARRAYS;
@ -600,7 +582,7 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
static final NamedFunction NF_throwException;
static final NamedFunction NF_profileBoolean;
static final MethodHandle MH_castReference;
static final MethodHandle MH_cast;
static final MethodHandle MH_selectAlternative;
static final MethodHandle MH_copyAsPrimitiveArray;
static final MethodHandle MH_fillNewTypedArray;
@ -623,8 +605,8 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
NF_throwException.resolve();
NF_profileBoolean.resolve();
MH_castReference = IMPL_LOOKUP.findStatic(MHI, "castReference",
MethodType.methodType(Object.class, Class.class, Object.class));
MH_cast = IMPL_LOOKUP.findVirtual(CLS, "cast",
MethodType.methodType(Object.class, Object.class));
MH_copyAsPrimitiveArray = IMPL_LOOKUP.findStatic(MHI, "copyAsPrimitiveArray",
MethodType.methodType(Object.class, Wrapper.class, Object[].class));
MH_arrayIdentity = IMPL_LOOKUP.findStatic(MHI, "identity",

View File

@ -339,7 +339,7 @@ public class CodeSource implements java.io.Serializable {
* @param strict If true then a strict equality match is performed.
* Otherwise a subset match is performed.
*/
private boolean matchCerts(CodeSource that, boolean strict)
boolean matchCerts(CodeSource that, boolean strict)
{
boolean match;

View File

@ -25,9 +25,10 @@
package java.security;
import java.util.Map;
import java.util.ArrayList;
import java.net.URL;
import java.util.ArrayList;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
@ -50,15 +51,15 @@ public class SecureClassLoader extends ClassLoader {
private final boolean initialized;
/*
* Map that maps the CodeSource URL (as a String) to ProtectionDomain.
* We use a String instead of a CodeSource/URL as the key to avoid
* Map that maps the CodeSource to a ProtectionDomain. The key is a
* CodeSourceKey class that uses a String instead of a URL to avoid
* potential expensive name service lookups. This does mean that URLs that
* are equivalent after nameservice lookup will be placed in separate
* ProtectionDomains; however during policy enforcement these URLs will be
* canonicalized and resolved resulting in a consistent set of granted
* permissions.
*/
private final Map<String, ProtectionDomain> pdcache
private final Map<CodeSourceKey, ProtectionDomain> pdcache
= new ConcurrentHashMap<>(11);
private static final Debug debug = Debug.getInstance("scl");
@ -209,17 +210,14 @@ public class SecureClassLoader extends ClassLoader {
return null;
}
// Use a String form of the URL as the key. It should behave in the
// same manner as the URL when compared for equality except that no
// nameservice lookup is done on the hostname (String comparison
// Use a CodeSourceKey object key. It should behave in the
// same manner as the CodeSource when compared for equality except
// that no nameservice lookup is done on the hostname (String comparison
// only), and the fragment is not considered.
String key = cs.getLocationNoFragString();
if (key == null) {
key = "<null>";
}
CodeSourceKey key = new CodeSourceKey(cs);
return pdcache.computeIfAbsent(key, new Function<>() {
@Override
public ProtectionDomain apply(String key /* not used */) {
public ProtectionDomain apply(CodeSourceKey key /* not used */) {
PermissionCollection perms
= SecureClassLoader.this.getPermissions(cs);
ProtectionDomain pd = new ProtectionDomain(
@ -242,4 +240,37 @@ public class SecureClassLoader extends ClassLoader {
}
}
private static class CodeSourceKey {
private final CodeSource cs;
CodeSourceKey(CodeSource cs) {
this.cs = cs;
}
@Override
public int hashCode() {
String locationNoFrag = cs.getLocationNoFragString();
return locationNoFrag != null ? locationNoFrag.hashCode() : 0;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof CodeSourceKey)) {
return false;
}
CodeSourceKey csk = (CodeSourceKey) obj;
if (!Objects.equals(cs.getLocationNoFragString(),
csk.cs.getLocationNoFragString())) {
return false;
}
return cs.matchCerts(csk.cs, true);
}
}
}

View File

@ -29,6 +29,9 @@ import static java.util.zip.ZipUtils.*;
import java.nio.file.attribute.FileTime;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.ZoneId;
import static java.util.zip.ZipConstants64.*;
@ -194,6 +197,85 @@ class ZipEntry implements ZipConstants, Cloneable {
return (xdostime != -1) ? extendedDosToJavaTime(xdostime) : -1;
}
/**
* Sets the last modification time of the entry in local date-time.
*
* <p> If the entry is output to a ZIP file or ZIP file formatted
* output stream the last modification time set by this method will
* be stored into the {@code date and time fields} of the zip file
* entry and encoded in standard {@code MS-DOS date and time format}.
* If the date-time set is out of the range of the standard {@code
* MS-DOS date and time format}, the time will also be stored into
* zip file entry's extended timestamp fields in {@code optional
* extra data} in UTC time. The {@link java.time.ZoneId#systemDefault()
* system default TimeZone} is used to convert the local date-time
* to UTC time.
*
* <p> {@code LocalDateTime} uses a precision of nanoseconds, whereas
* this class uses a precision of milliseconds. The conversion will
* truncate any excess precision information as though the amount in
* nanoseconds was subject to integer division by one million.
*
* @param time
* The last modification time of the entry in local date-time
*
* @see #getTimeLocal()
* @since 1.9
*/
public void setTimeLocal(LocalDateTime time) {
int year = time.getYear() - 1980;
if (year < 0) {
this.xdostime = DOSTIME_BEFORE_1980;
} else {
this.xdostime = (year << 25 |
time.getMonthValue() << 21 |
time.getDayOfMonth() << 16 |
time.getHour() << 11 |
time.getMinute() << 5 |
time.getSecond() >> 1)
+ ((long)(((time.getSecond() & 0x1) * 1000) +
time.getNano() / 1000_000) << 32);
}
if (xdostime != DOSTIME_BEFORE_1980 && year <= 0x7f) {
this.mtime = null;
} else {
this.mtime = FileTime.from(
ZonedDateTime.of(time, ZoneId.systemDefault()).toInstant());
}
}
/**
* Returns the last modification time of the entry in local date-time.
*
* <p> If the entry is read from a ZIP file or ZIP file formatted
* input stream, this is the last modification time from the zip
* file entry's {@code optional extra data} if the extended timestamp
* fields are present. Otherwise, the last modification time is read
* from entry's standard MS-DOS formatted {@code date and time fields}.
*
* <p> The {@link java.time.ZoneId#systemDefault() system default TimeZone}
* is used to convert the UTC time to local date-time.
*
* @return The last modification time of the entry in local date-time
*
* @see #setTimeLocal(LocalDateTime)
* @since 1.9
*/
public LocalDateTime getTimeLocal() {
if (mtime != null) {
return LocalDateTime.ofInstant(mtime.toInstant(), ZoneId.systemDefault());
}
int ms = (int)(xdostime >> 32);
return LocalDateTime.of((int)(((xdostime >> 25) & 0x7f) + 1980),
(int)((xdostime >> 21) & 0x0f),
(int)((xdostime >> 16) & 0x1f),
(int)((xdostime >> 11) & 0x1f),
(int)((xdostime >> 5) & 0x3f),
(int)((xdostime << 1) & 0x3e) + ms / 1000,
(ms % 1000) * 1000_000);
}
/**
* Sets the last modification time of the entry.
*
@ -498,15 +580,15 @@ class ZipEntry implements ZipConstants, Cloneable {
// flag its presence or absence. But if mtime is present
// in LOC it must be present in CEN as well.
if ((flag & 0x1) != 0 && (sz0 + 4) <= sz) {
mtime = unixTimeToFileTime(get32(extra, off + sz0));
mtime = unixTimeToFileTime(get32S(extra, off + sz0));
sz0 += 4;
}
if ((flag & 0x2) != 0 && (sz0 + 4) <= sz) {
atime = unixTimeToFileTime(get32(extra, off + sz0));
atime = unixTimeToFileTime(get32S(extra, off + sz0));
sz0 += 4;
}
if ((flag & 0x4) != 0 && (sz0 + 4) <= sz) {
ctime = unixTimeToFileTime(get32(extra, off + sz0));
ctime = unixTimeToFileTime(get32S(extra, off + sz0));
sz0 += 4;
}
break;

View File

@ -99,9 +99,9 @@ class ZipUtils {
if (year < 1980) {
return ZipEntry.DOSTIME_BEFORE_1980;
}
return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
return ((year - 1980) << 25 | (d.getMonth() + 1) << 21 |
d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
d.getSeconds() >> 1;
d.getSeconds() >> 1) & 0xffffffffL;
}
/**
@ -144,4 +144,13 @@ class ZipUtils {
public static final long get64(byte b[], int off) {
return get32(b, off) | (get32(b, off+4) << 32);
}
/**
* Fetches signed 32-bit value from byte array at specified offset.
* The bytes are assumed to be in Intel (little-endian) byte order.
*
*/
public static final int get32S(byte b[], int off) {
return (get16(b, off) | (get16(b, off+2) << 16));
}
}

View File

@ -112,7 +112,12 @@ final class ImageNativeSubstrate implements ImageSubstrate {
@Override
public byte[] getStringBytes(int offset) {
return getStringBytes(id, offset);
byte[] ret = getStringBytes(id, offset);
if (ret == null) {
throw new OutOfMemoryError("Error accessing array at offset "
+ offset);
}
return ret;
}
@Override

View File

@ -355,7 +355,7 @@ final class HandshakeHash {
try {
return cloneDigest(finMD).digest();
} catch (Exception e) {
throw new Error("BAD");
throw new Error("Error during hash calculation", e);
}
}
}

View File

@ -104,6 +104,9 @@ Java_jdk_internal_jimage_ImageNativeSubstrate_getStringBytes(JNIEnv *env,
size = strlen(data);
// Allocate byte array.
byteArray = (*env)->NewByteArray(env, (jsize) size);
if (byteArray == NULL) {
return NULL;
}
// Get array base address.
rawBytes = (*env)->GetByteArrayElements(env, byteArray, NULL);
// Copy bytes from image string table.
@ -122,6 +125,9 @@ Java_jdk_internal_jimage_ImageNativeSubstrate_getAttributes(JNIEnv *env,
jlong* ret;
attributes = (*env)->NewLongArray(env, JVM_ImageGetAttributesCount(env));
if (attributes == NULL) {
return NULL;
}
// Get base address for jlong array.
rawAttributes = (*env)->GetLongArrayElements(env, attributes, NULL);
ret = JVM_ImageGetAttributes(env, rawAttributes, id, offset);
@ -143,6 +149,9 @@ Java_jdk_internal_jimage_ImageNativeSubstrate_findAttributes(JNIEnv *env,
count = JVM_ImageGetAttributesCount(env);
attributes = (*env)->NewLongArray(env, JVM_ImageGetAttributesCount(env));
if (attributes == NULL) {
return NULL;
}
// Get base address for jlong array.
rawAttributes = (*env)->GetLongArrayElements(env, attributes, NULL);
size = (*env)->GetArrayLength(env, utf8);
@ -165,6 +174,9 @@ Java_jdk_internal_jimage_ImageNativeSubstrate_attributeOffsets(JNIEnv *env,
length = JVM_ImageAttributeOffsetsLength(env, id);
offsets = (*env)->NewIntArray(env, length);
if (offsets == NULL) {
return NULL;
}
// Get base address of result.
rawOffsets = (*env)->GetIntArrayElements(env, offsets, NULL);
ret = JVM_ImageAttributeOffsets(env, rawOffsets, length, id);

View File

@ -75,10 +75,11 @@ abstract class KrbKdcRep {
}
}
// XXX Can renew a ticket but not ask for a renewable renewed ticket
// See impl of Credentials.renew().
if (req.reqBody.kdcOptions.get(KDCOptions.RENEWABLE) !=
rep.encKDCRepPart.flags.get(KDCOptions.RENEWABLE)) {
// Reply to a renewable request should be renewable, but if request does
// not contain renewable, KDC is free to issue a renewable ticket (for
// example, if ticket_lifetime is too big).
if (req.reqBody.kdcOptions.get(KDCOptions.RENEWABLE) &&
!rep.encKDCRepPart.flags.get(KDCOptions.RENEWABLE)) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED);
}

View File

@ -83,6 +83,12 @@ public class Krb5KeyExchangeService implements ClientKeyExchangeService {
(PrivilegedExceptionAction<ServiceCreds>)
() -> Krb5Util.getServiceCreds(
GSSCaller.CALLER_SSL_SERVER, null, acc));
if (serviceCreds == null) {
if (debug != null && Debug.isOn("handshake")) {
System.out.println("Kerberos serviceCreds not available");
}
return null;
}
if (debug != null && Debug.isOn("handshake")) {
System.out.println("Using Kerberos creds");
}

View File

@ -633,17 +633,16 @@ public class PolicyTool {
type.equals(PolicyParser.PrincipalEntry.REPLACE_NAME)) {
return;
}
Class<?> PRIN = Class.forName("java.security.Principal");
Class<?> pc = Class.forName(type, true,
Thread.currentThread().getContextClassLoader());
if (!PRIN.isAssignableFrom(pc)) {
if (!Principal.class.isAssignableFrom(pc)) {
MessageFormat form = new MessageFormat(getMessage
("Illegal.Principal.Type.type"));
Object[] source = {type};
throw new InstantiationException(form.format(source));
}
if (ToolDialog.X500_PRIN_CLASS.equals(pc.getName())) {
if (X500Principal.class.getName().equals(pc.getName())) {
// PolicyParser checks validity of X500Principal name
// - PolicyTool needs to as well so that it doesn't store
// an invalid name that can't be read in later
@ -1563,14 +1562,6 @@ class ToolDialog extends JDialog {
public static final int NEW = 2;
public static final int OPEN = 3;
public static final String ALL_PERM_CLASS =
"java.security.AllPermission";
public static final String FILE_PERM_CLASS =
"java.io.FilePermission";
public static final String X500_PRIN_CLASS =
"javax.security.auth.x500.X500Principal";
/* popup menus */
public static final String PERM =
PolicyTool.getMessage
@ -1752,11 +1743,11 @@ class ToolDialog extends JDialog {
for (int i = 0; i < PERM_ARRAY.size(); i++) {
Perm next = PERM_ARRAY.get(i);
if (fullClassName) {
if (next.FULL_CLASS.equals(clazz)) {
if (next.getName().equals(clazz)) {
return next;
}
} else {
if (next.CLASS.equals(clazz)) {
if (next.getSimpleName().equals(clazz)) {
return next;
}
}
@ -1772,11 +1763,11 @@ class ToolDialog extends JDialog {
for (int i = 0; i < PRIN_ARRAY.size(); i++) {
Prin next = PRIN_ARRAY.get(i);
if (fullClassName) {
if (next.FULL_CLASS.equals(clazz)) {
if (next.getName().equals(clazz)) {
return next;
}
} else {
if (next.CLASS.equals(clazz)) {
if (next.getSimpleName().equals(clazz)) {
return next;
}
}
@ -2170,7 +2161,7 @@ class ToolDialog extends JDialog {
choice.getAccessibleContext().setAccessibleName(PRIN_TYPE);
for (int i = 0; i < PRIN_ARRAY.size(); i++) {
Prin next = PRIN_ARRAY.get(i);
choice.addItem(next.CLASS);
choice.addItem(next.getSimpleName());
}
if (edit) {
@ -2180,7 +2171,7 @@ class ToolDialog extends JDialog {
} else {
Prin inputPrin = getPrin(editMe.getPrincipalClass(), true);
if (inputPrin != null) {
choice.setSelectedItem(inputPrin.CLASS);
choice.setSelectedItem(inputPrin.getSimpleName());
}
}
}
@ -2286,7 +2277,7 @@ class ToolDialog extends JDialog {
choice.getAccessibleContext().setAccessibleName(PERM);
for (int i = 0; i < PERM_ARRAY.size(); i++) {
Perm next = PERM_ARRAY.get(i);
choice.addItem(next.CLASS);
choice.addItem(next.getSimpleName());
}
tw.addNewComponent(newTD, choice, PD_PERM_CHOICE,
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
@ -2300,7 +2291,7 @@ class ToolDialog extends JDialog {
if (edit) {
Perm inputPerm = getPerm(editMe.permission, true);
if (inputPerm != null) {
choice.setSelectedItem(inputPerm.CLASS);
choice.setSelectedItem(inputPerm.getSimpleName());
}
}
tw.addNewComponent(newTD, tf, PD_PERM_TEXTFIELD,
@ -2417,7 +2408,7 @@ class ToolDialog extends JDialog {
"\t'" + pname + "' will be interpreted " +
"as a key store alias.\n" +
"\tThe final principal class will be " +
ToolDialog.X500_PRIN_CLASS + ".\n" +
X500Principal.class.getName() + ".\n" +
"\tThe final principal name will be " +
"determined by the following:\n" +
"\n" +
@ -2452,7 +2443,7 @@ class ToolDialog extends JDialog {
if (tf.getText().trim().equals("") == false)
name = new String(tf.getText().trim());
if (permission.equals("") ||
(!permission.equals(ALL_PERM_CLASS) && name == null)) {
(!permission.equals(AllPermission.class.getName()) && name == null)) {
throw new InvalidParameterException(PolicyTool.getMessage
("Permission.and.Target.Name.must.have.a.value"));
}
@ -2467,7 +2458,8 @@ class ToolDialog extends JDialog {
// \\server\share 0, legal
// \\\\server\share 2, illegal
if (permission.equals(FILE_PERM_CLASS) && name.lastIndexOf("\\\\") > 0) {
if (permission.equals(FilePermission.class.getName())
&& name.lastIndexOf("\\\\") > 0) {
char result = tw.displayYesNoDialog(this,
PolicyTool.getMessage("Warning"),
PolicyTool.getMessage(
@ -3645,7 +3637,7 @@ class PrincipalTypeMenuListener implements ItemListener {
if (prinField.getText() != null &&
prinField.getText().length() > 0) {
Prin inputPrin = ToolDialog.getPrin(prinField.getText(), true);
prin.setSelectedItem(inputPrin.CLASS);
prin.setSelectedItem(inputPrin.getSimpleName());
}
return;
}
@ -3660,7 +3652,7 @@ class PrincipalTypeMenuListener implements ItemListener {
// set of names and actions
Prin inputPrin = ToolDialog.getPrin((String)e.getItem(), false);
if (inputPrin != null) {
prinField.setText(inputPrin.FULL_CLASS);
prinField.setText(inputPrin.getName());
}
}
}
@ -3711,7 +3703,7 @@ class PermissionMenuListener implements ItemListener {
Perm inputPerm = ToolDialog.getPerm(permField.getText(), true);
if (inputPerm != null) {
perms.setSelectedItem(inputPerm.CLASS);
perms.setSelectedItem(inputPerm.getSimpleName());
}
}
return;
@ -3732,7 +3724,7 @@ class PermissionMenuListener implements ItemListener {
if (inputPerm == null) {
permField.setText("");
} else {
permField.setText(inputPerm.FULL_CLASS);
permField.setText(inputPerm.getName());
}
td.setPermissionNames(inputPerm, names, nameField);
td.setPermissionActions(inputPerm, actions, actionsField);
@ -4082,26 +4074,30 @@ class TaggedList extends JList<String> {
*/
class Prin {
public final String CLASS;
public final String FULL_CLASS;
final Class<? extends Principal> CLASS;
public Prin(String clazz, String fullClass) {
Prin(Class<? extends Principal> clazz) {
this.CLASS = clazz;
this.FULL_CLASS = fullClass;
}
String getName() {
return CLASS.getName();
}
String getSimpleName() {
return CLASS.getSimpleName();
}
}
class KrbPrin extends Prin {
public KrbPrin() {
super("KerberosPrincipal",
"javax.security.auth.kerberos.KerberosPrincipal");
KrbPrin() {
super(javax.security.auth.kerberos.KerberosPrincipal.class);
}
}
class X500Prin extends Prin {
public X500Prin() {
super("X500Principal",
"javax.security.auth.x500.X500Principal");
X500Prin() {
super(javax.security.auth.x500.X500Principal.class);
}
}
@ -4110,31 +4106,36 @@ class X500Prin extends Prin {
*/
class Perm {
public final String CLASS;
public final String FULL_CLASS;
public final String[] TARGETS;
public final String[] ACTIONS;
final Class<? extends Permission> CLASS;
final String[] TARGETS;
final String[] ACTIONS;
public Perm(String clazz, String fullClass,
Perm(Class<? extends Permission> clazz,
String[] targets, String[] actions) {
this.CLASS = clazz;
this.FULL_CLASS = fullClass;
this.TARGETS = targets;
this.ACTIONS = actions;
}
String getName() {
return CLASS.getName();
}
String getSimpleName() {
return CLASS.getSimpleName();
}
}
class AllPerm extends Perm {
public AllPerm() {
super("AllPermission", "java.security.AllPermission", null, null);
AllPerm() {
super(java.security.AllPermission.class, null, null);
}
}
class AudioPerm extends Perm {
public AudioPerm() {
super("AudioPermission",
"javax.sound.sampled.AudioPermission",
AudioPerm() {
super(javax.sound.sampled.AudioPermission.class,
new String[] {
"play",
"record"
@ -4144,9 +4145,8 @@ class AudioPerm extends Perm {
}
class AuthPerm extends Perm {
public AuthPerm() {
super("AuthPermission",
"javax.security.auth.AuthPermission",
AuthPerm() {
super(javax.security.auth.AuthPermission.class,
new String[] {
"doAs",
"doAsPrivileged",
@ -4170,9 +4170,8 @@ class AuthPerm extends Perm {
}
class AWTPerm extends Perm {
public AWTPerm() {
super("AWTPermission",
"java.awt.AWTPermission",
AWTPerm() {
super(java.awt.AWTPermission.class,
new String[] {
"accessClipboard",
"accessEventQueue",
@ -4193,9 +4192,8 @@ class AWTPerm extends Perm {
}
class DelegationPerm extends Perm {
public DelegationPerm() {
super("DelegationPermission",
"javax.security.auth.kerberos.DelegationPermission",
DelegationPerm() {
super(javax.security.auth.kerberos.DelegationPermission.class,
new String[] {
// allow user input
},
@ -4204,9 +4202,8 @@ class DelegationPerm extends Perm {
}
class FilePerm extends Perm {
public FilePerm() {
super("FilePermission",
"java.io.FilePermission",
FilePerm() {
super(java.io.FilePermission.class,
new String[] {
"<<ALL FILES>>"
},
@ -4220,9 +4217,8 @@ class FilePerm extends Perm {
}
class URLPerm extends Perm {
public URLPerm() {
super("URLPermission",
"java.net.URLPermission",
URLPerm() {
super(java.net.URLPermission.class,
new String[] {
"<"+ PolicyTool.getMessage("url") + ">",
},
@ -4234,9 +4230,8 @@ class URLPerm extends Perm {
}
class InqSecContextPerm extends Perm {
public InqSecContextPerm() {
super("InquireSecContextPermission",
"com.sun.security.jgss.InquireSecContextPermission",
InqSecContextPerm() {
super(com.sun.security.jgss.InquireSecContextPermission.class,
new String[] {
"KRB5_GET_SESSION_KEY",
"KRB5_GET_TKT_FLAGS",
@ -4248,9 +4243,8 @@ class InqSecContextPerm extends Perm {
}
class LogPerm extends Perm {
public LogPerm() {
super("LoggingPermission",
"java.util.logging.LoggingPermission",
LogPerm() {
super(java.util.logging.LoggingPermission.class,
new String[] {
"control"
},
@ -4259,9 +4253,8 @@ class LogPerm extends Perm {
}
class MgmtPerm extends Perm {
public MgmtPerm() {
super("ManagementPermission",
"java.lang.management.ManagementPermission",
MgmtPerm() {
super(java.lang.management.ManagementPermission.class,
new String[] {
"control",
"monitor"
@ -4271,9 +4264,8 @@ class MgmtPerm extends Perm {
}
class MBeanPerm extends Perm {
public MBeanPerm() {
super("MBeanPermission",
"javax.management.MBeanPermission",
MBeanPerm() {
super(javax.management.MBeanPermission.class,
new String[] {
// allow user input
},
@ -4300,9 +4292,8 @@ class MBeanPerm extends Perm {
}
class MBeanSvrPerm extends Perm {
public MBeanSvrPerm() {
super("MBeanServerPermission",
"javax.management.MBeanServerPermission",
MBeanSvrPerm() {
super(javax.management.MBeanServerPermission.class,
new String[] {
"createMBeanServer",
"findMBeanServer",
@ -4314,9 +4305,8 @@ class MBeanSvrPerm extends Perm {
}
class MBeanTrustPerm extends Perm {
public MBeanTrustPerm() {
super("MBeanTrustPermission",
"javax.management.MBeanTrustPermission",
MBeanTrustPerm() {
super(javax.management.MBeanTrustPermission.class,
new String[] {
"register"
},
@ -4325,9 +4315,8 @@ class MBeanTrustPerm extends Perm {
}
class NetPerm extends Perm {
public NetPerm() {
super("NetPermission",
"java.net.NetPermission",
NetPerm() {
super(java.net.NetPermission.class,
new String[] {
"allowHttpTrace",
"setDefaultAuthenticator",
@ -4346,9 +4335,8 @@ class NetPerm extends Perm {
}
class NetworkPerm extends Perm {
public NetworkPerm() {
super("NetworkPermission",
"jdk.net.NetworkPermission",
NetworkPerm() {
super(jdk.net.NetworkPermission.class,
new String[] {
"setOption.SO_FLOW_SLA",
"getOption.SO_FLOW_SLA"
@ -4358,9 +4346,8 @@ class NetworkPerm extends Perm {
}
class PrivCredPerm extends Perm {
public PrivCredPerm() {
super("PrivateCredentialPermission",
"javax.security.auth.PrivateCredentialPermission",
PrivCredPerm() {
super(javax.security.auth.PrivateCredentialPermission.class,
new String[] {
// allow user input
},
@ -4371,9 +4358,8 @@ class PrivCredPerm extends Perm {
}
class PropPerm extends Perm {
public PropPerm() {
super("PropertyPermission",
"java.util.PropertyPermission",
PropPerm() {
super(java.util.PropertyPermission.class,
new String[] {
// allow user input
},
@ -4385,9 +4371,8 @@ class PropPerm extends Perm {
}
class ReflectPerm extends Perm {
public ReflectPerm() {
super("ReflectPermission",
"java.lang.reflect.ReflectPermission",
ReflectPerm() {
super(java.lang.reflect.ReflectPermission.class,
new String[] {
"suppressAccessChecks"
},
@ -4396,9 +4381,8 @@ class ReflectPerm extends Perm {
}
class RuntimePerm extends Perm {
public RuntimePerm() {
super("RuntimePermission",
"java.lang.RuntimePermission",
RuntimePerm() {
super(java.lang.RuntimePermission.class,
new String[] {
"createClassLoader",
"getClassLoader",
@ -4437,9 +4421,8 @@ class RuntimePerm extends Perm {
}
class SecurityPerm extends Perm {
public SecurityPerm() {
super("SecurityPermission",
"java.security.SecurityPermission",
SecurityPerm() {
super(java.security.SecurityPermission.class,
new String[] {
"createAccessControlContext",
"getDomainCombiner",
@ -4475,9 +4458,8 @@ class SecurityPerm extends Perm {
}
class SerialPerm extends Perm {
public SerialPerm() {
super("SerializablePermission",
"java.io.SerializablePermission",
SerialPerm() {
super(java.io.SerializablePermission.class,
new String[] {
"enableSubclassImplementation",
"enableSubstitution"
@ -4487,9 +4469,8 @@ class SerialPerm extends Perm {
}
class ServicePerm extends Perm {
public ServicePerm() {
super("ServicePermission",
"javax.security.auth.kerberos.ServicePermission",
ServicePerm() {
super(javax.security.auth.kerberos.ServicePermission.class,
new String[] {
// allow user input
},
@ -4501,9 +4482,8 @@ class ServicePerm extends Perm {
}
class SocketPerm extends Perm {
public SocketPerm() {
super("SocketPermission",
"java.net.SocketPermission",
SocketPerm() {
super(java.net.SocketPermission.class,
new String[] {
// allow user input
},
@ -4517,9 +4497,8 @@ class SocketPerm extends Perm {
}
class SQLPerm extends Perm {
public SQLPerm() {
super("SQLPermission",
"java.sql.SQLPermission",
SQLPerm() {
super(java.sql.SQLPermission.class,
new String[] {
"setLog",
"callAbort",
@ -4531,9 +4510,8 @@ class SQLPerm extends Perm {
}
class SSLPerm extends Perm {
public SSLPerm() {
super("SSLPermission",
"javax.net.ssl.SSLPermission",
SSLPerm() {
super(javax.net.ssl.SSLPermission.class,
new String[] {
"setHostnameVerifier",
"getSSLSessionContext"
@ -4543,9 +4521,8 @@ class SSLPerm extends Perm {
}
class SubjDelegPerm extends Perm {
public SubjDelegPerm() {
super("SubjectDelegationPermission",
"javax.management.remote.SubjectDelegationPermission",
SubjDelegPerm() {
super(javax.management.remote.SubjectDelegationPermission.class,
new String[] {
// allow user input
},

View File

@ -154,17 +154,6 @@ javax/management/remote/mandatory/notif/NotifReconnectDeadlockTest.java generi
############################################################################
# jdk_math
############################################################################
# jdk_other
# 6988950
demo/jvmti/compiledMethodLoad/CompiledMethodLoadTest.java generic-all
############################################################################
# jdk_net
# 7148829
@ -390,10 +379,4 @@ sun/jvmstat/monitor/MonitoredVm/MonitorVmStartTerminate.java generic-all
# 8064572 8060736 8062938
sun/jvmstat/monitor/MonitoredVm/CR6672135.java generic-all
# 8079273
demo/jvmti/hprof/CpuOldTest.java generic-all
demo/jvmti/hprof/CpuTimesTest.java generic-all
demo/jvmti/hprof/OptionsTest.java generic-all
demo/jvmti/hprof/StackMapTableTest.java generic-all
############################################################################

View File

@ -42,7 +42,8 @@ tier2 = \
:jdk_svc
tier3 = \
:jdk_rmi
:jdk_rmi \
:jdk_beans
###############################################################################
#

View File

@ -122,7 +122,6 @@ public class DemoRun {
String libprefix = os_name.contains("Windows")?"":"lib";
String libsuffix = os_name.contains("Windows")?".dll":
os_name.contains("OS X")?".dylib":".so";
boolean hprof = demo_name.equals("hprof");
String java = sdk_home
+ File.separator + "bin"
+ File.separator + "java";
@ -155,12 +154,6 @@ public class DemoRun {
cmdLine += (cmd[i++] = "-Xcheck:jni");
cmdLine += " ";
cmdLine += (cmd[i++] = "-Xverify:all");
if ( hprof ) {
/* Load hprof with -agentlib since it's part of jre */
cmdLine += " ";
cmdLine += (cmd[i++] = "-agentlib:" + demo_name
+ (demo_options.equals("")?"":("="+demo_options)));
} else {
String libname = sdk_home
+ File.separator + "demo"
+ File.separator + "jvmti"
@ -169,8 +162,7 @@ public class DemoRun {
+ File.separator + libprefix + demo_name + libsuffix;
cmdLine += " ";
cmdLine += (cmd[i++] = "-agentpath:" + libname
+ (demo_options.equals("")?"":("="+demo_options)));
}
+ (demo_options.equals("") ? "" : ("=" + demo_options)));
/* Add any special VM options */
for ( j = 0; j < nvm_options; j++ ) {
cmdLine += " ";

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2004, 2014, 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 5012882
* @summary Test jvmti hprof
*
* @compile -g:lines HelloWorld.java ../DemoRun.java
* @build CpuSamplesTest
* @run main CpuSamplesTest HelloWorld
*/
public class CpuSamplesTest {
public static void main(String args[]) throws Exception {
DemoRun hprof;
/* Run JVMTI hprof agent with cpu=samples */
hprof = new DemoRun("hprof", "cpu=samples,file=cpusamples.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */
System.out.println("Test passed - cleanly terminated");
}
}

View File

@ -1,53 +0,0 @@
/*
* Copyright (c) 2004, 2014, 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 5097131 6299047
* @summary Test jvmti hprof
*
* @compile -g HelloWorld.java DefineClass.java ../DemoRun.java
* @build CpuTimesDefineClassTest
* @run main CpuTimesDefineClassTest DefineClass
*
*
*/
public class CpuTimesDefineClassTest {
public static void main(String args[]) throws Exception {
DemoRun hprof;
/* Run JVMTI hprof agent with cpu=times */
hprof = new DemoRun("hprof", "cpu=times,file=cputimedefineclass.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */
System.out.println("Test passed - cleanly terminated");
}
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2004, 2014, 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 5012882 6299047
* @summary Test jvmti hprof
*
* @compile -g HelloWorld.java ../DemoRun.java
* @build CpuTimesTest
* @run main CpuTimesTest HelloWorld
*/
public class CpuTimesTest {
public static void main(String args[]) throws Exception {
DemoRun hprof;
/* Run JVMTI hprof agent with cpu=times */
hprof = new DemoRun("hprof", "cpu=times,file=cputimes.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */
System.out.println("Test passed - cleanly terminated");
}
}

View File

@ -1,70 +0,0 @@
/*
* Copyright (c) 2004, 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.
*/
/* Testcase that does a defineClass with a NULL name on HelloWorld.class */
import java.io.*;
public class DefineClass extends ClassLoader {
public static void main(String args[]) {
DefineClass t = new DefineClass();
t.run(args);
}
public void run(String args[]) {
Class n;
byte b[] = new byte[10000];
int len = 0;
String cdir;
String cfile;
/* Class is found here: */
cdir = System.getProperty("test.classes", ".");
cfile = cdir + java.io.File.separator + "HelloWorld.class";
try {
/* Construct byte array with complete class image in it. */
FileInputStream fis = new FileInputStream(cfile);
int nbytes;
do {
nbytes = fis.read(b, len, b.length-len);
if ( nbytes > 0 ) {
len += nbytes;
}
} while ( nbytes > 0 );
} catch ( Throwable x ) {
System.err.println("Cannot find " + cfile);
x.printStackTrace();
}
/* Define the class with null for the name */
n = defineClass(null, b, 0, len);
/* Try to create an instance of it */
try {
n.newInstance();
} catch ( Throwable x ) {
x.printStackTrace();
}
}
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2004, 2014, 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 5012882 6299047
* @summary Test jvmti hprof
*
* @compile -g HelloWorld.java ../DemoRun.java
* @build HeapAllTest
* @run main HeapAllTest HelloWorld
*/
public class HeapAllTest {
public static void main(String args[]) throws Exception {
DemoRun hprof;
/* Run JVMTI hprof agent with heap=all */
hprof = new DemoRun("hprof", "heap=all,file=heapall.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */
System.out.println("Test passed - cleanly terminated");
}
}

View File

@ -1,64 +0,0 @@
/*
* Copyright (c) 2005, 2014, 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 4965057 6313381
* @summary Test jvmti hprof format=b
*
* @compile -g:source HelloWorld.java ../DemoRun.java
* @build HeapBinaryFormatTest
* @run main HeapBinaryFormatTest HelloWorld
*/
public class HeapBinaryFormatTest {
public static void main(String args[]) throws Exception {
DemoRun hprof;
/* Run JVMTI hprof agent to get binary format dump */
hprof = new DemoRun("hprof", "heap=dump,format=b,logflags=4,file=heapbinaryformat.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Try a variation */
String vm_opts[] = new String[1];
vm_opts[0] = "-Xmx2100m";
/* Crashes on small Linux machines: (like fyi)
How can I tell how much real memory is on a machine?
hprof.runit(args[0], vm_opts);
*/
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */
System.out.println("Test passed - cleanly terminated");
}
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2004, 2014, 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 5012882 6299047
* @summary Test jvmti hprof
*
* @compile -g:source HelloWorld.java ../DemoRun.java
* @build HeapDumpTest
* @run main HeapDumpTest HelloWorld
*/
public class HeapDumpTest {
public static void main(String args[]) throws Exception {
DemoRun hprof;
/* Run JVMTI hprof agent with heap=dump */
hprof = new DemoRun("hprof", "heap=dump,file=heapdump.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */
System.out.println("Test passed - cleanly terminated");
}
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2004, 2014, 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 5012882 6299047
* @summary Test jvmti hprof
*
* @compile -g:vars HelloWorld.java ../DemoRun.java
* @build HeapSitesTest
* @run main HeapSitesTest HelloWorld
*/
public class HeapSitesTest {
public static void main(String args[]) throws Exception {
DemoRun hprof;
/* Run JVMTI hprof agent with heap=sites */
hprof = new DemoRun("hprof", "heap=sites,file=heapsites.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */
System.out.println("Test passed - cleanly terminated");
}
}

View File

@ -1,119 +0,0 @@
/*
* Copyright (c) 2004, 2009, 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.
*/
/* HelloWorld:
*
* Sample target application for HPROF tests
*
*/
/* Just some classes that create a variety of references */
class AAAA {
public int AAAA_i;
public static int AAAA_si;
public Object AAAA_j;
public static Object AAAA_sj;
public long AAAA_k;
public static long AAAA_sk;
}
interface IIII {
Object o = new Object();
}
class BBBB extends AAAA implements IIII {
public byte BBBB_ii;
public static byte BBBB_sii;
public Object BBBB_jj;
public static Object BBBB_sjj;
public short BBBB_kk;
public static short BBBB_skk;
}
class REFS {
private static String s1 = new String("REFS_string1");
private String is2 = new String("REFS_string2");
private static String s3 = new String("REFS_string3");
private static String s4 = new String("REFS_string4");
private String is5 = new String("REFS_string5");
private AAAA aaaa;
private BBBB bbbb;
public void test() {
aaaa = new AAAA();
bbbb = new BBBB();
aaaa.AAAA_i = 1;
AAAA.AAAA_si = 2;
aaaa.AAAA_j = s1;
AAAA.AAAA_sj = is2;
aaaa.AAAA_k = 5;
AAAA.AAAA_sk = 6;
bbbb.BBBB_ii = 11;
BBBB.BBBB_sii = 22;
bbbb.BBBB_jj = s3;
BBBB.BBBB_sjj = s4;
bbbb.BBBB_kk = 55;
BBBB.BBBB_skk = 66;
bbbb.AAAA_i = 111;
bbbb.AAAA_j = is5;
bbbb.AAAA_k = 555;
}
}
/* Fairly simple hello world program that does some exercises first. */
public class HelloWorld {
public static void main(String args[]) {
/* References exercise. */
REFS r = new REFS();
r.test();
/* Use a generic type exercise. */
java.util.List<String> l = new java.util.ArrayList<String>();
String.format("%s", "");
/* Create a class that has lots of different bytecodes exercise. */
/* (Don't run it!) */
UseAllBytecodes x = new UseAllBytecodes(1,2);
/* Just some code with branches exercise. */
try {
if ( args.length == 0 ) {
System.out.println("No arguments passed in (doesn't matter)");
} else {
System.out.println("Arguments passed in (doesn't matter)");
}
} catch ( Throwable e ) {
System.out.println("ERROR: System.out.println() did a throw");
} finally {
System.out.println("Hello, world!");
}
}
}

View File

@ -1,56 +0,0 @@
/*
* Copyright (c) 2004, 2014, 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 5012882
* @summary Test jvmti hprof
*
* @compile -g ../Context.java ../DemoRun.java
* @build MonitorTest
* @run main MonitorTest Context 25 200 1000
*/
/* To create monitor contention, increase the default configuration.
* Hprof seems to have historically not output anything unless certain
* limits have been reached on the total contention time.
*/
public class MonitorTest {
public static void main(String args[]) throws Exception {
DemoRun hprof;
/* Run JVMTI hprof agent with monitor=y */
hprof = new DemoRun("hprof", "monitor=y,file=monitor.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */
System.out.println("Test passed - cleanly terminated");
}
}

View File

@ -1,62 +0,0 @@
/*
* Copyright (c) 2004, 2014, 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 5083441 6299047
* @summary Test jvmti hprof
*
* @compile -g:lines HelloWorld.java ../DemoRun.java
* @build OptionsTest
* @run main OptionsTest HelloWorld
*/
import java.util.*;
public class OptionsTest {
public static void main(String args[]) throws Exception {
DemoRun hprof;
List<String> options = new LinkedList<String>();
options.add("cpu=samples,depth=0,file=options0.txt");
options.add("cpu=times,depth=0,file=options1.txt");
options.add("cpu=old,depth=0,file=options2.txt");
options.add("depth=0,file=options3.txt");
for(String option: options) {
/* Run JVMTI hprof agent with various options */
hprof = new DemoRun("hprof", option);
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed with " + option
+ " - ERROR seen in output");
}
}
/* Must be a pass. */
System.out.println("Test passed - cleanly terminated");
}
}

View File

@ -1,63 +0,0 @@
/*
* Copyright (c) 2005, 2014, 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 6266289 6299047 6855180 6855551
* @summary Test jvmti hprof and java_crw_demo with StackMapTable attributes
*
* @compile ../DemoRun.java
* @compile -g:lines HelloWorld.java
* @build StackMapTableTest
* @run main StackMapTableTest HelloWorld
*/
import java.util.*;
public class StackMapTableTest {
public static void main(String args[]) throws Exception {
DemoRun hprof;
List<String> options = new LinkedList<String>();
options.add("cpu=samples,file=stackmaptable0.txt");
options.add("cpu=times,file=stackmaptable1.txt");
options.add("heap=sites,file=stackmaptable2.txt");
options.add("file=stackmaptable3.txt");
for(String option: options) {
/* Run JVMTI hprof agent with various options */
hprof = new DemoRun("hprof", option);
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed with " + option
+ " - ERROR seen in output");
}
}
/* Must be a pass. */
System.out.println("Test passed - cleanly terminated");
}
}

View File

@ -1,309 +0,0 @@
/*
* Copyright (c) 1996, 2005, 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.
*/
/*
A simple Java class definition that helps self-test the runtime
interpreter. Used for getfield/putfield, invoke* opcodes and
their _quick variants.
See src/share/java/runtime/selftest.c for details of the test
environment.
*/
/* Used to be sun/misc/SelfTest.java */
interface UseAllBytecodesInterface
{
public void test_an_interface(int p1);
}
public class UseAllBytecodes implements UseAllBytecodesInterface
{
public int i1, i2;
public float f1, f2;
public double d1, d2;
public long l1, l2;
public static int si1, si2;
public static float sf1, sf2;
public static double sd1, sd2;
public static long sl1, sl2;
public UseAllBytecodesInterface interfaceObject;
public int multi[][][];
public UseAllBytecodes()
{
/* This constructor is not intended to ever be run. It is here
to force CONSTANT_Methodref constants into the CP */
set_i1(11);
set_i2(22);
set_f1(1.1f);
set_f2(2.2f);
set_d1(1.0);
set_d2(2.0);
set_l1(3);
set_l2(4);
set_si1(33);
set_si2(44);
set_sf1(3.3f);
set_sf2(4.4f);
set_sd1(3.0);
set_sd2(4.0);
set_sl1(5);
set_sl2(6);
test_areturn();
test_athrow1();
test_athrow2();
test_athrow3();
test_athrow4();
/* This puts a CONSTANT_InterfaceMethodref into the CP */
interfaceObject.test_an_interface(1234);
/* This creates an array and puts it into the CP */
multi = new int[2][3][4];
}
public UseAllBytecodes(int p1)
{
i1 = p1;
i2 = 12345678; /* This puts a CONSTANT_Integer into the CP */
d1 = (double) p1;
d2 = 1.2e234; /* This puts a CONSTANT_Double into the CP */
}
public UseAllBytecodes(int p1, int p2)
{
i1 = p1;
i2 = p2;
}
/* These methods should return something other than their
arguments, so the self test can easily determine that
the correct value was returned. */
public int set_i1(int p1)
{
i1 = p1;
return i1 + 1;
}
public int set_i2(int p2)
{
i2 = p2;
return i2 + 1;
}
public float set_f1(float p1)
{
f1 = p1;
return f1 + 1.0e34f;
}
public float set_f2(float p2)
{
f2 = p2;
return f2 + 1.0e34f;
}
public double set_d1(double p1)
{
d1 = p1;
return d1 + 1.0e234;
}
public double set_d2(double p2)
{
d2 = p2;
return d2 + 1.0e234;
}
public long set_l1(long p1)
{
l1 = p1;
return l1 + 1;
}
public long set_l2(long p2)
{
l2 = p2;
return l2 + 1;
}
public static void set_si1(int p1)
{
si1 = p1;
}
public static void set_si2(int p2)
{
si2 = p2;
}
public static void set_sf1(float p1)
{
sf1 = p1;
}
public static void set_sf2(float p2)
{
sf2 = p2;
}
public static void set_sd1(double p1)
{
sd1 = p1;
}
public static void set_sd2(double p2)
{
sd2 = p2;
}
public static void set_sl1(long p1)
{
sl1 = p1;
}
public static void set_sl2(long p2)
{
sl2 = p2;
}
public UseAllBytecodes test_areturn()
{
return this;
}
/* This method does the same thing as set_i1.
It is here to test the invokeinterface opcode. */
public void test_an_interface(int p1)
{
i1 = p1;
}
/* The following 10 methods test various permutations of
try-and-catch. */
public static void test_athrow1() throws NullPointerException
{
try
{
si1 = -1;
throw new NullPointerException();
}
catch (Exception e)
{
si1 = 1;
}
}
public static void test_athrow2()
{
int i = 1;
try
{
si1 = -1;
test_athrow1();
}
catch (Exception e)
{
// This should *not* catch the exception;
// should be caught in test_athrow1.
si1 = i + 1;
}
}
public static void test_athrow3()
{
int i = 1;
try
{
// Ultimately throws NullPointerException
si1 = -1;
si2 = -1;
test_athrow5();
}
catch (NullPointerException np)
{
si1 = i + 1;
}
catch (NoSuchMethodException e)
{
si2 = i + 1;
}
si1++; // total is 3
}
public static void test_athrow4()
{
int i = 2;
try
{
// Ultimately throws NoSuchMethodException
si1 = -1;
si2 = -1;
test_athrow7();
}
catch (NullPointerException e)
{
si1 = i + 1;
}
catch (NoSuchMethodException nsm)
{
si2 = i + 1;
}
si2++; // total is 4
}
public static void test_throw_nosuchmethod() throws NoSuchMethodException
{
throw new NoSuchMethodException();
}
public static void test_throw_nullpointer() throws NullPointerException
{
throw new NullPointerException();
}
public static void test_athrow5() throws NullPointerException, NoSuchMethodException
{
test_athrow6();
}
public static void test_athrow6() throws NullPointerException, NoSuchMethodException
{
test_throw_nullpointer();
}
public static void test_athrow7() throws NullPointerException, NoSuchMethodException
{
test_athrow8();
}
public static void test_athrow8() throws NullPointerException, NoSuchMethodException
{
test_throw_nosuchmethod();
}
}

View File

@ -168,6 +168,11 @@ public class CatchExceptionTest {
try {
returned = target.invokeWithArguments(args);
} catch (Throwable ex) {
if (CodeCacheOverflowProcessor.isThrowableCausedByVME(ex)) {
// This error will be treated by CodeCacheOverflowProcessor
// to prevent the test from failing because of code cache overflow.
throw new Error(ex);
}
testCase.assertCatch(ex);
returned = ex;
}

View File

@ -123,7 +123,7 @@ public class AdaptServerSocket {
public static void main(String[] args) throws Exception {
test(0, 0, false);
test(50, 500, false);
test(50, 5000, false);
test(500, 50, true);
}

View File

@ -21,28 +21,44 @@
* questions.
*/
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.security.CodeSource;
import java.security.Key;
import java.security.KeyStoreException;
import java.security.KeyStoreSpi;
import java.security.NoSuchAlgorithmException;
import java.security.Permission;
import java.security.Policy;
import java.security.ProtectionDomain;
import java.security.Provider;
import java.security.SecureClassLoader;
import java.security.Security;
import java.security.UnrecoverableKeyException;
import java.security.URIParameter;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.PropertyPermission;
/*
* @test
* @bug 6826789
* @bug 6826789 8131486
* @summary Make sure equivalent ProtectionDomains are granted the same
* permissions when the CodeSource URLs are different but resolve
* to the same ip address after name service resolution.
* @run main/othervm/java.security.policy=DefineClass.policy DefineClass
* @run main/othervm DefineClass
*/
public class DefineClass {
@ -53,42 +69,100 @@ public class DefineClass {
new PropertyPermission("user.name", "read")
};
// Base64 encoded bytes of a simple class: "public class Foo {}"
// Base64 encoded bytes of simple class: "package foo; public class Foo {}"
private final static String FOO_CLASS =
"yv66vgAAADQADQoAAwAKBwALBwAMAQAGPGluaXQ+AQADKClWAQAEQ29kZQEA" +
"yv66vgAAADMADQoAAwAKBwALBwAMAQAGPGluaXQ+AQADKClWAQAEQ29kZQEA" +
"D0xpbmVOdW1iZXJUYWJsZQEAClNvdXJjZUZpbGUBAAhGb28uamF2YQwABAAF" +
"AQADRm9vAQAQamF2YS9sYW5nL09iamVjdAAhAAIAAwAAAAAAAQABAAQABQAB" +
"AAYAAAAdAAEAAQAAAAUqtwABsQAAAAEABwAAAAYAAQAAAAEAAQAIAAAAAgAJ";
"AQAHZm9vL0ZvbwEAEGphdmEvbGFuZy9PYmplY3QAIQACAAMAAAAAAAEAAQAE" +
"AAUAAQAGAAAAHQABAAEAAAAFKrcAAbEAAAABAAcAAAAGAAEAAAABAAEACAAA" +
"AAIACQ==";
// Base64 encoded bytes of a simple class: "public class Bar {}"
// Base64 encoded bytes of simple class: "package bar; public class Bar {}"
private final static String BAR_CLASS =
"yv66vgAAADQADQoAAwAKBwALBwAMAQAGPGluaXQ+AQADKClWAQAEQ29kZQEA" +
"yv66vgAAADMADQoAAwAKBwALBwAMAQAGPGluaXQ+AQADKClWAQAEQ29kZQEA" +
"D0xpbmVOdW1iZXJUYWJsZQEAClNvdXJjZUZpbGUBAAhCYXIuamF2YQwABAAF" +
"AQADQmFyAQAQamF2YS9sYW5nL09iamVjdAAhAAIAAwAAAAAAAQABAAQABQAB" +
"AAYAAAAdAAEAAQAAAAUqtwABsQAAAAEABwAAAAYAAQAAAAEAAQAIAAAAAgAJ";
"AQAHYmFyL0JhcgEAEGphdmEvbGFuZy9PYmplY3QAIQACAAMAAAAAAAEAAQAE" +
"AAUAAQAGAAAAHQABAAEAAAAFKrcAAbEAAAABAAcAAAAGAAEAAAABAAEACAAA" +
"AAIACQ==";
// Base64 encoded bytes of simple class: "package baz; public class Baz {}"
private final static String BAZ_CLASS =
"yv66vgAAADQADQoAAwAKBwALBwAMAQAGPGluaXQ+AQADKClWAQAEQ29kZQEA" +
"D0xpbmVOdW1iZXJUYWJsZQEAClNvdXJjZUZpbGUBAAhCYXouamF2YQwABAAF" +
"AQAHYmF6L0JhegEAEGphdmEvbGFuZy9PYmplY3QAIQACAAMAAAAAAAEAAQAE" +
"AAUAAQAGAAAAHQABAAEAAAAFKrcAAbEAAAABAAcAAAAGAAEAAAABAAEACAAA" +
"AAIACQ==";
private final static String BAZ_CERT =
"-----BEGIN CERTIFICATE-----\n" +
"MIIEFzCCA8OgAwIBAgIESpPf8TANBglghkgBZQMEAwIFADAOMQwwCgYDVQQDEwNG\n" +
"b28wHhcNMTUwNzE1MTY1ODM5WhcNMTUxMDEzMTY1ODM5WjAOMQwwCgYDVQQDEwNG\n" +
"b28wggNCMIICNQYHKoZIzjgEATCCAigCggEBAI95Ndm5qum/q+2Ies9JUbbzLsWe\n" +
"O683GOjqxJYfPv02BudDUanEGDM5uAnnwq4cU5unR1uF0BGtuLR5h3VJhGlcrA6P\n" +
"FLM2CCiiL/onEQo9YqmTRTQJoP5pbEZY+EvdIIGcNwmgEFexla3NACM9ulSEtikf\n" +
"nWSO+INEhneXnOwEtDSmrC516Zhd4j2wKS/BEYyf+p2BgeczjbeStzDXueNJWS9o\n" +
"CZhyFTkV6j1ri0ZTxjNFj4A7MqTC4PJykCVuTj+KOwg4ocRQ5OGMGimjfd9eoUPe\n" +
"S2b/BJA+1c8WI+FY1IfGCOl/IRzYHcojy244B2X4IuNCvkhMBXY5OWAc1mcCHQC6\n" +
"9pamhXj3397n+mfJd8eF7zKyM7rlgMC81WldAoIBABamXFggSFBwTnUCo5dXBA00\n" +
"2jo0eMFU1OSlwC0kLuBPluYeS9CQSr2sjzfuseCfMYLSPJBDy2QviABBYO35ygmz\n" +
"IHannDKmJ/JHPpGHm6LE50S9IIFUTLVbgCw2jR+oPtSJ6U4PoGiOMkKKXHjEeMaN\n" +
"BSe3HJo6uwsL4SxEaJY559POdNsQGmWqK4f2TGgm2z7HL0tVmYNLtO2wL3yQ6aSW\n" +
"06VdU1vr/EXU9hn2Pz3tu4c5JcLyJOB3MSltqIfsHkdI+H77X963VIQxayIy3uVT\n" +
"3a8CESsNHwLaMJcyJP4nrtqLnUspItm6i+Oe2eEDpjxSgQvGiLfi7UMW4e8X294D\n" +
"ggEFAAKCAQBsGeU8/STExzQsJ8kFM9xarA/2VAFMzyUpd3IQ2UGHQC5rEnGh/RiU\n" +
"T20y7a2hCpQ1f/qgLnY8hku9GRVY3z8WamBzWLzCAEAx67EsS58mf4o8R3sUbkH5\n" +
"/mRaZoNVSPUy+tXoLmTzIetU4W+JT8Rq4OcXXU9uo9TreeBehhVexS3vpVgQeUIn\n" +
"MmMma8WHpovIJQQlp4cyjalX7Beda/tqX/HPLkAS4TRqQAz7hFr3FqFrVMKFSGo4\n" +
"fTS06GGdQ4tw9c6NQLuQ9WF9BxYSwSk9yENQvKDZaBNarqPMnsh1Gi/QcKMRBVhM\n" +
"RT/9vb4QUi/pOowhhKCDBLgjY60QgX3HoyEwHzAdBgNVHQ4EFgQUa787CE+3ZNAb\n" +
"g1ql9yJVVrRCdx0wDQYJYIZIAWUDBAMCBQADPwAwPAIcCUkZIRrBlKdTzhKYBEOm\n" +
"E1i45MMum1RuHc28agIcfHQkkjBA4FfH5UMRgKpIyRR8V/dVboxDj4hKOA==\n" +
"-----END CERTIFICATE-----";
public static void main(String[] args) throws Exception {
Security.addProvider(new TestProvider());
MySecureClassLoader scl = new MySecureClassLoader();
Policy p = Policy.getPolicy();
File policyFile = new File(System.getProperty("test.src", "."),
"DefineClass.policy");
Policy p = Policy.getInstance("JavaPolicy",
new URIParameter(policyFile.toURI()));
Policy.setPolicy(p);
System.setSecurityManager(new SecurityManager());
ArrayList<Permission> perms1 = getPermissions(scl, p,
"http://localhost/",
"Foo", FOO_CLASS);
"foo.Foo", FOO_CLASS,
null);
checkPerms(perms1, GRANTED_PERMS);
ArrayList<Permission> perms2 = getPermissions(scl, p,
"http://127.0.0.1/",
"Bar", BAR_CLASS);
"bar.Bar", BAR_CLASS,
null);
checkPerms(perms2, GRANTED_PERMS);
assert(perms1.equals(perms2));
// check that class signed by baz is granted an additional permission
Certificate[] chain = new Certificate[] {getCert(BAZ_CERT)};
ArrayList<Permission> perms3 = getPermissions(scl, p,
"http://localhost/",
"baz.Baz", BAZ_CLASS,
chain);
List<Permission> perms = new ArrayList<>(Arrays.asList(GRANTED_PERMS));
perms.add(new PropertyPermission("user.dir", "read"));
checkPerms(perms3, perms.toArray(new Permission[0]));
}
// returns the permissions granted to the codebase URL
private static ArrayList<Permission> getPermissions(MySecureClassLoader scl,
Policy p, String url,
String className,
String classBytes)
String classBytes,
Certificate[] chain)
throws IOException {
CodeSource cs = new CodeSource(new URL(url), (Certificate[])null);
CodeSource cs = new CodeSource(new URL(url), chain);
Base64.Decoder bd = Base64.getDecoder();
byte[] bytes = bd.decode(classBytes);
Class<?> c = scl.defineMyClass(className, bytes, cs);
@ -105,10 +179,125 @@ public class DefineClass {
}
}
private static Certificate getCert(String base64Cert) throws Exception {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
InputStream is = new ByteArrayInputStream(base64Cert.getBytes("UTF-8"));
return cf.generateCertificate(is);
}
// A SecureClassLoader that allows the test to define its own classes
private static class MySecureClassLoader extends SecureClassLoader {
Class<?> defineMyClass(String name, byte[] b, CodeSource cs) {
return super.defineClass(name, b, 0, b.length, cs);
}
}
private static class TestProvider extends Provider {
TestProvider() {
super("Test8131486", 0.0, "For testing only");
putService(new Provider.Service(this, "KeyStore", "Test8131486",
"DefineClass$TestKeyStore", null, null));
}
}
/**
* A KeyStore containing a single certificate entry named "baz".
*/
public static class TestKeyStore extends KeyStoreSpi {
private final String baz = "baz";
private final List<String> aliases = Collections.singletonList(baz);
private final Certificate bazCert;
public TestKeyStore() {
try {
this.bazCert = getCert(BAZ_CERT);
} catch (Exception e) {
throw new Error();
}
}
@Override
public Enumeration<String> engineAliases() {
return Collections.enumeration(aliases);
}
@Override
public boolean engineContainsAlias(String alias) {
return alias.equals(baz);
}
@Override
public void engineDeleteEntry(String alias) throws KeyStoreException {
throw new KeyStoreException();
}
@Override
public Certificate engineGetCertificate(String alias) {
return alias.equals(baz) ? bazCert : null;
}
@Override
public String engineGetCertificateAlias(Certificate cert) {
return cert.equals(bazCert) ? baz : null;
}
@Override
public Certificate[] engineGetCertificateChain(String alias) {
return alias.equals(baz) ? new Certificate[] {bazCert} : null;
}
@Override
public Date engineGetCreationDate(String alias) {
return alias.equals(baz) ? new Date() : null;
}
@Override
public Key engineGetKey(String alias, char[] password)
throws NoSuchAlgorithmException, UnrecoverableKeyException {
return null;
}
@Override
public boolean engineIsCertificateEntry(String alias) {
return alias.equals(baz);
}
@Override
public boolean engineIsKeyEntry(String alias) {
return false;
}
@Override
public void engineLoad(InputStream stream, char[] password)
throws IOException, NoSuchAlgorithmException, CertificateException {
}
@Override
public void engineSetCertificateEntry(String alias, Certificate cert)
throws KeyStoreException {
throw new KeyStoreException();
}
@Override
public void engineSetKeyEntry(String alias, byte[] key,
Certificate[] chain)
throws KeyStoreException {
throw new KeyStoreException();
}
@Override
public void engineSetKeyEntry(String alias, Key key, char[] password,
Certificate[] chain)
throws KeyStoreException {
throw new KeyStoreException();
}
@Override
public int engineSize() { return 1; }
@Override
public void engineStore(OutputStream stream, char[] password)
throws IOException, NoSuchAlgorithmException, CertificateException {
}
}
}

View File

@ -1,7 +1,7 @@
keystore "NONE", "Test8131486", "Test8131486";
grant {
permission java.lang.RuntimePermission "createClassLoader";
permission java.lang.RuntimePermission "getProtectionDomain";
permission java.security.SecurityPermission "getPolicy";
};
grant codebase "http://localhost/" {
permission java.util.PropertyPermission "user.home", "read";
@ -9,3 +9,6 @@ grant codebase "http://localhost/" {
grant codebase "http://127.0.0.1/" {
permission java.util.PropertyPermission "user.name", "read";
};
grant codebase "http://localhost/", signedby "baz" {
permission java.util.PropertyPermission "user.dir", "read";
};

View File

@ -120,7 +120,8 @@ public class ConcurrentAssociateTest {
}
};
int ps = Runtime.getRuntime().availableProcessors();
// Bound concurrency to avoid degenerate performance
int ps = Math.min(Runtime.getRuntime().availableProcessors(), 32);
Stream<CompletableFuture> runners = IntStream.range(0, ps)
.mapToObj(i -> sr.get())
.map(CompletableFuture::runAsync);

View File

@ -23,7 +23,7 @@
/**
* @test
* @bug 4759491 6303183 7012868 8015666 8023713 8068790 8076641
* @bug 4759491 6303183 7012868 8015666 8023713 8068790 8076641 8075526 8130914
* @summary Test ZOS and ZIS timestamp in extra field correctly
*/
@ -54,8 +54,12 @@ public class TestExtraTime {
for (byte[] extra : new byte[][] { null, new byte[] {1, 2, 3}}) {
test(mtime, null, null, null, extra);
// ms-dos 1980 epoch problem
test(FileTime.from(10, TimeUnit.MILLISECONDS), null, null, null, extra);
// negative epoch time
test(FileTime.from(-100, TimeUnit.DAYS), null, null, null, extra);
// non-default tz
test(mtime, null, null, tz, extra);

View File

@ -0,0 +1,111 @@
/*
* Copyright (c) 2015, 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 8075526
* @summary Test timestamp via ZipEntry.get/setTimeLocal()
*/
import java.io.*;
import java.nio.file.*;
import java.time.*;
import java.util.*;
import java.util.zip.*;
public class TestLocalTime {
private static TimeZone tz0 = TimeZone.getDefault();
public static void main(String[] args) throws Throwable{
try {
LocalDateTime ldt = LocalDateTime.now();
test(getBytes(ldt), ldt); // now
ldt = ldt.withYear(1968); test(getBytes(ldt), ldt);
ldt = ldt.withYear(1970); test(getBytes(ldt), ldt);
ldt = ldt.withYear(1982); test(getBytes(ldt), ldt);
ldt = ldt.withYear(2037); test(getBytes(ldt), ldt);
ldt = ldt.withYear(2100); test(getBytes(ldt), ldt);
ldt = ldt.withYear(2106); test(getBytes(ldt), ldt);
TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
// dos time does not support < 1980, have to use
// utc in mtime.
testWithTZ(tz, ldt.withYear(1982));
testWithTZ(tz, ldt.withYear(2037));
testWithTZ(tz, ldt.withYear(2100));
testWithTZ(tz, ldt.withYear(2106));
} finally {
TimeZone.setDefault(tz0);
}
}
static byte[] getBytes(LocalDateTime mtime) throws Throwable {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
ZipEntry ze = new ZipEntry("TestLocalTime.java");
ze.setTimeLocal(mtime);
check(ze, mtime);
zos.putNextEntry(ze);
zos.write(new byte[] { 1, 2, 3, 4});
zos.close();
return baos.toByteArray();
}
static void testWithTZ(TimeZone tz, LocalDateTime ldt) throws Throwable {
TimeZone.setDefault(tz);
byte[] zbytes = getBytes(ldt);
TimeZone.setDefault(tz0);
test(zbytes, ldt);
}
static void test(byte[] zbytes, LocalDateTime expected) throws Throwable {
System.out.printf("--------------------%nTesting: [%s]%n", expected);
// ZipInputStream
ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(zbytes));
ZipEntry ze = zis.getNextEntry();
zis.close();
check(ze, expected);
// ZipFile
Path zpath = Paths.get(System.getProperty("test.dir", "."),
"TestLocalTime.zip");
try {
Files.copy(new ByteArrayInputStream(zbytes), zpath);
ZipFile zf = new ZipFile(zpath.toFile());
ze = zf.getEntry("TestLocalTime.java");
check(ze, expected);
zf.close();
} finally {
Files.deleteIfExists(zpath);
}
}
static void check(ZipEntry ze, LocalDateTime expected) {
LocalDateTime ldt = ze.getTimeLocal();
if (ldt.atOffset(ZoneOffset.UTC).toEpochSecond() >> 1
!= expected.atOffset(ZoneOffset.UTC).toEpochSecond() >> 1) {
throw new RuntimeException("Timestamp: storing mtime failed!");
}
}
}

View File

@ -1,5 +1,5 @@
/**
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2015, 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
@ -72,7 +72,6 @@ import java.security.Security;
* -DCLIENT_PROTOCOL=DEFAULT -Djdk.tls.client.protocols=TLSv1.2
* -DCIPHER=SSL_RSA_WITH_RC4_128_MD5
* TestJSSE javax.net.ssl.SSLHandshakeException
* @key intermittent
*
*/

View File

@ -26,7 +26,7 @@
* @bug 4858522
* @modules java.management/sun.management
* @summary Basic unit test of HotspotRuntimeMBean.getTotalSafepointTime()
* @author Steve Bohne
* @run main/othervm -XX:+UsePerfData GetTotalSafepointTime
*/
/*

View File

@ -0,0 +1,118 @@
/*
* Copyright (c) 2015, 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.
*/
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
/*
* @test
* @bug 4515853 8075297
* @summary Checks that Kerberos client tries slave KDC
* if master KDC is not responding
* @run main/othervm BogusKDC
*/
public class BogusKDC {
static final String TEST_SRC = System.getProperty("test.src", ".");
static final String HOST = "localhost";
static final String NOT_EXISTING_HOST = "not.existing.host";
static final String REALM = "TEST.REALM";
static final String USER = "USER";
static final String USER_PRINCIPAL = USER + "@" + REALM;
static final String USER_PASSWORD = "password";
static final String KRBTGT_PRINCIPAL = "krbtgt/" + REALM;
static final String KRB5_CONF = "krb5.conf";
static final int WRONG_KDC_PORT = 21;
static final String KRB5_CONF_TEMPLATE = ""
+ "[libdefaults]\n"
+ "default_realm = TEST.REALM\n"
+ "max_retries = 1\n"
+ "\n"
+ "[realms]\n"
+ "TEST.REALM = {\n"
+ " kdc = %s\n"
+ " kdc = localhost:%d\n"
+ "}";
public static void main(String[] args) throws LoginException, IOException {
Map<String, String> principals = new HashMap<>();
principals.put(USER_PRINCIPAL, USER_PASSWORD);
principals.put(KRBTGT_PRINCIPAL, null);
System.setProperty("java.security.krb5.conf", KRB5_CONF);
// start a local KDC
KDC kdc = KDC.startKDC(HOST, KRB5_CONF, REALM, principals, null, null);
System.setProperty("java.security.auth.login.config",
TEST_SRC + File.separator + "refreshKrb5Config.jaas");
CallbackHandler handler = new Helper.UserPasswordHandler(
USER, USER_PASSWORD);
// create a krb5 config with non-existing host for master KDC,
// and wrong port for slave KDC
try (PrintWriter w = new PrintWriter(new FileWriter(KRB5_CONF))) {
w.write(String.format(KRB5_CONF_TEMPLATE,
KDC.KDCNameService.NOT_EXISTING_HOST, WRONG_KDC_PORT));
w.flush();
}
// login with not-refreshable config
try {
new LoginContext("NotRefreshable", handler).login();
throw new RuntimeException("Expected exception not thrown");
} catch (LoginException le) {
System.out.println("Expected login failure: " + le);
}
// create a krb5 config with non-existing host for master KDC,
// but correct port for slave KDC
try (PrintWriter w = new PrintWriter(new FileWriter(KRB5_CONF))) {
w.write(String.format(KRB5_CONF_TEMPLATE,
KDC.KDCNameService.NOT_EXISTING_HOST, kdc.getPort()));
w.flush();
}
// login with not-refreshable config
try {
new LoginContext("NotRefreshable", handler).login();
throw new RuntimeException("Expected exception not thrown");
} catch (LoginException le) {
System.out.println("Expected login failure: " + le);
}
// login with refreshable config
new LoginContext("Refreshable", handler).login();
System.out.println("Test passed");
}
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2015, 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.
*/
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
public class Helper {
static class UserPasswordHandler implements CallbackHandler {
private final String name;
private final String password;
UserPasswordHandler(String name, String password) {
this.name = name;
this.password = password;
}
@Override
public void handle(Callback[] callbacks)
throws UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword(
password.toCharArray());
} else if (callback instanceof NameCallback) {
((NameCallback)callback).setName(name);
} else {
throw new UnsupportedCallbackException(callback);
}
}
}
}
}

View File

@ -28,6 +28,10 @@ import java.net.*;
import java.io.*;
import java.lang.reflect.Method;
import java.security.SecureRandom;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalUnit;
import java.util.*;
import java.util.concurrent.*;
@ -939,6 +943,13 @@ public class KDC {
} else if (till.isZero()) {
till = new KerberosTime(
new Date().getTime() + 1000 * DEFAULT_LIFETIME);
} else if (till.greaterThan(new KerberosTime(Instant.now()
.plus(1, ChronoUnit.DAYS)))) {
// If till is more than 1 day later, make it renewable
till = new KerberosTime(
new Date().getTime() + 1000 * DEFAULT_LIFETIME);
body.kdcOptions.set(KDCOptions.RENEWABLE, true);
if (rtime == null) rtime = till;
}
if (rtime == null && body.kdcOptions.get(KDCOptions.RENEWABLE)) {
rtime = new KerberosTime(
@ -1320,14 +1331,17 @@ public class KDC {
}
}
public static void startKDC(final String host, final String krbConfFileName,
public static KDC startKDC(final String host, final String krbConfFileName,
final String realm, final Map<String, String> principals,
final String ktab, final KtabMode mode) {
KDC kdc;
try {
KDC kdc = KDC.create(realm, host, 0, true);
kdc = KDC.create(realm, host, 0, true);
kdc.setOption(KDC.Option.PREAUTH_REQUIRED, Boolean.FALSE);
if (krbConfFileName != null) {
KDC.saveConfig(krbConfFileName, kdc);
}
// Add principals
if (principals != null) {
@ -1379,6 +1393,7 @@ public class KDC {
throw new RuntimeException("KDC: unexpected exception", e);
}
return kdc;
}
/**
@ -1428,13 +1443,20 @@ public class KDC {
}
public static class KDCNameService implements NameServiceDescriptor {
public static String NOT_EXISTING_HOST = "not.existing.host";
@Override
public NameService createNameService() throws Exception {
NameService ns = new NameService() {
@Override
public InetAddress[] lookupAllHostAddr(String host)
throws UnknownHostException {
// Everything is localhost
// Everything is localhost except NOT_EXISTING_HOST
if (NOT_EXISTING_HOST.equals(host)) {
throw new UnknownHostException("Unknown host name: "
+ NOT_EXISTING_HOST);
}
return new InetAddress[]{
InetAddress.getByAddress(host, new byte[]{127,0,0,1})
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -21,31 +21,27 @@
* questions.
*/
/* @test
* @bug 5012882 6299047
* @summary Test jvmti hprof
*
* @compile -g HelloWorld.java ../DemoRun.java
* @build CpuOldTest
* @run main CpuOldTest HelloWorld
/*
* @test
* @bug 8131051
* @summary KDC might issue a renewable ticket even if not requested
* @compile -XDignore.symbol.file LongLife.java
* @run main/othervm LongLife
*/
public class CpuOldTest {
import sun.security.krb5.Config;
public static void main(String args[]) throws Exception {
DemoRun hprof;
public class LongLife {
/* Run JVMTI hprof agent with cpu=old */
hprof = new DemoRun("hprof", "cpu=old,file=cpuold.txt");
hprof.runit(args[0]);
public static void main(String[] args) throws Exception {
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in output");
}
OneKDC kdc = new OneKDC(null).writeJAASConf();
/* Must be a pass. */
System.out.println("Test passed - cleanly terminated");
// A lifetime 2d will make it renewable
KDC.saveConfig(OneKDC.KRB5_CONF, kdc,
"ticket_lifetime = 2d");
Config.refresh();
Context.fromJAAS("client");
}
}

View File

@ -95,7 +95,7 @@ public class OneKDC extends KDC {
* entries with names using existing OneKDC principals.
* @throws java.lang.Exception if anything goes wrong
*/
public void writeJAASConf() throws IOException {
public OneKDC writeJAASConf() throws IOException {
System.setProperty("java.security.auth.login.config", JAAS_CONF);
File f = new File(JAAS_CONF);
FileOutputStream fos = new FileOutputStream(f);
@ -123,6 +123,7 @@ public class OneKDC extends KDC {
" isInitiator=false;\n};\n"
).getBytes());
fos.close();
return this;
}
/**

View File

@ -0,0 +1,100 @@
/*
* Copyright (c) 2015, 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.
*/
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
/*
* @test
* @bug 4745056 8075297
* @summary Checks if refreshKrb5Config is set to true for Krb5LoginModule,
* then configuration will be refreshed before login() method is called
* @run main/othervm RefreshKrb5Config
*/
public class RefreshKrb5Config {
static final String TEST_SRC = System.getProperty("test.src", ".");
static final String HOST = "localhost";
static final String NOT_EXISTING_HOST = "not.existing.host";
static final String REALM = "TEST.REALM";
static final String USER = "USER";
static final String USER_PRINCIPAL = USER + "@" + REALM;
static final String USER_PASSWORD = "password";
static final String KRBTGT_PRINCIPAL = "krbtgt/" + REALM;
static final String KRB5_CONF_FILENAME = "krb5.conf";
public static void main(String[] args) throws LoginException, IOException {
Map<String, String> principals = new HashMap<>();
principals.put(USER_PRINCIPAL, USER_PASSWORD);
principals.put(KRBTGT_PRINCIPAL, null);
System.setProperty("java.security.krb5.conf", KRB5_CONF_FILENAME);
// start a local KDC, and save krb5 config
KDC kdc = KDC.startKDC(HOST, null, REALM, principals, null, null);
KDC.saveConfig(KRB5_CONF_FILENAME, kdc, "max_retries = 1");
System.setProperty("java.security.auth.login.config",
TEST_SRC + File.separator + "refreshKrb5Config.jaas");
CallbackHandler handler = new Helper.UserPasswordHandler(
USER, USER_PASSWORD);
// set incorrect KDC
System.out.println("java.security.krb5.kdc = " + NOT_EXISTING_HOST);
System.setProperty("java.security.krb5.kdc", NOT_EXISTING_HOST);
System.out.println("java.security.krb5.realm = " + REALM);
System.setProperty("java.security.krb5.realm", REALM);
try {
new LoginContext("Refreshable", handler).login();
throw new RuntimeException("Expected exception not thrown");
} catch (LoginException le) {
System.out.println("Expected login failure: " + le);
}
// reset properties
System.out.println("Reset java.security.krb5.kdc");
System.clearProperty("java.security.krb5.kdc");
System.out.println("Reset java.security.krb5.realm");
System.clearProperty("java.security.krb5.realm");
// login with not-refreshable config
try {
new LoginContext("NotRefreshable", handler).login();
throw new RuntimeException("Expected exception not thrown");
} catch (LoginException le) {
System.out.println("Expected login failure: " + le);
}
// login with refreshable config
new LoginContext("Refreshable", handler).login();
System.out.println("Test passed");
}
}

View File

@ -0,0 +1,11 @@
Refreshable {
com.sun.security.auth.module.Krb5LoginModule required
useTicketCache=false
refreshKrb5Config=true;
};
NotRefreshable {
com.sun.security.auth.module.Krb5LoginModule required
useTicketCache=false
refreshKrb5Config=false;
};