提交 2c21cf4c 编写于 作者: L lana

Merge

...@@ -169,3 +169,5 @@ db471a7af03168e4441c245b1d9976f720a7cb77 jdk8-b44 ...@@ -169,3 +169,5 @@ db471a7af03168e4441c245b1d9976f720a7cb77 jdk8-b44
b92353a01aa049bc508fc56f0347d5934b7c4390 jdk8-b45 b92353a01aa049bc508fc56f0347d5934b7c4390 jdk8-b45
8d2ed9d58453c8049715a72a6d26b6b66b37a94c jdk8-b46 8d2ed9d58453c8049715a72a6d26b6b66b37a94c jdk8-b46
00b22b23269a57d0bb46c57753be2fe9a9d2c1a3 jdk8-b47 00b22b23269a57d0bb46c57753be2fe9a9d2c1a3 jdk8-b47
3e4ab821f46166fcf63e8fe5c8046216003c941f jdk8-b48
51707c3b75c0f521794d9ab425f4e5b2351c70c1 jdk8-b49
...@@ -3383,3 +3383,397 @@ included with JRE 7, JDK 7, and OpenJDK 7, except where noted: ...@@ -3383,3 +3383,397 @@ included with JRE 7, JDK 7, and OpenJDK 7, except where noted:
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
%% This notice is provided with respect to Mozilla Network Security
Services (NSS), which is supplied with the JDK test suite in the OpenJDK
source code repository. It is licensed under Mozilla Public License (MPL),
version 2.0.
The NSS libraries are supplied in executable form, built from unmodified
NSS source code labeled with the "NSS_3.13.1_RTM" release tag.
The NSS source code is available in the OpenJDK source code repository at:
jdk/test/sun/security/pkcs11/nss/src
The NSS libraries are available in the OpenJDK source code repository at:
jdk/test/sun/security/pkcs11/nss/lib
--- begin of LICENSE ---
Mozilla Public License Version 2.0
==================================
1. Definitions
--------------
1.1. "Contributor"
means each individual or legal entity that creates, contributes to
the creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used
by a Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached
the notice in Exhibit A, the Executable Form of such Source Code
Form, and Modifications of such Source Code Form, in each case
including portions thereof.
1.5. "Incompatible With Secondary Licenses"
means
(a) that the initial Contributor has attached the notice described
in Exhibit B to the Covered Software; or
(b) that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the
terms of a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in
a separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible,
whether at the time of the initial grant or subsequently, any and
all of the rights conveyed by this License.
1.10. "Modifications"
means any of the following:
(a) any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered
Software; or
(b) any new file in Source Code Form that contains any Covered
Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the
License, by the making, using, selling, offering for sale, having
made, import, or transfer of either its Contributions or its
Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU
Lesser General Public License, Version 2.1, the GNU Affero General
Public License, Version 3.0, or any later versions of those
licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that
controls, is controlled by, or is under common control with You. For
purposes of this definition, "control" means (a) the power, direct
or indirect, to cause the direction or management of such entity,
whether by contract or otherwise, or (b) ownership of more than
fifty percent (50%) of the outstanding shares or beneficial
ownership of such entity.
2. License Grants and Conditions
--------------------------------
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
(a) under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
(b) under Patent Claims of such Contributor to make, use, sell, offer
for sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
(a) for any code that a Contributor has removed from Covered Software;
or
(b) for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
(c) under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights
to grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
in Section 2.1.
3. Responsibilities
-------------------
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
(a) such Covered Software must also be made available in Source Code
Form, as described in Section 3.1, and You must inform recipients of
the Executable Form how they can obtain a copy of such Source Code
Form by reasonable means in a timely manner, at a charge no more
than the cost of distribution to the recipient; and
(b) You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter
the recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty,
or limitations of liability) contained within the Source Code Form of
the Covered Software, except that You may alter any license notices to
the extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
---------------------------------------------------
If it is impossible for You to comply with any of the terms of this
License with respect to some or all of the Covered Software due to
statute, judicial order, or regulation then You must: (a) comply with
the terms of this License to the maximum extent possible; and (b)
describe the limitations and the code they affect. Such description must
be placed in a text file included with all distributions of the Covered
Software under this License. Except to the extent prohibited by statute
or regulation, such description must be sufficiently detailed for a
recipient of ordinary skill to be able to understand it.
5. Termination
--------------
5.1. The rights granted under this License will terminate automatically
if You fail to comply with any of its terms. However, if You become
compliant, then the rights granted under this License from a particular
Contributor are reinstated (a) provisionally, unless and until such
Contributor explicitly and finally terminates Your grants, and (b) on an
ongoing basis, if such Contributor fails to notify You of the
non-compliance by some reasonable means prior to 60 days after You have
come back into compliance. Moreover, Your grants from a particular
Contributor are reinstated on an ongoing basis if such Contributor
notifies You of the non-compliance by some reasonable means, this is the
first time You have received notice of non-compliance with this License
from such Contributor, and You become compliant prior to 30 days after
Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
end user license agreements (excluding distributors and resellers) which
have been validly granted by You or Your distributors under this License
prior to termination shall survive termination.
************************************************************************
* *
* 6. Disclaimer of Warranty *
* ------------------------- *
* *
* Covered Software is provided under this License on an "as is" *
* basis, without warranty of any kind, either expressed, implied, or *
* statutory, including, without limitation, warranties that the *
* Covered Software is free of defects, merchantable, fit for a *
* particular purpose or non-infringing. The entire risk as to the *
* quality and performance of the Covered Software is with You. *
* Should any Covered Software prove defective in any respect, You *
* (not any Contributor) assume the cost of any necessary servicing, *
* repair, or correction. This disclaimer of warranty constitutes an *
* essential part of this License. No use of any Covered Software is *
* authorized under this License except under this disclaimer. *
* *
************************************************************************
************************************************************************
* *
* 7. Limitation of Liability *
* -------------------------- *
* *
* Under no circumstances and under no legal theory, whether tort *
* (including negligence), contract, or otherwise, shall any *
* Contributor, or anyone who distributes Covered Software as *
* permitted above, be liable to You for any direct, indirect, *
* special, incidental, or consequential damages of any character *
* including, without limitation, damages for lost profits, loss of *
* goodwill, work stoppage, computer failure or malfunction, or any *
* and all other commercial damages or losses, even if such party *
* shall have been informed of the possibility of such damages. This *
* limitation of liability shall not apply to liability for death or *
* personal injury resulting from such party's negligence to the *
* extent applicable law prohibits such limitation. Some *
* jurisdictions do not allow the exclusion or limitation of *
* incidental or consequential damages, so this exclusion and *
* limitation may not apply to You. *
* *
************************************************************************
8. Litigation
-------------
Any litigation relating to this License may be brought only in the
courts of a jurisdiction where the defendant maintains its principal
place of business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions.
Nothing in this Section shall prevent a party's ability to bring
cross-claims or counter-claims.
9. Miscellaneous
----------------
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides
that the language of a contract shall be construed against the drafter
shall not be used to construe this License against a Contributor.
10. Versions of the License
---------------------------
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses
If You choose to distribute Source Code Form that is Incompatible With
Secondary Licenses under the terms of this version of the License, the
notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
-------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular
file, then You may include the notice in a location (such as a LICENSE
file in a relevant directory) where a recipient would be likely to look
for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
---------------------------------------------------------
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.
--- end of LICENSE ---
-------------------------------------------------------------------------------
# #
# Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -44,15 +44,8 @@ ifneq ($(PLATFORM), windows) ...@@ -44,15 +44,8 @@ ifneq ($(PLATFORM), windows)
JGSS_WRAPPER = jgss/wrapper JGSS_WRAPPER = jgss/wrapper
endif endif
# Build PKCS#11 on all platforms except 64-bit Windows. # Build PKCS#11 on all platforms
# We exclude windows-amd64 because we don't have any
# 64-bit PKCS#11 implementations to test with on that platform.
PKCS11 = pkcs11 PKCS11 = pkcs11
ifeq ($(ARCH_DATA_MODEL), 64)
ifeq ($(PLATFORM), windows)
PKCS11 =
endif
endif
# Build Microsoft CryptoAPI provider only on Windows platform. # Build Microsoft CryptoAPI provider only on Windows platform.
MSCAPI = MSCAPI =
......
...@@ -35,16 +35,16 @@ class MacOSXPreferences extends AbstractPreferences { ...@@ -35,16 +35,16 @@ class MacOSXPreferences extends AbstractPreferences {
private static final String defaultAppName = "com.apple.java.util.prefs"; private static final String defaultAppName = "com.apple.java.util.prefs";
// true if this node is a child of userRoot or is userRoot // true if this node is a child of userRoot or is userRoot
private boolean isUser; private final boolean isUser;
// true if this node is userRoot or systemRoot // true if this node is userRoot or systemRoot
private boolean isRoot; private final boolean isRoot;
// CF's storage location for this node and its keys // CF's storage location for this node and its keys
private MacOSXPreferencesFile file; private final MacOSXPreferencesFile file;
// absolutePath() + "/" // absolutePath() + "/"
private String path; private final String path;
// User root and system root nodes // User root and system root nodes
private static MacOSXPreferences userRoot = null; private static MacOSXPreferences userRoot = null;
...@@ -73,36 +73,40 @@ class MacOSXPreferences extends AbstractPreferences { ...@@ -73,36 +73,40 @@ class MacOSXPreferences extends AbstractPreferences {
// Create a new root node. Called by getUserRoot() and getSystemRoot() // Create a new root node. Called by getUserRoot() and getSystemRoot()
// Synchronization is provided by the caller. // Synchronization is provided by the caller.
private MacOSXPreferences(boolean newIsUser) private MacOSXPreferences(boolean newIsUser) {
{ this(null, "", false, true, newIsUser);
super(null, "");
isUser = newIsUser;
isRoot = true;
initFields();
} }
// Create a new non-root node with the given parent. // Create a new non-root node with the given parent.
// Called by childSpi(). // Called by childSpi().
private MacOSXPreferences(MacOSXPreferences parent, String name) private MacOSXPreferences(MacOSXPreferences parent, String name) {
{ this(parent, name, false, false, false);
super(parent, name);
isUser = isUserNode();
isRoot = false;
initFields();
} }
private MacOSXPreferences(MacOSXPreferences parent, String name,
boolean isNew)
{
this(parent, name, isNew, false, false);
}
private void initFields() private MacOSXPreferences(MacOSXPreferences parent, String name,
boolean isNew, boolean isRoot, boolean isUser)
{ {
super(parent, name);
this.isRoot = isRoot;
if (isRoot)
this.isUser = isUser;
else
this.isUser = isUserNode();
path = isRoot ? absolutePath() : absolutePath() + "/"; path = isRoot ? absolutePath() : absolutePath() + "/";
file = cfFileForNode(isUser); file = cfFileForNode(isUser);
newNode = file.addNode(path); if (isNew)
newNode = isNew;
else
newNode = file.addNode(path);
} }
// Create and return the MacOSXPreferencesFile for this node. // Create and return the MacOSXPreferencesFile for this node.
// Does not write anything to the file. // Does not write anything to the file.
private MacOSXPreferencesFile cfFileForNode(boolean isUser) private MacOSXPreferencesFile cfFileForNode(boolean isUser)
...@@ -160,7 +164,7 @@ class MacOSXPreferences extends AbstractPreferences { ...@@ -160,7 +164,7 @@ class MacOSXPreferences extends AbstractPreferences {
// AbstractPreferences implementation // AbstractPreferences implementation
@Override @Override
protected void removeNodeSpi() protected void removeNodeSpi()
throws BackingStoreException throws BackingStoreException
{ {
// Disallow flush or sync between these two operations // Disallow flush or sync between these two operations
// (they may be manipulating two different files) // (they may be manipulating two different files)
...@@ -180,7 +184,7 @@ class MacOSXPreferences extends AbstractPreferences { ...@@ -180,7 +184,7 @@ class MacOSXPreferences extends AbstractPreferences {
// AbstractPreferences implementation // AbstractPreferences implementation
@Override @Override
protected String[] childrenNamesSpi() protected String[] childrenNamesSpi()
throws BackingStoreException throws BackingStoreException
{ {
String[] result = file.getChildrenForNode(path); String[] result = file.getChildrenForNode(path);
if (result == null) throw new BackingStoreException("Couldn't get list of children for node '" + path + "'"); if (result == null) throw new BackingStoreException("Couldn't get list of children for node '" + path + "'");
...@@ -190,7 +194,7 @@ class MacOSXPreferences extends AbstractPreferences { ...@@ -190,7 +194,7 @@ class MacOSXPreferences extends AbstractPreferences {
// AbstractPreferences implementation // AbstractPreferences implementation
@Override @Override
protected String[] keysSpi() protected String[] keysSpi()
throws BackingStoreException throws BackingStoreException
{ {
String[] result = file.getKeysForNode(path); String[] result = file.getKeysForNode(path);
if (result == null) throw new BackingStoreException("Couldn't get list of keys for node '" + path + "'"); if (result == null) throw new BackingStoreException("Couldn't get list of keys for node '" + path + "'");
...@@ -204,15 +208,15 @@ class MacOSXPreferences extends AbstractPreferences { ...@@ -204,15 +208,15 @@ class MacOSXPreferences extends AbstractPreferences {
// Add to parent's child list here and disallow sync // Add to parent's child list here and disallow sync
// because parent and child might be in different files. // because parent and child might be in different files.
synchronized(MacOSXPreferencesFile.class) { synchronized(MacOSXPreferencesFile.class) {
file.addChildToNode(path, name); boolean isNew = file.addChildToNode(path, name);
return new MacOSXPreferences(this, name); return new MacOSXPreferences(this, name, isNew);
} }
} }
// AbstractPreferences override // AbstractPreferences override
@Override @Override
public void flush() public void flush()
throws BackingStoreException throws BackingStoreException
{ {
// Flush should *not* check for removal, unlike sync, but should // Flush should *not* check for removal, unlike sync, but should
// prevent simultaneous removal. // prevent simultaneous removal.
...@@ -227,7 +231,7 @@ class MacOSXPreferences extends AbstractPreferences { ...@@ -227,7 +231,7 @@ class MacOSXPreferences extends AbstractPreferences {
// AbstractPreferences implementation // AbstractPreferences implementation
@Override @Override
protected void flushSpi() protected void flushSpi()
throws BackingStoreException throws BackingStoreException
{ {
// nothing here - overridden flush() doesn't call this // nothing here - overridden flush() doesn't call this
} }
...@@ -235,7 +239,7 @@ class MacOSXPreferences extends AbstractPreferences { ...@@ -235,7 +239,7 @@ class MacOSXPreferences extends AbstractPreferences {
// AbstractPreferences override // AbstractPreferences override
@Override @Override
public void sync() public void sync()
throws BackingStoreException throws BackingStoreException
{ {
synchronized(lock) { synchronized(lock) {
if (isRemoved()) if (isRemoved())
...@@ -256,7 +260,7 @@ class MacOSXPreferences extends AbstractPreferences { ...@@ -256,7 +260,7 @@ class MacOSXPreferences extends AbstractPreferences {
// AbstractPreferences implementation // AbstractPreferences implementation
@Override @Override
protected void syncSpi() protected void syncSpi()
throws BackingStoreException throws BackingStoreException
{ {
// nothing here - overridden sync() doesn't call this // nothing here - overridden sync() doesn't call this
} }
......
...@@ -360,11 +360,11 @@ class MacOSXPreferencesFile { ...@@ -360,11 +360,11 @@ class MacOSXPreferencesFile {
} }
} }
void addChildToNode(String path, String child) boolean addChildToNode(String path, String child)
{ {
synchronized(MacOSXPreferencesFile.class) { synchronized(MacOSXPreferencesFile.class) {
markChanged(); markChanged();
addChildToNode(path, child+"/", appName, user, host); return addChildToNode(path, child+"/", appName, user, host);
} }
} }
...@@ -433,7 +433,7 @@ class MacOSXPreferencesFile { ...@@ -433,7 +433,7 @@ class MacOSXPreferencesFile {
addNode(String path, String name, long user, long host); addNode(String path, String name, long user, long host);
private static final native void private static final native void
removeNode(String path, String name, long user, long host); removeNode(String path, String name, long user, long host);
private static final native void private static final native boolean
addChildToNode(String path, String child, addChildToNode(String path, String child,
String name, long user, long host); String name, long user, long host);
private static final native void private static final native void
......
...@@ -641,7 +641,7 @@ Java_java_util_prefs_MacOSXPreferencesFile_removeNode ...@@ -641,7 +641,7 @@ Java_java_util_prefs_MacOSXPreferencesFile_removeNode
// child must end with '/' // child must end with '/'
JNIEXPORT void JNICALL JNIEXPORT Boolean JNICALL
Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode
(JNIEnv *env, jobject klass, jobject jpath, jobject jchild, (JNIEnv *env, jobject klass, jobject jpath, jobject jchild,
jobject jname, jlong juser, jlong jhost) jobject jname, jlong juser, jlong jhost)
...@@ -656,6 +656,7 @@ Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode ...@@ -656,6 +656,7 @@ Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode
CFDictionaryRef node; CFDictionaryRef node;
CFStringRef topKey; CFStringRef topKey;
CFMutableDictionaryRef topValue; CFMutableDictionaryRef topValue;
Boolean beforeAdd = false;
if (!path || !child || !name) goto badparams; if (!path || !child || !name) goto badparams;
...@@ -665,9 +666,12 @@ Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode ...@@ -665,9 +666,12 @@ Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode
// copyMutableNode creates the node if necessary // copyMutableNode creates the node if necessary
parent = copyMutableNode(path, name, user, host, &topKey, &topValue); parent = copyMutableNode(path, name, user, host, &topKey, &topValue);
throwIfNull(parent, "copyMutableNode failed"); throwIfNull(parent, "copyMutableNode failed");
beforeAdd = CFDictionaryContainsKey(parent, child);
CFDictionaryAddValue(parent, child, node); CFDictionaryAddValue(parent, child, node);
if (!beforeAdd)
beforeAdd = CFDictionaryContainsKey(parent, child);
else
beforeAdd = false;
CFPreferencesSetValue(topKey, topValue, name, user, host); CFPreferencesSetValue(topKey, topValue, name, user, host);
CFRelease(parent); CFRelease(parent);
...@@ -680,6 +684,7 @@ Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode ...@@ -680,6 +684,7 @@ Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode
if (path) CFRelease(path); if (path) CFRelease(path);
if (child) CFRelease(child); if (child) CFRelease(child);
if (name) CFRelease(name); if (name) CFRelease(name);
return beforeAdd;
} }
......
...@@ -36,6 +36,7 @@ import java.io.OutputStream; ...@@ -36,6 +36,7 @@ import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
...@@ -381,12 +382,15 @@ class Driver { ...@@ -381,12 +382,15 @@ class Driver {
String prefix = base.getName(); String prefix = base.getName();
if (prefix.length() < 3) prefix += "tmp"; if (prefix.length() < 3) prefix += "tmp";
File where = base.getParentFile(); File where = (base.getParentFile() == null && suffix.equals(".bak"))
? new File(".").getAbsoluteFile()
: base.getParentFile();
if ( base.getParentFile() == null && suffix.equals(".bak")) Path tmpfile = (where == null)
where = new File(".").getAbsoluteFile(); ? Files.createTempFile(prefix, suffix)
: Files.createTempFile(where.toPath(), prefix, suffix);
return Files.createTempFile(where.toPath(), prefix, suffix).toFile(); return tmpfile.toFile();
} }
static private static private
......
...@@ -137,7 +137,7 @@ public final class HttpCookie implements Cloneable { ...@@ -137,7 +137,7 @@ public final class HttpCookie implements Cloneable {
private HttpCookie(String name, String value, String header) { private HttpCookie(String name, String value, String header) {
name = name.trim(); name = name.trim();
if (name.length() == 0 || !isToken(name) || isReserved(name)) { if (name.length() == 0 || !isToken(name)) {
throw new IllegalArgumentException("Illegal cookie name"); throw new IllegalArgumentException("Illegal cookie name");
} }
...@@ -781,33 +781,6 @@ public final class HttpCookie implements Cloneable { ...@@ -781,33 +781,6 @@ public final class HttpCookie implements Cloneable {
return true; return true;
} }
/*
* @param name
* the name to be tested
*
* @return {@code true} if the name is reserved by cookie specification,
* {@code false} if it is not
*/
private static boolean isReserved(String name) {
if (name.equalsIgnoreCase("Comment")
|| name.equalsIgnoreCase("CommentURL") // rfc2965 only
|| name.equalsIgnoreCase("Discard") // rfc2965 only
|| name.equalsIgnoreCase("Domain")
|| name.equalsIgnoreCase("Expires") // netscape draft only
|| name.equalsIgnoreCase("Max-Age")
|| name.equalsIgnoreCase("Path")
|| name.equalsIgnoreCase("Port") // rfc2965 only
|| name.equalsIgnoreCase("Secure")
|| name.equalsIgnoreCase("Version")
|| name.equalsIgnoreCase("HttpOnly")
|| name.charAt(0) == '$')
{
return true;
}
return false;
}
/* /*
* Parse header string to cookie object. * Parse header string to cookie object.
* *
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
package javax.security.auth.kerberos; package javax.security.auth.kerberos;
import java.io.*; import java.io.*;
import sun.security.krb5.Asn1Exception;
import sun.security.krb5.KrbException; import sun.security.krb5.KrbException;
import sun.security.krb5.PrincipalName; import sun.security.krb5.PrincipalName;
import sun.security.krb5.Realm; import sun.security.krb5.Realm;
...@@ -81,14 +80,12 @@ public final class KerberosPrincipal ...@@ -81,14 +80,12 @@ public final class KerberosPrincipal
public static final int KRB_NT_UID = 5; public static final int KRB_NT_UID = 5;
private transient String fullName; private transient String fullName;
private transient String realm; private transient String realm;
private transient int nameType; private transient int nameType;
private static final char NAME_REALM_SEPARATOR = '@';
/** /**
* Constructs a KerberosPrincipal from the provided string input. The * Constructs a KerberosPrincipal from the provided string input. The
...@@ -233,41 +230,35 @@ public final class KerberosPrincipal ...@@ -233,41 +230,35 @@ public final class KerberosPrincipal
* realm in their DER-encoded form as specified in Section 5.2.2 of * realm in their DER-encoded form as specified in Section 5.2.2 of
* <a href=http://www.ietf.org/rfc/rfc4120.txt> RFC4120</a>. * <a href=http://www.ietf.org/rfc/rfc4120.txt> RFC4120</a>.
*/ */
private void writeObject(ObjectOutputStream oos) private void writeObject(ObjectOutputStream oos)
throws IOException { throws IOException {
PrincipalName krb5Principal = null; PrincipalName krb5Principal;
try { try {
krb5Principal = new PrincipalName(fullName,nameType); krb5Principal = new PrincipalName(fullName, nameType);
oos.writeObject(krb5Principal.asn1Encode()); oos.writeObject(krb5Principal.asn1Encode());
oos.writeObject(krb5Principal.getRealm().asn1Encode()); oos.writeObject(krb5Principal.getRealm().asn1Encode());
} catch (Exception e) { } catch (Exception e) {
IOException ioe = new IOException(e.getMessage()); throw new IOException(e);
ioe.initCause(e);
throw ioe;
} }
} }
/** /**
* Reads this object from a stream (i.e., deserializes it) * Reads this object from a stream (i.e., deserializes it)
*/ */
private void readObject(ObjectInputStream ois) private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException { throws IOException, ClassNotFoundException {
byte[] asn1EncPrincipal = (byte [])ois.readObject(); byte[] asn1EncPrincipal = (byte [])ois.readObject();
byte[] encRealm = (byte [])ois.readObject(); byte[] encRealm = (byte [])ois.readObject();
try { try {
PrincipalName krb5Principal = new PrincipalName(new Realm realmObject = new Realm(new DerValue(encRealm));
DerValue(asn1EncPrincipal)); PrincipalName krb5Principal = new PrincipalName(
realm = (new Realm(new DerValue(encRealm))).toString(); new DerValue(asn1EncPrincipal), realmObject);
fullName = krb5Principal.toString() + NAME_REALM_SEPARATOR + realm = realmObject.toString();
realm.toString(); fullName = krb5Principal.toString();
nameType = krb5Principal.getNameType(); nameType = krb5Principal.getNameType();
} catch (Exception e) { } catch (Exception e) {
IOException ioe = new IOException(e.getMessage()); throw new IOException(e);
ioe.initCause(e);
throw ioe;
} }
} }
...@@ -288,9 +279,7 @@ public final class KerberosPrincipal ...@@ -288,9 +279,7 @@ public final class KerberosPrincipal
* <a href=http://www.ietf.org/rfc/rfc4120.txt> RFC4120</a>. * <a href=http://www.ietf.org/rfc/rfc4120.txt> RFC4120</a>.
* *
* @return the name type. * @return the name type.
*
*/ */
public int getNameType() { public int getNameType() {
return nameType; return nameType;
} }
......
...@@ -137,8 +137,9 @@ public final class SunLayoutEngine implements LayoutEngine, LayoutEngineFactory ...@@ -137,8 +137,9 @@ public final class SunLayoutEngine implements LayoutEngine, LayoutEngineFactory
LayoutEngine e = (LayoutEngine)cache.get(key); LayoutEngine e = (LayoutEngine)cache.get(key);
if (e == null) { if (e == null) {
e = new SunLayoutEngine(key.copy()); LayoutEngineKey copy = key.copy();
cache.put(key, e); e = new SunLayoutEngine(copy);
cache.put(copy, e);
} }
return e; return e;
} }
......
...@@ -33,6 +33,8 @@ import java.nio.charset.CharsetEncoder; ...@@ -33,6 +33,8 @@ import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult; import java.nio.charset.CoderResult;
import java.util.Arrays; import java.util.Arrays;
import sun.nio.cs.Surrogate; import sun.nio.cs.Surrogate;
import sun.nio.cs.ArrayDecoder;
import sun.nio.cs.ArrayEncoder;
import static sun.nio.cs.CharsetMapping.*; import static sun.nio.cs.CharsetMapping.*;
/* /*
...@@ -107,7 +109,7 @@ public class DoubleByte { ...@@ -107,7 +109,7 @@ public class DoubleByte {
} }
public static class Decoder extends CharsetDecoder public static class Decoder extends CharsetDecoder
implements DelegatableDecoder implements DelegatableDecoder, ArrayDecoder
{ {
final char[][] b2c; final char[][] b2c;
...@@ -209,6 +211,29 @@ public class DoubleByte { ...@@ -209,6 +211,29 @@ public class DoubleByte {
return decodeBufferLoop(src, dst); return decodeBufferLoop(src, dst);
} }
public int decode(byte[] src, int sp, int len, char[] dst) {
int dp = 0;
int sl = sp + len;
char repl = replacement().charAt(0);
while (sp < sl) {
int b1 = src[sp++] & 0xff;
char c = b2cSB[b1];
if (c == UNMAPPABLE_DECODING) {
if (sp < sl) {
int b2 = src[sp++] & 0xff;
if (b2 >= b2Min && b2 <= b2Max) {
c = b2c[b1][b2 - b2Min];
}
}
if (c == UNMAPPABLE_DECODING) {
c = repl;
}
}
dst[dp++] = c;
}
return dp;
}
public void implReset() { public void implReset() {
super.implReset(); super.implReset();
} }
...@@ -228,6 +253,7 @@ public class DoubleByte { ...@@ -228,6 +253,7 @@ public class DoubleByte {
return UNMAPPABLE_DECODING; return UNMAPPABLE_DECODING;
return b2c[b1][b2 - b2Min]; return b2c[b1][b2 - b2Min];
} }
} }
// IBM_EBCDIC_DBCS // IBM_EBCDIC_DBCS
...@@ -367,6 +393,46 @@ public class DoubleByte { ...@@ -367,6 +393,46 @@ public class DoubleByte {
src.position(mark); src.position(mark);
} }
} }
public int decode(byte[] src, int sp, int len, char[] dst) {
int dp = 0;
int sl = sp + len;
currentState = SBCS;
char repl = replacement().charAt(0);
while (sp < sl) {
int b1 = src[sp++] & 0xff;
if (b1 == SO) { // Shift out
if (currentState != SBCS)
dst[dp++] = repl;
else
currentState = DBCS;
} else if (b1 == SI) {
if (currentState != DBCS)
dst[dp++] = repl;
else
currentState = SBCS;
} else {
char c = UNMAPPABLE_DECODING;
if (currentState == SBCS) {
c = b2cSB[b1];
if (c == UNMAPPABLE_DECODING)
c = repl;
} else {
if (sl == sp) {
c = repl;
} else {
int b2 = src[sp++] & 0xff;
if (b2 < b2Min || b2 > b2Max ||
(c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
c = repl;
}
}
}
dst[dp++] = c;
}
}
return dp;
}
} }
// EBCDIC_DBCS_ONLY // EBCDIC_DBCS_ONLY
...@@ -405,9 +471,37 @@ public class DoubleByte { ...@@ -405,9 +471,37 @@ public class DoubleByte {
return CoderResult.malformedForLength(1); return CoderResult.malformedForLength(1);
return CoderResult.unmappableForLength(2); return CoderResult.unmappableForLength(2);
} }
public int decode(byte[] src, int sp, int len, char[] dst) {
int dp = 0;
int sl = sp + len;
char repl = replacement().charAt(0);
while (sp < sl) {
int b1 = src[sp++] & 0xff;
char c = b2cSB[b1];
if (c == UNMAPPABLE_DECODING) {
if (sp < sl) {
int b2 = src[sp++] & 0xff;
if (b2 < b2Min || b2 > b2Max ||
(c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
if (b1 == SS2 || b1 == SS3) {
sp--;
}
c = repl;
}
} else {
c = repl;
}
}
dst[dp++] = c;
}
return dp;
}
} }
public static class Encoder extends CharsetEncoder { public static class Encoder extends CharsetEncoder
implements ArrayEncoder
{
final int MAX_SINGLEBYTE = 0xff; final int MAX_SINGLEBYTE = 0xff;
private final char[] c2b; private final char[] c2b;
private final char[] c2bIndex; private final char[] c2bIndex;
...@@ -516,6 +610,35 @@ public class DoubleByte { ...@@ -516,6 +610,35 @@ public class DoubleByte {
return encodeBufferLoop(src, dst); return encodeBufferLoop(src, dst);
} }
public int encode(char[] src, int sp, int len, byte[] dst) {
int dp = 0;
int sl = sp + len;
int dl = dst.length;
while (sp < sl) {
char c = src[sp++];
int bb = encodeChar(c);
if (bb == UNMAPPABLE_ENCODING) {
if (Character.isHighSurrogate(c) && sp < sl &&
Character.isLowSurrogate(src[sp])) {
sp++;
}
byte[] repl = replacement();
dst[dp++] = repl[0];
if (repl.length > 1)
dst[dp++] = repl[1];
continue;
} //else
if (bb > MAX_SINGLEBYTE) { // DoubleByte
dst[dp++] = (byte)(bb >> 8);
dst[dp++] = (byte)bb;
} else { // SingleByte
dst[dp++] = (byte)bb;
}
}
return dp;
}
public int encodeChar(char ch) { public int encodeChar(char ch) {
return c2b[c2bIndex[ch >> 8] + (ch & 0xff)]; return c2b[c2bIndex[ch >> 8] + (ch & 0xff)];
} }
...@@ -604,7 +727,6 @@ public class DoubleByte { ...@@ -604,7 +727,6 @@ public class DoubleByte {
} }
} }
// EBCDIC_DBCS_ONLY
public static class Encoder_EBCDIC_DBCSONLY extends Encoder { public static class Encoder_EBCDIC_DBCSONLY extends Encoder {
Encoder_EBCDIC_DBCSONLY(Charset cs, byte[] repl, Encoder_EBCDIC_DBCSONLY(Charset cs, byte[] repl,
char[] c2b, char[] c2bIndex) { char[] c2b, char[] c2bIndex) {
...@@ -619,7 +741,6 @@ public class DoubleByte { ...@@ -619,7 +741,6 @@ public class DoubleByte {
} }
} }
// for IBM_EBCDIC_DBCS
public static class Encoder_EBCDIC extends Encoder { public static class Encoder_EBCDIC extends Encoder {
static final int SBCS = 0; static final int SBCS = 0;
static final int DBCS = 1; static final int DBCS = 1;
...@@ -741,6 +862,47 @@ public class DoubleByte { ...@@ -741,6 +862,47 @@ public class DoubleByte {
src.position(mark); src.position(mark);
} }
} }
public int encode(char[] src, int sp, int len, byte[] dst) {
int dp = 0;
int sl = sp + len;
while (sp < sl) {
char c = src[sp++];
int bb = encodeChar(c);
if (bb == UNMAPPABLE_ENCODING) {
if (Character.isHighSurrogate(c) && sp < sl &&
Character.isLowSurrogate(src[sp])) {
sp++;
}
byte[] repl = replacement();
dst[dp++] = repl[0];
if (repl.length > 1)
dst[dp++] = repl[1];
continue;
} //else
if (bb > MAX_SINGLEBYTE) { // DoubleByte
if (currentState == SBCS) {
currentState = DBCS;
dst[dp++] = SO;
}
dst[dp++] = (byte)(bb >> 8);
dst[dp++] = (byte)bb;
} else { // SingleByte
if (currentState == DBCS) {
currentState = SBCS;
dst[dp++] = SI;
}
dst[dp++] = (byte)bb;
}
}
if (currentState == DBCS) {
currentState = SBCS;
dst[dp++] = SI;
}
return dp;
}
} }
// EUC_SIMPLE // EUC_SIMPLE
......
...@@ -175,6 +175,40 @@ public class HKSCS { ...@@ -175,6 +175,40 @@ public class HKSCS {
} }
} }
public int decode(byte[] src, int sp, int len, char[] dst) {
int dp = 0;
int sl = sp + len;
char repl = replacement().charAt(0);
while (sp < sl) {
int b1 = src[sp++] & 0xff;
char c = decodeSingle(b1);
if (c == UNMAPPABLE_DECODING) {
if (sl == sp) {
c = repl;
} else {
int b2 = src[sp++] & 0xff;
if (b2 < b2Min || b2 > b2Max) {
c = repl;
} else if ((c = decodeDouble(b1, b2)) == UNMAPPABLE_DECODING) {
c = decodeDoubleEx(b1, b2); //supp
if (c == UNMAPPABLE_DECODING) {
c = decodeBig5(b1, b2); //big5
if (c == UNMAPPABLE_DECODING)
c = repl;
} else {
// supplementary character in u+2xxxx area
dst[dp++] = Surrogate.high(0x20000 + c);
dst[dp++] = Surrogate.low(0x20000 + c);
continue;
}
}
}
}
dst[dp++] = c;
}
return dp;
}
public CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) { public CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) {
if (src.hasArray() && dst.hasArray()) if (src.hasArray() && dst.hasArray())
return decodeArrayLoop(src, dst); return decodeArrayLoop(src, dst);
...@@ -322,6 +356,36 @@ public class HKSCS { ...@@ -322,6 +356,36 @@ public class HKSCS {
return encodeBufferLoop(src, dst); return encodeBufferLoop(src, dst);
} }
public int encode(char[] src, int sp, int len, byte[] dst) {
int dp = 0;
int sl = sp + len;
while (sp < sl) {
char c = src[sp++];
int bb = encodeChar(c);
if (bb == UNMAPPABLE_ENCODING) {
if (!Character.isHighSurrogate(c) || sp == sl ||
!Character.isLowSurrogate(src[sp]) ||
(bb = encodeSupp(Character.toCodePoint(c, src[sp++])))
== UNMAPPABLE_ENCODING) {
byte[] repl = replacement();
dst[dp++] = repl[0];
if (repl.length > 1)
dst[dp++] = repl[1];
continue;
}
sp++;
}
if (bb > MAX_SINGLEBYTE) { // DoubleByte
dst[dp++] = (byte)(bb >> 8);
dst[dp++] = (byte)bb;
} else { // SingleByte
dst[dp++] = (byte)bb;
}
}
return dp;
}
static char[] C2B_UNMAPPABLE = new char[0x100]; static char[] C2B_UNMAPPABLE = new char[0x100];
static { static {
Arrays.fill(C2B_UNMAPPABLE, (char)UNMAPPABLE_ENCODING); Arrays.fill(C2B_UNMAPPABLE, (char)UNMAPPABLE_ENCODING);
......
...@@ -27,10 +27,8 @@ package sun.security.jgss.krb5; ...@@ -27,10 +27,8 @@ package sun.security.jgss.krb5;
import org.ietf.jgss.*; import org.ietf.jgss.*;
import sun.security.jgss.spi.*; import sun.security.jgss.spi.*;
import javax.security.auth.kerberos.*;
import sun.security.krb5.PrincipalName; import sun.security.krb5.PrincipalName;
import sun.security.krb5.KrbException; import sun.security.krb5.KrbException;
import sun.security.krb5.ServiceName;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
...@@ -119,8 +117,8 @@ public class Krb5NameElement ...@@ -119,8 +117,8 @@ public class Krb5NameElement
hostName = components[1]; hostName = components[1];
String principal = getHostBasedInstance(service, hostName); String principal = getHostBasedInstance(service, hostName);
principalName = new ServiceName(principal, principalName = new PrincipalName(principal,
PrincipalName.KRB_NT_SRV_HST); PrincipalName.KRB_NT_SRV_HST);
} }
} }
......
...@@ -464,8 +464,7 @@ public class Credentials { ...@@ -464,8 +464,7 @@ public class Credentials {
System.out.println(">>> DEBUG: ----Credentials----"); System.out.println(">>> DEBUG: ----Credentials----");
System.out.println("\tclient: " + c.client.toString()); System.out.println("\tclient: " + c.client.toString());
System.out.println("\tserver: " + c.server.toString()); System.out.println("\tserver: " + c.server.toString());
System.out.println("\tticket: realm: " + c.ticket.realm.toString()); System.out.println("\tticket: sname: " + c.ticket.sname.toString());
System.out.println("\t sname: " + c.ticket.sname.toString());
if (c.startTime != null) { if (c.startTime != null) {
System.out.println("\tstartTime: " + c.startTime.getTime()); System.out.println("\tstartTime: " + c.startTime.getTime());
} }
......
...@@ -179,7 +179,6 @@ public class KrbApReq { ...@@ -179,7 +179,6 @@ public class KrbApReq {
KrbApReq(APOptions apOptions, KrbApReq(APOptions apOptions,
Ticket ticket, Ticket ticket,
EncryptionKey key, EncryptionKey key,
Realm crealm,
PrincipalName cname, PrincipalName cname,
Checksum cksum, Checksum cksum,
KerberosTime ctime, KerberosTime ctime,
...@@ -189,7 +188,7 @@ public class KrbApReq { ...@@ -189,7 +188,7 @@ public class KrbApReq {
throws Asn1Exception, IOException, throws Asn1Exception, IOException,
KdcErrException, KrbCryptoException { KdcErrException, KrbCryptoException {
init(apOptions, ticket, key, crealm, cname, init(apOptions, ticket, key, cname,
cksum, ctime, subKey, seqNumber, authorizationData, cksum, ctime, subKey, seqNumber, authorizationData,
KeyUsage.KU_PA_TGS_REQ_AUTHENTICATOR); KeyUsage.KU_PA_TGS_REQ_AUTHENTICATOR);
...@@ -208,7 +207,6 @@ public class KrbApReq { ...@@ -208,7 +207,6 @@ public class KrbApReq {
init(options, init(options,
tgs_creds.ticket, tgs_creds.ticket,
tgs_creds.key, tgs_creds.key,
tgs_creds.client.getRealm(),
tgs_creds.client, tgs_creds.client,
cksum, cksum,
ctime, ctime,
...@@ -221,7 +219,6 @@ public class KrbApReq { ...@@ -221,7 +219,6 @@ public class KrbApReq {
private void init(APOptions apOptions, private void init(APOptions apOptions,
Ticket ticket, Ticket ticket,
EncryptionKey key, EncryptionKey key,
Realm crealm,
PrincipalName cname, PrincipalName cname,
Checksum cksum, Checksum cksum,
KerberosTime ctime, KerberosTime ctime,
...@@ -232,7 +229,7 @@ public class KrbApReq { ...@@ -232,7 +229,7 @@ public class KrbApReq {
throws Asn1Exception, IOException, throws Asn1Exception, IOException,
KdcErrException, KrbCryptoException { KdcErrException, KrbCryptoException {
createMessage(apOptions, ticket, key, crealm, cname, createMessage(apOptions, ticket, key, cname,
cksum, ctime, subKey, seqNumber, authorizationData, cksum, ctime, subKey, seqNumber, authorizationData,
usage); usage);
obuf = apReqMessg.asn1Encode(); obuf = apReqMessg.asn1Encode();
...@@ -289,9 +286,6 @@ public class KrbApReq { ...@@ -289,9 +286,6 @@ public class KrbApReq {
ctime = authenticator.ctime; ctime = authenticator.ctime;
cusec = authenticator.cusec; cusec = authenticator.cusec;
authenticator.ctime.setMicroSeconds(authenticator.cusec); authenticator.ctime.setMicroSeconds(authenticator.cusec);
authenticator.cname.setRealm(authenticator.crealm);
apReqMessg.ticket.sname.setRealm(apReqMessg.ticket.realm);
enc_ticketPart.cname.setRealm(enc_ticketPart.crealm);
if (!authenticator.cname.equals(enc_ticketPart.cname)) if (!authenticator.cname.equals(enc_ticketPart.cname))
throw new KrbApErrException(Krb5.KRB_AP_ERR_BADMATCH); throw new KrbApErrException(Krb5.KRB_AP_ERR_BADMATCH);
...@@ -457,7 +451,6 @@ public class KrbApReq { ...@@ -457,7 +451,6 @@ public class KrbApReq {
private void createMessage(APOptions apOptions, private void createMessage(APOptions apOptions,
Ticket ticket, Ticket ticket,
EncryptionKey key, EncryptionKey key,
Realm crealm,
PrincipalName cname, PrincipalName cname,
Checksum cksum, Checksum cksum,
KerberosTime ctime, KerberosTime ctime,
...@@ -474,8 +467,7 @@ public class KrbApReq { ...@@ -474,8 +467,7 @@ public class KrbApReq {
seqno = new Integer(seqNumber.current()); seqno = new Integer(seqNumber.current());
authenticator = authenticator =
new Authenticator(crealm, new Authenticator(cname,
cname,
cksum, cksum,
ctime.getMicroSeconds(), ctime.getMicroSeconds(),
ctime, ctime,
......
...@@ -48,8 +48,7 @@ abstract class KrbAppMessage { ...@@ -48,8 +48,7 @@ abstract class KrbAppMessage {
HostAddress rAddress, HostAddress rAddress,
boolean timestampRequired, boolean timestampRequired,
boolean seqNumberRequired, boolean seqNumberRequired,
PrincipalName packetPrincipal, PrincipalName packetPrincipal)
Realm packetRealm)
throws KrbApErrException { throws KrbApErrException {
if (!Krb5.AP_EMPTY_ADDRESSES_ALLOWED || sAddress != null) { if (!Krb5.AP_EMPTY_ADDRESSES_ALLOWED || sAddress != null) {
......
...@@ -152,11 +152,10 @@ class KrbAsRep extends KrbKdcRep { ...@@ -152,11 +152,10 @@ class KrbAsRep extends KrbKdcRep {
DerValue encoding = new DerValue(enc_as_rep_part); DerValue encoding = new DerValue(enc_as_rep_part);
EncASRepPart enc_part = new EncASRepPart(encoding); EncASRepPart enc_part = new EncASRepPart(encoding);
rep.ticket.sname.setRealm(rep.ticket.realm);
rep.encKDCRepPart = enc_part; rep.encKDCRepPart = enc_part;
ASReq req = asReq.getMessage(); ASReq req = asReq.getMessage();
check(req, rep); check(true, req, rep);
creds = new Credentials( creds = new Credentials(
rep.ticket, rep.ticket,
......
...@@ -115,10 +115,8 @@ public class KrbAsReq { ...@@ -115,10 +115,8 @@ public class KrbAsReq {
} }
if (sname == null) { if (sname == null) {
sname = new PrincipalName("krbtgt" + String realm = cname.getRealmAsString();
PrincipalName.NAME_COMPONENT_SEPARATOR + sname = PrincipalName.tgsService(realm, realm);
cname.getRealmAsString(),
PrincipalName.KRB_NT_SRV_INST);
} }
if (till == null) { if (till == null) {
...@@ -128,7 +126,6 @@ public class KrbAsReq { ...@@ -128,7 +126,6 @@ public class KrbAsReq {
// enc-authorization-data and additional-tickets never in AS-REQ // enc-authorization-data and additional-tickets never in AS-REQ
KDCReqBody kdc_req_body = new KDCReqBody(options, KDCReqBody kdc_req_body = new KDCReqBody(options,
cname, cname,
cname.getRealm(),
sname, sname,
from, from,
till, till,
......
...@@ -99,9 +99,6 @@ public final class KrbAsReqBuilder { ...@@ -99,9 +99,6 @@ public final class KrbAsReqBuilder {
// Called by other constructors // Called by other constructors
private void init(PrincipalName cname) private void init(PrincipalName cname)
throws KrbException { throws KrbException {
if (cname.getRealm() == null) {
cname.setRealm(Config.getInstance().getDefaultRealm());
}
this.cname = cname; this.cname = cname;
state = State.INIT; state = State.INIT;
} }
......
...@@ -96,12 +96,11 @@ public class KrbCred { ...@@ -96,12 +96,11 @@ public class KrbCred {
PrincipalName princ = delegatedCreds.getClient(); PrincipalName princ = delegatedCreds.getClient();
Realm realm = princ.getRealm(); Realm realm = princ.getRealm();
PrincipalName tgService = delegatedCreds.getServer(); PrincipalName tgService = delegatedCreds.getServer();
Realm tgsRealm = tgService.getRealm();
KrbCredInfo credInfo = new KrbCredInfo(sessionKey, realm, KrbCredInfo credInfo = new KrbCredInfo(sessionKey,
princ, delegatedCreds.flags, delegatedCreds.authTime, princ, delegatedCreds.flags, delegatedCreds.authTime,
delegatedCreds.startTime, delegatedCreds.endTime, delegatedCreds.startTime, delegatedCreds.endTime,
delegatedCreds.renewTill, tgsRealm, tgService, delegatedCreds.renewTill, tgService,
delegatedCreds.cAddr); delegatedCreds.cAddr);
timeStamp = new KerberosTime(KerberosTime.NOW); timeStamp = new KerberosTime(KerberosTime.NOW);
...@@ -138,19 +137,13 @@ public class KrbCred { ...@@ -138,19 +137,13 @@ public class KrbCred {
KrbCredInfo credInfo = encPart.ticketInfo[0]; KrbCredInfo credInfo = encPart.ticketInfo[0];
EncryptionKey credInfoKey = credInfo.key; EncryptionKey credInfoKey = credInfo.key;
Realm prealm = credInfo.prealm;
// XXX PrincipalName can store realm + principalname or
// just principal name.
PrincipalName pname = credInfo.pname; PrincipalName pname = credInfo.pname;
pname.setRealm(prealm);
TicketFlags flags = credInfo.flags; TicketFlags flags = credInfo.flags;
KerberosTime authtime = credInfo.authtime; KerberosTime authtime = credInfo.authtime;
KerberosTime starttime = credInfo.starttime; KerberosTime starttime = credInfo.starttime;
KerberosTime endtime = credInfo.endtime; KerberosTime endtime = credInfo.endtime;
KerberosTime renewTill = credInfo.renewTill; KerberosTime renewTill = credInfo.renewTill;
Realm srealm = credInfo.srealm;
PrincipalName sname = credInfo.sname; PrincipalName sname = credInfo.sname;
sname.setRealm(srealm);
HostAddresses caddr = credInfo.caddr; HostAddresses caddr = credInfo.caddr;
if (DEBUG) { if (DEBUG) {
......
...@@ -45,6 +45,10 @@ public class KrbException extends Exception { ...@@ -45,6 +45,10 @@ public class KrbException extends Exception {
super(s); super(s);
} }
public KrbException(Throwable cause) {
super(cause);
}
public KrbException(int i) { public KrbException(int i) {
returnCode = i; returnCode = i;
} }
......
...@@ -35,28 +35,17 @@ import sun.security.krb5.internal.*; ...@@ -35,28 +35,17 @@ import sun.security.krb5.internal.*;
abstract class KrbKdcRep { abstract class KrbKdcRep {
static void check( static void check(
boolean isAsReq,
KDCReq req, KDCReq req,
KDCRep rep KDCRep rep
) throws KrbApErrException { ) throws KrbApErrException {
if (!req.reqBody.cname.equalsWithoutRealm(rep.cname)) { if (isAsReq && !req.reqBody.cname.equals(rep.cname)) {
rep.encKDCRepPart.key.destroy(); rep.encKDCRepPart.key.destroy();
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED);
} }
/**** XXX if (!req.reqBody.sname.equals(rep.encKDCRepPart.sname)) {
if (!req.reqBody.crealm.equals(rep.crealm)) {
rep.encKDCRepPart.key.destroy();
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED);
}
*****/
if (!req.reqBody.sname.equalsWithoutRealm(rep.encKDCRepPart.sname)) {
rep.encKDCRepPart.key.destroy();
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED);
}
if (!req.reqBody.crealm.equals(rep.encKDCRepPart.srealm)) {
rep.encKDCRepPart.key.destroy(); rep.encKDCRepPart.key.destroy();
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED);
} }
...@@ -73,7 +62,6 @@ abstract class KrbKdcRep { ...@@ -73,7 +62,6 @@ abstract class KrbKdcRep {
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED);
} }
for (int i = 1; i < 6; i++) { for (int i = 1; i < 6; i++) {
if (req.reqBody.kdcOptions.get(i) != if (req.reqBody.kdcOptions.get(i) !=
rep.encKDCRepPart.flags.get(i)) { rep.encKDCRepPart.flags.get(i)) {
......
...@@ -89,8 +89,7 @@ class KrbPriv extends KrbAppMessage { ...@@ -89,8 +89,7 @@ class KrbPriv extends KrbAppMessage {
raddr, raddr,
timestampRequired, timestampRequired,
seqNumberRequired, seqNumberRequired,
creds.client, creds.client
creds.client.getRealm()
); );
} }
...@@ -151,8 +150,7 @@ class KrbPriv extends KrbAppMessage { ...@@ -151,8 +150,7 @@ class KrbPriv extends KrbAppMessage {
HostAddress rAddress, HostAddress rAddress,
boolean timestampRequired, boolean timestampRequired,
boolean seqNumberRequired, boolean seqNumberRequired,
PrincipalName cname, PrincipalName cname
Realm crealm
) throws Asn1Exception, KdcErrException, ) throws Asn1Exception, KdcErrException,
KrbApErrException, IOException, KrbCryptoException { KrbApErrException, IOException, KrbCryptoException {
...@@ -172,8 +170,7 @@ class KrbPriv extends KrbAppMessage { ...@@ -172,8 +170,7 @@ class KrbPriv extends KrbAppMessage {
rAddress, rAddress,
timestampRequired, timestampRequired,
seqNumberRequired, seqNumberRequired,
cname, cname
crealm
); );
return enc_part.userData; return enc_part.userData;
......
...@@ -90,8 +90,7 @@ class KrbSafe extends KrbAppMessage { ...@@ -90,8 +90,7 @@ class KrbSafe extends KrbAppMessage {
raddr, raddr,
timestampRequired, timestampRequired,
seqNumberRequired, seqNumberRequired,
creds.client, creds.client
creds.client.getRealm()
); );
} }
...@@ -154,8 +153,7 @@ class KrbSafe extends KrbAppMessage { ...@@ -154,8 +153,7 @@ class KrbSafe extends KrbAppMessage {
HostAddress rAddress, HostAddress rAddress,
boolean timestampRequired, boolean timestampRequired,
boolean seqNumberRequired, boolean seqNumberRequired,
PrincipalName cname, PrincipalName cname
Realm crealm
) throws Asn1Exception, KdcErrException, ) throws Asn1Exception, KdcErrException,
KrbApErrException, IOException, KrbCryptoException { KrbApErrException, IOException, KrbCryptoException {
...@@ -177,8 +175,7 @@ class KrbSafe extends KrbAppMessage { ...@@ -177,8 +175,7 @@ class KrbSafe extends KrbAppMessage {
rAddress, rAddress,
timestampRequired, timestampRequired,
seqNumberRequired, seqNumberRequired,
cname, cname
crealm
); );
return krb_safe.safeBody.userData; return krb_safe.safeBody.userData;
......
...@@ -82,12 +82,11 @@ public class KrbTgsRep extends KrbKdcRep { ...@@ -82,12 +82,11 @@ public class KrbTgsRep extends KrbKdcRep {
byte[] enc_tgs_rep_part = rep.encPart.reset(enc_tgs_rep_bytes); byte[] enc_tgs_rep_part = rep.encPart.reset(enc_tgs_rep_bytes);
ref = new DerValue(enc_tgs_rep_part); ref = new DerValue(enc_tgs_rep_part);
EncTGSRepPart enc_part = new EncTGSRepPart(ref); EncTGSRepPart enc_part = new EncTGSRepPart(ref);
rep.ticket.sname.setRealm(rep.ticket.realm);
rep.encKDCRepPart = enc_part; rep.encKDCRepPart = enc_part;
check(req, rep); check(false, req, rep);
creds = new Credentials(rep.ticket, this.creds = new Credentials(rep.ticket,
req.reqBody.cname, req.reqBody.cname,
rep.ticket.sname, rep.ticket.sname,
enc_part.key, enc_part.key,
...@@ -99,7 +98,6 @@ public class KrbTgsRep extends KrbKdcRep { ...@@ -99,7 +98,6 @@ public class KrbTgsRep extends KrbKdcRep {
enc_part.caddr enc_part.caddr
); );
this.rep = rep; this.rep = rep;
this.creds = creds;
this.secondTicket = tgsReq.getSecondTicket(); this.secondTicket = tgsReq.getSecondTicket();
} }
......
...@@ -148,7 +148,6 @@ public class KrbTgsReq { ...@@ -148,7 +148,6 @@ public class KrbTgsReq {
asCreds.key, asCreds.key,
ctime, ctime,
princName, princName,
princName.getRealm(),
servName, servName,
from, from,
till, till,
...@@ -214,7 +213,6 @@ public class KrbTgsReq { ...@@ -214,7 +213,6 @@ public class KrbTgsReq {
EncryptionKey key, EncryptionKey key,
KerberosTime ctime, KerberosTime ctime,
PrincipalName cname, PrincipalName cname,
Realm crealm,
PrincipalName sname, PrincipalName sname,
KerberosTime from, KerberosTime from,
KerberosTime till, KerberosTime till,
...@@ -273,8 +271,6 @@ public class KrbTgsReq { ...@@ -273,8 +271,6 @@ public class KrbTgsReq {
KDCReqBody reqBody = new KDCReqBody( KDCReqBody reqBody = new KDCReqBody(
kdc_options, kdc_options,
cname, cname,
// crealm,
sname.getRealm(), // TO
sname, sname,
from, from,
req_till, req_till,
...@@ -315,7 +311,6 @@ public class KrbTgsReq { ...@@ -315,7 +311,6 @@ public class KrbTgsReq {
new APOptions(), new APOptions(),
ticket, ticket,
key, key,
crealm,
cname, cname,
cksum, cksum,
ctime, ctime,
......
...@@ -38,15 +38,25 @@ import java.util.Vector; ...@@ -38,15 +38,25 @@ import java.util.Vector;
import java.util.Locale; import java.util.Locale;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Arrays;
import sun.security.krb5.internal.ccache.CCacheOutputStream; import sun.security.krb5.internal.ccache.CCacheOutputStream;
import sun.security.krb5.internal.util.KerberosString; import sun.security.krb5.internal.util.KerberosString;
/** /**
* This class encapsulates a Kerberos principal. * Implements the ASN.1 PrincipalName type and its realm in a single class.
* <xmp>
* Realm ::= KerberosString
*
* PrincipalName ::= SEQUENCE {
* name-type [0] Int32,
* name-string [1] SEQUENCE OF KerberosString
* }
* </xmp>
* This class is immutable.
* @see Realm
*/ */
public class PrincipalName public class PrincipalName implements Cloneable {
implements Cloneable {
//name types //name types
...@@ -80,8 +90,6 @@ public class PrincipalName ...@@ -80,8 +90,6 @@ public class PrincipalName
*/ */
public static final int KRB_NT_UID = 5; public static final int KRB_NT_UID = 5;
/** /**
* TGS Name * TGS Name
*/ */
...@@ -96,98 +104,109 @@ public class PrincipalName ...@@ -96,98 +104,109 @@ public class PrincipalName
public static final String NAME_REALM_SEPARATOR_STR = "@"; public static final String NAME_REALM_SEPARATOR_STR = "@";
public static final String REALM_COMPONENT_SEPARATOR_STR = "."; public static final String REALM_COMPONENT_SEPARATOR_STR = ".";
private int nameType; // Instance fields.
private String[] nameStrings; // Principal names don't mutate often
/**
* The name type, from PrincipalName's name-type field.
*/
private final int nameType;
/**
* The name strings, from PrincipalName's name-strings field. This field
* must be neither null nor empty. Each entry of it must also be neither
* null nor empty. Make sure to clone the field when it's passed in or out.
*/
private final String[] nameStrings;
/**
* The realm this principal belongs to.
*/
private final Realm nameRealm; // not null
// cached default salt, not used in clone
private transient String salt = null;
private Realm nameRealm; // optional; a null realm means use default // There are 3 basic constructors. All other constructors must call them.
// Note: the nameRealm is not included in the default ASN.1 encoding // All basic constructors must call validateNameStrings.
// 1. From name components
// 2. From name
// 3. From DER encoding
// cached salt, might be changed by KDC info, not used in clone /**
private String salt = null; * Creates a PrincipalName.
*/
public PrincipalName(int nameType, String[] nameStrings, Realm nameRealm) {
if (nameRealm == null) {
throw new IllegalArgumentException("Null realm not allowed");
}
validateNameStrings(nameStrings);
this.nameType = nameType;
this.nameStrings = nameStrings.clone();
this.nameRealm = nameRealm;
}
protected PrincipalName() { // This method is called by Windows NativeCred.c
public PrincipalName(String[] nameParts, String realm) throws RealmException {
this(KRB_NT_UNKNOWN, nameParts, new Realm(realm));
} }
public PrincipalName(String[] nameParts, int type) public PrincipalName(String[] nameParts, int type)
throws IllegalArgumentException, IOException { throws IllegalArgumentException, RealmException {
if (nameParts == null) { this(type, nameParts, Realm.getDefault());
throw new IllegalArgumentException("Null input not allowed");
}
nameStrings = new String[nameParts.length];
System.arraycopy(nameParts, 0, nameStrings, 0, nameParts.length);
nameType = type;
nameRealm = null;
} }
public PrincipalName(String[] nameParts) throws IOException { // Validate a nameStrings argument
this(nameParts, KRB_NT_UNKNOWN); private static void validateNameStrings(String[] ns) {
if (ns == null) {
throw new IllegalArgumentException("Null nameStrings not allowed");
}
if (ns.length == 0) {
throw new IllegalArgumentException("Empty nameStrings not allowed");
}
for (String s: ns) {
if (s == null) {
throw new IllegalArgumentException("Null nameString not allowed");
}
if (s.isEmpty()) {
throw new IllegalArgumentException("Empty nameString not allowed");
}
}
} }
public Object clone() { public Object clone() {
try { try {
PrincipalName pName = (PrincipalName) super.clone(); PrincipalName pName = (PrincipalName) super.clone();
// Re-assign mutable fields UNSAFE.putObject(this, NAME_STRINGS_OFFSET, nameStrings.clone());
if (nameStrings != null) {
pName.nameStrings = nameStrings.clone();
}
if (nameRealm != null) {
pName.nameRealm = (Realm)nameRealm.clone();
}
return pName; return pName;
} catch (CloneNotSupportedException ex) { } catch (CloneNotSupportedException ex) {
throw new AssertionError("Should never happen"); throw new AssertionError("Should never happen");
} }
} }
/* private static final long NAME_STRINGS_OFFSET;
* Added to workaround a bug where the equals method that takes a private static final sun.misc.Unsafe UNSAFE;
* PrincipalName is not being called but Object.equals(Object) is static {
* being called. try {
*/ sun.misc.Unsafe unsafe = sun.misc.Unsafe.getUnsafe();
public boolean equals(Object o) { NAME_STRINGS_OFFSET = unsafe.objectFieldOffset(
if (o instanceof PrincipalName) PrincipalName.class.getDeclaredField("nameStrings"));
return equals((PrincipalName)o); UNSAFE = unsafe;
else } catch (ReflectiveOperationException e) {
return false; throw new Error(e);
}
public boolean equals(PrincipalName other) {
if (!equalsWithoutRealm(other)) {
return false;
}
if ((nameRealm != null && other.nameRealm == null) ||
(nameRealm == null && other.nameRealm != null)) {
return false;
}
if (nameRealm != null && other.nameRealm != null) {
if (!nameRealm.equals(other.nameRealm)) {
return false;
}
} }
return true;
} }
boolean equalsWithoutRealm(PrincipalName other) { @Override
public boolean equals(Object o) {
if ((nameStrings != null && other.nameStrings == null) || if (this == o) {
(nameStrings == null && other.nameStrings != null)) return true;
return false;
if (nameStrings != null && other.nameStrings != null) {
if (nameStrings.length != other.nameStrings.length)
return false;
for (int i = 0; i < nameStrings.length; i++)
if (!nameStrings[i].equals(other.nameStrings[i]))
return false;
} }
if (o instanceof PrincipalName) {
return true; PrincipalName other = (PrincipalName)o;
return nameRealm.equals(other.nameRealm) &&
Arrays.equals(nameStrings, other.nameStrings);
}
return false;
} }
/** /**
...@@ -208,20 +227,23 @@ public class PrincipalName ...@@ -208,20 +227,23 @@ public class PrincipalName
* http://www.ietf.org/rfc/rfc4120.txt</a>. * http://www.ietf.org/rfc/rfc4120.txt</a>.
* *
* @param encoding a Der-encoded data. * @param encoding a Der-encoded data.
* @param realm the realm for this name
* @exception Asn1Exception if an error occurs while decoding * @exception Asn1Exception if an error occurs while decoding
* an ASN1 encoded data. * an ASN1 encoded data.
* @exception Asn1Exception if there is an ASN1 encoding error * @exception Asn1Exception if there is an ASN1 encoding error
* @exception IOException if an I/O error occurs * @exception IOException if an I/O error occurs
* @exception IllegalArgumentException if encoding is null * @exception IllegalArgumentException if encoding is null
* reading encoded data. * reading encoded data.
*
*/ */
public PrincipalName(DerValue encoding) public PrincipalName(DerValue encoding, Realm realm)
throws Asn1Exception, IOException { throws Asn1Exception, IOException {
nameRealm = null; if (realm == null) {
throw new IllegalArgumentException("Null realm not allowed");
}
nameRealm = realm;
DerValue der; DerValue der;
if (encoding == null) { if (encoding == null) {
throw new IllegalArgumentException("Null input not allowed"); throw new IllegalArgumentException("Null encoding not allowed");
} }
if (encoding.getTag() != DerValue.tag_Sequence) { if (encoding.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
...@@ -243,14 +265,12 @@ public class PrincipalName ...@@ -243,14 +265,12 @@ public class PrincipalName
DerValue subSubDer; DerValue subSubDer;
while(subDer.getData().available() > 0) { while(subDer.getData().available() > 0) {
subSubDer = subDer.getData().getDerValue(); subSubDer = subDer.getData().getDerValue();
v.addElement(new KerberosString(subSubDer).toString()); String namePart = new KerberosString(subSubDer).toString();
} v.addElement(namePart);
if (v.size() > 0) {
nameStrings = new String[v.size()];
v.copyInto(nameStrings);
} else {
nameStrings = new String[] {""};
} }
nameStrings = new String[v.size()];
v.copyInto(nameStrings);
validateNameStrings(nameStrings);
} else { } else {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
...@@ -267,32 +287,35 @@ public class PrincipalName ...@@ -267,32 +287,35 @@ public class PrincipalName
* more marshaled value. * more marshaled value.
* @param explicitTag tag number. * @param explicitTag tag number.
* @param optional indicate if this data field is optional * @param optional indicate if this data field is optional
* @return an instance of <code>PrincipalName</code>. * @param realm the realm for the name
* * @return an instance of <code>PrincipalName</code>, or null if the
* field is optional and missing.
*/ */
public static PrincipalName parse(DerInputStream data, public static PrincipalName parse(DerInputStream data,
byte explicitTag, boolean byte explicitTag, boolean
optional) optional,
throws Asn1Exception, IOException { Realm realm)
throws Asn1Exception, IOException, RealmException {
if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != if ((optional) && (((byte)data.peekByte() & (byte)0x1F) !=
explicitTag)) explicitTag))
return null; return null;
DerValue der = data.getDerValue(); DerValue der = data.getDerValue();
if (explicitTag != (der.getTag() & (byte)0x1F)) if (explicitTag != (der.getTag() & (byte)0x1F)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
else { } else {
DerValue subDer = der.getData().getDerValue(); DerValue subDer = der.getData().getDerValue();
return new PrincipalName(subDer); if (realm == null) {
realm = Realm.getDefault();
}
return new PrincipalName(subDer, realm);
} }
} }
// This is protected because the definition of a principal
// string is fixed
// XXX Error checkin consistent with MIT krb5_parse_name // XXX Error checkin consistent with MIT krb5_parse_name
// Code repetition, realm parsed again by class Realm // Code repetition, realm parsed again by class Realm
protected static String[] parseName(String name) { private static String[] parseName(String name) {
Vector<String> tempStrings = new Vector<>(); Vector<String> tempStrings = new Vector<>();
String temp = name; String temp = name;
...@@ -312,13 +335,13 @@ public class PrincipalName ...@@ -312,13 +335,13 @@ public class PrincipalName
continue; continue;
} }
else { else {
if (componentStart < i) { if (componentStart <= i) {
component = temp.substring(componentStart, i); component = temp.substring(componentStart, i);
tempStrings.addElement(component); tempStrings.addElement(component);
} }
componentStart = i + 1; componentStart = i + 1;
} }
} else } else {
if (temp.charAt(i) == NAME_REALM_SEPARATOR) { if (temp.charAt(i) == NAME_REALM_SEPARATOR) {
/* /*
* If this separator is escaped then don't treat it * If this separator is escaped then don't treat it
...@@ -337,11 +360,11 @@ public class PrincipalName ...@@ -337,11 +360,11 @@ public class PrincipalName
break; break;
} }
} }
}
i++; i++;
} }
if (i == temp.length()) if (i == temp.length()) {
if (componentStart < i) {
component = temp.substring(componentStart, i); component = temp.substring(componentStart, i);
tempStrings.addElement(component); tempStrings.addElement(component);
} }
...@@ -351,30 +374,26 @@ public class PrincipalName ...@@ -351,30 +374,26 @@ public class PrincipalName
return result; return result;
} }
public PrincipalName(String name, int type) /**
throws RealmException { * Constructs a PrincipalName from a string.
* @param name the name
* @param type the type
* @param realm the realm, null if not known. Note that when realm is not
* null, it will be always used even if there is a realm part in name. When
* realm is null, will read realm part from name, or try to map a realm
* (for KRB_NT_SRV_HST), or use the default realm, or fail
* @throws RealmException
*/
public PrincipalName(String name, int type, String realm)
throws RealmException {
if (name == null) { if (name == null) {
throw new IllegalArgumentException("Null name not allowed"); throw new IllegalArgumentException("Null name not allowed");
} }
String[] nameParts = parseName(name); String[] nameParts = parseName(name);
Realm tempRealm = null; validateNameStrings(nameParts);
String realmString = Realm.parseRealmAtSeparator(name); if (realm == null) {
realm = Realm.parseRealmAtSeparator(name);
if (realmString == null) {
try {
Config config = Config.getInstance();
realmString = config.getDefaultRealm();
} catch (KrbException e) {
RealmException re =
new RealmException(e.getMessage());
re.initCause(e);
throw re;
}
} }
if (realmString != null)
tempRealm = new Realm(realmString);
switch (type) { switch (type) {
case KRB_NT_SRV_HST: case KRB_NT_SRV_HST:
if (nameParts.length >= 2) { if (nameParts.length >= 2) {
...@@ -401,18 +420,22 @@ public class PrincipalName ...@@ -401,18 +420,22 @@ public class PrincipalName
} }
nameStrings = nameParts; nameStrings = nameParts;
nameType = type; nameType = type;
if (realm != null) {
nameRealm = new Realm(realm);
} else {
// We will try to get realm name from the mapping in // We will try to get realm name from the mapping in
// the configuration. If it is not specified // the configuration. If it is not specified
// we will use the default realm. This nametype does // we will use the default realm. This nametype does
// not allow a realm to be specified. The name string must of // not allow a realm to be specified. The name string must of
// the form service@host and this is internally changed into // the form service@host and this is internally changed into
// service/host by Kerberos // service/host by Kerberos
String mapRealm = mapHostToRealm(nameParts[1]);
String mapRealm = mapHostToRealm(nameParts[1]); if (mapRealm != null) {
if (mapRealm != null) { nameRealm = new Realm(mapRealm);
nameRealm = new Realm(mapRealm); } else {
} else { nameRealm = Realm.getDefault();
nameRealm = tempRealm; }
} }
break; break;
case KRB_NT_UNKNOWN: case KRB_NT_UNKNOWN:
...@@ -422,20 +445,34 @@ public class PrincipalName ...@@ -422,20 +445,34 @@ public class PrincipalName
case KRB_NT_UID: case KRB_NT_UID:
nameStrings = nameParts; nameStrings = nameParts;
nameType = type; nameType = type;
nameRealm = tempRealm; if (realm != null) {
nameRealm = new Realm(realm);
} else {
nameRealm = Realm.getDefault();
}
break; break;
default: default:
throw new IllegalArgumentException("Illegal name type"); throw new IllegalArgumentException("Illegal name type");
} }
} }
public PrincipalName(String name, int type) throws RealmException {
this(name, type, (String)null);
}
public PrincipalName(String name) throws RealmException { public PrincipalName(String name) throws RealmException {
this(name, KRB_NT_UNKNOWN); this(name, KRB_NT_UNKNOWN);
} }
public PrincipalName(String name, String realm) throws RealmException { public PrincipalName(String name, String realm) throws RealmException {
this(name, KRB_NT_UNKNOWN); this(name, KRB_NT_UNKNOWN, realm);
nameRealm = new Realm(realm); }
public static PrincipalName tgsService(String r1, String r2)
throws KrbException {
return new PrincipalName(PrincipalName.KRB_NT_SRV_INST,
new String[] {PrincipalName.TGS_DEFAULT_SRV_NAME, r1},
new Realm(r2));
} }
public String getRealmAsString() { public String getRealmAsString() {
...@@ -475,29 +512,17 @@ public class PrincipalName ...@@ -475,29 +512,17 @@ public class PrincipalName
} }
public String getRealmString() { public String getRealmString() {
if (nameRealm != null) return nameRealm.toString();
return nameRealm.toString();
return null;
} }
public Realm getRealm() { public Realm getRealm() {
return nameRealm; return nameRealm;
} }
public void setRealm(Realm new_nameRealm) throws RealmException {
nameRealm = new_nameRealm;
}
public void setRealm(String realmsString) throws RealmException {
nameRealm = new Realm(realmsString);
}
public String getSalt() { public String getSalt() {
if (salt == null) { if (salt == null) {
StringBuffer salt = new StringBuffer(); StringBuffer salt = new StringBuffer();
if (nameRealm != null) { salt.append(nameRealm.toString());
salt.append(nameRealm.toString());
}
for (int i = 0; i < nameStrings.length; i++) { for (int i = 0; i < nameStrings.length; i++) {
salt.append(nameStrings[i]); salt.append(nameStrings[i]);
} }
...@@ -513,11 +538,8 @@ public class PrincipalName ...@@ -513,11 +538,8 @@ public class PrincipalName
str.append("/"); str.append("/");
str.append(nameStrings[i]); str.append(nameStrings[i]);
} }
if (nameRealm != null) { str.append("@");
str.append("@"); str.append(nameRealm.toString());
str.append(nameRealm.toString());
}
return str.toString(); return str.toString();
} }
...@@ -532,7 +554,8 @@ public class PrincipalName ...@@ -532,7 +554,8 @@ public class PrincipalName
} }
/** /**
* Encodes a <code>PrincipalName</code> object. * Encodes a <code>PrincipalName</code> object. Note that only the type and
* names are encoded. To encode the realm, call getRealm().asn1Encode().
* @return the byte array of the encoded PrncipalName object. * @return the byte array of the encoded PrncipalName object.
* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
* @exception IOException if an I/O error occurs while reading encoded data. * @exception IOException if an I/O error occurs while reading encoded data.
...@@ -597,12 +620,10 @@ public class PrincipalName ...@@ -597,12 +620,10 @@ public class PrincipalName
public void writePrincipal(CCacheOutputStream cos) throws IOException { public void writePrincipal(CCacheOutputStream cos) throws IOException {
cos.write32(nameType); cos.write32(nameType);
cos.write32(nameStrings.length); cos.write32(nameStrings.length);
if (nameRealm != null) { byte[] realmBytes = null;
byte[] realmBytes = null; realmBytes = nameRealm.toString().getBytes();
realmBytes = nameRealm.toString().getBytes(); cos.write32(realmBytes.length);
cos.write32(realmBytes.length); cos.write(realmBytes, 0, realmBytes.length);
cos.write(realmBytes, 0, realmBytes.length);
}
byte[] bytes = null; byte[] bytes = null;
for (int i = 0; i < nameStrings.length; i++) { for (int i = 0; i < nameStrings.length; i++) {
bytes = nameStrings[i].getBytes(); bytes = nameStrings[i].getBytes();
...@@ -611,31 +632,6 @@ public class PrincipalName ...@@ -611,31 +632,6 @@ public class PrincipalName
} }
} }
/**
* Creates a KRB_NT_SRV_INST name from the supplied
* name components and realm.
* @param primary the primary component of the name
* @param instance the instance component of the name
* @param realm the realm
* @throws KrbException
*/
protected PrincipalName(String primary, String instance, String realm,
int type)
throws KrbException {
if (type != KRB_NT_SRV_INST) {
throw new KrbException(Krb5.KRB_ERR_GENERIC, "Bad name type");
}
String[] nParts = new String[2];
nParts[0] = primary;
nParts[1] = instance;
this.nameStrings = nParts;
this.nameRealm = new Realm(realm);
this.nameType = type;
}
/** /**
* Returns the instance component of a name. * Returns the instance component of a name.
* In a multi-component name such as a KRB_NT_SRV_INST * In a multi-component name such as a KRB_NT_SRV_INST
......
...@@ -46,24 +46,29 @@ import sun.security.krb5.internal.util.KerberosString; ...@@ -46,24 +46,29 @@ import sun.security.krb5.internal.util.KerberosString;
* <xmp> * <xmp>
* Realm ::= GeneralString * Realm ::= GeneralString
* </xmp> * </xmp>
* This class is immutable.
*/ */
public class Realm implements Cloneable { public class Realm implements Cloneable {
private String realm; private final String realm; // not null nor empty
private static boolean DEBUG = Krb5.DEBUG; private static boolean DEBUG = Krb5.DEBUG;
private Realm() {
}
public Realm(String name) throws RealmException { public Realm(String name) throws RealmException {
realm = parseRealm(name); realm = parseRealm(name);
} }
public Object clone() { public static Realm getDefault() throws RealmException {
Realm new_realm = new Realm(); try {
if (realm != null) { return new Realm(Config.getInstance().getDefaultRealm());
new_realm.realm = new String(realm); } catch (RealmException re) {
throw re;
} catch (KrbException ke) {
throw new RealmException(ke);
} }
return new_realm; }
// Immutable class, no need to clone
public Object clone() {
return this;
} }
public boolean equals(Object obj) { public boolean equals(Object obj) {
...@@ -76,21 +81,11 @@ public class Realm implements Cloneable { ...@@ -76,21 +81,11 @@ public class Realm implements Cloneable {
} }
Realm that = (Realm)obj; Realm that = (Realm)obj;
if (this.realm != null && that.realm != null ) { return this.realm.equals(that.realm);
return this.realm.equals(that.realm);
} else {
return (this.realm == null && that.realm == null);
}
} }
public int hashCode() { public int hashCode() {
int result = 17 ; return realm.hashCode();
if( realm != null ) {
result = 37 * result + realm.hashCode();
}
return result;
} }
/** /**
...@@ -116,6 +111,7 @@ public class Realm implements Cloneable { ...@@ -116,6 +111,7 @@ public class Realm implements Cloneable {
return realm; return realm;
} }
// Extract realm from a string like dummy@REALM
public static String parseRealmAtSeparator(String name) public static String parseRealmAtSeparator(String name)
throws RealmException { throws RealmException {
if (name == null) { if (name == null) {
...@@ -128,8 +124,12 @@ public class Realm implements Cloneable { ...@@ -128,8 +124,12 @@ public class Realm implements Cloneable {
while (i < temp.length()) { while (i < temp.length()) {
if (temp.charAt(i) == PrincipalName.NAME_REALM_SEPARATOR) { if (temp.charAt(i) == PrincipalName.NAME_REALM_SEPARATOR) {
if (i == 0 || temp.charAt(i - 1) != '\\') { if (i == 0 || temp.charAt(i - 1) != '\\') {
if (i + 1 < temp.length()) if (i + 1 < temp.length()) {
result = temp.substring(i + 1, temp.length()); result = temp.substring(i + 1, temp.length());
} else {
throw new IllegalArgumentException
("empty realm part not allowed");
}
break; break;
} }
} }
...@@ -219,7 +219,8 @@ public class Realm implements Cloneable { ...@@ -219,7 +219,8 @@ public class Realm implements Cloneable {
* @return an instance of Realm. * @return an instance of Realm.
* *
*/ */
public static Realm parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException, RealmException { public static Realm parse(DerInputStream data, byte explicitTag, boolean optional)
throws Asn1Exception, IOException, RealmException {
if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag)) { if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag)) {
return null; return null;
} }
......
...@@ -47,4 +47,7 @@ public class RealmException extends KrbException { ...@@ -47,4 +47,7 @@ public class RealmException extends KrbException {
super(i,s); super(i,s);
} }
public RealmException(Throwable cause) {
super(cause);
}
} }
...@@ -42,11 +42,10 @@ public class ASRep extends KDCRep { ...@@ -42,11 +42,10 @@ public class ASRep extends KDCRep {
public ASRep( public ASRep(
PAData[] new_pAData, PAData[] new_pAData,
Realm new_crealm,
PrincipalName new_cname, PrincipalName new_cname,
Ticket new_ticket, Ticket new_ticket,
EncryptedData new_encPart) throws IOException { EncryptedData new_encPart) throws IOException {
super(new_pAData, new_crealm, new_cname, new_ticket, super(new_pAData, new_cname, new_ticket,
new_encPart, Krb5.KRB_AS_REP); new_encPart, Krb5.KRB_AS_REP);
} }
......
...@@ -61,7 +61,6 @@ import java.math.BigInteger; ...@@ -61,7 +61,6 @@ import java.math.BigInteger;
public class Authenticator { public class Authenticator {
public int authenticator_vno; public int authenticator_vno;
public Realm crealm;
public PrincipalName cname; public PrincipalName cname;
Checksum cksum; //optional Checksum cksum; //optional
public int cusec; public int cusec;
...@@ -71,7 +70,6 @@ public class Authenticator { ...@@ -71,7 +70,6 @@ public class Authenticator {
public AuthorizationData authorizationData; //optional public AuthorizationData authorizationData; //optional
public Authenticator( public Authenticator(
Realm new_crealm,
PrincipalName new_cname, PrincipalName new_cname,
Checksum new_cksum, Checksum new_cksum,
int new_cusec, int new_cusec,
...@@ -80,7 +78,6 @@ public class Authenticator { ...@@ -80,7 +78,6 @@ public class Authenticator {
Integer new_seqNumber, Integer new_seqNumber,
AuthorizationData new_authorizationData) { AuthorizationData new_authorizationData) {
authenticator_vno = Krb5.AUTHNETICATOR_VNO; authenticator_vno = Krb5.AUTHNETICATOR_VNO;
crealm = new_crealm;
cname = new_cname; cname = new_cname;
cksum = new_cksum; cksum = new_cksum;
cusec = new_cusec; cusec = new_cusec;
...@@ -131,8 +128,8 @@ public class Authenticator { ...@@ -131,8 +128,8 @@ public class Authenticator {
if (authenticator_vno != 5) { if (authenticator_vno != 5) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION); throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
} }
crealm = Realm.parse(der.getData(), (byte) 0x01, false); Realm crealm = Realm.parse(der.getData(), (byte) 0x01, false);
cname = PrincipalName.parse(der.getData(), (byte) 0x02, false); cname = PrincipalName.parse(der.getData(), (byte) 0x02, false, crealm);
cksum = Checksum.parse(der.getData(), (byte) 0x03, true); cksum = Checksum.parse(der.getData(), (byte) 0x03, true);
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & (byte) 0x1F) == 0x04) { if ((subDer.getTag() & (byte) 0x1F) == 0x04) {
...@@ -180,7 +177,7 @@ public class Authenticator { ...@@ -180,7 +177,7 @@ public class Authenticator {
DerOutputStream temp = new DerOutputStream(); DerOutputStream temp = new DerOutputStream();
temp.putInteger(BigInteger.valueOf(authenticator_vno)); temp.putInteger(BigInteger.valueOf(authenticator_vno));
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp.toByteArray())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp.toByteArray()));
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), crealm.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), cname.getRealm().asn1Encode()));
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), cname.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), cname.asn1Encode()));
if (cksum != null) { if (cksum != null) {
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x03), cksum.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x03), cksum.asn1Encode()));
......
...@@ -72,23 +72,9 @@ rs. ...@@ -72,23 +72,9 @@ rs.
public static Credentials acquireServiceCreds( public static Credentials acquireServiceCreds(
String service, Credentials ccreds) String service, Credentials ccreds)
throws KrbException, IOException { throws KrbException, IOException {
ServiceName sname = new ServiceName(service); PrincipalName sname = new PrincipalName(service);
String serviceRealm = sname.getRealmString(); String serviceRealm = sname.getRealmString();
String localRealm = ccreds.getClient().getRealmString(); String localRealm = ccreds.getClient().getRealmString();
String defaultRealm = Config.getInstance().getDefaultRealm();
if (localRealm == null) {
PrincipalName temp = null;
if ((temp = ccreds.getServer()) != null)
localRealm = temp.getRealmString();
}
if (localRealm == null) {
localRealm = defaultRealm;
}
if (serviceRealm == null) {
serviceRealm = localRealm;
sname.setRealm(serviceRealm);
}
/* /*
if (!localRealm.equalsIgnoreCase(serviceRealm)) { //do cross-realm auth entication if (!localRealm.equalsIgnoreCase(serviceRealm)) { //do cross-realm auth entication
...@@ -128,13 +114,12 @@ rs. ...@@ -128,13 +114,12 @@ rs.
int i = 0, k = 0; int i = 0, k = 0;
Credentials cTgt = null, newTgt = null, theTgt = null; Credentials cTgt = null, newTgt = null, theTgt = null;
ServiceName tempService = null; PrincipalName tempService = null;
String realm = null, newTgtRealm = null, theTgtRealm = null; String realm = null, newTgtRealm = null, theTgtRealm = null;
for (cTgt = ccreds, i = 0; i < realms.length;) for (cTgt = ccreds, i = 0; i < realms.length;)
{ {
tempService = new ServiceName(PrincipalName.TGS_DEFAULT_SRV_NAME, tempService = PrincipalName.tgsService(serviceRealm, realms[i]);
serviceRealm, realms[i]);
if (DEBUG) if (DEBUG)
{ {
...@@ -164,9 +149,7 @@ rs. ...@@ -164,9 +149,7 @@ rs.
newTgt == null && k > i; k--) newTgt == null && k > i; k--)
{ {
tempService = new ServiceName( tempService = PrincipalName.tgsService(realms[k], realms[i]);
PrincipalName.TGS_DEFAULT_SRV_NAME,
realms[k], realms[i]);
if (DEBUG) if (DEBUG)
{ {
System.out.println(">>> Credentials acquireServiceCreds: inner loop: [" + k +"] tempService=" + tempService); System.out.println(">>> Credentials acquireServiceCreds: inner loop: [" + k +"] tempService=" + tempService);
...@@ -306,7 +289,7 @@ rs. ...@@ -306,7 +289,7 @@ rs.
* This method does the real job to request the service credential. * This method does the real job to request the service credential.
*/ */
private static Credentials serviceCreds( private static Credentials serviceCreds(
ServiceName service, Credentials ccreds) PrincipalName service, Credentials ccreds)
throws KrbException, IOException { throws KrbException, IOException {
return new KrbTgsReq(ccreds, service).sendAndGetCreds(); return new KrbTgsReq(ccreds, service).sendAndGetCreds();
} }
......
...@@ -46,7 +46,6 @@ public class EncASRepPart extends EncKDCRepPart { ...@@ -46,7 +46,6 @@ public class EncASRepPart extends EncKDCRepPart {
KerberosTime new_starttime, KerberosTime new_starttime,
KerberosTime new_endtime, KerberosTime new_endtime,
KerberosTime new_renewTill, KerberosTime new_renewTill,
Realm new_srealm,
PrincipalName new_sname, PrincipalName new_sname,
HostAddresses new_caddr) { HostAddresses new_caddr) {
super( super(
...@@ -59,7 +58,6 @@ public class EncASRepPart extends EncKDCRepPart { ...@@ -59,7 +58,6 @@ public class EncASRepPart extends EncKDCRepPart {
new_starttime, new_starttime,
new_endtime, new_endtime,
new_renewTill, new_renewTill,
new_srealm,
new_sname, new_sname,
new_caddr, new_caddr,
Krb5.KRB_ENC_AS_REP_PART Krb5.KRB_ENC_AS_REP_PART
......
...@@ -74,7 +74,6 @@ public class EncKDCRepPart { ...@@ -74,7 +74,6 @@ public class EncKDCRepPart {
public KerberosTime starttime; //optional public KerberosTime starttime; //optional
public KerberosTime endtime; public KerberosTime endtime;
public KerberosTime renewTill; //optional public KerberosTime renewTill; //optional
public Realm srealm;
public PrincipalName sname; public PrincipalName sname;
public HostAddresses caddr; //optional public HostAddresses caddr; //optional
public int msgType; //not included in sequence public int msgType; //not included in sequence
...@@ -89,7 +88,6 @@ public class EncKDCRepPart { ...@@ -89,7 +88,6 @@ public class EncKDCRepPart {
KerberosTime new_starttime, KerberosTime new_starttime,
KerberosTime new_endtime, KerberosTime new_endtime,
KerberosTime new_renewTill, KerberosTime new_renewTill,
Realm new_srealm,
PrincipalName new_sname, PrincipalName new_sname,
HostAddresses new_caddr, HostAddresses new_caddr,
int new_msgType) { int new_msgType) {
...@@ -102,7 +100,6 @@ public class EncKDCRepPart { ...@@ -102,7 +100,6 @@ public class EncKDCRepPart {
starttime = new_starttime; starttime = new_starttime;
endtime = new_endtime; endtime = new_endtime;
renewTill = new_renewTill; renewTill = new_renewTill;
srealm = new_srealm;
sname = new_sname; sname = new_sname;
caddr = new_caddr; caddr = new_caddr;
msgType = new_msgType; msgType = new_msgType;
...@@ -158,8 +155,8 @@ public class EncKDCRepPart { ...@@ -158,8 +155,8 @@ public class EncKDCRepPart {
starttime = KerberosTime.parse(der.getData(), (byte) 0x06, true); starttime = KerberosTime.parse(der.getData(), (byte) 0x06, true);
endtime = KerberosTime.parse(der.getData(), (byte) 0x07, false); endtime = KerberosTime.parse(der.getData(), (byte) 0x07, false);
renewTill = KerberosTime.parse(der.getData(), (byte) 0x08, true); renewTill = KerberosTime.parse(der.getData(), (byte) 0x08, true);
srealm = Realm.parse(der.getData(), (byte) 0x09, false); Realm srealm = Realm.parse(der.getData(), (byte) 0x09, false);
sname = PrincipalName.parse(der.getData(), (byte) 0x0A, false); sname = PrincipalName.parse(der.getData(), (byte) 0x0A, false, srealm);
if (der.getData().available() > 0) { if (der.getData().available() > 0) {
caddr = HostAddresses.parse(der.getData(), (byte) 0x0B, true); caddr = HostAddresses.parse(der.getData(), (byte) 0x0B, true);
} }
...@@ -206,7 +203,7 @@ public class EncKDCRepPart { ...@@ -206,7 +203,7 @@ public class EncKDCRepPart {
true, (byte) 0x08), renewTill.asn1Encode()); true, (byte) 0x08), renewTill.asn1Encode());
} }
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x09), srealm.asn1Encode()); true, (byte) 0x09), sname.getRealm().asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x0A), sname.asn1Encode()); true, (byte) 0x0A), sname.asn1Encode());
if (caddr != null) { if (caddr != null) {
......
...@@ -45,7 +45,6 @@ public class EncTGSRepPart extends EncKDCRepPart { ...@@ -45,7 +45,6 @@ public class EncTGSRepPart extends EncKDCRepPart {
KerberosTime new_starttime, KerberosTime new_starttime,
KerberosTime new_endtime, KerberosTime new_endtime,
KerberosTime new_renewTill, KerberosTime new_renewTill,
Realm new_srealm,
PrincipalName new_sname, PrincipalName new_sname,
HostAddresses new_caddr) { HostAddresses new_caddr) {
super( super(
...@@ -58,7 +57,6 @@ public class EncTGSRepPart extends EncKDCRepPart { ...@@ -58,7 +57,6 @@ public class EncTGSRepPart extends EncKDCRepPart {
new_starttime, new_starttime,
new_endtime, new_endtime,
new_renewTill, new_renewTill,
new_srealm,
new_sname, new_sname,
new_caddr, new_caddr,
Krb5.KRB_ENC_TGS_REP_PART); Krb5.KRB_ENC_TGS_REP_PART);
......
...@@ -65,7 +65,6 @@ public class EncTicketPart { ...@@ -65,7 +65,6 @@ public class EncTicketPart {
public TicketFlags flags; public TicketFlags flags;
public EncryptionKey key; public EncryptionKey key;
public Realm crealm;
public PrincipalName cname; public PrincipalName cname;
public TransitedEncoding transited; public TransitedEncoding transited;
public KerberosTime authtime; public KerberosTime authtime;
...@@ -78,7 +77,6 @@ public class EncTicketPart { ...@@ -78,7 +77,6 @@ public class EncTicketPart {
public EncTicketPart( public EncTicketPart(
TicketFlags new_flags, TicketFlags new_flags,
EncryptionKey new_key, EncryptionKey new_key,
Realm new_crealm,
PrincipalName new_cname, PrincipalName new_cname,
TransitedEncoding new_transited, TransitedEncoding new_transited,
KerberosTime new_authtime, KerberosTime new_authtime,
...@@ -89,7 +87,6 @@ public class EncTicketPart { ...@@ -89,7 +87,6 @@ public class EncTicketPart {
AuthorizationData new_authorizationData) { AuthorizationData new_authorizationData) {
flags = new_flags; flags = new_flags;
key = new_key; key = new_key;
crealm = new_crealm;
cname = new_cname; cname = new_cname;
transited = new_transited; transited = new_transited;
authtime = new_authtime; authtime = new_authtime;
...@@ -151,8 +148,8 @@ public class EncTicketPart { ...@@ -151,8 +148,8 @@ public class EncTicketPart {
} }
flags = TicketFlags.parse(der.getData(), (byte) 0x00, false); flags = TicketFlags.parse(der.getData(), (byte) 0x00, false);
key = EncryptionKey.parse(der.getData(), (byte) 0x01, false); key = EncryptionKey.parse(der.getData(), (byte) 0x01, false);
crealm = Realm.parse(der.getData(), (byte) 0x02, false); Realm crealm = Realm.parse(der.getData(), (byte) 0x02, false);
cname = PrincipalName.parse(der.getData(), (byte) 0x03, false); cname = PrincipalName.parse(der.getData(), (byte) 0x03, false, crealm);
transited = TransitedEncoding.parse(der.getData(), (byte) 0x04, false); transited = TransitedEncoding.parse(der.getData(), (byte) 0x04, false);
authtime = KerberosTime.parse(der.getData(), (byte) 0x05, false); authtime = KerberosTime.parse(der.getData(), (byte) 0x05, false);
starttime = KerberosTime.parse(der.getData(), (byte) 0x06, true); starttime = KerberosTime.parse(der.getData(), (byte) 0x06, true);
...@@ -186,7 +183,7 @@ public class EncTicketPart { ...@@ -186,7 +183,7 @@ public class EncTicketPart {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x01), key.asn1Encode()); true, (byte) 0x01), key.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x02), crealm.asn1Encode()); true, (byte) 0x02), cname.getRealm().asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x03), cname.asn1Encode()); true, (byte) 0x03), cname.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
......
...@@ -61,7 +61,6 @@ import java.math.BigInteger; ...@@ -61,7 +61,6 @@ import java.math.BigInteger;
*/ */
public class KDCRep { public class KDCRep {
public Realm crealm;
public PrincipalName cname; public PrincipalName cname;
public Ticket ticket; public Ticket ticket;
public EncryptedData encPart; public EncryptedData encPart;
...@@ -73,7 +72,6 @@ public class KDCRep { ...@@ -73,7 +72,6 @@ public class KDCRep {
public KDCRep( public KDCRep(
PAData[] new_pAData, PAData[] new_pAData,
Realm new_crealm,
PrincipalName new_cname, PrincipalName new_cname,
Ticket new_ticket, Ticket new_ticket,
EncryptedData new_encPart, EncryptedData new_encPart,
...@@ -90,7 +88,6 @@ public class KDCRep { ...@@ -90,7 +88,6 @@ public class KDCRep {
} }
} }
} }
crealm = new_crealm;
cname = new_cname; cname = new_cname;
ticket = new_ticket; ticket = new_ticket;
encPart = new_encPart; encPart = new_encPart;
...@@ -174,8 +171,8 @@ public class KDCRep { ...@@ -174,8 +171,8 @@ public class KDCRep {
} else { } else {
pAData = null; pAData = null;
} }
crealm = Realm.parse(der.getData(), (byte) 0x03, false); Realm crealm = Realm.parse(der.getData(), (byte) 0x03, false);
cname = PrincipalName.parse(der.getData(), (byte) 0x04, false); cname = PrincipalName.parse(der.getData(), (byte) 0x04, false, crealm);
ticket = Ticket.parse(der.getData(), (byte) 0x05, false); ticket = Ticket.parse(der.getData(), (byte) 0x05, false);
encPart = EncryptedData.parse(der.getData(), (byte) 0x06, false); encPart = EncryptedData.parse(der.getData(), (byte) 0x06, false);
if (der.getData().available() > 0) { if (der.getData().available() > 0) {
...@@ -212,7 +209,7 @@ public class KDCRep { ...@@ -212,7 +209,7 @@ public class KDCRep {
true, (byte) 0x02), temp); true, (byte) 0x02), temp);
} }
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x03), crealm.asn1Encode()); true, (byte) 0x03), cname.getRealm().asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x04), cname.asn1Encode()); true, (byte) 0x04), cname.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
......
...@@ -72,7 +72,6 @@ import java.math.BigInteger; ...@@ -72,7 +72,6 @@ import java.math.BigInteger;
public class KDCReqBody { public class KDCReqBody {
public KDCOptions kdcOptions; public KDCOptions kdcOptions;
public PrincipalName cname; //optional in ASReq only public PrincipalName cname; //optional in ASReq only
public Realm crealm;
public PrincipalName sname; //optional public PrincipalName sname; //optional
public KerberosTime from; //optional public KerberosTime from; //optional
public KerberosTime till; public KerberosTime till;
...@@ -87,7 +86,6 @@ public class KDCReqBody { ...@@ -87,7 +86,6 @@ public class KDCReqBody {
public KDCReqBody( public KDCReqBody(
KDCOptions new_kdcOptions, KDCOptions new_kdcOptions,
PrincipalName new_cname, //optional in ASReq only PrincipalName new_cname, //optional in ASReq only
Realm new_crealm,
PrincipalName new_sname, //optional PrincipalName new_sname, //optional
KerberosTime new_from, //optional KerberosTime new_from, //optional
KerberosTime new_till, KerberosTime new_till,
...@@ -100,7 +98,6 @@ public class KDCReqBody { ...@@ -100,7 +98,6 @@ public class KDCReqBody {
) throws IOException { ) throws IOException {
kdcOptions = new_kdcOptions; kdcOptions = new_kdcOptions;
cname = new_cname; cname = new_cname;
crealm = new_crealm;
sname = new_sname; sname = new_sname;
from = new_from; from = new_from;
till = new_till; till = new_till;
...@@ -142,12 +139,22 @@ public class KDCReqBody { ...@@ -142,12 +139,22 @@ public class KDCReqBody {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
kdcOptions = KDCOptions.parse(encoding.getData(), (byte)0x00, false); kdcOptions = KDCOptions.parse(encoding.getData(), (byte)0x00, false);
cname = PrincipalName.parse(encoding.getData(), (byte)0x01, true);
// cname only appears in AS-REQ and it shares the realm field with
// sname. This is the only place where realm comes after the name.
// We first give cname a fake realm and reassign it the correct
// realm after the realm field is read.
cname = PrincipalName.parse(encoding.getData(), (byte)0x01, true,
new Realm("PLACEHOLDER"));
if ((msgType != Krb5.KRB_AS_REQ) && (cname != null)) { if ((msgType != Krb5.KRB_AS_REQ) && (cname != null)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
crealm = Realm.parse(encoding.getData(), (byte)0x02, false); Realm realm = Realm.parse(encoding.getData(), (byte)0x02, false);
sname = PrincipalName.parse(encoding.getData(), (byte)0x03, true); if (cname != null) {
cname = new PrincipalName(
cname.getNameType(), cname.getNameStrings(), realm);
}
sname = PrincipalName.parse(encoding.getData(), (byte)0x03, true, realm);
from = KerberosTime.parse(encoding.getData(), (byte)0x04, true); from = KerberosTime.parse(encoding.getData(), (byte)0x04, true);
till = KerberosTime.parse(encoding.getData(), (byte)0x05, false); till = KerberosTime.parse(encoding.getData(), (byte)0x05, false);
rtime = KerberosTime.parse(encoding.getData(), (byte)0x06, true); rtime = KerberosTime.parse(encoding.getData(), (byte)0x06, true);
...@@ -223,9 +230,11 @@ public class KDCReqBody { ...@@ -223,9 +230,11 @@ public class KDCReqBody {
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), cname.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), cname.asn1Encode()));
} }
} }
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), crealm.asn1Encode()));
if (sname != null) { if (sname != null) {
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), sname.getRealm().asn1Encode()));
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), sname.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), sname.asn1Encode()));
} else if (cname != null) {
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), cname.getRealm().asn1Encode()));
} }
if (from != null) { if (from != null) {
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), from.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), from.asn1Encode()));
......
...@@ -90,9 +90,7 @@ public class KRBError implements java.io.Serializable { ...@@ -90,9 +90,7 @@ public class KRBError implements java.io.Serializable {
private KerberosTime sTime; private KerberosTime sTime;
private Integer suSec; private Integer suSec;
private int errorCode; private int errorCode;
private Realm crealm; //optional
private PrincipalName cname; //optional private PrincipalName cname; //optional
private Realm realm;
private PrincipalName sname; private PrincipalName sname;
private String eText; //optional private String eText; //optional
private byte[] eData; //optional private byte[] eData; //optional
...@@ -128,9 +126,7 @@ public class KRBError implements java.io.Serializable { ...@@ -128,9 +126,7 @@ public class KRBError implements java.io.Serializable {
KerberosTime new_sTime, KerberosTime new_sTime,
Integer new_suSec, Integer new_suSec,
int new_errorCode, int new_errorCode,
Realm new_crealm,
PrincipalName new_cname, PrincipalName new_cname,
Realm new_realm,
PrincipalName new_sname, PrincipalName new_sname,
String new_eText, String new_eText,
byte[] new_eData byte[] new_eData
...@@ -142,9 +138,7 @@ public class KRBError implements java.io.Serializable { ...@@ -142,9 +138,7 @@ public class KRBError implements java.io.Serializable {
sTime = new_sTime; sTime = new_sTime;
suSec = new_suSec; suSec = new_suSec;
errorCode = new_errorCode; errorCode = new_errorCode;
crealm = new_crealm;
cname = new_cname; cname = new_cname;
realm = new_realm;
sname = new_sname; sname = new_sname;
eText = new_eText; eText = new_eText;
eData = new_eData; eData = new_eData;
...@@ -159,9 +153,7 @@ public class KRBError implements java.io.Serializable { ...@@ -159,9 +153,7 @@ public class KRBError implements java.io.Serializable {
KerberosTime new_sTime, KerberosTime new_sTime,
Integer new_suSec, Integer new_suSec,
int new_errorCode, int new_errorCode,
Realm new_crealm,
PrincipalName new_cname, PrincipalName new_cname,
Realm new_realm,
PrincipalName new_sname, PrincipalName new_sname,
String new_eText, String new_eText,
byte[] new_eData, byte[] new_eData,
...@@ -174,9 +166,7 @@ public class KRBError implements java.io.Serializable { ...@@ -174,9 +166,7 @@ public class KRBError implements java.io.Serializable {
sTime = new_sTime; sTime = new_sTime;
suSec = new_suSec; suSec = new_suSec;
errorCode = new_errorCode; errorCode = new_errorCode;
crealm = new_crealm;
cname = new_cname; cname = new_cname;
realm = new_realm;
sname = new_sname; sname = new_sname;
eText = new_eText; eText = new_eText;
eData = new_eData; eData = new_eData;
...@@ -359,10 +349,10 @@ public class KRBError implements java.io.Serializable { ...@@ -359,10 +349,10 @@ public class KRBError implements java.io.Serializable {
errorCode = subDer.getData().getBigInteger().intValue(); errorCode = subDer.getData().getBigInteger().intValue();
} }
else throw new Asn1Exception(Krb5.ASN1_BAD_ID); else throw new Asn1Exception(Krb5.ASN1_BAD_ID);
crealm = Realm.parse(der.getData(), (byte)0x07, true); Realm crealm = Realm.parse(der.getData(), (byte)0x07, true);
cname = PrincipalName.parse(der.getData(), (byte)0x08, true); cname = PrincipalName.parse(der.getData(), (byte)0x08, true, crealm);
realm = Realm.parse(der.getData(), (byte)0x09, false); Realm realm = Realm.parse(der.getData(), (byte)0x09, false);
sname = PrincipalName.parse(der.getData(), (byte)0x0A, false); sname = PrincipalName.parse(der.getData(), (byte)0x0A, false, realm);
eText = null; eText = null;
eData = null; eData = null;
eCksum = null; eCksum = null;
...@@ -403,15 +393,9 @@ public class KRBError implements java.io.Serializable { ...@@ -403,15 +393,9 @@ public class KRBError implements java.io.Serializable {
System.out.println("\t suSec is " + suSec); System.out.println("\t suSec is " + suSec);
System.out.println("\t error code is " + errorCode); System.out.println("\t error code is " + errorCode);
System.out.println("\t error Message is " + Krb5.getErrorMessage(errorCode)); System.out.println("\t error Message is " + Krb5.getErrorMessage(errorCode));
if (crealm != null) {
System.out.println("\t crealm is " + crealm.toString());
}
if (cname != null) { if (cname != null) {
System.out.println("\t cname is " + cname.toString()); System.out.println("\t cname is " + cname.toString());
} }
if (realm != null) {
System.out.println("\t realm is " + realm.toString());
}
if (sname != null) { if (sname != null) {
System.out.println("\t sname is " + sname.toString()); System.out.println("\t sname is " + sname.toString());
} }
...@@ -458,14 +442,12 @@ public class KRBError implements java.io.Serializable { ...@@ -458,14 +442,12 @@ public class KRBError implements java.io.Serializable {
temp.putInteger(BigInteger.valueOf(errorCode)); temp.putInteger(BigInteger.valueOf(errorCode));
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), temp);
if (crealm != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), crealm.asn1Encode());
}
if (cname != null) { if (cname != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), cname.getRealm().asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), cname.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), cname.asn1Encode());
} }
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), realm.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), sname.getRealm().asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), sname.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), sname.asn1Encode());
if (eText != null) { if (eText != null) {
...@@ -506,9 +488,7 @@ public class KRBError implements java.io.Serializable { ...@@ -506,9 +488,7 @@ public class KRBError implements java.io.Serializable {
isEqual(sTime, other.sTime) && isEqual(sTime, other.sTime) &&
isEqual(suSec, other.suSec) && isEqual(suSec, other.suSec) &&
errorCode == other.errorCode && errorCode == other.errorCode &&
isEqual(crealm, other.crealm) &&
isEqual(cname, other.cname) && isEqual(cname, other.cname) &&
isEqual(realm, other.realm) &&
isEqual(sname, other.sname) && isEqual(sname, other.sname) &&
isEqual(eText, other.eText) && isEqual(eText, other.eText) &&
java.util.Arrays.equals(eData, other.eData) && java.util.Arrays.equals(eData, other.eData) &&
...@@ -528,9 +508,7 @@ public class KRBError implements java.io.Serializable { ...@@ -528,9 +508,7 @@ public class KRBError implements java.io.Serializable {
if (sTime != null) result = 37 * result + sTime.hashCode(); if (sTime != null) result = 37 * result + sTime.hashCode();
if (suSec != null) result = 37 * result + suSec.hashCode(); if (suSec != null) result = 37 * result + suSec.hashCode();
result = 37 * result + errorCode; result = 37 * result + errorCode;
if (crealm != null) result = 37 * result + crealm.hashCode();
if (cname != null) result = 37 * result + cname.hashCode(); if (cname != null) result = 37 * result + cname.hashCode();
if (realm != null) result = 37 * result + realm.hashCode();
if (sname != null) result = 37 * result + sname.hashCode(); if (sname != null) result = 37 * result + sname.hashCode();
if (eText != null) result = 37 * result + eText.hashCode(); if (eText != null) result = 37 * result + eText.hashCode();
result = 37 * result + Arrays.hashCode(eData); result = 37 * result + Arrays.hashCode(eData);
......
...@@ -63,14 +63,12 @@ import java.io.IOException; ...@@ -63,14 +63,12 @@ import java.io.IOException;
public class KrbCredInfo { public class KrbCredInfo {
public EncryptionKey key; public EncryptionKey key;
public Realm prealm; //optional
public PrincipalName pname; //optional public PrincipalName pname; //optional
public TicketFlags flags; //optional public TicketFlags flags; //optional
public KerberosTime authtime; //optional public KerberosTime authtime; //optional
public KerberosTime starttime; //optional public KerberosTime starttime; //optional
public KerberosTime endtime; //optional public KerberosTime endtime; //optional
public KerberosTime renewTill; //optional public KerberosTime renewTill; //optional
public Realm srealm; //optional
public PrincipalName sname; //optional public PrincipalName sname; //optional
public HostAddresses caddr; //optional public HostAddresses caddr; //optional
...@@ -79,26 +77,22 @@ public class KrbCredInfo { ...@@ -79,26 +77,22 @@ public class KrbCredInfo {
public KrbCredInfo( public KrbCredInfo(
EncryptionKey new_key, EncryptionKey new_key,
Realm new_prealm,
PrincipalName new_pname, PrincipalName new_pname,
TicketFlags new_flags, TicketFlags new_flags,
KerberosTime new_authtime, KerberosTime new_authtime,
KerberosTime new_starttime, KerberosTime new_starttime,
KerberosTime new_endtime, KerberosTime new_endtime,
KerberosTime new_renewTill, KerberosTime new_renewTill,
Realm new_srealm,
PrincipalName new_sname, PrincipalName new_sname,
HostAddresses new_caddr HostAddresses new_caddr
) { ) {
key = new_key; key = new_key;
prealm = new_prealm;
pname = new_pname; pname = new_pname;
flags = new_flags; flags = new_flags;
authtime = new_authtime; authtime = new_authtime;
starttime = new_starttime; starttime = new_starttime;
endtime = new_endtime; endtime = new_endtime;
renewTill = new_renewTill; renewTill = new_renewTill;
srealm = new_srealm;
sname = new_sname; sname = new_sname;
caddr = new_caddr; caddr = new_caddr;
} }
...@@ -115,21 +109,20 @@ public class KrbCredInfo { ...@@ -115,21 +109,20 @@ public class KrbCredInfo {
if (encoding.getTag() != DerValue.tag_Sequence) { if (encoding.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
prealm = null;
pname = null; pname = null;
flags = null; flags = null;
authtime = null; authtime = null;
starttime = null; starttime = null;
endtime = null; endtime = null;
renewTill = null; renewTill = null;
srealm = null;
sname = null; sname = null;
caddr = null; caddr = null;
key = EncryptionKey.parse(encoding.getData(), (byte)0x00, false); key = EncryptionKey.parse(encoding.getData(), (byte)0x00, false);
Realm prealm = null, srealm = null;
if (encoding.getData().available() > 0) if (encoding.getData().available() > 0)
prealm = Realm.parse(encoding.getData(), (byte)0x01, true); prealm = Realm.parse(encoding.getData(), (byte)0x01, true);
if (encoding.getData().available() > 0) if (encoding.getData().available() > 0)
pname = PrincipalName.parse(encoding.getData(), (byte)0x02, true); pname = PrincipalName.parse(encoding.getData(), (byte)0x02, true, prealm);
if (encoding.getData().available() > 0) if (encoding.getData().available() > 0)
flags = TicketFlags.parse(encoding.getData(), (byte)0x03, true); flags = TicketFlags.parse(encoding.getData(), (byte)0x03, true);
if (encoding.getData().available() > 0) if (encoding.getData().available() > 0)
...@@ -143,7 +136,7 @@ public class KrbCredInfo { ...@@ -143,7 +136,7 @@ public class KrbCredInfo {
if (encoding.getData().available() > 0) if (encoding.getData().available() > 0)
srealm = Realm.parse(encoding.getData(), (byte)0x08, true); srealm = Realm.parse(encoding.getData(), (byte)0x08, true);
if (encoding.getData().available() > 0) if (encoding.getData().available() > 0)
sname = PrincipalName.parse(encoding.getData(), (byte)0x09, true); sname = PrincipalName.parse(encoding.getData(), (byte)0x09, true, srealm);
if (encoding.getData().available() > 0) if (encoding.getData().available() > 0)
caddr = HostAddresses.parse(encoding.getData(), (byte)0x0A, true); caddr = HostAddresses.parse(encoding.getData(), (byte)0x0A, true);
if (encoding.getData().available() > 0) if (encoding.getData().available() > 0)
...@@ -159,10 +152,10 @@ public class KrbCredInfo { ...@@ -159,10 +152,10 @@ public class KrbCredInfo {
public byte[] asn1Encode() throws Asn1Exception, IOException { public byte[] asn1Encode() throws Asn1Exception, IOException {
Vector<DerValue> v = new Vector<>(); Vector<DerValue> v = new Vector<>();
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), key.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), key.asn1Encode()));
if (prealm != null) if (pname != null) {
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), prealm.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), pname.getRealm().asn1Encode()));
if (pname != null)
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), pname.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), pname.asn1Encode()));
}
if (flags != null) if (flags != null)
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), flags.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), flags.asn1Encode()));
if (authtime != null) if (authtime != null)
...@@ -173,10 +166,10 @@ public class KrbCredInfo { ...@@ -173,10 +166,10 @@ public class KrbCredInfo {
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), endtime.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), endtime.asn1Encode()));
if (renewTill != null) if (renewTill != null)
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), renewTill.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), renewTill.asn1Encode()));
if (srealm != null) if (sname != null) {
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), srealm.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), sname.getRealm().asn1Encode()));
if (sname != null)
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), sname.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), sname.asn1Encode()));
}
if (caddr != null) if (caddr != null)
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), caddr.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), caddr.asn1Encode()));
DerValue der[] = new DerValue[v.size()]; DerValue der[] = new DerValue[v.size()];
...@@ -190,8 +183,6 @@ public class KrbCredInfo { ...@@ -190,8 +183,6 @@ public class KrbCredInfo {
KrbCredInfo kcred = new KrbCredInfo(); KrbCredInfo kcred = new KrbCredInfo();
kcred.key = (EncryptionKey)key.clone(); kcred.key = (EncryptionKey)key.clone();
// optional fields // optional fields
if (prealm != null)
kcred.prealm = (Realm)prealm.clone();
if (pname != null) if (pname != null)
kcred.pname = (PrincipalName)pname.clone(); kcred.pname = (PrincipalName)pname.clone();
if (flags != null) if (flags != null)
...@@ -204,8 +195,6 @@ public class KrbCredInfo { ...@@ -204,8 +195,6 @@ public class KrbCredInfo {
kcred.endtime = (KerberosTime)endtime.clone(); kcred.endtime = (KerberosTime)endtime.clone();
if (renewTill != null) if (renewTill != null)
kcred.renewTill = (KerberosTime)renewTill.clone(); kcred.renewTill = (KerberosTime)renewTill.clone();
if (srealm != null)
kcred.srealm = (Realm)srealm.clone();
if (sname != null) if (sname != null)
kcred.sname = (PrincipalName)sname.clone(); kcred.sname = (PrincipalName)sname.clone();
if (caddr != null) if (caddr != null)
......
...@@ -42,12 +42,11 @@ public class TGSRep extends KDCRep { ...@@ -42,12 +42,11 @@ public class TGSRep extends KDCRep {
public TGSRep( public TGSRep(
PAData[] new_pAData, PAData[] new_pAData,
Realm new_crealm,
PrincipalName new_cname, PrincipalName new_cname,
Ticket new_ticket, Ticket new_ticket,
EncryptedData new_encPart EncryptedData new_encPart
) throws IOException { ) throws IOException {
super(new_pAData, new_crealm, new_cname, new_ticket, super(new_pAData, new_cname, new_ticket,
new_encPart, Krb5.KRB_TGS_REP); new_encPart, Krb5.KRB_TGS_REP);
} }
......
...@@ -60,7 +60,6 @@ import java.math.BigInteger; ...@@ -60,7 +60,6 @@ import java.math.BigInteger;
public class Ticket implements Cloneable { public class Ticket implements Cloneable {
public int tkt_vno; public int tkt_vno;
public Realm realm;
public PrincipalName sname; public PrincipalName sname;
public EncryptedData encPart; public EncryptedData encPart;
...@@ -69,7 +68,6 @@ public class Ticket implements Cloneable { ...@@ -69,7 +68,6 @@ public class Ticket implements Cloneable {
public Object clone() { public Object clone() {
Ticket new_ticket = new Ticket(); Ticket new_ticket = new Ticket();
new_ticket.realm = (Realm)realm.clone();
new_ticket.sname = (PrincipalName)sname.clone(); new_ticket.sname = (PrincipalName)sname.clone();
new_ticket.encPart = (EncryptedData)encPart.clone(); new_ticket.encPart = (EncryptedData)encPart.clone();
new_ticket.tkt_vno = tkt_vno; new_ticket.tkt_vno = tkt_vno;
...@@ -77,12 +75,10 @@ public class Ticket implements Cloneable { ...@@ -77,12 +75,10 @@ public class Ticket implements Cloneable {
} }
public Ticket( public Ticket(
Realm new_realm,
PrincipalName new_sname, PrincipalName new_sname,
EncryptedData new_encPart EncryptedData new_encPart
) { ) {
tkt_vno = Krb5.TICKET_VNO; tkt_vno = Krb5.TICKET_VNO;
realm = new_realm;
sname = new_sname; sname = new_sname;
encPart = new_encPart; encPart = new_encPart;
} }
...@@ -123,8 +119,8 @@ public class Ticket implements Cloneable { ...@@ -123,8 +119,8 @@ public class Ticket implements Cloneable {
tkt_vno = subDer.getData().getBigInteger().intValue(); tkt_vno = subDer.getData().getBigInteger().intValue();
if (tkt_vno != Krb5.TICKET_VNO) if (tkt_vno != Krb5.TICKET_VNO)
throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION); throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
realm = Realm.parse(der.getData(), (byte)0x01, false); Realm srealm = Realm.parse(der.getData(), (byte)0x01, false);
sname = PrincipalName.parse(der.getData(), (byte)0x02, false); sname = PrincipalName.parse(der.getData(), (byte)0x02, false, srealm);
encPart = EncryptedData.parse(der.getData(), (byte)0x03, false); encPart = EncryptedData.parse(der.getData(), (byte)0x03, false);
if (der.getData().available() > 0) if (der.getData().available() > 0)
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
...@@ -142,7 +138,7 @@ public class Ticket implements Cloneable { ...@@ -142,7 +138,7 @@ public class Ticket implements Cloneable {
DerValue der[] = new DerValue[4]; DerValue der[] = new DerValue[4];
temp.putInteger(BigInteger.valueOf(tkt_vno)); temp.putInteger(BigInteger.valueOf(tkt_vno));
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), realm.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), sname.getRealm().asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), sname.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), sname.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), encPart.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), encPart.asn1Encode());
temp = new DerOutputStream(); temp = new DerOutputStream();
......
...@@ -114,7 +114,6 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC ...@@ -114,7 +114,6 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC
// made public for KinitOptions to call directly // made public for KinitOptions to call directly
public PrincipalName readPrincipal(int version) throws IOException, RealmException { public PrincipalName readPrincipal(int version) throws IOException, RealmException {
int type, length, namelength, kret; int type, length, namelength, kret;
PrincipalName p;
String[] pname = null; String[] pname = null;
String realm; String realm;
/* Read principal type */ /* Read principal type */
...@@ -144,11 +143,13 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC ...@@ -144,11 +143,13 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC
realm = result[0]; realm = result[0];
pname = new String[length]; pname = new String[length];
System.arraycopy(result, 1, pname, 0, length); System.arraycopy(result, 1, pname, 0, length);
p = new PrincipalName(pname, type); return new PrincipalName(type, pname, new Realm(realm));
p.setRealm(realm); }
try {
return new PrincipalName(result, type);
} catch (RealmException re) {
return null;
} }
else p = new PrincipalName(result, type);
return p;
} }
/* /*
...@@ -342,10 +343,10 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC ...@@ -342,10 +343,10 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC
Credentials readCred(int version) throws IOException,RealmException, KrbApErrException, Asn1Exception { Credentials readCred(int version) throws IOException,RealmException, KrbApErrException, Asn1Exception {
PrincipalName cpname = readPrincipal(version); PrincipalName cpname = readPrincipal(version);
if (DEBUG) if (DEBUG)
System.out.println(">>>DEBUG <CCacheInputStream> client principal is " + cpname.toString()); System.out.println(">>>DEBUG <CCacheInputStream> client principal is " + cpname);
PrincipalName spname = readPrincipal(version); PrincipalName spname = readPrincipal(version);
if (DEBUG) if (DEBUG)
System.out.println(">>>DEBUG <CCacheInputStream> server principal is " + spname.toString()); System.out.println(">>>DEBUG <CCacheInputStream> server principal is " + spname);
EncryptionKey key = readKey(version); EncryptionKey key = readKey(version);
if (DEBUG) if (DEBUG)
System.out.println(">>>DEBUG <CCacheInputStream> key type: " + key.getEType()); System.out.println(">>>DEBUG <CCacheInputStream> key type: " + key.getEType());
......
...@@ -36,9 +36,7 @@ import sun.security.krb5.internal.*; ...@@ -36,9 +36,7 @@ import sun.security.krb5.internal.*;
public class Credentials { public class Credentials {
PrincipalName cname; PrincipalName cname;
Realm crealm;
PrincipalName sname; PrincipalName sname;
Realm srealm;
EncryptionKey key; EncryptionKey key;
KerberosTime authtime; KerberosTime authtime;
KerberosTime starttime;//optional KerberosTime starttime;//optional
...@@ -67,15 +65,7 @@ public class Credentials { ...@@ -67,15 +65,7 @@ public class Credentials {
Ticket new_ticket, Ticket new_ticket,
Ticket new_secondTicket) { Ticket new_secondTicket) {
cname = (PrincipalName) new_cname.clone(); cname = (PrincipalName) new_cname.clone();
if (new_cname.getRealm() != null) {
crealm = (Realm) new_cname.getRealm().clone();
}
sname = (PrincipalName) new_sname.clone(); sname = (PrincipalName) new_sname.clone();
if (new_sname.getRealm() != null) {
srealm = (Realm) new_sname.getRealm().clone();
}
key = (EncryptionKey) new_key.clone(); key = (EncryptionKey) new_key.clone();
authtime = (KerberosTime) new_authtime.clone(); authtime = (KerberosTime) new_authtime.clone();
...@@ -110,7 +100,6 @@ public class Credentials { ...@@ -110,7 +100,6 @@ public class Credentials {
{ {
return; return;
} }
crealm = (Realm) kdcRep.crealm.clone();
cname = (PrincipalName) kdcRep.cname.clone(); cname = (PrincipalName) kdcRep.cname.clone();
ticket = (Ticket) kdcRep.ticket.clone(); ticket = (Ticket) kdcRep.ticket.clone();
key = (EncryptionKey) kdcRep.encKDCRepPart.key.clone(); key = (EncryptionKey) kdcRep.encKDCRepPart.key.clone();
...@@ -123,7 +112,6 @@ public class Credentials { ...@@ -123,7 +112,6 @@ public class Credentials {
if (kdcRep.encKDCRepPart.renewTill != null) { if (kdcRep.encKDCRepPart.renewTill != null) {
renewTill = (KerberosTime) kdcRep.encKDCRepPart.renewTill.clone(); renewTill = (KerberosTime) kdcRep.encKDCRepPart.renewTill.clone();
} }
srealm = (Realm) kdcRep.encKDCRepPart.srealm.clone();
sname = (PrincipalName) kdcRep.encKDCRepPart.sname.clone(); sname = (PrincipalName) kdcRep.encKDCRepPart.sname.clone();
caddr = (HostAddresses) kdcRep.encKDCRepPart.caddr.clone(); caddr = (HostAddresses) kdcRep.encKDCRepPart.caddr.clone();
secondTicket = (Ticket) new_secondTicket.clone(); secondTicket = (Ticket) new_secondTicket.clone();
...@@ -138,17 +126,7 @@ public class Credentials { ...@@ -138,17 +126,7 @@ public class Credentials {
public Credentials(KDCRep kdcRep, Ticket new_ticket) { public Credentials(KDCRep kdcRep, Ticket new_ticket) {
sname = (PrincipalName) kdcRep.encKDCRepPart.sname.clone(); sname = (PrincipalName) kdcRep.encKDCRepPart.sname.clone();
srealm = (Realm) kdcRep.encKDCRepPart.srealm.clone();
try {
sname.setRealm(srealm);
} catch (RealmException e) {
}
cname = (PrincipalName) kdcRep.cname.clone(); cname = (PrincipalName) kdcRep.cname.clone();
crealm = (Realm) kdcRep.crealm.clone();
try {
cname.setRealm(crealm);
} catch (RealmException e) {
}
key = (EncryptionKey) kdcRep.encKDCRepPart.key.clone(); key = (EncryptionKey) kdcRep.encKDCRepPart.key.clone();
authtime = (KerberosTime) kdcRep.encKDCRepPart.authtime.clone(); authtime = (KerberosTime) kdcRep.encKDCRepPart.authtime.clone();
if (kdcRep.encKDCRepPart.starttime != null) { if (kdcRep.encKDCRepPart.starttime != null) {
...@@ -202,9 +180,6 @@ public class Credentials { ...@@ -202,9 +180,6 @@ public class Credentials {
} }
public PrincipalName getServicePrincipal() throws RealmException { public PrincipalName getServicePrincipal() throws RealmException {
if (sname.getRealm() == null) {
sname.setRealm(srealm);
}
return sname; return sname;
} }
......
...@@ -120,6 +120,6 @@ public abstract class CredentialsCache { ...@@ -120,6 +120,6 @@ public abstract class CredentialsCache {
public abstract void save() throws IOException, KrbException; public abstract void save() throws IOException, KrbException;
public abstract Credentials[] getCredsList(); public abstract Credentials[] getCredsList();
public abstract Credentials getDefaultCreds(); public abstract Credentials getDefaultCreds();
public abstract Credentials getCreds(PrincipalName sname, Realm srealm) ; public abstract Credentials getCreds(PrincipalName sname);
public abstract Credentials getCreds(LoginOptions options, PrincipalName sname, Realm srealm) ; public abstract Credentials getCreds(LoginOptions options, PrincipalName sname);
} }
...@@ -59,7 +59,6 @@ public class FileCredentialsCache extends CredentialsCache ...@@ -59,7 +59,6 @@ public class FileCredentialsCache extends CredentialsCache
public int version; public int version;
public Tag tag; // optional public Tag tag; // optional
public PrincipalName primaryPrincipal; public PrincipalName primaryPrincipal;
public Realm primaryRealm;
private Vector<Credentials> credentialsList; private Vector<Credentials> credentialsList;
private static String dir; private static String dir;
private static boolean DEBUG = Krb5.DEBUG; private static boolean DEBUG = Krb5.DEBUG;
...@@ -79,7 +78,6 @@ public class FileCredentialsCache extends CredentialsCache ...@@ -79,7 +78,6 @@ public class FileCredentialsCache extends CredentialsCache
} }
if (principal != null) { if (principal != null) {
fcc.primaryPrincipal = principal; fcc.primaryPrincipal = principal;
fcc.primaryRealm = principal.getRealm();
} }
fcc.load(cacheName); fcc.load(cacheName);
return fcc; return fcc;
...@@ -153,7 +151,6 @@ public class FileCredentialsCache extends CredentialsCache ...@@ -153,7 +151,6 @@ public class FileCredentialsCache extends CredentialsCache
synchronized void init(PrincipalName principal, String name) synchronized void init(PrincipalName principal, String name)
throws IOException, KrbException { throws IOException, KrbException {
primaryPrincipal = principal; primaryPrincipal = principal;
primaryRealm = principal.getRealm();
CCacheOutputStream cos = CCacheOutputStream cos =
new CCacheOutputStream(new FileOutputStream(name)); new CCacheOutputStream(new FileOutputStream(name));
version = KRB5_FCC_FVNO_3; version = KRB5_FCC_FVNO_3;
...@@ -183,7 +180,6 @@ public class FileCredentialsCache extends CredentialsCache ...@@ -183,7 +180,6 @@ public class FileCredentialsCache extends CredentialsCache
} }
} else } else
primaryPrincipal = p; primaryPrincipal = p;
primaryRealm = primaryPrincipal.getRealm();
credentialsList = new Vector<Credentials> (); credentialsList = new Vector<Credentials> ();
while (cis.available() > 0) { while (cis.available() > 0) {
Credentials cred = cis.readCred(version); Credentials cred = cis.readCred(version);
...@@ -291,18 +287,16 @@ public class FileCredentialsCache extends CredentialsCache ...@@ -291,18 +287,16 @@ public class FileCredentialsCache extends CredentialsCache
} }
public Credentials getCreds(LoginOptions options, public Credentials getCreds(LoginOptions options, PrincipalName sname) {
PrincipalName sname, Realm srealm) {
if (options == null) { if (options == null) {
return getCreds(sname, srealm); return getCreds(sname);
} else { } else {
Credentials[] list = getCredsList(); Credentials[] list = getCredsList();
if (list == null) { if (list == null) {
return null; return null;
} else { } else {
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
if (sname.match(list[i].sname) && if (sname.match(list[i].sname)) {
(srealm.toString().equals(list[i].srealm.toString()))) {
if (list[i].flags.match(options)) { if (list[i].flags.match(options)) {
return list[i]; return list[i];
} }
...@@ -317,16 +311,14 @@ public class FileCredentialsCache extends CredentialsCache ...@@ -317,16 +311,14 @@ public class FileCredentialsCache extends CredentialsCache
/** /**
* Gets a credentials for a specified service. * Gets a credentials for a specified service.
* @param sname service principal name. * @param sname service principal name.
* @param srealm the realm that the service belongs to.
*/ */
public Credentials getCreds(PrincipalName sname, Realm srealm) { public Credentials getCreds(PrincipalName sname) {
Credentials[] list = getCredsList(); Credentials[] list = getCredsList();
if (list == null) { if (list == null) {
return null; return null;
} else { } else {
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
if (sname.match(list[i].sname) && if (sname.match(list[i].sname)) {
(srealm.toString().equals(list[i].srealm.toString()))) {
return list[i]; return list[i];
} }
} }
...@@ -343,7 +335,7 @@ public class FileCredentialsCache extends CredentialsCache ...@@ -343,7 +335,7 @@ public class FileCredentialsCache extends CredentialsCache
if (list[i].sname.toString().startsWith("krbtgt")) { if (list[i].sname.toString().startsWith("krbtgt")) {
String[] nameStrings = list[i].sname.getNameStrings(); String[] nameStrings = list[i].sname.getNameStrings();
// find the TGT for the current realm krbtgt/realm@realm // find the TGT for the current realm krbtgt/realm@realm
if (nameStrings[1].equals(list[i].srealm.toString())) { if (nameStrings[1].equals(list[i].sname.getRealm().toString())) {
return list[i]; return list[i];
} }
} }
......
...@@ -64,7 +64,7 @@ public abstract class MemoryCredentialsCache extends CredentialsCache { ...@@ -64,7 +64,7 @@ public abstract class MemoryCredentialsCache extends CredentialsCache {
public abstract Credentials[] getCredsList(); public abstract Credentials[] getCredsList();
public abstract Credentials getCreds(PrincipalName sname, Realm srealm) ; public abstract Credentials getCreds(PrincipalName sname) ;
public abstract PrincipalName getPrimaryPrincipal(); public abstract PrincipalName getPrimaryPrincipal();
......
...@@ -83,8 +83,7 @@ public class KeyTabInputStream extends KrbDataInputStream implements KeyTabConst ...@@ -83,8 +83,7 @@ public class KeyTabInputStream extends KrbDataInputStream implements KeyTabConst
} }
int nameType = read(4); int nameType = read(4);
index -= 4; index -= 4;
PrincipalName service = new PrincipalName(nameParts, nameType); PrincipalName service = new PrincipalName(nameType, nameParts, realm);
service.setRealm(realm);
KerberosTime timeStamp = readTimeStamp(); KerberosTime timeStamp = readTimeStamp();
int keyVersion = read() & 0xff; int keyVersion = read() & 0xff;
......
...@@ -163,7 +163,7 @@ public final class KerberosClientKeyExchangeImpl ...@@ -163,7 +163,7 @@ public final class KerberosClientKeyExchangeImpl
EncryptedData encPart = t.encPart; EncryptedData encPart = t.encPart;
PrincipalName ticketSname = t.sname; PrincipalName ticketSname = t.sname;
Realm ticketRealm = t.realm; Realm ticketRealm = t.sname.getRealm();
String serverPrincipal = serverKeys[0].getPrincipal().getName(); String serverPrincipal = serverKeys[0].getPrincipal().getName();
...@@ -175,8 +175,7 @@ public final class KerberosClientKeyExchangeImpl ...@@ -175,8 +175,7 @@ public final class KerberosClientKeyExchangeImpl
*/ */
// Check that ticket Sname matches serverPrincipal // Check that ticket Sname matches serverPrincipal
String ticketPrinc = ticketSname.toString().concat("@" + String ticketPrinc = ticketSname.toString();
ticketRealm.toString());
if (!ticketPrinc.equals(serverPrincipal)) { if (!ticketPrinc.equals(serverPrincipal)) {
if (debug != null && Debug.isOn("handshake")) if (debug != null && Debug.isOn("handshake"))
System.out.println("Service principal in Ticket does not" System.out.println("Service principal in Ticket does not"
...@@ -224,7 +223,6 @@ public final class KerberosClientKeyExchangeImpl ...@@ -224,7 +223,6 @@ public final class KerberosClientKeyExchangeImpl
if (debug != null && Debug.isOn("handshake")) { if (debug != null && Debug.isOn("handshake")) {
System.out.println("server principal: " + serverPrincipal); System.out.println("server principal: " + serverPrincipal);
System.out.println("realm: " + encTicketPart.crealm.toString());
System.out.println("cname: " + encTicketPart.cname.toString()); System.out.println("cname: " + encTicketPart.cname.toString());
} }
} catch (IOException e) { } catch (IOException e) {
......
/* /*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -55,7 +55,7 @@ class LinuxUserDefinedFileAttributeView ...@@ -55,7 +55,7 @@ class LinuxUserDefinedFileAttributeView
name = USER_NAMESPACE + name; name = USER_NAMESPACE + name;
byte[] bytes = name.getBytes(); byte[] bytes = name.getBytes();
if (bytes.length > XATTR_NAME_MAX) { if (bytes.length > XATTR_NAME_MAX) {
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, "'" + name + "' is too big"); null, "'" + name + "' is too big");
} }
return bytes; return bytes;
...@@ -116,7 +116,7 @@ class LinuxUserDefinedFileAttributeView ...@@ -116,7 +116,7 @@ class LinuxUserDefinedFileAttributeView
buffer = NativeBuffers.getNativeBuffer(size); buffer = NativeBuffers.getNativeBuffer(size);
continue; continue;
} }
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, "Unable to get list of extended attributes: " + null, "Unable to get list of extended attributes: " +
x.getMessage()); x.getMessage());
} }
...@@ -138,7 +138,7 @@ class LinuxUserDefinedFileAttributeView ...@@ -138,7 +138,7 @@ class LinuxUserDefinedFileAttributeView
// fgetxattr returns size if called with size==0 // fgetxattr returns size if called with size==0
return fgetxattr(fd, nameAsBytes(file,name), 0L, 0); return fgetxattr(fd, nameAsBytes(file,name), 0L, 0);
} catch (UnixException x) { } catch (UnixException x) {
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, "Unable to get size of extended attribute '" + name + null, "Unable to get size of extended attribute '" + name +
"': " + x.getMessage()); "': " + x.getMessage());
} finally { } finally {
...@@ -191,7 +191,7 @@ class LinuxUserDefinedFileAttributeView ...@@ -191,7 +191,7 @@ class LinuxUserDefinedFileAttributeView
} catch (UnixException x) { } catch (UnixException x) {
String msg = (x.errno() == ERANGE) ? String msg = (x.errno() == ERANGE) ?
"Insufficient space in buffer" : x.getMessage(); "Insufficient space in buffer" : x.getMessage();
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, "Error reading extended attribute '" + name + "': " + msg); null, "Error reading extended attribute '" + name + "': " + msg);
} finally { } finally {
close(fd); close(fd);
...@@ -243,7 +243,7 @@ class LinuxUserDefinedFileAttributeView ...@@ -243,7 +243,7 @@ class LinuxUserDefinedFileAttributeView
src.position(pos + rem); src.position(pos + rem);
return rem; return rem;
} catch (UnixException x) { } catch (UnixException x) {
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, "Error writing extended attribute '" + name + "': " + null, "Error writing extended attribute '" + name + "': " +
x.getMessage()); x.getMessage());
} finally { } finally {
...@@ -264,7 +264,7 @@ class LinuxUserDefinedFileAttributeView ...@@ -264,7 +264,7 @@ class LinuxUserDefinedFileAttributeView
try { try {
fremovexattr(fd, nameAsBytes(file,name)); fremovexattr(fd, nameAsBytes(file,name));
} catch (UnixException x) { } catch (UnixException x) {
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, "Unable to delete extended attribute '" + name + "': " + x.getMessage()); null, "Unable to delete extended attribute '" + name + "': " + x.getMessage());
} finally { } finally {
close(fd); close(fd);
......
/* /*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -246,7 +246,7 @@ class LinuxWatchService ...@@ -246,7 +246,7 @@ class LinuxWatchService
return x.asIOException(dir); return x.asIOException(dir);
} }
if (!attrs.isDirectory()) { if (!attrs.isDirectory()) {
return new NotDirectoryException(dir.getPathForExecptionMessage()); return new NotDirectoryException(dir.getPathForExceptionMessage());
} }
// register with inotify (replaces existing mask if already registered) // register with inotify (replaces existing mask if already registered)
......
/* /*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -324,7 +324,7 @@ class SolarisAclFileAttributeView ...@@ -324,7 +324,7 @@ class SolarisAclFileAttributeView
return decode(address, n); return decode(address, n);
} catch (UnixException x) { } catch (UnixException x) {
if ((x.errno() == ENOSYS) || !isAclsEnabled(fd)) { if ((x.errno() == ENOSYS) || !isAclsEnabled(fd)) {
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, x.getMessage() + " (file system does not support NFSv4 ACLs)"); null, x.getMessage() + " (file system does not support NFSv4 ACLs)");
} }
x.rethrowAsIOException(file); x.rethrowAsIOException(file);
...@@ -355,7 +355,7 @@ class SolarisAclFileAttributeView ...@@ -355,7 +355,7 @@ class SolarisAclFileAttributeView
facl(fd, ACE_SETACL, n, address); facl(fd, ACE_SETACL, n, address);
} catch (UnixException x) { } catch (UnixException x) {
if ((x.errno() == ENOSYS) || !isAclsEnabled(fd)) { if ((x.errno() == ENOSYS) || !isAclsEnabled(fd)) {
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, x.getMessage() + " (file system does not support NFSv4 ACLs)"); null, x.getMessage() + " (file system does not support NFSv4 ACLs)");
} }
if (x.errno() == EINVAL && (n < 3)) if (x.errno() == EINVAL && (n < 3))
......
/* /*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -49,7 +49,7 @@ class SolarisUserDefinedFileAttributeView ...@@ -49,7 +49,7 @@ class SolarisUserDefinedFileAttributeView
if (bytes.length <= 1 || if (bytes.length <= 1 ||
(bytes.length == 2 && bytes[1] == '.')) (bytes.length == 2 && bytes[1] == '.'))
{ {
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, "'" + name + "' is not a valid name"); null, "'" + name + "' is not a valid name");
} }
} }
...@@ -96,7 +96,7 @@ class SolarisUserDefinedFileAttributeView ...@@ -96,7 +96,7 @@ class SolarisUserDefinedFileAttributeView
} }
return Collections.unmodifiableList(list); return Collections.unmodifiableList(list);
} catch (UnixException x) { } catch (UnixException x) {
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, "Unable to get list of extended attributes: " + null, "Unable to get list of extended attributes: " +
x.getMessage()); x.getMessage());
} }
...@@ -126,7 +126,7 @@ class SolarisUserDefinedFileAttributeView ...@@ -126,7 +126,7 @@ class SolarisUserDefinedFileAttributeView
close(afd); close(afd);
} }
} catch (UnixException x) { } catch (UnixException x) {
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, "Unable to get size of extended attribute '" + name + null, "Unable to get size of extended attribute '" + name +
"': " + x.getMessage()); "': " + x.getMessage());
} }
...@@ -165,7 +165,7 @@ class SolarisUserDefinedFileAttributeView ...@@ -165,7 +165,7 @@ class SolarisUserDefinedFileAttributeView
fc.close(); fc.close();
} }
} catch (UnixException x) { } catch (UnixException x) {
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, "Unable to read extended attribute '" + name + null, "Unable to read extended attribute '" + name +
"': " + x.getMessage()); "': " + x.getMessage());
} }
...@@ -201,7 +201,7 @@ class SolarisUserDefinedFileAttributeView ...@@ -201,7 +201,7 @@ class SolarisUserDefinedFileAttributeView
fc.close(); fc.close();
} }
} catch (UnixException x) { } catch (UnixException x) {
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, "Unable to write extended attribute '" + name + null, "Unable to write extended attribute '" + name +
"': " + x.getMessage()); "': " + x.getMessage());
} }
...@@ -224,7 +224,7 @@ class SolarisUserDefinedFileAttributeView ...@@ -224,7 +224,7 @@ class SolarisUserDefinedFileAttributeView
close(dfd); close(dfd);
} }
} catch (UnixException x) { } catch (UnixException x) {
throw new FileSystemException(file.getPathForExecptionMessage(), throw new FileSystemException(file.getPathForExceptionMessage(),
null, "Unable to delete extended attribute '" + name + null, "Unable to delete extended attribute '" + name +
"': " + x.getMessage()); "': " + x.getMessage());
} finally { } finally {
......
/* /*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -288,7 +288,7 @@ class SolarisWatchService ...@@ -288,7 +288,7 @@ class SolarisWatchService
return x.asIOException(dir); return x.asIOException(dir);
} }
if (!attrs.isDirectory()) { if (!attrs.isDirectory()) {
return new NotDirectoryException(dir.getPathForExecptionMessage()); return new NotDirectoryException(dir.getPathForExceptionMessage());
} }
// return existing watch key after updating events if already // return existing watch key after updating events if already
......
/* /*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -383,8 +383,8 @@ class UnixCopyFile { ...@@ -383,8 +383,8 @@ class UnixCopyFile {
} catch (UnixException x) { } catch (UnixException x) {
if (x.errno() == EXDEV) { if (x.errno() == EXDEV) {
throw new AtomicMoveNotSupportedException( throw new AtomicMoveNotSupportedException(
source.getPathForExecptionMessage(), source.getPathForExceptionMessage(),
target.getPathForExecptionMessage(), target.getPathForExceptionMessage(),
x.errorString()); x.errorString());
} }
x.rethrowAsIOException(source, target); x.rethrowAsIOException(source, target);
...@@ -420,7 +420,7 @@ class UnixCopyFile { ...@@ -420,7 +420,7 @@ class UnixCopyFile {
return; // nothing to do as files are identical return; // nothing to do as files are identical
if (!flags.replaceExisting) { if (!flags.replaceExisting) {
throw new FileAlreadyExistsException( throw new FileAlreadyExistsException(
target.getPathForExecptionMessage()); target.getPathForExceptionMessage());
} }
// attempt to delete target // attempt to delete target
...@@ -436,7 +436,7 @@ class UnixCopyFile { ...@@ -436,7 +436,7 @@ class UnixCopyFile {
(x.errno() == EEXIST || x.errno() == ENOTEMPTY)) (x.errno() == EEXIST || x.errno() == ENOTEMPTY))
{ {
throw new DirectoryNotEmptyException( throw new DirectoryNotEmptyException(
target.getPathForExecptionMessage()); target.getPathForExceptionMessage());
} }
x.rethrowAsIOException(target); x.rethrowAsIOException(target);
} }
...@@ -489,7 +489,7 @@ class UnixCopyFile { ...@@ -489,7 +489,7 @@ class UnixCopyFile {
(x.errno() == EEXIST || x.errno() == ENOTEMPTY)) (x.errno() == EEXIST || x.errno() == ENOTEMPTY))
{ {
throw new DirectoryNotEmptyException( throw new DirectoryNotEmptyException(
source.getPathForExecptionMessage()); source.getPathForExceptionMessage());
} }
x.rethrowAsIOException(source); x.rethrowAsIOException(source);
} }
...@@ -542,7 +542,7 @@ class UnixCopyFile { ...@@ -542,7 +542,7 @@ class UnixCopyFile {
return; // nothing to do as files are identical return; // nothing to do as files are identical
if (!flags.replaceExisting) if (!flags.replaceExisting)
throw new FileAlreadyExistsException( throw new FileAlreadyExistsException(
target.getPathForExecptionMessage()); target.getPathForExceptionMessage());
try { try {
if (targetAttrs.isDirectory()) { if (targetAttrs.isDirectory()) {
rmdir(target); rmdir(target);
...@@ -555,7 +555,7 @@ class UnixCopyFile { ...@@ -555,7 +555,7 @@ class UnixCopyFile {
(x.errno() == EEXIST || x.errno() == ENOTEMPTY)) (x.errno() == EEXIST || x.errno() == ENOTEMPTY))
{ {
throw new DirectoryNotEmptyException( throw new DirectoryNotEmptyException(
target.getPathForExecptionMessage()); target.getPathForExceptionMessage());
} }
x.rethrowAsIOException(target); x.rethrowAsIOException(target);
} }
......
/* /*
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -97,8 +97,8 @@ class UnixException extends Exception { ...@@ -97,8 +97,8 @@ class UnixException extends Exception {
} }
void rethrowAsIOException(UnixPath file, UnixPath other) throws IOException { void rethrowAsIOException(UnixPath file, UnixPath other) throws IOException {
String a = (file == null) ? null : file.getPathForExecptionMessage(); String a = (file == null) ? null : file.getPathForExceptionMessage();
String b = (other == null) ? null : other.getPathForExecptionMessage(); String b = (other == null) ? null : other.getPathForExceptionMessage();
IOException x = translateToIOException(a, b); IOException x = translateToIOException(a, b);
throw x; throw x;
} }
...@@ -108,6 +108,6 @@ class UnixException extends Exception { ...@@ -108,6 +108,6 @@ class UnixException extends Exception {
} }
IOException asIOException(UnixPath file) { IOException asIOException(UnixPath file) {
return translateToIOException(file.getPathForExecptionMessage(), null); return translateToIOException(file.getPathForExceptionMessage(), null);
} }
} }
/* /*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -238,7 +238,7 @@ public abstract class UnixFileSystemProvider ...@@ -238,7 +238,7 @@ public abstract class UnixFileSystemProvider
// DirectoryNotEmptyException if not empty // DirectoryNotEmptyException if not empty
if (attrs != null && attrs.isDirectory() && if (attrs != null && attrs.isDirectory() &&
(x.errno() == EEXIST || x.errno() == ENOTEMPTY)) (x.errno() == EEXIST || x.errno() == ENOTEMPTY))
throw new DirectoryNotEmptyException(file.getPathForExecptionMessage()); throw new DirectoryNotEmptyException(file.getPathForExceptionMessage());
x.rethrowAsIOException(file); x.rethrowAsIOException(file);
return false; return false;
...@@ -401,7 +401,7 @@ public abstract class UnixFileSystemProvider ...@@ -401,7 +401,7 @@ public abstract class UnixFileSystemProvider
return new UnixDirectoryStream(dir, ptr, filter); return new UnixDirectoryStream(dir, ptr, filter);
} catch (UnixException x) { } catch (UnixException x) {
if (x.errno() == ENOTDIR) if (x.errno() == ENOTDIR)
throw new NotDirectoryException(dir.getPathForExecptionMessage()); throw new NotDirectoryException(dir.getPathForExceptionMessage());
x.rethrowAsIOException(dir); x.rethrowAsIOException(dir);
} }
} }
...@@ -421,7 +421,7 @@ public abstract class UnixFileSystemProvider ...@@ -421,7 +421,7 @@ public abstract class UnixFileSystemProvider
if (dfd2 != -1) if (dfd2 != -1)
UnixNativeDispatcher.close(dfd2); UnixNativeDispatcher.close(dfd2);
if (x.errno() == UnixConstants.ENOTDIR) if (x.errno() == UnixConstants.ENOTDIR)
throw new NotDirectoryException(dir.getPathForExecptionMessage()); throw new NotDirectoryException(dir.getPathForExceptionMessage());
x.rethrowAsIOException(dir); x.rethrowAsIOException(dir);
} }
return new UnixSecureDirectoryStream(dir, dp, dfd2, filter); return new UnixSecureDirectoryStream(dir, dp, dfd2, filter);
...@@ -490,7 +490,7 @@ public abstract class UnixFileSystemProvider ...@@ -490,7 +490,7 @@ public abstract class UnixFileSystemProvider
return new UnixPath(link.getFileSystem(), target); return new UnixPath(link.getFileSystem(), target);
} catch (UnixException x) { } catch (UnixException x) {
if (x.errno() == UnixConstants.EINVAL) if (x.errno() == UnixConstants.EINVAL)
throw new NotLinkException(link.getPathForExecptionMessage()); throw new NotLinkException(link.getPathForExceptionMessage());
x.rethrowAsIOException(link); x.rethrowAsIOException(link);
return null; // keep compiler happy return null; // keep compiler happy
} }
......
/* /*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -179,7 +179,7 @@ class UnixPath ...@@ -179,7 +179,7 @@ class UnixPath
} }
// use this message when throwing exceptions // use this message when throwing exceptions
String getPathForExecptionMessage() { String getPathForExceptionMessage() {
return toString(); return toString();
} }
...@@ -780,7 +780,7 @@ class UnixPath ...@@ -780,7 +780,7 @@ class UnixPath
x.setError(ELOOP); x.setError(ELOOP);
if (x.errno() == ELOOP) if (x.errno() == ELOOP)
throw new FileSystemException(getPathForExecptionMessage(), null, throw new FileSystemException(getPathForExceptionMessage(), null,
x.getMessage() + " or unable to access attributes of symbolic link"); x.getMessage() + " or unable to access attributes of symbolic link");
x.rethrowAsIOException(this); x.rethrowAsIOException(this);
......
...@@ -196,7 +196,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -196,7 +196,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
struct addrinfo *next struct addrinfo *next
= (struct addrinfo*) malloc(sizeof(struct addrinfo)); = (struct addrinfo*) malloc(sizeof(struct addrinfo));
if (!next) { if (!next) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
ret = NULL; ret = NULL;
goto cleanupAndReturn; goto cleanupAndReturn;
} }
...@@ -465,7 +465,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -465,7 +465,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
struct addrinfo *next struct addrinfo *next
= (struct addrinfo*) malloc(sizeof(struct addrinfo)); = (struct addrinfo*) malloc(sizeof(struct addrinfo));
if (!next) { if (!next) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
ret = NULL; ret = NULL;
goto cleanupAndReturn; goto cleanupAndReturn;
} }
......
...@@ -267,7 +267,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -267,7 +267,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
struct addrinfo *next struct addrinfo *next
= (struct addrinfo*) malloc(sizeof(struct addrinfo)); = (struct addrinfo*) malloc(sizeof(struct addrinfo));
if (!next) { if (!next) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
ret = NULL; ret = NULL;
goto cleanupAndReturn; goto cleanupAndReturn;
} }
......
...@@ -804,7 +804,7 @@ static netif *enumInterfaces(JNIEnv *env) { ...@@ -804,7 +804,7 @@ static netif *enumInterfaces(JNIEnv *env) {
do{ \ do{ \
_pointer = (_type)malloc( _size ); \ _pointer = (_type)malloc( _size ); \
if (_pointer == NULL) { \ if (_pointer == NULL) { \
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); \ JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed"); \
return ifs; /* return untouched list */ \ return ifs; /* return untouched list */ \
} \ } \
} while(0) } while(0)
......
...@@ -485,7 +485,7 @@ Java_java_net_PlainDatagramSocketImpl_send(JNIEnv *env, jobject this, ...@@ -485,7 +485,7 @@ Java_java_net_PlainDatagramSocketImpl_send(JNIEnv *env, jobject this,
fullPacket = (char *)malloc(packetBufferLen); fullPacket = (char *)malloc(packetBufferLen);
if (!fullPacket) { if (!fullPacket) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Send buffer native heap allocation failed");
return; return;
} else { } else {
mallocedPacket = JNI_TRUE; mallocedPacket = JNI_TRUE;
...@@ -714,7 +714,7 @@ Java_java_net_PlainDatagramSocketImpl_peekData(JNIEnv *env, jobject this, ...@@ -714,7 +714,7 @@ Java_java_net_PlainDatagramSocketImpl_peekData(JNIEnv *env, jobject this,
fullPacket = (char *)malloc(packetBufferLen); fullPacket = (char *)malloc(packetBufferLen);
if (!fullPacket) { if (!fullPacket) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Peek buffer native heap allocation failed");
return -1; return -1;
} else { } else {
mallocedPacket = JNI_TRUE; mallocedPacket = JNI_TRUE;
...@@ -874,7 +874,7 @@ Java_java_net_PlainDatagramSocketImpl_receive0(JNIEnv *env, jobject this, ...@@ -874,7 +874,7 @@ Java_java_net_PlainDatagramSocketImpl_receive0(JNIEnv *env, jobject this,
fullPacket = (char *)malloc(packetBufferLen); fullPacket = (char *)malloc(packetBufferLen);
if (!fullPacket) { if (!fullPacket) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Receive buffer native heap allocation failed");
return; return;
} else { } else {
mallocedPacket = JNI_TRUE; mallocedPacket = JNI_TRUE;
......
...@@ -206,9 +206,7 @@ public class Kinit { ...@@ -206,9 +206,7 @@ public class Kinit {
System.out.println(">>> Kinit realm name is " + realm); System.out.println(">>> Kinit realm name is " + realm);
} }
PrincipalName sname = new PrincipalName("krbtgt" + "/" + realm, PrincipalName sname = PrincipalName.tgsService(realm, realm);
PrincipalName.KRB_NT_SRV_INST);
sname.setRealm(realm);
builder.setTarget(sname); builder.setTarget(sname);
if (DEBUG) { if (DEBUG) {
......
...@@ -146,15 +146,6 @@ class KinitOptions { ...@@ -146,15 +146,6 @@ class KinitOptions {
"Principal name: " + p + "Principal name: " + p +
e.getMessage()); e.getMessage());
} }
if (principal.getRealm() == null) {
String realm =
Config.getInstance().getDefault("default_realm",
"libdefaults");
if (realm != null) {
principal.setRealm(realm);
} else throw new IllegalArgumentException("invalid " +
"Realm name");
}
} else if (this.password == null) { } else if (this.password == null) {
// Have already processed a Principal, this must be a password // Have already processed a Principal, this must be a password
password = args[i].toCharArray(); password = args[i].toCharArray();
...@@ -175,16 +166,6 @@ class KinitOptions { ...@@ -175,16 +166,6 @@ class KinitOptions {
} }
PrincipalName getDefaultPrincipal() { PrincipalName getDefaultPrincipal() {
String cname;
String realm = null;
try {
realm = Config.getInstance().getDefaultRealm();
} catch (KrbException e) {
System.out.println ("Can not get default realm " +
e.getMessage());
e.printStackTrace();
return null;
}
// get default principal name from the cachename if it is // get default principal name from the cachename if it is
// available. // available.
...@@ -204,10 +185,6 @@ class KinitOptions { ...@@ -204,10 +185,6 @@ class KinitOptions {
} }
PrincipalName p = cis.readPrincipal(version); PrincipalName p = cis.readPrincipal(version);
cis.close(); cis.close();
String temp = p.getRealmString();
if (temp == null) {
p.setRealm(realm);
}
if (DEBUG) { if (DEBUG) {
System.out.println(">>>KinitOptions principal name from "+ System.out.println(">>>KinitOptions principal name from "+
"the cache is :" + p); "the cache is :" + p);
...@@ -230,19 +207,15 @@ class KinitOptions { ...@@ -230,19 +207,15 @@ class KinitOptions {
System.out.println(">>>KinitOptions default username is :" System.out.println(">>>KinitOptions default username is :"
+ username); + username);
} }
if (realm != null) { try {
try { PrincipalName p = new PrincipalName(username);
PrincipalName p = new PrincipalName(username); return p;
if (p.getRealm() == null) } catch (RealmException e) {
p.setRealm(realm); // ignore exception , return null
return p; if (DEBUG) {
} catch (RealmException e) { System.out.println ("Exception in getting principal " +
// ignore exception , return null "name " + e.getMessage());
if (DEBUG) { e.printStackTrace();
System.out.println ("Exception in getting principal " +
"name " + e.getMessage());
e.printStackTrace();
}
} }
} }
return null; return null;
......
...@@ -273,9 +273,6 @@ public class Ktab { ...@@ -273,9 +273,6 @@ public class Ktab {
PrincipalName pname = null; PrincipalName pname = null;
try { try {
pname = new PrincipalName(principal); pname = new PrincipalName(principal);
if (pname.getRealm() == null) {
pname.setRealm(Config.getInstance().getDefaultRealm());
}
} catch (KrbException e) { } catch (KrbException e) {
System.err.println("Failed to add " + principal + System.err.println("Failed to add " + principal +
" to keytab."); " to keytab.");
...@@ -382,9 +379,6 @@ public class Ktab { ...@@ -382,9 +379,6 @@ public class Ktab {
PrincipalName pname = null; PrincipalName pname = null;
try { try {
pname = new PrincipalName(principal); pname = new PrincipalName(principal);
if (pname.getRealm() == null) {
pname.setRealm(Config.getInstance().getDefaultRealm());
}
if (!forced) { if (!forced) {
String answer; String answer;
BufferedReader cis = BufferedReader cis =
......
...@@ -265,7 +265,7 @@ JNIEXPORT jint JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketRece ...@@ -265,7 +265,7 @@ JNIEXPORT jint JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketRece
} }
fullPacket = (char *)malloc(packetBufferLen); fullPacket = (char *)malloc(packetBufferLen);
if (!fullPacket) { if (!fullPacket) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
return -1; return -1;
} }
} else { } else {
...@@ -427,7 +427,7 @@ JNIEXPORT void JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketSend ...@@ -427,7 +427,7 @@ JNIEXPORT void JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketSend
} }
fullPacket = (char *)malloc(length); fullPacket = (char *)malloc(length);
if (!fullPacket) { if (!fullPacket) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
return; return;
} }
} else { } else {
......
...@@ -197,7 +197,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -197,7 +197,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
struct addrinfo *next struct addrinfo *next
= (struct addrinfo*) malloc(sizeof(struct addrinfo)); = (struct addrinfo*) malloc(sizeof(struct addrinfo));
if (!next) { if (!next) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
ret = NULL; ret = NULL;
goto cleanupAndReturn; goto cleanupAndReturn;
} }
......
...@@ -270,7 +270,7 @@ int enumInterfaces(JNIEnv *env, netif **netifPP) ...@@ -270,7 +270,7 @@ int enumInterfaces(JNIEnv *env, netif **netifPP)
} }
} }
if (curr == NULL) { if (curr == NULL) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failure"); JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure");
free_netif(netifP); free_netif(netifP);
free(tableP); free(tableP);
return -1; return -1;
...@@ -370,7 +370,7 @@ int enumAddresses_win(JNIEnv *env, netif *netifP, netaddr **netaddrPP) ...@@ -370,7 +370,7 @@ int enumAddresses_win(JNIEnv *env, netif *netifP, netaddr **netaddrPP)
netaddr *curr = (netaddr *)malloc(sizeof(netaddr)); netaddr *curr = (netaddr *)malloc(sizeof(netaddr));
if (curr == NULL) { if (curr == NULL) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failure"); JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure");
free_netaddr(netaddrP); free_netaddr(netaddrP);
free(tableP); free(tableP);
return -1; return -1;
......
...@@ -243,7 +243,7 @@ jboolean exceedSizeLimit(JNIEnv *env, jint fd, jint addr, jint size) ...@@ -243,7 +243,7 @@ jboolean exceedSizeLimit(JNIEnv *env, jint fd, jint addr, jint size)
addrList = curr; addrList = curr;
} }
LeaveCriticalSection(&sizeCheckLock); LeaveCriticalSection(&sizeCheckLock);
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
return JNI_TRUE; return JNI_TRUE;
} }
curr->addr = htonl((*addrp)->S_un.S_addr); curr->addr = htonl((*addrp)->S_un.S_addr);
...@@ -740,7 +740,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_send(JNIEnv *env, jobject this, ...@@ -740,7 +740,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_send(JNIEnv *env, jobject this,
*/ */
fullPacket = (char *)malloc(packetBufferLen); fullPacket = (char *)malloc(packetBufferLen);
if (!fullPacket) { if (!fullPacket) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Send buf native heap allocation failed");
return; return;
} }
} else { } else {
...@@ -1003,7 +1003,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_peekData(JNIEnv *env, jobject thi ...@@ -1003,7 +1003,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_peekData(JNIEnv *env, jobject thi
*/ */
fullPacket = (char *)malloc(packetBufferLen); fullPacket = (char *)malloc(packetBufferLen);
if (!fullPacket) { if (!fullPacket) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
return -1; return -1;
} }
} else { } else {
...@@ -1287,7 +1287,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_receive0(JNIEnv *env, jobject thi ...@@ -1287,7 +1287,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_receive0(JNIEnv *env, jobject thi
*/ */
fullPacket = (char *)malloc(packetBufferLen); fullPacket = (char *)malloc(packetBufferLen);
if (!fullPacket) { if (!fullPacket) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Receive buf native heap allocation failed");
return; return;
} }
} else { } else {
......
...@@ -67,7 +67,6 @@ jmethodID encryptionKeyConstructor = 0; ...@@ -67,7 +67,6 @@ jmethodID encryptionKeyConstructor = 0;
jmethodID ticketFlagsConstructor = 0; jmethodID ticketFlagsConstructor = 0;
jmethodID kerberosTimeConstructor = 0; jmethodID kerberosTimeConstructor = 0;
jmethodID krbcredsConstructor = 0; jmethodID krbcredsConstructor = 0;
jmethodID setRealmMethod = 0;
/* /*
* Function prototypes for internal routines * Function prototypes for internal routines
...@@ -279,7 +278,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad( ...@@ -279,7 +278,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(
} }
principalNameConstructor = (*env)->GetMethodID(env, principalNameClass, principalNameConstructor = (*env)->GetMethodID(env, principalNameClass,
"<init>", "([Ljava/lang/String;)V"); "<init>", "([Ljava/lang/String;Ljava/lang/String;)V");
if (principalNameConstructor == 0) { if (principalNameConstructor == 0) {
printf("LSA: Couldn't find PrincipalName constructor\n"); printf("LSA: Couldn't find PrincipalName constructor\n");
return JNI_ERR; return JNI_ERR;
...@@ -318,14 +317,6 @@ JNIEXPORT jint JNICALL JNI_OnLoad( ...@@ -318,14 +317,6 @@ JNIEXPORT jint JNICALL JNI_OnLoad(
printf("LSA: Found KerberosTime constructor\n"); printf("LSA: Found KerberosTime constructor\n");
} }
// load the setRealm method in PrincipalName
setRealmMethod = (*env)->GetMethodID(env, principalNameClass,
"setRealm", "(Ljava/lang/String;)V");
if (setRealmMethod == 0) {
printf("LSA: Couldn't find setRealm in PrincipalName\n");
return JNI_ERR;
}
if (native_debug) { if (native_debug) {
printf("LSA: Finished OnLoad processing\n"); printf("LSA: Finished OnLoad processing\n");
} }
...@@ -952,13 +943,12 @@ jobject BuildPrincipal(JNIEnv *env, PKERB_EXTERNAL_NAME principalName, ...@@ -952,13 +943,12 @@ jobject BuildPrincipal(JNIEnv *env, PKERB_EXTERNAL_NAME principalName,
// Do I have to worry about storage reclamation here? // Do I have to worry about storage reclamation here?
} }
principal = (*env)->NewObject(env, principalNameClass,
principalNameConstructor, stringArray);
// now set the realm in the principal // now set the realm in the principal
realmLen = (ULONG)wcslen((PWCHAR)realm); realmLen = (ULONG)wcslen((PWCHAR)realm);
realmStr = (*env)->NewString(env, (PWCHAR)realm, (USHORT)realmLen); realmStr = (*env)->NewString(env, (PWCHAR)realm, (USHORT)realmLen);
(*env)->CallVoidMethod(env, principal, setRealmMethod, realmStr);
principal = (*env)->NewObject(env, principalNameClass,
principalNameConstructor, stringArray, realmStr);
// free local resources // free local resources
LocalFree(realm); LocalFree(realm);
......
...@@ -122,9 +122,6 @@ ...@@ -122,9 +122,6 @@
# jdk_lang # jdk_lang
# 7123972
java/lang/annotation/loaderLeak/Main.java generic-all
# 6944188 # 6944188
java/lang/management/ThreadMXBean/ThreadStateTest.java generic-all java/lang/management/ThreadMXBean/ThreadStateTest.java generic-all
...@@ -161,9 +158,6 @@ java/lang/Math/WorstCaseTests.java generic-all ...@@ -161,9 +158,6 @@ java/lang/Math/WorstCaseTests.java generic-all
# 6988950 # 6988950
demo/jvmti/compiledMethodLoad/CompiledMethodLoadTest.java generic-all demo/jvmti/compiledMethodLoad/CompiledMethodLoadTest.java generic-all
# Need to be marked othervm, or changed to be samevm safe
com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java generic-all
# 7162111 # 7162111
demo/jvmti/mtrace/TraceJFrame.java macosx-all demo/jvmti/mtrace/TraceJFrame.java macosx-all
javax/script/CauseExceptionTest.java macosx-all javax/script/CauseExceptionTest.java macosx-all
...@@ -268,21 +262,11 @@ java/nio/channels/Selector/OutOfBand.java macosx-all ...@@ -268,21 +262,11 @@ java/nio/channels/Selector/OutOfBand.java macosx-all
# jdk_rmi # jdk_rmi
# 7140992
java/rmi/server/Unreferenced/finiteGCLatency/FiniteGCLatency.java generic-all
# 6948101
java/rmi/transport/pinLastArguments/PinLastArguments.java generic-all
# 7146541 # 7146541
java/rmi/transport/rapidExportUnexport/RapidExportUnexport.java linux-all java/rmi/transport/rapidExportUnexport/RapidExportUnexport.java linux-all
# 7132247 # 7132247
java/rmi/registry/readTest/readTest.sh windows-all java/rmi/registry/readTest/readTest.sh windows-all
# 7142596
java/rmi/transport/pinClientSocketFactory/PinClientSocketFactory.java generic-all
############################################################################ ############################################################################
# jdk_security # jdk_security
......
...@@ -9,4 +9,4 @@ keys=2d dnd i18n ...@@ -9,4 +9,4 @@ keys=2d dnd i18n
othervm.dirs=java/rmi sun/rmi javax/management othervm.dirs=java/rmi sun/rmi javax/management
# Tests that cannot run concurrently # Tests that cannot run concurrently
exclusiveAccess.dirs=java/rmi sun/rmi sun/management/jmxremote sun/tools/jstatd exclusiveAccess.dirs=java/rmi/Naming sun/management/jmxremote sun/tools/jstatd
/* /*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,50 +28,111 @@ ...@@ -28,50 +28,111 @@
* LoginContext * LoginContext
* @author Brad Wetmore * @author Brad Wetmore
* *
* @run main/othervm -Xmx2m -XX:OldSize=1m -XX:NewSize=512k TestProviderLeak * @run main/othervm -Xmx20m TestProviderLeak
* *
* The original test invocation is below, but had to use the above
* workaround for bug 6923123.
*
* run main/othervm -Xmx2m TestProviderLeak
*/ */
/* /*
* We force the leak to become a problem by specifying the minimum * We force the leak to become a problem by eating up most JVM free memory.
* size heap we can (above). In current runs on a server and client * In current runs on a server and client machine, it took roughly 50-150
* machine, it took roughly 220-240 iterations to have the memory leak * iterations to have the memory leak or time-out shut down other operations.
* shut down other operations. It complained about "Unable to verify * It complained about "JCE cannot authenticate the provider SunJCE" or timed
* the SunJCE provider." * out.
*/ */
import javax.crypto.*; import javax.crypto.*;
import javax.crypto.spec.*; import javax.crypto.spec.*;
import java.util.*;
import java.util.concurrent.*;
public class TestProviderLeak { public class TestProviderLeak {
private static final int MB = 1024 * 1024;
// Currently, 3MB heap size is reserved for running testing iterations.
// It is tweaked to make sure the test quickly triggers the memory leak
// or throws out TimeoutException.
private static final int RESERVATION = 3;
// The maximum time, 5 seconds, to wait for each iteration.
private static final int TIME_OUT = 5;
private static Deque<byte []> eatupMemory() throws Exception {
dumpMemoryStats("Before memory allocation");
Deque<byte []> data = new ArrayDeque<byte []>();
boolean hasException = false;
while (!hasException) {
byte [] megaByte;
try {
megaByte = new byte [MB];
data.add(megaByte);
} catch (OutOfMemoryError e) {
System.out.println("OOME is thrown when allocating "
+ data.size() + "MB memory.");
megaByte = null;
for (int j = 0; j < RESERVATION && !data.isEmpty(); j++) {
data.removeLast();
}
System.gc();
hasException = true;
}
}
dumpMemoryStats("After memory allocation");
return data;
}
private static void dumpMemoryStats(String s) throws Exception { private static void dumpMemoryStats(String s) throws Exception {
Runtime rt = Runtime.getRuntime(); Runtime rt = Runtime.getRuntime();
System.out.println(s + ":\t" + System.out.println(s + ":\t"
rt.freeMemory() + " bytes free"); + rt.freeMemory() + " bytes free");
} }
public static void main(String [] args) throws Exception { public static void main(String [] args) throws Exception {
SecretKeyFactory skf = // Eat up memory
Deque<byte []> dummyData = eatupMemory();
assert (dummyData != null);
// Prepare the test
final SecretKeyFactory skf =
SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1", "SunJCE"); SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1", "SunJCE");
PBEKeySpec pbeKS = new PBEKeySpec( final PBEKeySpec pbeKS = new PBEKeySpec(
"passPhrase".toCharArray(), new byte [] { 0 }, 5, 512); "passPhrase".toCharArray(), new byte [] { 0 }, 5, 512);
for (int i = 0; i <= 1000; i++) {
try { ExecutorService executor = Executors.newSingleThreadExecutor();
skf.generateSecret(pbeKS); Callable<SecretKey> task = new Callable<SecretKey>() {
@Override
public SecretKey call() throws Exception {
return skf.generateSecret(pbeKS);
}
};
// Start testing iteration
try {
for (int i = 0; i <= 1000; i++) {
if ((i % 20) == 0) { if ((i % 20) == 0) {
// Calling gc() isn't dependable, but doesn't hurt. // Calling gc() isn't dependable, but doesn't hurt.
// Gives better output in leak cases. // Gives better output in leak cases.
System.gc(); System.gc();
dumpMemoryStats("Iteration " + i); dumpMemoryStats("Iteration " + i);
} }
} catch (Exception e) {
dumpMemoryStats("\nException seen at iteration " + i); Future<SecretKey> future = executor.submit(task);
throw e;
try {
future.get(TIME_OUT, TimeUnit.SECONDS);
} catch (Exception e) {
dumpMemoryStats("\nException seen at iteration " + i);
throw e;
}
} }
} finally {
// JTReg will time out after two minutes. Proactively release
// the memory to avoid JTReg time-out situation.
dummyData = null;
System.gc();
dumpMemoryStats("Memory dereference");
executor.shutdownNow();
} }
} }
} }
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,26 +25,21 @@ ...@@ -25,26 +25,21 @@
* @test * @test
* @bug 6676075 * @bug 6676075
* @summary RegistryContext (com.sun.jndi.url.rmi.rmiURLContext) coding problem * @summary RegistryContext (com.sun.jndi.url.rmi.rmiURLContext) coding problem
* @library ../../../../../../java/rmi/testlibrary
* @build TestLibrary
* @run main ContextWithNullProperties
*/ */
import java.rmi.RemoteException; import com.sun.jndi.rmi.registry.RegistryContext;
import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry;
import com.sun.jndi.rmi.registry.*;
public class ContextWithNullProperties { public class ContextWithNullProperties {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Registry registry = TestLibrary.createRegistryOnUnusedPort();
// Create registry on port 1099 if one is not already running. int registryPort = TestLibrary.getRegistryPort(registry);
try {
LocateRegistry.createRegistry(1099);
} catch (RemoteException e) {
}
System.out.println("Connecting to the default Registry..."); System.out.println("Connecting to the default Registry...");
// Connect to the default Registry. // Connect to the default Registry.
// Pass null as the JNDI environment properties (see final argument) // Pass null as the JNDI environment properties (see final argument)
RegistryContext ctx = new RegistryContext(null, -1, null); RegistryContext ctx = new RegistryContext(null, registryPort, null);
} }
} }
/*
* Copyright (c) 2007, 2012, 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 * @test
* @bug 4278121 * @bug 4278121
* @summary Ensure that calling unbind() on an unbound name returns * @summary Ensure that calling unbind() on an unbound name returns
* successfully. * successfully.
* @library ../../../../../../java/rmi/testlibrary
* @build TestLibrary
* @run main UnbindIdempotent
*/ */
import javax.naming.*; import java.rmi.registry.Registry;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
public class UnbindIdempotent { public class UnbindIdempotent {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Registry registry = TestLibrary.createRegistryOnUnusedPort();
// Create registry on port 1099 if one is not already running. int registryPort = TestLibrary.getRegistryPort(registry);
try { InitialContext ictx = new InitialContext();
java.rmi.registry.LocateRegistry.createRegistry(1099);
} catch (java.rmi.RemoteException e) {
}
Context ictx = new InitialContext();
Context rctx; Context rctx;
try { try {
rctx = (Context)ictx.lookup("rmi://localhost:1099"); rctx = (Context)ictx.lookup("rmi://localhost:" + Integer.toString(registryPort));
} catch (NamingException e) { } catch (NamingException e) {
// Unable to set up for test. // Unable to set up for test.
return; return;
......
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -20,22 +20,45 @@ ...@@ -20,22 +20,45 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
/* /*
* @test * @test
* @bug 6856069 * @bug 7183458
* @summary PrincipalName.clone() does not invoke super.clone() * @summary Verify advance of space is not overly widened by bold styling.
* @run main StyledSpaceAdvance
*/ */
import java.awt.Font;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.util.Locale;
public class StyledSpaceAdvance {
import sun.security.krb5.ServiceName; static String name = "Gulim";
public static void main(String args[]) {
for (int sz=9;sz<18;sz++) {
test(sz);
}
}
public class ServiceNameClone { static void test(int sz) {
public static void main(String[] args) throws Exception { Font reg = new Font(name, Font.PLAIN, sz);
ServiceName sn = new ServiceName("me@HERE"); Font bold = new Font(name, Font.BOLD, sz);
if (sn.clone().getClass() != ServiceName.class) { //System.out.println("reg="+reg);
throw new Exception("ServiceName's clone is not a ServiceName"); //System.out.println("bold="+bold);
} FontRenderContext frc = new FontRenderContext(null, false, false);
if (!sn.clone().equals(sn)) { if (reg.getFontName(Locale.ENGLISH).equals(name) &&
throw new Exception("ServiceName's clone changed"); bold.getFontName(Locale.ENGLISH).equals(name)) {
} Rectangle2D rb = reg.getStringBounds(" ", frc);
Rectangle2D bb = bold.getStringBounds(" ", frc);
if (bb.getWidth() > rb.getWidth() + 1.01f) {
System.err.println("reg="+reg+" bds = " + rb);
System.err.println("bold="+bold+" bds = " + bb);
throw new RuntimeException("Advance difference too great.");
}
} else {
System.out.println("Skipping test because fonts aren't as expected");
}
} }
} }
...@@ -57,9 +57,17 @@ public class Main { ...@@ -57,9 +57,17 @@ public class Main {
System.gc(); System.gc();
System.gc(); System.gc();
loader = null; loader = null;
System.gc();
System.gc(); // Might require multiple calls to System.gc() for weak-references
if (c.get() != null) throw new AssertionError(); // processing to be complete. If the weak-reference is not cleared as
// expected we will hang here until timed out by the test harness.
while (true) {
System.gc();
Thread.sleep(20);
if (c.get() == null) {
break;
}
}
} }
} }
......
...@@ -243,10 +243,6 @@ public class TestHttpCookie { ...@@ -243,10 +243,6 @@ public class TestHttpCookie {
test("set-cookie2: Customer = \"WILE_E_COYOTE\"; Version = \"1\"; Path = \"/acme\"") test("set-cookie2: Customer = \"WILE_E_COYOTE\"; Version = \"1\"; Path = \"/acme\"")
.n("Customer").v("WILE_E_COYOTE").ver(1).p("/acme"); .n("Customer").v("WILE_E_COYOTE").ver(1).p("/acme");
// $NAME is reserved; result should be null
test("set-cookie2: $Customer = \"WILE_E_COYOTE\"; Version = \"1\"; Path = \"/acme\"")
.nil();
// a 'full' cookie // a 'full' cookie
test("set-cookie2: Customer=\"WILE_E_COYOTE\"" + test("set-cookie2: Customer=\"WILE_E_COYOTE\"" +
";Version=\"1\"" + ";Version=\"1\"" +
......
/*
* Copyright (c) 2012, 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 7183292
*/
import java.net.*;
import java.util.*;
import java.io.*;
import com.sun.net.httpserver.*;
public class IllegalCookieNameTest {
public static void main(String[] args) throws IOException {
HttpServer s = null;
try {
InetSocketAddress addr = new InetSocketAddress(0);
s = HttpServer.create(addr, 10);
s.createContext("/", new HHandler());
s.start();
String u = "http://127.0.0.1:" + s.getAddress().getPort() + "/";
CookieHandler.setDefault(new TestCookieHandler());
URL url = new URL(u);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.getHeaderFields();
System.out.println ("OK");
} finally {
s.stop(1);
}
}
}
class TestCookieHandler extends CookieHandler {
@Override
public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) {
return new HashMap<String, List<String>>();
}
@Override
public void put(URI uri, Map<String, List<String>> responseHeaders) {
}
}
class HHandler implements HttpHandler {
public void handle (HttpExchange e) {
try {
Headers h = e.getResponseHeaders();
h.set ("Set-Cookie", "domain=; expires=Mon, 01-Jan-1990 00:00:00 GMT; path=/; domain=.foo.com");
e.sendResponseHeaders(200, -1);
e.close();
} catch (Exception ex) {
System.out.println (ex);
}
}
}
/* /*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,10 +25,13 @@ ...@@ -25,10 +25,13 @@
* @bug 4387038 * @bug 4387038
* @summary Ensure that java.rmi.Naming.lookup functions properly for names * @summary Ensure that java.rmi.Naming.lookup functions properly for names
* containing embedded ':' characters. * containing embedded ':' characters.
*
* @library ../testlibrary
* @build TestLibrary
* @run main LookupNameWithColon
*/ */
import java.rmi.Naming; import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry; import java.rmi.registry.Registry;
public class LookupNameWithColon { public class LookupNameWithColon {
...@@ -38,15 +41,12 @@ public class LookupNameWithColon { ...@@ -38,15 +41,12 @@ public class LookupNameWithColon {
"multiple:colons:in:name" "multiple:colons:in:name"
}; };
Registry reg; Registry reg = TestLibrary.createRegistryOnUnusedPort();
try { int port = TestLibrary.getRegistryPort(reg);
reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
} catch (Exception ex) {
reg = LocateRegistry.getRegistry();
}
for (int i = 0; i < names.length; i++) { for (int i = 0; i < names.length; i++) {
reg.rebind(names[i], reg); reg.rebind(names[i], reg);
Naming.lookup("rmi://localhost/" + names[i]); Naming.lookup("rmi://localhost:" + port + "/" + names[i]);
} }
} }
} }
/* /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -39,9 +39,6 @@ import java.rmi.*; ...@@ -39,9 +39,6 @@ import java.rmi.*;
import java.rmi.registry.*; import java.rmi.registry.*;
public class RmiIsNoScheme implements Remote, Serializable { public class RmiIsNoScheme implements Remote, Serializable {
private static final int REGISTRY_PORT = 2002;
private RmiIsNoScheme() {} private RmiIsNoScheme() {}
public static void main(String[] args) { public static void main(String[] args) {
...@@ -49,10 +46,11 @@ public class RmiIsNoScheme implements Remote, Serializable { ...@@ -49,10 +46,11 @@ public class RmiIsNoScheme implements Remote, Serializable {
System.err.println("\nRegression test for bug 4626311\n"); System.err.println("\nRegression test for bug 4626311\n");
try { try {
LocateRegistry.createRegistry(REGISTRY_PORT); Registry registry = TestLibrary.createRegistryOnUnusedPort();
Naming.rebind("//:" + REGISTRY_PORT + "/RmiIsNoScheme", int registryPort = TestLibrary.getRegistryPort(registry);
Naming.rebind("//:" + registryPort + "/RmiIsNoScheme",
new RmiIsNoScheme()); new RmiIsNoScheme());
String name = Naming.list("//:" + REGISTRY_PORT)[0]; String name = Naming.list("//:" + registryPort)[0];
System.err.println("name = " + name); System.err.println("name = " + name);
if (name.startsWith("rmi:", 0) == false) { if (name.startsWith("rmi:", 0) == false) {
System.err.println("TEST PASSED: rmi scheme not present"); System.err.println("TEST PASSED: rmi scheme not present");
......
/* /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 * under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. * published by the Free Software Foundation.
* *
* This code is distributed in the hope that it will be useful, but WITHOUT * This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * 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 * version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code). * accompanied this code).
* *
* You should have received a copy of the GNU General Public License version * 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, * 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
* *
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 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 * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
/* /*
* @test * @test
* @bug 5083594 * @bug 5083594
* @summary Ensure that Naming.java correctly parses host names with '_' in * @summary Ensure that Naming.java correctly parses host names with '_' in
* them. * them.
* @author Vinod Johnson * @author Vinod Johnson
* *
* @library ../testlibrary * @library ../testlibrary
* @build TestLibrary * @build TestLibrary
* @build UnderscoreHost UnderscoreHost_Stub * @build UnderscoreHost UnderscoreHost_Stub
* @run main/othervm UnderscoreHost * @run main/othervm UnderscoreHost
*/ */
import java.io.IOException; import java.io.IOException;
...@@ -77,11 +77,12 @@ public class UnderscoreHost extends UnicastRemoteObject implements Remote { ...@@ -77,11 +77,12 @@ public class UnderscoreHost extends UnicastRemoteObject implements Remote {
try { try {
HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory(); HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
RMISocketFactory.setSocketFactory(hvf); RMISocketFactory.setSocketFactory(hvf);
Registry r = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); Registry r = TestLibrary.createRegistryOnUnusedPort();
int port = TestLibrary.getRegistryPort(r);
t = new UnderscoreHost(); t = new UnderscoreHost();
r.rebind(NAME, t); r.rebind(NAME, t);
Naming.lookup("rmi://" + HOSTNAME + Naming.lookup("rmi://" + HOSTNAME +
":" + Registry.REGISTRY_PORT + "/" + NAME); ":" + port + "/" + NAME);
/* /*
* This test is coded to pass whether java.net.URI obeys * This test is coded to pass whether java.net.URI obeys
* RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.). * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
......
/* /*
* Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -45,7 +45,9 @@ import java.util.Vector; ...@@ -45,7 +45,9 @@ import java.util.Vector;
/** /**
* Ensure that all legal forms of Naming URLs operate with the * Ensure that all legal forms of Naming URLs operate with the
* java.rmi.Naming interface * java.rmi.Naming interface. This test requires using the default RMI Registry
* port as it tests all of the RMI naming URL's, including the ones which do not
* take a port (and therefore uses the default port).
*/ */
public class LegalRegistryNames extends UnicastRemoteObject public class LegalRegistryNames extends UnicastRemoteObject
implements Legal implements Legal
......
...@@ -29,11 +29,12 @@ grant { ...@@ -29,11 +29,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// Needed to create an activation group // Needed to create an activation group
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
...@@ -21,11 +21,12 @@ grant { ...@@ -21,11 +21,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// required for test to create an ActivationGroup // required for test to create an ActivationGroup
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
...@@ -32,11 +32,12 @@ grant { ...@@ -32,11 +32,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// required for test to create an ActivationGroup // required for test to create an ActivationGroup
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
...@@ -21,17 +21,18 @@ grant { ...@@ -21,17 +21,18 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// Needed to create an activation group // Needed to create an activation group
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
// allow exporting of remote objects on an arbitrary port. // allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept"; permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
// allow exporting object with non-public remote interface // allow exporting object with non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe"; permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
......
...@@ -21,11 +21,12 @@ grant { ...@@ -21,11 +21,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// Needed to create an activation group // Needed to create an activation group
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
...@@ -31,11 +31,12 @@ grant { ...@@ -31,11 +31,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// allow exporting of remote objects on an arbitrary port. // allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
......
...@@ -30,11 +30,12 @@ grant { ...@@ -30,11 +30,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// Needed to create an activation group // Needed to create an activation group
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
...@@ -17,11 +17,12 @@ grant { ...@@ -17,11 +17,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// allow exporting of remote objects on an arbitrary port. // allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
......
...@@ -21,11 +21,12 @@ grant { ...@@ -21,11 +21,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// Needed to create an activation group // Needed to create an activation group
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
...@@ -21,17 +21,18 @@ grant { ...@@ -21,17 +21,18 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// Needed to create an activation group // Needed to create an activation group
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
// allow exporting of remote objects on an arbitrary port. // allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept"; permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
// allow exporting object with non-public remote interface // allow exporting object with non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe"; permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
......
/* /*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -58,7 +58,7 @@ public class LookupActivationSystem implements Remote, Serializable { ...@@ -58,7 +58,7 @@ public class LookupActivationSystem implements Remote, Serializable {
System.err.println("look up activation system"); System.err.println("look up activation system");
Registry rmidRegistry = Registry rmidRegistry =
LocateRegistry.getRegistry(ActivationSystem.SYSTEM_PORT); LocateRegistry.getRegistry(rmid.getPort());
ActivationSystem system = (ActivationSystem) ActivationSystem system = (ActivationSystem)
rmidRegistry.lookup(NAME); rmidRegistry.lookup(NAME);
......
...@@ -21,17 +21,18 @@ grant { ...@@ -21,17 +21,18 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// Needed to create an activation group // Needed to create an activation group
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
// allow exporting of remote objects on an arbitrary port. // allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept"; permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
// allow exporting of non-public remote interface // allow exporting of non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe"; permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
......
...@@ -21,11 +21,12 @@ grant { ...@@ -21,11 +21,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// Needed to create an activation group // Needed to create an activation group
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
...@@ -21,11 +21,12 @@ grant { ...@@ -21,11 +21,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// Needed to create an activation group // Needed to create an activation group
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
...@@ -21,11 +21,12 @@ grant { ...@@ -21,11 +21,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// Used in remote impl of Activator.inactive; by the method // Used in remote impl of Activator.inactive; by the method
// "restartThread.dispose()"when it calls thread.interrupt() // "restartThread.dispose()"when it calls thread.interrupt()
......
...@@ -21,11 +21,12 @@ grant { ...@@ -21,11 +21,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// Used in remote impl of Activator.inactive; by the method // Used in remote impl of Activator.inactive; by the method
// "restartThread.dispose()"when it calls thread.interrupt() // "restartThread.dispose()"when it calls thread.interrupt()
......
...@@ -21,11 +21,12 @@ grant { ...@@ -21,11 +21,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// allow exporting of remote objects on an arbitrary port. // allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
......
...@@ -21,11 +21,12 @@ grant { ...@@ -21,11 +21,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// Needed to create an activation group // Needed to create an activation group
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
...@@ -21,11 +21,12 @@ grant { ...@@ -21,11 +21,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// required for test to create an ActivationGroup // required for test to create an ActivationGroup
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
...@@ -15,11 +15,12 @@ grant { ...@@ -15,11 +15,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// test needs to export rmid and communicate with objects on arbitrary ports // test needs to export rmid and communicate with objects on arbitrary ports
permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
......
...@@ -21,11 +21,12 @@ grant { ...@@ -21,11 +21,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// required for test to create an ActivationGroup // required for test to create an ActivationGroup
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
/* /*
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -61,7 +61,7 @@ public class StubClassesPermitted ...@@ -61,7 +61,7 @@ public class StubClassesPermitted
extends Activatable implements Runnable, CanCreateStubs extends Activatable implements Runnable, CanCreateStubs
{ {
public static boolean sameGroup = false; public static boolean sameGroup = false;
private static int registryPort = -1;
private static CanCreateStubs canCreateStubs = null; private static CanCreateStubs canCreateStubs = null;
private static Registry registry = null; private static Registry registry = null;
...@@ -76,8 +76,8 @@ public class StubClassesPermitted ...@@ -76,8 +76,8 @@ public class StubClassesPermitted
try { try {
TestLibrary.suggestSecurityManager("java.lang.SecurityManager"); TestLibrary.suggestSecurityManager("java.lang.SecurityManager");
registry = java.rmi.registry.LocateRegistry. registry = TestLibrary.createRegistryOnUnusedPort();
createRegistry(TestLibrary.REGISTRY_PORT); registryPort = TestLibrary.getRegistryPort(registry);
// must run with java.lang.SecurityManager or the test // must run with java.lang.SecurityManager or the test
// result will be nullified if running with a build where // result will be nullified if running with a build where
...@@ -192,7 +192,7 @@ public class StubClassesPermitted ...@@ -192,7 +192,7 @@ public class StubClassesPermitted
// obtain reference to the test registry // obtain reference to the test registry
registry = java.rmi.registry.LocateRegistry. registry = java.rmi.registry.LocateRegistry.
getRegistry(TestLibrary.REGISTRY_PORT); getRegistry(registryPort);
} }
/** /**
......
...@@ -21,15 +21,22 @@ grant { ...@@ -21,15 +21,22 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// required for test to create an ActivationGroup // required for test to create an ActivationGroup
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
// required for test to get the registry port
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp";
// test needs to export rmid and communicate with objects on arbitrary ports // test needs to export rmid and communicate with objects on arbitrary ports
permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
}; };
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -74,7 +74,7 @@ public class UnregisterGroup ...@@ -74,7 +74,7 @@ public class UnregisterGroup
private static boolean done = false; private static boolean done = false;
private static ActivateMe lastResortExitObj = null; private static ActivateMe lastResortExitObj = null;
private static final int NUM_OBJECTS = 10; private static final int NUM_OBJECTS = 10;
private static int PORT = 2006; private static int registryPort = -1;
public UnregisterGroup(ActivationID id, MarshalledObject mobj) public UnregisterGroup(ActivationID id, MarshalledObject mobj)
throws Exception throws Exception
...@@ -116,7 +116,7 @@ public class UnregisterGroup ...@@ -116,7 +116,7 @@ public class UnregisterGroup
try { try {
CallbackInterface cobj = CallbackInterface cobj =
(CallbackInterface)Naming.lookup("//:" + PORT + "/Callback"); (CallbackInterface)Naming.lookup("//:" + registryPort + "/Callback");
cobj.inc(); cobj.inc();
} catch (Exception e) { } catch (Exception e) {
System.err.println("cobj.inc exception"); System.err.println("cobj.inc exception");
...@@ -235,7 +235,8 @@ public class UnregisterGroup ...@@ -235,7 +235,8 @@ public class UnregisterGroup
try { try {
// create reg and export callback object // create reg and export callback object
registry = LocateRegistry.createRegistry(PORT); registry = TestLibrary.createRegistryOnUnusedPort();
registryPort = TestLibrary.getRegistryPort(registry);
Callback robj = new Callback(); Callback robj = new Callback();
registry.bind("Callback", robj); registry.bind("Callback", robj);
......
...@@ -21,11 +21,12 @@ grant { ...@@ -21,11 +21,12 @@ grant {
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to determine test environment // used by TestLibrary to determine test environment
permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.classes", "read";
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// required for test to create an ActivationGroup // required for test to create an ActivationGroup
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
/* /*
* Copyright (c) 1998, 2000, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -53,31 +53,37 @@ public class SetChildEnv ...@@ -53,31 +53,37 @@ public class SetChildEnv
public static void main(String argv[]) public static void main(String argv[])
throws Exception throws Exception
{ {
int runningPort = TestLibrary.getUnusedRandomPort();
System.out.println("java.compiler=" + System.getProperty("java.compiler")); System.out.println("java.compiler=" + System.getProperty("java.compiler"));
// don't embed spaces in any of the test args/props, because // don't embed spaces in any of the test args/props, because
// they won't be parsed properly // they won't be parsed properly
runwith (new String[0], new String[0]); runwith (new String[0], new String[0], runningPort);
runwith ( runwith (
new String[] { "-verbosegc" }, new String[] { "-verbosegc" },
new String[] { "foo.bar=SetChildEnvTest", new String[] { "foo.bar=SetChildEnvTest",
"sun.rmi.server.doSomething=true" } "sun.rmi.server.doSomething=true" },
runningPort
); );
runwith ( runwith (
new String[] { }, new String[] { },
new String[] { "parameter.count=zero" } new String[] { "parameter.count=zero" },
runningPort
); );
runwith ( runwith (
new String[] { "-Xmx32m" }, new String[] { "-Xmx32m" },
new String[] { } new String[] { },
runningPort
); );
} }
private static void runwith( private static void runwith(
String[] params, // extra args String[] params, // extra args
String[] props // extra system properties String[] props, // extra system properties
int port // port on which to communicate
) )
throws Exception throws Exception
{ {
...@@ -89,7 +95,8 @@ public class SetChildEnv ...@@ -89,7 +95,8 @@ public class SetChildEnv
RMID.removeLog(); RMID.removeLog();
RMID rmid = RMID.createRMID(watcher.otherEnd(), watcher.otherEnd(), RMID rmid = RMID.createRMID(watcher.otherEnd(), watcher.otherEnd(),
true); // debugExec turned on true, // debugExec turned on
true, port);
rmid.start(); rmid.start();
...@@ -195,7 +202,7 @@ public class SetChildEnv ...@@ -195,7 +202,7 @@ public class SetChildEnv
actsys.unregisterGroup(gid); actsys.unregisterGroup(gid);
Thread.sleep(5000); Thread.sleep(5000);
rmid.destroy(); ActivationLibrary.rmidCleanup(rmid);
} }
public static class DebugExecWatcher public static class DebugExecWatcher
...@@ -243,7 +250,19 @@ public class SetChildEnv ...@@ -243,7 +250,19 @@ public class SetChildEnv
System.err.println(line); System.err.println(line);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); /* During termination of distant rmid, StreamPipes will be broken when
* distant vm terminates. A "Pipe broken" exception is expected because
* DebugExecWatcher points to the same streams as StreamPipes used by RMID.
* If we get this exception. We just terminate the thread.
*/
if (e.getMessage().equals("Pipe broken")) {
try {
str.close();
} catch (IOException ioe) {}
}
else {
e.printStackTrace();
}
} }
} }
} }
......
...@@ -27,6 +27,7 @@ grant { ...@@ -27,6 +27,7 @@ grant {
permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "test.src", "read";
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// required for test to create an ActivationGroup // required for test to create an ActivationGroup
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
/* /*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -31,8 +31,7 @@ ...@@ -31,8 +31,7 @@
* @library ../../testlibrary * @library ../../testlibrary
* @build RMID ActivationLibrary * @build RMID ActivationLibrary
* @build InheritedChannelNotServerSocket * @build InheritedChannelNotServerSocket
* @run main/othervm/timeout=240 -Djava.rmi.activation.port=5398 * @run main/othervm/timeout=240 InheritedChannelNotServerSocket
* InheritedChannelNotServerSocket
*/ */
import java.io.IOException; import java.io.IOException;
...@@ -55,8 +54,6 @@ import java.rmi.registry.Registry; ...@@ -55,8 +54,6 @@ import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject; import java.rmi.server.UnicastRemoteObject;
public class InheritedChannelNotServerSocket { public class InheritedChannelNotServerSocket {
private static final int PORT = 5398;
private static final Object lock = new Object(); private static final Object lock = new Object();
private static boolean notified = false; private static boolean notified = false;
...@@ -79,7 +76,8 @@ public class InheritedChannelNotServerSocket { ...@@ -79,7 +76,8 @@ public class InheritedChannelNotServerSocket {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for bug 6261402\n"); System.err.println("\nRegression test for bug 6261402\n");
System.setProperty("java.rmi.activation.port",
Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT));
RMID rmid = null; RMID rmid = null;
Callback obj = null; Callback obj = null;
try { try {
...@@ -91,7 +89,8 @@ public class InheritedChannelNotServerSocket { ...@@ -91,7 +89,8 @@ public class InheritedChannelNotServerSocket {
Callback proxy = Callback proxy =
(Callback) UnicastRemoteObject.exportObject(obj, 0); (Callback) UnicastRemoteObject.exportObject(obj, 0);
Registry registry = Registry registry =
LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); LocateRegistry.createRegistry(
TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
registry.bind("Callback", proxy); registry.bind("Callback", proxy);
/* /*
...@@ -99,7 +98,8 @@ public class InheritedChannelNotServerSocket { ...@@ -99,7 +98,8 @@ public class InheritedChannelNotServerSocket {
*/ */
System.err.println("start rmid with inherited channel"); System.err.println("start rmid with inherited channel");
RMID.removeLog(); RMID.removeLog();
rmid = RMID.createRMID(System.out, System.err, true, true, PORT); rmid = RMID.createRMID(System.out, System.err, true, true,
TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT);
rmid.addOptions(new String[]{ rmid.addOptions(new String[]{
"-Djava.nio.channels.spi.SelectorProvider=" + "-Djava.nio.channels.spi.SelectorProvider=" +
"InheritedChannelNotServerSocket$SP"}); "InheritedChannelNotServerSocket$SP"});
...@@ -122,7 +122,7 @@ public class InheritedChannelNotServerSocket { ...@@ -122,7 +122,7 @@ public class InheritedChannelNotServerSocket {
if (obj != null) { if (obj != null) {
UnicastRemoteObject.unexportObject(obj, true); UnicastRemoteObject.unexportObject(obj, true);
} }
ActivationLibrary.rmidCleanup(rmid, PORT); ActivationLibrary.rmidCleanup(rmid);
} }
} }
...@@ -175,7 +175,7 @@ public class InheritedChannelNotServerSocket { ...@@ -175,7 +175,7 @@ public class InheritedChannelNotServerSocket {
try { try {
System.err.println("notify test..."); System.err.println("notify test...");
Registry registry = Registry registry =
LocateRegistry.getRegistry(TestLibrary.REGISTRY_PORT); LocateRegistry.getRegistry(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
Callback obj = (Callback) registry.lookup("Callback"); Callback obj = (Callback) registry.lookup("Callback");
obj.notifyTest(); obj.notifyTest();
} catch (NotBoundException nbe) { } catch (NotBoundException nbe) {
......
/* /*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -29,7 +29,8 @@ ...@@ -29,7 +29,8 @@
* @library ../../testlibrary * @library ../../testlibrary
* @build RMID ActivationLibrary * @build RMID ActivationLibrary
* @build RmidViaInheritedChannel * @build RmidViaInheritedChannel
* @run main/othervm/timeout=240 -Djava.rmi.activation.port=5398 RmidViaInheritedChannel * @build TestLibrary
* @run main/othervm/timeout=240 RmidViaInheritedChannel
*/ */
import java.io.IOException; import java.io.IOException;
...@@ -48,8 +49,6 @@ import java.rmi.registry.Registry; ...@@ -48,8 +49,6 @@ import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject; import java.rmi.server.UnicastRemoteObject;
public class RmidViaInheritedChannel implements Callback { public class RmidViaInheritedChannel implements Callback {
private static final int PORT = 5398;
private static final Object lock = new Object(); private static final Object lock = new Object();
private static boolean notified = false; private static boolean notified = false;
...@@ -64,7 +63,8 @@ public class RmidViaInheritedChannel implements Callback { ...@@ -64,7 +63,8 @@ public class RmidViaInheritedChannel implements Callback {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.setProperty("java.rmi.activation.port",
Integer.toString(TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
RMID rmid = null; RMID rmid = null;
Callback obj = null; Callback obj = null;
...@@ -77,7 +77,8 @@ public class RmidViaInheritedChannel implements Callback { ...@@ -77,7 +77,8 @@ public class RmidViaInheritedChannel implements Callback {
Callback proxy = (Callback) Callback proxy = (Callback)
UnicastRemoteObject.exportObject(obj, 0); UnicastRemoteObject.exportObject(obj, 0);
Registry registry = Registry registry =
LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); LocateRegistry.createRegistry(
TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT);
registry.bind("Callback", proxy); registry.bind("Callback", proxy);
/* /*
...@@ -85,7 +86,8 @@ public class RmidViaInheritedChannel implements Callback { ...@@ -85,7 +86,8 @@ public class RmidViaInheritedChannel implements Callback {
*/ */
System.err.println("start rmid with inherited channel"); System.err.println("start rmid with inherited channel");
RMID.removeLog(); RMID.removeLog();
rmid = RMID.createRMID(System.out, System.err, true, false, PORT); rmid = RMID.createRMID(System.out, System.err, true, false,
TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT);
rmid.addOptions(new String[]{ rmid.addOptions(new String[]{
"-Djava.nio.channels.spi.SelectorProvider=RmidViaInheritedChannel$RmidSelectorProvider"}); "-Djava.nio.channels.spi.SelectorProvider=RmidViaInheritedChannel$RmidSelectorProvider"});
rmid.start(); rmid.start();
...@@ -108,7 +110,7 @@ public class RmidViaInheritedChannel implements Callback { ...@@ -108,7 +110,7 @@ public class RmidViaInheritedChannel implements Callback {
if (obj != null) { if (obj != null) {
UnicastRemoteObject.unexportObject(obj, true); UnicastRemoteObject.unexportObject(obj, true);
} }
ActivationLibrary.rmidCleanup(rmid, PORT); ActivationLibrary.rmidCleanup(rmid);
} }
} }
...@@ -166,7 +168,8 @@ public class RmidViaInheritedChannel implements Callback { ...@@ -166,7 +168,8 @@ public class RmidViaInheritedChannel implements Callback {
channel = ServerSocketChannel.open(); channel = ServerSocketChannel.open();
ServerSocket serverSocket = channel.socket(); ServerSocket serverSocket = channel.socket();
serverSocket.bind( serverSocket.bind(
new InetSocketAddress(InetAddress.getLocalHost(), PORT)); new InetSocketAddress(InetAddress.getLocalHost(),
TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
System.err.println("serverSocket = " + serverSocket); System.err.println("serverSocket = " + serverSocket);
/* /*
...@@ -175,7 +178,7 @@ public class RmidViaInheritedChannel implements Callback { ...@@ -175,7 +178,7 @@ public class RmidViaInheritedChannel implements Callback {
try { try {
System.err.println("notify test..."); System.err.println("notify test...");
Registry registry = Registry registry =
LocateRegistry.getRegistry(TestLibrary.REGISTRY_PORT); LocateRegistry.getRegistry(TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT);
Callback obj = (Callback) registry.lookup("Callback"); Callback obj = (Callback) registry.lookup("Callback");
obj.notifyTest(); obj.notifyTest();
} catch (NotBoundException nbe) { } catch (NotBoundException nbe) {
......
...@@ -2,4 +2,5 @@ grant { ...@@ -2,4 +2,5 @@ grant {
permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
permission java.net.SocketPermission "*", "connect,accept"; permission java.net.SocketPermission "*", "connect,accept";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
}; };
/* /*
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* @author Laird Dornin * @author Laird Dornin
* *
* @library ../../testlibrary * @library ../../testlibrary
* @build StreamPipe TestParams TestLibrary JavaVM * @build StreamPipe TestParams TestLibrary JavaVM RMID
* @build AltSecurityManager TestSecurityManager * @build AltSecurityManager TestSecurityManager
* @run main/othervm AltSecurityManager * @run main/othervm AltSecurityManager
*/ */
...@@ -41,23 +41,41 @@ ...@@ -41,23 +41,41 @@
* if registry and rmid take too long to exit. * if registry and rmid take too long to exit.
*/ */
public class AltSecurityManager implements Runnable { public class AltSecurityManager implements Runnable {
private final int regPort;
// variable to hold registry and rmid children // variable to hold registry and rmid children
static JavaVM vm = null; static JavaVM vm = null;
// names of utilities // names of utilities
static String utilityToStart = null; static String utilityToStart = null;
static String registry = "sun.rmi.registry.RegistryImpl"; static final String REGISTRY_IMPL = "sun.rmi.registry.RegistryImpl";
static String rmid = "sun.rmi.server.Activation"; static final String ACTIVATION = "sun.rmi.server.Activation";
// children should exit in at least this time. // children should exit in at least this time.
static long TIME_OUT = 15000; static long TIME_OUT = 15000;
public AltSecurityManager(int port) {
if (port <= 0) {
TestLibrary.bomb("Port must be greater then 0.");
}
this.regPort = port;
}
public void run() { public void run() {
try { try {
vm = new JavaVM(utilityToStart, if (utilityToStart.equals(REGISTRY_IMPL)) {
" -Djava.security.manager=TestSecurityManager", vm = new JavaVM(utilityToStart,
""); " -Djava.security.manager=TestSecurityManager",
Integer.toString(regPort));
} else if (utilityToStart.contains(ACTIVATION)) {
vm = new JavaVM(utilityToStart,
" -Djava.security.manager=TestSecurityManager",
"-port " + Integer.toString(regPort));
} else {
TestLibrary.bomb("Utility to start must be " + REGISTRY_IMPL +
" or " + ACTIVATION);
}
System.err.println("starting " + utilityToStart); System.err.println("starting " + utilityToStart);
vm.start(); vm.start();
vm.getVM().waitFor(); vm.getVM().waitFor();
...@@ -75,7 +93,8 @@ public class AltSecurityManager implements Runnable { ...@@ -75,7 +93,8 @@ public class AltSecurityManager implements Runnable {
utilityToStart = utility; utilityToStart = utility;
try { try {
Thread thread = new Thread(new AltSecurityManager()); int port = TestLibrary.getUnusedRandomPort();
Thread thread = new Thread(new AltSecurityManager(port));
System.err.println("expecting RuntimeException for " + System.err.println("expecting RuntimeException for " +
"checkListen in child process"); "checkListen in child process");
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
...@@ -90,8 +109,8 @@ public class AltSecurityManager implements Runnable { ...@@ -90,8 +109,8 @@ public class AltSecurityManager implements Runnable {
// dont pollute other tests; increase the likelihood // dont pollute other tests; increase the likelihood
// that rmid will go away if it did not exit already. // that rmid will go away if it did not exit already.
if (utility.equals(rmid)) { if (utility.equals(ACTIVATION)) {
RMID.shutdown(); RMID.shutdown(port);
} }
TestLibrary.bomb(utilityToStart + TestLibrary.bomb(utilityToStart +
...@@ -111,10 +130,10 @@ public class AltSecurityManager implements Runnable { ...@@ -111,10 +130,10 @@ public class AltSecurityManager implements Runnable {
System.err.println("\nRegression test for bug 4183202\n"); System.err.println("\nRegression test for bug 4183202\n");
// make sure the registry exits early. // make sure the registry exits early.
ensureExit(registry); ensureExit(REGISTRY_IMPL);
// make sure rmid exits early // make sure rmid exits early
ensureExit(rmid); ensureExit(ACTIVATION);
System.err.println("test passed"); System.err.println("test passed");
......
/* /*
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
* @author Peter Jones * @author Peter Jones
* *
* @library ../../testlibrary * @library ../../testlibrary
* @build ClassPathCodebase Dummy * @build ClassPathCodebase Dummy TestLibrary
* @run main/othervm/policy=security.policy ClassPathCodebase * @run main/othervm/policy=security.policy ClassPathCodebase
*/ */
...@@ -83,11 +83,12 @@ public class ClassPathCodebase { ...@@ -83,11 +83,12 @@ public class ClassPathCodebase {
System.getProperty("java.home") + File.separator + System.getProperty("java.home") + File.separator +
"bin" + File.separator + "rmiregistry"; "bin" + File.separator + "rmiregistry";
int port = TestLibrary.getUnusedRandomPort();
String cmdarray[] = new String[] { String cmdarray[] = new String[] {
rmiregistryCommand, rmiregistryCommand,
"-J-Denv.class.path=.", "-J-Denv.class.path=.",
"-J-Djava.rmi.server.codebase=" + exportCodebaseURL, "-J-Djava.rmi.server.codebase=" + exportCodebaseURL,
Integer.toString(TestLibrary.REGISTRY_PORT) }; Integer.toString(port) };
System.err.println("\nCommand used to spawn rmiregistry process:"); System.err.println("\nCommand used to spawn rmiregistry process:");
System.err.println("\t" + Arrays.asList(cmdarray).toString()); System.err.println("\t" + Arrays.asList(cmdarray).toString());
...@@ -118,7 +119,7 @@ public class ClassPathCodebase { ...@@ -118,7 +119,7 @@ public class ClassPathCodebase {
* dummy object to it. * dummy object to it.
*/ */
Registry registry = LocateRegistry.getRegistry( Registry registry = LocateRegistry.getRegistry(
"localhost", TestLibrary.REGISTRY_PORT); "localhost", port);
try { try {
registry.bind(dummyBinding, dummyObject); registry.bind(dummyBinding, dummyObject);
...@@ -133,7 +134,7 @@ public class ClassPathCodebase { ...@@ -133,7 +134,7 @@ public class ClassPathCodebase {
{ {
System.err.println( System.err.println(
"Error: another registry running on port " + "Error: another registry running on port " +
TestLibrary.REGISTRY_PORT + "?"); port + "?");
} }
throw e; throw e;
} }
......
/* /*
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
/* @test /* @test
* @bug 4399304 * @bug 4399304
* @summary check that registry allows empty names * @summary check that registry allows empty names
* @library ../../testlibrary
* @build TestLibrary
* @run main/othervm EmptyName * @run main/othervm EmptyName
*/ */
import java.rmi.registry.LocateRegistry; import java.rmi.registry.LocateRegistry;
...@@ -32,7 +34,7 @@ import java.rmi.server.RemoteObject; ...@@ -32,7 +34,7 @@ import java.rmi.server.RemoteObject;
public class EmptyName { public class EmptyName {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Registry impl = LocateRegistry.createRegistry(0); Registry impl = TestLibrary.createRegistryOnUnusedPort();
Registry stub = (Registry) RemoteObject.toStub(impl); Registry stub = (Registry) RemoteObject.toStub(impl);
stub.bind("", stub); stub.bind("", stub);
stub.lookup(""); stub.lookup("");
......
/* /*
* Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -35,8 +35,10 @@ ...@@ -35,8 +35,10 @@
* "interface hash": 4905912898345647071L. * "interface hash": 4905912898345647071L.
* *
* @author Peter Jones * @author Peter Jones
* @library ../../testlibrary
* @build InterfaceHash * @build InterfaceHash
* @build ReferenceRegistryStub * @build ReferenceRegistryStub
* @build TestLibrary
* @run main/othervm InterfaceHash * @run main/othervm InterfaceHash
*/ */
...@@ -58,7 +60,7 @@ import sun.rmi.transport.tcp.TCPEndpoint; ...@@ -58,7 +60,7 @@ import sun.rmi.transport.tcp.TCPEndpoint;
public class InterfaceHash { public class InterfaceHash {
private static final int PORT = 2020; private static final int PORT = TestLibrary.getUnusedRandomPort();
private static final String NAME = "WMM"; private static final String NAME = "WMM";
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
......
/* /*
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
* @summary Can't run multiple registries in the same VM * @summary Can't run multiple registries in the same VM
* @author Ann Wollrath * @author Ann Wollrath
* *
* @library ../../testlibrary
* @build TestLibrary
* @build MultipleRegistries * @build MultipleRegistries
* @run main/othervm/timeout=240 MultipleRegistries * @run main/othervm/timeout=240 MultipleRegistries
*/ */
...@@ -58,12 +60,13 @@ public class MultipleRegistries implements RemoteInterface { ...@@ -58,12 +60,13 @@ public class MultipleRegistries implements RemoteInterface {
System.err.println("proxy = " + proxy); System.err.println("proxy = " + proxy);
System.err.println("export registries"); System.err.println("export registries");
Registry registryImpl1 = LocateRegistry.createRegistry(2030); Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort();
Registry registryImpl2 = LocateRegistry.createRegistry(2040); int port1 = TestLibrary.getRegistryPort(registryImpl1);
Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort();
int port2 = TestLibrary.getRegistryPort(registryImpl2);
System.err.println("bind remote object in registries"); System.err.println("bind remote object in registries");
Registry registry1 = LocateRegistry.getRegistry(2030); Registry registry1 = LocateRegistry.getRegistry(port1);
Registry registry2 = LocateRegistry.getRegistry(2040); Registry registry2 = LocateRegistry.getRegistry(port2);
registry1.bind(NAME, proxy); registry1.bind(NAME, proxy);
registry2.bind(NAME, proxy); registry2.bind(NAME, proxy);
......
/* /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -29,18 +29,19 @@ import java.rmi.server.UnicastRemoteObject; ...@@ -29,18 +29,19 @@ import java.rmi.server.UnicastRemoteObject;
public class readTest { public class readTest {
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
int port = 7491;
try { try {
testPkg.Server obj = new testPkg.Server(); testPkg.Server obj = new testPkg.Server();
testPkg.Hello stub = (testPkg.Hello) UnicastRemoteObject.exportObject(obj, 0); testPkg.Hello stub = (testPkg.Hello) UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry // Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry(port); Registry registry =
LocateRegistry.getRegistry(TestLibrary.READTEST_REGISTRY_PORT);
registry.bind("Hello", stub); registry.bind("Hello", stub);
System.err.println("Server ready"); System.err.println("Server ready");
// now, let's test client // now, let's test client
testPkg.Client client = new testPkg.Client(port); testPkg.Client client =
new testPkg.Client(TestLibrary.READTEST_REGISTRY_PORT);
String testStubReturn = client.testStub(); String testStubReturn = client.testStub();
if(!testStubReturn.equals(obj.hello)) { if(!testStubReturn.equals(obj.hello)) {
throw new RuntimeException("Test Fails : unexpected string from stub call"); throw new RuntimeException("Test Fails : unexpected string from stub call");
......
# #
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# @test # @test
# @bug 7102369 7094468 7100592 # @bug 7102369 7094468 7100592
# @library ../../testlibrary
# @build TestLibrary
# @summary remove java.rmi.server.codebase property parsing from registyimpl # @summary remove java.rmi.server.codebase property parsing from registyimpl
# @run shell readTest.sh # @run shell readTest.sh
...@@ -44,22 +46,24 @@ case "$OS" in ...@@ -44,22 +46,24 @@ case "$OS" in
;; ;;
esac esac
TEST_CLASSPATH=.:$TESTCLASSES
cp -r ${TESTSRC}${FS}* . cp -r ${TESTSRC}${FS}* .
${TESTJAVA}${FS}bin${FS}javac testPkg${FS}*java ${TESTJAVA}${FS}bin${FS}javac testPkg${FS}*java
${TESTJAVA}${FS}bin${FS}javac readTest.java ${TESTJAVA}${FS}bin${FS}javac -cp $TEST_CLASSPATH readTest.java
mkdir rmi_tmp mkdir rmi_tmp
RMIREG_OUT=rmi.out RMIREG_OUT=rmi.out
#start rmiregistry without any local classes on classpath #start rmiregistry without any local classes on classpath
cd rmi_tmp cd rmi_tmp
${TESTJAVA}${FS}bin${FS}rmiregistry 7491 > ..${FS}${RMIREG_OUT} 2>&1 & # NOTE: This RMI Registry port must match TestLibrary.READTEST_REGISTRY_PORT
${TESTJAVA}${FS}bin${FS}rmiregistry 64005 > ..${FS}${RMIREG_OUT} 2>&1 &
RMIREG_PID=$! RMIREG_PID=$!
# allow some time to start # allow some time to start
sleep 3 sleep 3
cd .. cd ..
# trailing / after code base is important for rmi codebase property. # trailing / after code base is important for rmi codebase property.
${TESTJAVA}${FS}bin${FS}java -Djava.rmi.server.codebase=${FILEURL}`pwd`/ readTest > OUT.TXT 2>&1 & ${TESTJAVA}${FS}bin${FS}java -cp $TEST_CLASSPATH -Djava.rmi.server.codebase=${FILEURL}`pwd`/ readTest > OUT.TXT 2>&1 &
TEST_PID=$! TEST_PID=$!
#bulk of testcase - let it run for a while #bulk of testcase - let it run for a while
sleep 5 sleep 5
......
/* /*
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -49,22 +49,21 @@ import java.rmi.registry.*; ...@@ -49,22 +49,21 @@ import java.rmi.registry.*;
import java.rmi.server.*; import java.rmi.server.*;
public class Reexport { public class Reexport {
static public final int regport = TestLibrary.REGISTRY_PORT;
static public void main(String[] argv) { static public void main(String[] argv) {
Registry reg = null; Registry reg = null;
int regPort = TestLibrary.getUnusedRandomPort();
try { try {
System.err.println("\nregression test for 4120329\n"); System.err.println("\nregression test for 4120329\n");
// establish the registry (we hope) // establish the registry (we hope)
System.err.println("Starting registry on port " + regport); System.err.println("Starting registry on port " + regPort);
Reexport.makeRegistry(regport); Reexport.makeRegistry(regPort);
// Get a handle to the registry // Get a handle to the registry
System.err.println("Creating duplicate registry, this should fail..."); System.err.println("Creating duplicate registry, this should fail...");
reg = createReg(true); reg = createReg(true, regPort);
if (reg != null) { if (reg != null) {
TestLibrary.bomb("failed was able to duplicate the registry?!?"); TestLibrary.bomb("failed was able to duplicate the registry?!?");
...@@ -73,7 +72,7 @@ public class Reexport { ...@@ -73,7 +72,7 @@ public class Reexport {
// Kill the first registry. // Kill the first registry.
System.err.println("Bringing down the first registry"); System.err.println("Bringing down the first registry");
try { try {
Reexport.killRegistry(); Reexport.killRegistry(regPort);
} catch (Exception foo) { } catch (Exception foo) {
} }
...@@ -81,7 +80,7 @@ public class Reexport { ...@@ -81,7 +80,7 @@ public class Reexport {
System.err.println("Trying again to start our own " + System.err.println("Trying again to start our own " +
"registry... this should work"); "registry... this should work");
reg = createReg(false); reg = createReg(false, regPort);
if (reg == null) { if (reg == null) {
TestLibrary.bomb("Could not create registry on second try"); TestLibrary.bomb("Could not create registry on second try");
...@@ -93,17 +92,17 @@ public class Reexport { ...@@ -93,17 +92,17 @@ public class Reexport {
TestLibrary.bomb(e); TestLibrary.bomb(e);
} finally { } finally {
// dont leave the registry around to affect other tests. // dont leave the registry around to affect other tests.
killRegistry(); killRegistry(regPort);
reg = null; reg = null;
} }
} }
static Registry createReg(boolean remoteOk) { static Registry createReg(boolean remoteOk, int port) {
Registry reg = null; Registry reg = null;
try { try {
reg = LocateRegistry.createRegistry(regport); reg = LocateRegistry.createRegistry(port);
} catch (Throwable e) { } catch (Throwable e) {
if (remoteOk) { if (remoteOk) {
System.err.println("EXPECTING PORT IN USE EXCEPTION:"); System.err.println("EXPECTING PORT IN USE EXCEPTION:");
...@@ -140,10 +139,10 @@ public class Reexport { ...@@ -140,10 +139,10 @@ public class Reexport {
} }
private static Process subreg = null; private static Process subreg = null;
public static void killRegistry() { public static void killRegistry(int port) {
if (Reexport.subreg != null) { if (Reexport.subreg != null) {
RegistryRunner.requestExit(); RegistryRunner.requestExit(port);
try { try {
Reexport.subreg.waitFor(); Reexport.subreg.waitFor();
......
/* /*
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -59,19 +59,21 @@ ...@@ -59,19 +59,21 @@
* @build Apple AppleEvent AppleImpl AppleUserImpl * @build Apple AppleEvent AppleImpl AppleUserImpl
* @build Orange OrangeEcho OrangeEchoImpl OrangeImpl * @build Orange OrangeEcho OrangeEchoImpl OrangeImpl
* @build ApplicationServer * @build ApplicationServer
* @build TestLibrary
* *
* @run main/othervm/policy=security.policy AppleUserImpl -seconds 30 * @run main/othervm/policy=security.policy AppleUserImpl -seconds 30
* *
* @author Peter Jones, Nigel Daley * @author Peter Jones, Nigel Daley
*/ */
import java.rmi.RemoteException;
import java.rmi.NoSuchObjectException; import java.rmi.NoSuchObjectException;
import java.rmi.server.UnicastRemoteObject; import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry; import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Random; import java.util.Random;
import java.util.logging.Logger;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* The AppleUserImpl class implements the behavior of the remote * The AppleUserImpl class implements the behavior of the remote
...@@ -80,7 +82,7 @@ import java.util.logging.Level; ...@@ -80,7 +82,7 @@ import java.util.logging.Level;
* AppleUserThread is created for each apple. * AppleUserThread is created for each apple.
*/ */
public class AppleUserImpl extends UnicastRemoteObject implements AppleUser { public class AppleUserImpl extends UnicastRemoteObject implements AppleUser {
private static int registryPort = -1;
private static final Logger logger = private static final Logger logger =
Logger.getLogger("reliability.appleuser"); Logger.getLogger("reliability.appleuser");
private static int threadNum = 0; private static int threadNum = 0;
...@@ -308,8 +310,10 @@ public class AppleUserImpl extends UnicastRemoteObject implements AppleUser { ...@@ -308,8 +310,10 @@ public class AppleUserImpl extends UnicastRemoteObject implements AppleUser {
synchronized (user) { synchronized (user) {
// create new registry and bind new AppleUserImpl in registry // create new registry and bind new AppleUserImpl in registry
LocateRegistry.createRegistry(2006); Registry registry = TestLibrary.createRegistryOnUnusedPort();
LocateRegistry.getRegistry(2006).rebind("AppleUser",user); registryPort = TestLibrary.getRegistryPort(registry);
LocateRegistry.getRegistry(registryPort).rebind("AppleUser",
user);
// start the other server if applicable // start the other server if applicable
if (othervm) { if (othervm) {
...@@ -318,7 +322,9 @@ public class AppleUserImpl extends UnicastRemoteObject implements AppleUser { ...@@ -318,7 +322,9 @@ public class AppleUserImpl extends UnicastRemoteObject implements AppleUser {
"started in separate process"); "started in separate process");
} else { } else {
Class app = Class.forName("ApplicationServer"); Class app = Class.forName("ApplicationServer");
server = new Thread((Runnable) app.newInstance()); java.lang.reflect.Constructor appConstructor =
app.getDeclaredConstructor(new Class[] {Integer.TYPE});
server = new Thread((Runnable) appConstructor.newInstance(registryPort));
logger.log(Level.INFO, "Starting application server " + logger.log(Level.INFO, "Starting application server " +
"in same process"); "in same process");
server.start(); server.start();
......
/* /*
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -38,18 +38,21 @@ public class ApplicationServer implements Runnable { ...@@ -38,18 +38,21 @@ public class ApplicationServer implements Runnable {
private static final int LOOKUP_ATTEMPTS = 5; private static final int LOOKUP_ATTEMPTS = 5;
private static final int DEFAULT_NUMAPPLES = 10; private static final int DEFAULT_NUMAPPLES = 10;
private static final String DEFAULT_REGISTRYHOST = "localhost"; private static final String DEFAULT_REGISTRYHOST = "localhost";
private static final int DEFAULT_REGISTRYPORT = -1;
private final int numApples; private final int numApples;
private final String registryHost; private final String registryHost;
private final int registryPort;
private final Apple[] apples; private final Apple[] apples;
private AppleUser user; private AppleUser user;
ApplicationServer() { ApplicationServer(int registryPort) {
this(DEFAULT_NUMAPPLES, DEFAULT_REGISTRYHOST); this(DEFAULT_NUMAPPLES, DEFAULT_REGISTRYHOST, registryPort);
} }
ApplicationServer(int numApples, String registryHost) { ApplicationServer(int numApples, String registryHost, int registryPort) {
this.numApples = numApples; this.numApples = numApples;
this.registryHost = registryHost; this.registryHost = registryHost;
this.registryPort = registryPort;
apples = new Apple[numApples]; apples = new Apple[numApples];
} }
...@@ -71,7 +74,7 @@ public class ApplicationServer implements Runnable { ...@@ -71,7 +74,7 @@ public class ApplicationServer implements Runnable {
for (i = 0; i < LOOKUP_ATTEMPTS; i++) { for (i = 0; i < LOOKUP_ATTEMPTS; i++) {
try { try {
Registry registry = LocateRegistry.getRegistry( Registry registry = LocateRegistry.getRegistry(
registryHost, 2006); registryHost, registryPort);
user = (AppleUser) registry.lookup("AppleUser"); user = (AppleUser) registry.lookup("AppleUser");
user.startTest(); user.startTest();
break; //successfully obtained AppleUser break; //successfully obtained AppleUser
...@@ -120,16 +123,20 @@ public class ApplicationServer implements Runnable { ...@@ -120,16 +123,20 @@ public class ApplicationServer implements Runnable {
private static void usage() { private static void usage() {
System.err.println("Usage: ApplicationServer [-numApples <numApples>]"); System.err.println("Usage: ApplicationServer [-numApples <numApples>]");
System.err.println(" [-registryHost <host>]"); System.err.println(" [-registryHost <host>]");
System.err.println(" -registryPort <port>");
System.err.println(" numApples The number of apples (threads) to use."); System.err.println(" numApples The number of apples (threads) to use.");
System.err.println(" The default is 10 apples."); System.err.println(" The default is 10 apples.");
System.err.println(" host The host running rmiregistry " + System.err.println(" host The host running rmiregistry " +
"which contains AppleUser."); "which contains AppleUser.");
System.err.println(" The default is \"localhost\"."); System.err.println(" The default is \"localhost\".");
System.err.println(" port The port the rmiregistry is running" +
"on.");
System.err.println(); System.err.println();
} }
public static void main(String[] args) { public static void main(String[] args) {
int num = DEFAULT_NUMAPPLES; int num = DEFAULT_NUMAPPLES;
int port = -1;
String host = DEFAULT_REGISTRYHOST; String host = DEFAULT_REGISTRYHOST;
// parse command line args // parse command line args
...@@ -142,17 +149,25 @@ public class ApplicationServer implements Runnable { ...@@ -142,17 +149,25 @@ public class ApplicationServer implements Runnable {
} else if (arg.equals("-registryHost")) { } else if (arg.equals("-registryHost")) {
i++; i++;
host = args[i]; host = args[i];
} else if (arg.equals("-registryPort")) {
i++;
port = Integer.parseInt(args[i]);
} else { } else {
usage(); usage();
} }
} }
if (port == -1) {
usage();
throw new RuntimeException("Port must be specified.");
}
} catch (Throwable t) { } catch (Throwable t) {
usage(); usage();
throw new RuntimeException("TEST FAILED: Bad argument"); throw new RuntimeException("TEST FAILED: Bad argument");
} }
// start the client server // start the client server
Thread server = new Thread(new ApplicationServer(num,host)); Thread server = new Thread(new ApplicationServer(num,host,port));
server.start(); server.start();
// main should exit once all exported remote objects are gc'd // main should exit once all exported remote objects are gc'd
} }
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -128,8 +128,9 @@ public class EchoImpl ...@@ -128,8 +128,9 @@ public class EchoImpl
ActivationGroup.createGroup(groupID, groupDesc, 0); ActivationGroup.createGroup(groupID, groupDesc, 0);
EchoImpl impl = new EchoImpl(protocol); EchoImpl impl = new EchoImpl(protocol);
System.out.println("EchoServer: binding in registry"); int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));
Naming.rebind("//:" + UseCustomSocketFactory.REGISTRY_PORT + System.out.println("EchoServer: binding in registry on port:" + registryPort);
Naming.rebind("//:" + registryPort +
"/EchoServer", impl); "/EchoServer", impl);
System.out.println("EchoServer ready."); System.out.println("EchoServer ready.");
} catch (Exception e) { } catch (Exception e) {
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
* @build EchoImpl * @build EchoImpl
* @build EchoImpl_Stub * @build EchoImpl_Stub
* @build UseCustomSocketFactory * @build UseCustomSocketFactory
* @build TestLibrary
* @run main/othervm/policy=security.policy/timeout=360 UseCustomSocketFactory * @run main/othervm/policy=security.policy/timeout=360 UseCustomSocketFactory
*/ */
...@@ -42,8 +43,8 @@ import java.rmi.server.*; ...@@ -42,8 +43,8 @@ import java.rmi.server.*;
import java.rmi.registry.*; import java.rmi.registry.*;
public class UseCustomSocketFactory { public class UseCustomSocketFactory {
static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort();
final static int REGISTRY_PORT = 2006;
static String[] protocol = new String[] { "", "compress", "xor" }; static String[] protocol = new String[] { "", "compress", "xor" };
public static void main(String[] args) { public static void main(String[] args) {
...@@ -68,7 +69,7 @@ public class UseCustomSocketFactory { ...@@ -68,7 +69,7 @@ public class UseCustomSocketFactory {
" -C-Djava.security.manager=java.rmi.RMISecurityManager "}); " -C-Djava.security.manager=java.rmi.RMISecurityManager "});
rmid.start(); rmid.start();
Echo[] echo = spawnAndTest(); Echo[] echo = spawnAndTest(rmid.getPort());
reactivateAndTest(echo); reactivateAndTest(echo);
} catch (IOException e) { } catch (IOException e) {
TestLibrary.bomb("creating rmid", e); TestLibrary.bomb("creating rmid", e);
...@@ -78,17 +79,20 @@ public class UseCustomSocketFactory { ...@@ -78,17 +79,20 @@ public class UseCustomSocketFactory {
} }
} }
private static Echo[] spawnAndTest() { private static Echo[] spawnAndTest(int rmidPort) {
System.err.println("\nCreate Test-->"); System.err.println("\nCreate Test-->");
Echo[] echo = new Echo[protocol.length]; Echo[] echo = new Echo[protocol.length];
for (int i = 0; i < protocol.length; i++) { for (int i = 0; i < protocol.length; i++) {
JavaVM serverVM = new JavaVM("EchoImpl", JavaVM serverVM = new JavaVM("EchoImpl",
"-Djava.security.policy=" + "-Djava.security.policy=" +
TestParams.defaultPolicy, TestParams.defaultPolicy +
" -Drmi.registry.port=" +
REGISTRY_PORT +
" -Djava.rmi.activation.port=" +
rmidPort,
protocol[i]); protocol[i]);
System.err.println("\nusing protocol: " + System.err.println("\nusing protocol: " +
......
...@@ -30,6 +30,9 @@ grant { ...@@ -30,6 +30,9 @@ grant {
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "rmi.registry.port", "read";
permission java.util.PropertyPermission "java.rmi.activation.port", "write";
// required for test to create an ActivationGroup // required for test to create an ActivationGroup
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -65,8 +65,9 @@ public class HelloImpl ...@@ -65,8 +65,9 @@ public class HelloImpl
if (args.length >= 1) if (args.length >= 1)
protocol = args[0]; protocol = args[0];
int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));
registry = java.rmi.registry.LocateRegistry. registry = java.rmi.registry.LocateRegistry.
getRegistry("localhost", TestLibrary.REGISTRY_PORT, getRegistry("localhost", registryPort,
new Compress.CompressRMIClientSocketFactory()); new Compress.CompressRMIClientSocketFactory());
UseCustomSocketFactory.checkStub(registry, "RMIClientSocket"); UseCustomSocketFactory.checkStub(registry, "RMIClientSocket");
hello = (Hello) registry.lookup("/HelloServer"); hello = (Hello) registry.lookup("/HelloServer");
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
* @build Hello * @build Hello
* @build HelloImpl * @build HelloImpl
* @build HelloImpl_Stub * @build HelloImpl_Stub
* @build TestLibrary
* @build UseCustomSocketFactory * @build UseCustomSocketFactory
* @build Compress * @build Compress
* @run main/othervm/policy=security.policy/timeout=240 UseCustomSocketFactory * @run main/othervm/policy=security.policy/timeout=240 UseCustomSocketFactory
...@@ -58,6 +59,7 @@ public class UseCustomSocketFactory { ...@@ -58,6 +59,7 @@ public class UseCustomSocketFactory {
System.out.println("\nRegression test for bug 4148850\n"); System.out.println("\nRegression test for bug 4148850\n");
TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
int registryPort = TestLibrary.getUnusedRandomPort();
try { try {
impl = new HelloImpl(); impl = new HelloImpl();
...@@ -67,7 +69,7 @@ public class UseCustomSocketFactory { ...@@ -67,7 +69,7 @@ public class UseCustomSocketFactory {
* allow the rmiregistry to be secure. * allow the rmiregistry to be secure.
*/ */
registry = LocateRegistry. registry = LocateRegistry.
createRegistry(TestLibrary.REGISTRY_PORT, createRegistry(registryPort,
new Compress.CompressRMIClientSocketFactory(), new Compress.CompressRMIClientSocketFactory(),
new Compress.CompressRMIServerSocketFactory()); new Compress.CompressRMIServerSocketFactory());
registry.rebind("/HelloServer", impl); registry.rebind("/HelloServer", impl);
...@@ -77,8 +79,12 @@ public class UseCustomSocketFactory { ...@@ -77,8 +79,12 @@ public class UseCustomSocketFactory {
TestLibrary.bomb("creating registry", e); TestLibrary.bomb("creating registry", e);
} }
JavaVM serverVM = new JavaVM("HelloImpl", "-Djava.security.policy=" + JavaVM serverVM = new JavaVM("HelloImpl",
TestParams.defaultPolicy, ""); "-Djava.security.policy=" +
TestParams.defaultPolicy +
" -Drmi.registry.port=" +
registryPort,
"");
try { try {
......
...@@ -22,6 +22,8 @@ grant { ...@@ -22,6 +22,8 @@ grant {
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "rmi.registry.port", "read";
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -64,8 +64,9 @@ public class EchoImpl ...@@ -64,8 +64,9 @@ public class EchoImpl
System.out.println("EchoServer: creating remote object"); System.out.println("EchoServer: creating remote object");
EchoImpl impl = new EchoImpl(protocol); EchoImpl impl = new EchoImpl(protocol);
int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));
System.out.println("EchoServer: binding in registry"); System.out.println("EchoServer: binding in registry");
Naming.rebind("//:" + TestLibrary.REGISTRY_PORT + Naming.rebind("//:" + registryPort +
"/EchoServer", impl); "/EchoServer", impl);
System.out.println("EchoServer ready."); System.out.println("EchoServer ready.");
} catch (Exception e) { } catch (Exception e) {
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -46,6 +46,8 @@ public class UseCustomSocketFactory { ...@@ -46,6 +46,8 @@ public class UseCustomSocketFactory {
public static void main(String[] args) { public static void main(String[] args) {
int registryPort = -1;
String[] protocol = new String[] { "", "compress", "xor" }; String[] protocol = new String[] { "", "compress", "xor" };
System.out.println("\nRegression test for bug 4127826\n"); System.out.println("\nRegression test for bug 4127826\n");
...@@ -53,7 +55,8 @@ public class UseCustomSocketFactory { ...@@ -53,7 +55,8 @@ public class UseCustomSocketFactory {
TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
try { try {
LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); Registry registry = TestLibrary.createRegistryOnUnusedPort();
registryPort = TestLibrary.getRegistryPort(registry);
} catch (Exception e) { } catch (Exception e) {
TestLibrary.bomb("creating registry", e); TestLibrary.bomb("creating registry", e);
} }
...@@ -65,7 +68,9 @@ public class UseCustomSocketFactory { ...@@ -65,7 +68,9 @@ public class UseCustomSocketFactory {
JavaVM serverVM = new JavaVM("EchoImpl", JavaVM serverVM = new JavaVM("EchoImpl",
"-Djava.security.policy=" + "-Djava.security.policy=" +
TestParams.defaultPolicy, TestParams.defaultPolicy +
" -Drmi.registry.port=" +
registryPort,
protocol[i]); protocol[i]);
System.err.println("\nusing protocol: " + System.err.println("\nusing protocol: " +
(protocol[i] == "" ? "none" : protocol[i])); (protocol[i] == "" ? "none" : protocol[i]));
...@@ -79,7 +84,7 @@ public class UseCustomSocketFactory { ...@@ -79,7 +84,7 @@ public class UseCustomSocketFactory {
Echo obj = null; Echo obj = null;
do { do {
try { try {
obj = (Echo) Naming.lookup("//:" + TestLibrary.REGISTRY_PORT + obj = (Echo) Naming.lookup("//:" + registryPort +
"/EchoServer"); "/EchoServer");
break; break;
} catch (NotBoundException e) { } catch (NotBoundException e) {
...@@ -109,7 +114,7 @@ public class UseCustomSocketFactory { ...@@ -109,7 +114,7 @@ public class UseCustomSocketFactory {
} finally { } finally {
serverVM.destroy(); serverVM.destroy();
try { try {
Naming.unbind("//:" + TestLibrary.REGISTRY_PORT + Naming.unbind("//:" + registryPort +
"/EchoServer"); "/EchoServer");
} catch (Exception e) { } catch (Exception e) {
TestLibrary.bomb("unbinding EchoServer", e); TestLibrary.bomb("unbinding EchoServer", e);
......
...@@ -22,9 +22,18 @@ grant { ...@@ -22,9 +22,18 @@ grant {
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "rmi.registry.port", "read";
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
// used by TestLibrary to get the RMI Registry port
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.proxy";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp";
// test needs to export rmid and communicate with objects on arbitrary ports // test needs to export rmid and communicate with objects on arbitrary ports
permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
}; };
/* /*
* Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
* @summary retryServerSocket should not retry on BindException * @summary retryServerSocket should not retry on BindException
* @author Ann Wollrath * @author Ann Wollrath
* *
* @library ../../testlibrary
* @build AddrInUse * @build AddrInUse
* @run main/othervm AddrInUse * @run main/othervm AddrInUse
*/ */
...@@ -36,7 +37,7 @@ import java.rmi.server.ExportException; ...@@ -36,7 +37,7 @@ import java.rmi.server.ExportException;
public class AddrInUse implements Runnable { public class AddrInUse implements Runnable {
private static final int PORT = 9999; private static int port = -1;
private static final long TIMEOUT = 10000; private static final long TIMEOUT = 10000;
private boolean exportSucceeded = false; private boolean exportSucceeded = false;
...@@ -49,7 +50,7 @@ public class AddrInUse implements Runnable { ...@@ -49,7 +50,7 @@ public class AddrInUse implements Runnable {
* has already been bound, and record the result. * has already been bound, and record the result.
*/ */
try { try {
LocateRegistry.createRegistry(PORT); LocateRegistry.createRegistry(port);
synchronized (this) { synchronized (this) {
exportSucceeded = true; exportSucceeded = true;
notifyAll(); notifyAll();
...@@ -68,8 +69,9 @@ public class AddrInUse implements Runnable { ...@@ -68,8 +69,9 @@ public class AddrInUse implements Runnable {
/* /*
* Bind a server socket to a port. * Bind a server socket to a port.
*/ */
System.err.println("create a ServerSocket on port " + PORT + "..."); ServerSocket server = new ServerSocket(0);
ServerSocket server = new ServerSocket(PORT); port = server.getLocalPort();
System.err.println("Created a ServerSocket on port " + port + "...");
/* /*
* Start a thread that creates a registry on the same port, * Start a thread that creates a registry on the same port,
......
/* /*
* Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -82,15 +82,17 @@ public class KeepAliveDuringCall implements ShutdownMonitor { ...@@ -82,15 +82,17 @@ public class KeepAliveDuringCall implements ShutdownMonitor {
UnicastRemoteObject.exportObject(obj); UnicastRemoteObject.exportObject(obj);
System.err.println("exported shutdown monitor"); System.err.println("exported shutdown monitor");
Registry localRegistry = Registry localRegistry = TestLibrary.createRegistryOnUnusedPort();
LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); int registryPort = TestLibrary.getRegistryPort(localRegistry);
System.err.println("created local registry"); System.err.println("created local registry");
localRegistry.bind(BINDING, obj); localRegistry.bind(BINDING, obj);
System.err.println("bound shutdown monitor in local registry"); System.err.println("bound shutdown monitor in local registry");
System.err.println("starting remote ShutdownImpl VM..."); System.err.println("starting remote ShutdownImpl VM...");
(new JavaVM("ShutdownImpl")).start(); (new JavaVM("ShutdownImpl",
"-Drmi.registry.port=" +
registryPort, "")).start();
Shutdown s; Shutdown s;
synchronized (obj.lock) { synchronized (obj.lock) {
......
/* /*
* Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -68,8 +68,9 @@ public class ShutdownImpl implements Shutdown { ...@@ -68,8 +68,9 @@ public class ShutdownImpl implements Shutdown {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));
Registry registry = Registry registry =
LocateRegistry.getRegistry("", TestLibrary.REGISTRY_PORT); LocateRegistry.getRegistry("", registryPort);
ShutdownMonitor monitor = (ShutdownMonitor) ShutdownMonitor monitor = (ShutdownMonitor)
registry.lookup(KeepAliveDuringCall.BINDING); registry.lookup(KeepAliveDuringCall.BINDING);
System.err.println("(ShutdownImpl) retrieved shutdown monitor"); System.err.println("(ShutdownImpl) retrieved shutdown monitor");
......
/* /*
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,8 +28,10 @@ ...@@ -28,8 +28,10 @@
* *
* @author Ann Wollrath * @author Ann Wollrath
* *
* @library ../../../testlibrary
* @build UnexportLeak * @build UnexportLeak
* @build UnexportLeak_Stub * @build UnexportLeak_Stub
* @build TestLibrary
* @build Ping * @build Ping
* @run main/othervm UnexportLeak * @run main/othervm UnexportLeak
*/ */
...@@ -40,20 +42,18 @@ import java.rmi.server.*; ...@@ -40,20 +42,18 @@ import java.rmi.server.*;
import java.rmi.registry.*; import java.rmi.registry.*;
public class UnexportLeak implements Ping { public class UnexportLeak implements Ping {
private static int PORT = 2006;
public void ping() { public void ping() {
} }
public static void main(String[] args) { public static void main(String[] args) {
try { try {
System.err.println("\nRegression test for bug 4331349\n"); System.err.println("\nRegression test for bug 4331349\n");
LocateRegistry.createRegistry(PORT); Registry registry = TestLibrary.createRegistryOnUnusedPort();
int registryPort = TestLibrary.getRegistryPort(registry);
Remote obj = new UnexportLeak(); Remote obj = new UnexportLeak();
WeakReference wr = new WeakReference(obj); WeakReference wr = new WeakReference(obj);
UnicastRemoteObject.exportObject(obj); UnicastRemoteObject.exportObject(obj);
LocateRegistry.getRegistry(PORT).rebind("UnexportLeak", obj); LocateRegistry.getRegistry(registryPort).rebind("UnexportLeak", obj);
UnicastRemoteObject.unexportObject(obj, true); UnicastRemoteObject.unexportObject(obj, true);
obj = null; obj = null;
flushRefs(); flushRefs();
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
* @library ../../../testlibrary * @library ../../../testlibrary
* @build FiniteGCLatency * @build FiniteGCLatency
* @build FiniteGCLatency_Stub * @build FiniteGCLatency_Stub
* @build TestLibrary
* @run main/othervm/timeout=120 FiniteGCLatency * @run main/othervm/timeout=120 FiniteGCLatency
*/ */
...@@ -78,11 +79,11 @@ public class FiniteGCLatency implements Remote, Unreferenced { ...@@ -78,11 +79,11 @@ public class FiniteGCLatency implements Remote, Unreferenced {
try { try {
UnicastRemoteObject.exportObject(obj); UnicastRemoteObject.exportObject(obj);
System.err.println("exported remote object"); System.err.println("exported remote object");
Registry registry1 = TestLibrary.createRegistryOnUnusedPort();
LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); int port = TestLibrary.getRegistryPort(registry1);
System.err.println("created registry"); System.err.println("created registry");
Registry registry = LocateRegistry.getRegistry("", TestLibrary.REGISTRY_PORT); Registry registry = LocateRegistry.getRegistry("", port);
registry.bind(BINDING, obj); registry.bind(BINDING, obj);
System.err.println("bound remote object in registry"); System.err.println("bound remote object in registry");
......
/* /*
* Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -87,8 +87,9 @@ public class LeaseCheckInterval implements Remote, Unreferenced { ...@@ -87,8 +87,9 @@ public class LeaseCheckInterval implements Remote, Unreferenced {
UnicastRemoteObject.exportObject(obj); UnicastRemoteObject.exportObject(obj);
System.err.println("exported remote object"); System.err.println("exported remote object");
int registryPort = TestLibrary.getUnusedRandomPort();
Registry localRegistry = Registry localRegistry =
LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); LocateRegistry.createRegistry(registryPort);
System.err.println("created local registry"); System.err.println("created local registry");
localRegistry.bind(BINDING, obj); localRegistry.bind(BINDING, obj);
...@@ -96,7 +97,8 @@ public class LeaseCheckInterval implements Remote, Unreferenced { ...@@ -96,7 +97,8 @@ public class LeaseCheckInterval implements Remote, Unreferenced {
synchronized (obj.lock) { synchronized (obj.lock) {
System.err.println("starting remote client VM..."); System.err.println("starting remote client VM...");
(new JavaVM("SelfTerminator")).start(); (new JavaVM("SelfTerminator", "-Drmi.registry.port=" +
registryPort, "")).start();
System.err.println("waiting for unreferenced() callback..."); System.err.println("waiting for unreferenced() callback...");
obj.lock.wait(TIMEOUT); obj.lock.wait(TIMEOUT);
......
/* /*
* Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,8 +33,10 @@ public class SelfTerminator { ...@@ -33,8 +33,10 @@ public class SelfTerminator {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
int registryPort =
Integer.parseInt(System.getProperty("rmi.registry.port"));
Registry registry = Registry registry =
LocateRegistry.getRegistry("", TestLibrary.REGISTRY_PORT); LocateRegistry.getRegistry("", registryPort);
Remote stub = registry.lookup(LeaseCheckInterval.BINDING); Remote stub = registry.lookup(LeaseCheckInterval.BINDING);
Runtime.getRuntime().halt(0); Runtime.getRuntime().halt(0);
} catch (Exception e) { } catch (Exception e) {
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
* @library ../../../testlibrary * @library ../../../testlibrary
* @build UnreferencedContext * @build UnreferencedContext
* @build UnreferencedContext_Stub * @build UnreferencedContext_Stub
* @build TestLibrary
* @run main/othervm/timeout=120 UnreferencedContext * @run main/othervm/timeout=120 UnreferencedContext
*/ */
...@@ -119,10 +120,11 @@ public class UnreferencedContext implements Remote, Unreferenced, Runnable { ...@@ -119,10 +120,11 @@ public class UnreferencedContext implements Remote, Unreferenced, Runnable {
UnicastRemoteObject.exportObject(obj); UnicastRemoteObject.exportObject(obj);
System.err.println("exported remote object"); System.err.println("exported remote object");
LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); Registry registry1 = TestLibrary.createRegistryOnUnusedPort();
int port = TestLibrary.getRegistryPort(registry1);
System.err.println("created registry"); System.err.println("created registry");
Registry registry = LocateRegistry.getRegistry("", TestLibrary.REGISTRY_PORT); Registry registry = LocateRegistry.getRegistry("", port);
registry.bind(BINDING, obj); registry.bind(BINDING, obj);
System.err.println("bound remote object in registry"); System.err.println("bound remote object in registry");
......
/* /*
* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
* @build Ping * @build Ping
* @build UseCustomRef_Stub * @build UseCustomRef_Stub
* @build UseCustomRef_Skel * @build UseCustomRef_Skel
* @build TestLibrary
* @run main/othervm/policy=security.policy/secure=java.rmi.RMISecurityManager/timeout=120 UseCustomRef * @run main/othervm/policy=security.policy/secure=java.rmi.RMISecurityManager/timeout=120 UseCustomRef
* *
* This test was failing to run because the synthetic access * This test was failing to run because the synthetic access
...@@ -84,8 +85,9 @@ public class UseCustomRef ...@@ -84,8 +85,9 @@ public class UseCustomRef
TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
System.err.println("creating Registry..."); System.err.println("creating Registry...");
registry = LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT);
registry = TestLibrary.createRegistryOnUnusedPort();
int port = TestLibrary.getRegistryPort(registry);
/* /*
* create object with custom ref and bind in registry * create object with custom ref and bind in registry
*/ */
...@@ -97,7 +99,7 @@ public class UseCustomRef ...@@ -97,7 +99,7 @@ public class UseCustomRef
"instanceof CustomServerRef"); "instanceof CustomServerRef");
} }
String name = "//:" + TestLibrary.REGISTRY_PORT + "/UseCustomRef"; String name = "//:" + port + "/UseCustomRef";
// String name = "UseCustomRef"; // String name = "UseCustomRef";
System.err.println("binding object in registry..."); System.err.println("binding object in registry...");
Naming.rebind(name, cr); Naming.rebind(name, cr);
......
...@@ -8,8 +8,11 @@ grant codeBase "file:${java.home}/lib/ext/*" { ...@@ -8,8 +8,11 @@ grant codeBase "file:${java.home}/lib/ext/*" {
grant { grant {
// the test uses a class in the package sun.rmi.server // the test uses a class in the package sun.rmi.server
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server"; permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport"; permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.proxy";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp";
permission java.util.PropertyPermission "package.restrict.access.sun", "read"; permission java.util.PropertyPermission "package.restrict.access.sun", "read";
permission java.util.PropertyPermission "package.restrict.access.sun.rmi", "read"; permission java.util.PropertyPermission "package.restrict.access.sun.rmi", "read";
......
/* /*
* Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -169,37 +169,10 @@ public class ActivationLibrary { ...@@ -169,37 +169,10 @@ public class ActivationLibrary {
return false; return false;
} }
/**
* Check to see if an arry of Strings contains a given string.
*/
private static boolean
containsString(String[] strings, String contained)
{
if (strings == null) {
if (contained == null) {
return true;
}
return false;
}
for (int i = 0 ; i < strings.length ; i ++ ) {
if ((strings[i] != null) &&
(strings[i].indexOf(contained) >= 0))
{
return true;
}
}
return false;
}
/** cleanup after rmid */ /** cleanup after rmid */
public static void rmidCleanup(RMID rmid) { public static void rmidCleanup(RMID rmid) {
rmidCleanup(rmid, TestLibrary.RMID_PORT);
}
public static void rmidCleanup(RMID rmid, int port) {
if (rmid != null) { if (rmid != null) {
if (!ActivationLibrary.safeDestroy(rmid, port, SAFE_WAIT_TIME)) { if (!ActivationLibrary.safeDestroy(rmid, SAFE_WAIT_TIME)) {
TestLibrary.bomb("rmid not destroyed in: " + TestLibrary.bomb("rmid not destroyed in: " +
SAFE_WAIT_TIME + SAFE_WAIT_TIME +
" milliseconds"); " milliseconds");
...@@ -215,8 +188,8 @@ public class ActivationLibrary { ...@@ -215,8 +188,8 @@ public class ActivationLibrary {
* @return whether or not shutdown completed succesfully in the * @return whether or not shutdown completed succesfully in the
* timeAllowed * timeAllowed
*/ */
private static boolean safeDestroy(RMID rmid, int port, long timeAllowed) { private static boolean safeDestroy(RMID rmid, long timeAllowed) {
DestroyThread destroyThread = new DestroyThread(rmid, port); DestroyThread destroyThread = new DestroyThread(rmid);
destroyThread.start(); destroyThread.start();
try { try {
...@@ -236,9 +209,9 @@ public class ActivationLibrary { ...@@ -236,9 +209,9 @@ public class ActivationLibrary {
private final int port; private final int port;
private boolean succeeded = false; private boolean succeeded = false;
DestroyThread(RMID rmid, int port) { DestroyThread(RMID rmid) {
this.rmid = rmid; this.rmid = rmid;
this.port = port; this.port = rmid.getPort();
this.setDaemon(true); this.setDaemon(true);
} }
......
/* /*
* Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
import java.io.*; import java.io.*;
import java.rmi.*; import java.rmi.*;
import java.rmi.activation.*; import java.rmi.activation.*;
import java.util.Properties;
/** /**
* Utility class that creates an instance of rmid with a policy * Utility class that creates an instance of rmid with a policy
...@@ -133,7 +132,7 @@ public class RMID extends JavaVM { ...@@ -133,7 +132,7 @@ public class RMID extends JavaVM {
boolean debugExec) boolean debugExec)
{ {
return createRMID(out, err, debugExec, true, return createRMID(out, err, debugExec, true,
TestLibrary.RMID_PORT); TestLibrary.getUnusedRandomPort());
} }
public static RMID createRMID(OutputStream out, OutputStream err, public static RMID createRMID(OutputStream out, OutputStream err,
...@@ -208,7 +207,7 @@ public class RMID extends JavaVM { ...@@ -208,7 +207,7 @@ public class RMID extends JavaVM {
// if rmid is already running, then the test will fail with // if rmid is already running, then the test will fail with
// a well recognized exception (port already in use...). // a well recognized exception (port already in use...).
mesg("starting rmid..."); mesg("starting rmid on port #" + port + "...");
super.start(); super.start();
int slopFactor = 1; int slopFactor = 1;
...@@ -235,6 +234,14 @@ public class RMID extends JavaVM { ...@@ -235,6 +234,14 @@ public class RMID extends JavaVM {
// Checking if rmid is present // Checking if rmid is present
if (ActivationLibrary.rmidRunning(port)) { if (ActivationLibrary.rmidRunning(port)) {
/**
* We need to set the java.rmi.activation.port value as the
* activation system will use the property to determine the
* port #. The activation system will use this value if set.
* If it isn't set, the activation system will set it to an
* incorrect value.
*/
System.setProperty("java.rmi.activation.port", Integer.toString(port));
mesg("finished starting rmid."); mesg("finished starting rmid.");
return; return;
} }
...@@ -259,10 +266,6 @@ public class RMID extends JavaVM { ...@@ -259,10 +266,6 @@ public class RMID extends JavaVM {
* Shutdown does not nullify possible references to the rmid * Shutdown does not nullify possible references to the rmid
* process object (destroy does though). * process object (destroy does though).
*/ */
public static void shutdown() {
shutdown(TestLibrary.RMID_PORT);
}
public static void shutdown(int port) { public static void shutdown(int port) {
try { try {
...@@ -301,9 +304,7 @@ public class RMID extends JavaVM { ...@@ -301,9 +304,7 @@ public class RMID extends JavaVM {
* if rmid is a child process of the current VM. * if rmid is a child process of the current VM.
*/ */
public void destroy() { public void destroy() {
// attempt graceful shutdown of the activation system
// attempt graceful shutdown of the activation system on
// TestLibrary.RMID_PORT
shutdown(port); shutdown(port);
if (vm != null) { if (vm != null) {
...@@ -357,4 +358,6 @@ public class RMID extends JavaVM { ...@@ -357,4 +358,6 @@ public class RMID extends JavaVM {
vm = null; vm = null;
} }
} }
public int getPort() {return port;}
} }
/* /*
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -56,12 +56,13 @@ public class RegistryRunner extends UnicastRemoteObject ...@@ -56,12 +56,13 @@ public class RegistryRunner extends UnicastRemoteObject
* Request that the registry process exit and handle * Request that the registry process exit and handle
* related exceptions. * related exceptions.
*/ */
public static void requestExit() { public static void requestExit(int port) {
try { try {
RemoteExiter exiter = RemoteExiter exiter =
(RemoteExiter) (RemoteExiter)
Naming.lookup("rmi://localhost:" + Naming.lookup("rmi://localhost:" +
TestLibrary.REGISTRY_PORT + port +
"/RemoteExiter"); "/RemoteExiter");
try { try {
exiter.exit(); exiter.exit();
...@@ -84,7 +85,7 @@ public class RegistryRunner extends UnicastRemoteObject ...@@ -84,7 +85,7 @@ public class RegistryRunner extends UnicastRemoteObject
System.err.println("Usage: <port>"); System.err.println("Usage: <port>");
System.exit(0); System.exit(0);
} }
int port = TestLibrary.REGISTRY_PORT; int port = -1;
try { try {
port = Integer.parseInt(args[0]); port = Integer.parseInt(args[0]);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
......
/* /*
* Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -113,7 +113,9 @@ public class StreamPipe extends Thread { ...@@ -113,7 +113,9 @@ public class StreamPipe extends Thread {
w.flush(); w.flush();
line = r.readLine(); line = r.readLine();
} }
} catch (InterruptedIOException iioe) {
// Thread interrupted during IO operation. Terminate StreamPipe.
return;
} catch (IOException e) { } catch (IOException e) {
System.err.println("*** IOException in StreamPipe.run:"); System.err.println("*** IOException in StreamPipe.run:");
e.printStackTrace(); e.printStackTrace();
......
/* /*
* Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -36,37 +36,62 @@ ...@@ -36,37 +36,62 @@
* not make use of packages. * not make use of packages.
*/ */
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.net.URL;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.rmi.activation.Activatable; import java.net.ServerSocket;
import java.rmi.activation.ActivationID; import java.net.URL;
import java.rmi.NoSuchObjectException; import java.rmi.NoSuchObjectException;
import java.rmi.registry.Registry;
import java.rmi.Remote; import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.RemoteRef;
import java.rmi.server.UnicastRemoteObject; import java.rmi.server.UnicastRemoteObject;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties; import java.util.Properties;
import java.io.ByteArrayOutputStream; import sun.rmi.registry.RegistryImpl;
import java.security.AccessController; import sun.rmi.server.UnicastServerRef;
import java.security.PrivilegedAction; import sun.rmi.transport.Endpoint;
import sun.rmi.transport.LiveRef;
import sun.rmi.transport.tcp.TCPEndpoint;
/** /**
* Class of utility/library methods (i.e. procedures) that assist with * Class of utility/library methods (i.e. procedures) that assist with
* the writing and maintainance of rmi regression tests. * the writing and maintainance of rmi regression tests.
*/ */
public class TestLibrary { public class TestLibrary {
/**
/** standard test port number for registry */ * IMPORTANT!
public final static int REGISTRY_PORT = 2006; *
/** port for rmid necessary: not used to actually start rmid */ * RMI tests are run concurrently and port conflicts result when a single
public final static int RMID_PORT = 1098; * port number is used by multiple tests. When needing a port, use
* getUnusedRandomPort() wherever possible. If getUnusedRandomPort() cannot
* be used, reserve and specify a port to use for your test here. This
* will ensure there are no port conflicts amongst the RMI tests. The
* port numbers specified here may also be specified in the respective
* tests. Do not change the reserved port numbers here without also
* changing the port numbers in the respective tests.
*
* When needing an instance of the RMIRegistry, use
* createRegistryOnUnusedPort wherever possible to prevent port conflicts.
*
* Reserved port range: FIXED_PORT_MIN to FIXED_PORT_MAX (inclusive) for
* tests which cannot use a random port. If new fixed ports are added below
* FIXED_PORT_MIN or above FIXED_PORT_MAX, then adjust
* FIXED_PORT_MIN/MAX appropriately.
*/
public final static int FIXED_PORT_MIN = 64001;
public final static int FIXED_PORT_MAX = 64010;
public final static int RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT = 64001;
public final static int RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT = 64002;
public final static int INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT = 64003;
public final static int INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT = 64004;
public final static int READTEST_REGISTRY_PORT = 64005;
static void mesg(Object mesg) { static void mesg(Object mesg) {
System.err.println("TEST_LIBRARY: " + mesg.toString()); System.err.println("TEST_LIBRARY: " + mesg.toString());
...@@ -339,6 +364,83 @@ public class TestLibrary { ...@@ -339,6 +364,83 @@ public class TestLibrary {
} }
} }
/**
* Creates an RMI {@link Registry} on a random, un-reserved port.
*
* @returns an RMI Registry, using a random port.
* @throws RemoteException if there was a problem creating a Registry.
*/
public static Registry createRegistryOnUnusedPort() throws RemoteException {
return LocateRegistry.createRegistry(getUnusedRandomPort());
}
/**
* Returns the port number the RMI {@link Registry} is running on.
*
* @param registry the registry to find the port of.
* @return the port number the registry is using.
* @throws RuntimeException if there was a problem getting the port number.
*/
public static int getRegistryPort(Registry registry) {
int port = -1;
try {
RemoteRef remoteRef = ((RegistryImpl)registry).getRef();
LiveRef liveRef = ((UnicastServerRef)remoteRef).getLiveRef();
Endpoint endpoint = liveRef.getChannel().getEndpoint();
TCPEndpoint tcpEndpoint = (TCPEndpoint) endpoint;
port = tcpEndpoint.getPort();
} catch (Exception ex) {
throw new RuntimeException("Error getting registry port.", ex);
}
return port;
}
/**
* Returns an unused random port number which is not a reserved port. Will
* try up to 10 times to get a random port before giving up and throwing a
* RuntimeException.
*
* @return an unused random port number.
* @throws RuntimeException if there was a problem getting a port.
*/
public static int getUnusedRandomPort() {
int numTries = 0;
int unusedRandomPort = FIXED_PORT_MIN;
Exception ex = null;
while (numTries++ < 10) {
ex = null; //reset
try (ServerSocket ss = new ServerSocket(0)) {
unusedRandomPort = ss.getLocalPort();
} catch (Exception e) {
ex = e;
}
if (!isReservedPort(unusedRandomPort)) {
return unusedRandomPort;
}
}
// If we're here, then either an exception was thrown or the port is
// a reserved port.
throw new RuntimeException("Error getting unused random port.", ex);
}
/**
* Determines if a port is one of the reserved port numbers.
*
* @param port the port to test.
* @return {@code true} if the port is a reserved port, otherwise
* {@code false}.
*/
public static boolean isReservedPort(int port) {
return ((port >= FIXED_PORT_MIN) && (port <= FIXED_PORT_MAX) ||
(port == 1099));
}
/** /**
* Method to capture the stack trace of an exception and return it * Method to capture the stack trace of an exception and return it
* as a string. * as a string.
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
* *
* @library ../../testlibrary * @library ../../testlibrary
* @build CheckFQDN CheckFQDNClient CheckFQDN_Stub TellServerName * @build CheckFQDN CheckFQDNClient CheckFQDN_Stub TellServerName
* @build TestLibrary
* @run main/othervm/timeout=120 CheckFQDN * @run main/othervm/timeout=120 CheckFQDN
*/ */
...@@ -63,7 +64,7 @@ import java.io.*; ...@@ -63,7 +64,7 @@ import java.io.*;
*/ */
public class CheckFQDN extends UnicastRemoteObject public class CheckFQDN extends UnicastRemoteObject
implements TellServerName { implements TellServerName {
public static int REGISTRY_PORT =-1;
static String propertyBeingTested = null; static String propertyBeingTested = null;
static String propertyBeingTestedValue = null; static String propertyBeingTestedValue = null;
...@@ -77,8 +78,8 @@ public class CheckFQDN extends UnicastRemoteObject ...@@ -77,8 +78,8 @@ public class CheckFQDN extends UnicastRemoteObject
System.err.println System.err.println
("\nRegression test for bug/rfe 4115683\n"); ("\nRegression test for bug/rfe 4115683\n");
Registry registry = java.rmi.registry.LocateRegistry. Registry registry = TestLibrary.createRegistryOnUnusedPort();
createRegistry(TestLibrary.REGISTRY_PORT); REGISTRY_PORT = TestLibrary.getRegistryPort(registry);
registry.bind("CheckFQDN", checkFQDN); registry.bind("CheckFQDN", checkFQDN);
/* test the host name scheme in different environments.*/ /* test the host name scheme in different environments.*/
...@@ -117,7 +118,9 @@ public class CheckFQDN extends UnicastRemoteObject ...@@ -117,7 +118,9 @@ public class CheckFQDN extends UnicastRemoteObject
JavaVM jvm = new JavaVM("CheckFQDNClient", JavaVM jvm = new JavaVM("CheckFQDNClient",
propOption + property + propOption + property +
equal + equal +
propertyValue + extraProp, propertyValue + extraProp +
" -Drmi.registry.port=" +
REGISTRY_PORT,
""); "");
propertyBeingTested=property; propertyBeingTested=property;
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -58,8 +58,9 @@ public class CheckFQDNClient implements Runnable { ...@@ -58,8 +58,9 @@ public class CheckFQDNClient implements Runnable {
System.err.println("Client host name: " + System.err.println("Client host name: " +
hostname); hostname);
int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));
tell = (TellServerName) Naming.lookup("rmi://:" + tell = (TellServerName) Naming.lookup("rmi://:" +
TestLibrary.REGISTRY_PORT registryPort
+ "/CheckFQDN"); + "/CheckFQDN");
tell.tellServerName(hostname); tell.tellServerName(hostname);
System.err.println("client has exited"); System.err.println("client has exited");
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
* *
* @library ../../testlibrary * @library ../../testlibrary
* @build CheckLeaseLeak CheckLeaseLeak_Stub LeaseLeakClient LeaseLeak * @build CheckLeaseLeak CheckLeaseLeak_Stub LeaseLeakClient LeaseLeak
* @build TestLibrary
* @run main/othervm/timeout=240 CheckLeaseLeak * @run main/othervm/timeout=240 CheckLeaseLeak
* *
*/ */
...@@ -57,7 +58,6 @@ import java.lang.reflect.*; ...@@ -57,7 +58,6 @@ import java.lang.reflect.*;
import java.rmi.registry.*; import java.rmi.registry.*;
public class CheckLeaseLeak extends UnicastRemoteObject implements LeaseLeak { public class CheckLeaseLeak extends UnicastRemoteObject implements LeaseLeak {
public CheckLeaseLeak() throws RemoteException { } public CheckLeaseLeak() throws RemoteException { }
public void ping () throws RemoteException { } public void ping () throws RemoteException { }
...@@ -87,8 +87,8 @@ public class CheckLeaseLeak extends UnicastRemoteObject implements LeaseLeak { ...@@ -87,8 +87,8 @@ public class CheckLeaseLeak extends UnicastRemoteObject implements LeaseLeak {
try { try {
Registry registry = Registry registry =
java.rmi.registry.LocateRegistry. TestLibrary.createRegistryOnUnusedPort();
createRegistry(TestLibrary.REGISTRY_PORT); int registryPort = TestLibrary.getRegistryPort(registry);
leakServer = new CheckLeaseLeak(); leakServer = new CheckLeaseLeak();
registry.rebind("/LeaseLeak", leakServer); registry.rebind("/LeaseLeak", leakServer);
...@@ -99,7 +99,10 @@ public class CheckLeaseLeak extends UnicastRemoteObject implements LeaseLeak { ...@@ -99,7 +99,10 @@ public class CheckLeaseLeak extends UnicastRemoteObject implements LeaseLeak {
JavaVM jvm = new JavaVM("LeaseLeakClient", JavaVM jvm = new JavaVM("LeaseLeakClient",
" -Djava.security.policy=" + " -Djava.security.policy=" +
TestParams.defaultPolicy, ""); TestParams.defaultPolicy +
" -Drmi.registry.port=" +
registryPort,
"");
jvm.start(); jvm.start();
if (jvm.getVM().waitFor() == 1 ) { if (jvm.getVM().waitFor() == 1 ) {
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -31,11 +31,11 @@ public class LeaseLeakClient { ...@@ -31,11 +31,11 @@ public class LeaseLeakClient {
try { try {
LeaseLeak leaseLeak = null; LeaseLeak leaseLeak = null;
int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));
// put a reference on a remote object. // put a reference on a remote object.
Registry registry = Registry registry =
java.rmi.registry.LocateRegistry.getRegistry( java.rmi.registry.LocateRegistry.getRegistry(registryPort);
TestLibrary.REGISTRY_PORT);
leaseLeak = (LeaseLeak) registry.lookup("/LeaseLeak"); leaseLeak = (LeaseLeak) registry.lookup("/LeaseLeak");
leaseLeak.ping(); leaseLeak.ping();
......
...@@ -19,6 +19,7 @@ grant { ...@@ -19,6 +19,7 @@ grant {
permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "java.home", "read"; permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "rmi.registry.port", "read";
permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.policy", "read";
permission java.util.PropertyPermission "java.security.manager", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
......
/* /*
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
* the local port is released). * the local port is released).
* @author Peter Jones * @author Peter Jones
* *
* @build CloseServerSocket * @library ../../testlibrary
* @build CloseServerSocket TestLibrary
* @run main/othervm CloseServerSocket * @run main/othervm CloseServerSocket
*/ */
...@@ -44,8 +45,7 @@ import java.rmi.server.RMIServerSocketFactory; ...@@ -44,8 +45,7 @@ import java.rmi.server.RMIServerSocketFactory;
import java.rmi.server.UnicastRemoteObject; import java.rmi.server.UnicastRemoteObject;
public class CloseServerSocket implements Remote { public class CloseServerSocket implements Remote {
private static final int PORT = TestLibrary.getUnusedRandomPort();
private static final int PORT = 2020;
private CloseServerSocket() { } private CloseServerSocket() { }
...@@ -88,7 +88,7 @@ public class CloseServerSocket implements Remote { ...@@ -88,7 +88,7 @@ public class CloseServerSocket implements Remote {
} }
private static void verifyPortFree(int port) throws IOException { private static void verifyPortFree(int port) throws IOException {
ServerSocket ss = new ServerSocket(PORT); ServerSocket ss = new ServerSocket(port);
ss.close(); ss.close();
System.err.println("- port " + port + " is free"); System.err.println("- port " + port + " is free");
} }
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
* @build Test * @build Test
* @build TestImpl * @build TestImpl
* @build TestImpl_Stub * @build TestImpl_Stub
* @build TestLibrary
* @run main/othervm/policy=security.policy/timeout=360 DGCDeadLock * @run main/othervm/policy=security.policy/timeout=360 DGCDeadLock
*/ */
...@@ -53,7 +54,7 @@ import java.rmi.*; ...@@ -53,7 +54,7 @@ import java.rmi.*;
import java.io.*; import java.io.*;
public class DGCDeadLock implements Runnable { public class DGCDeadLock implements Runnable {
private static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort();
final static public int HOLD_TARGET_TIME = 25000; final static public int HOLD_TARGET_TIME = 25000;
public static int TEST_FAIL_TIME = HOLD_TARGET_TIME + 30000; public static int TEST_FAIL_TIME = HOLD_TARGET_TIME + 30000;
public static boolean finished = false; public static boolean finished = false;
...@@ -75,7 +76,9 @@ public class DGCDeadLock implements Runnable { ...@@ -75,7 +76,9 @@ public class DGCDeadLock implements Runnable {
TestParams.defaultPolicy + TestParams.defaultPolicy +
" -Djava.rmi.dgc.leaseValue=500000" + " -Djava.rmi.dgc.leaseValue=500000" +
" -Dsun.rmi.dgc.checkInterval=" + " -Dsun.rmi.dgc.checkInterval=" +
(HOLD_TARGET_TIME - 5000) + ""; (HOLD_TARGET_TIME - 5000) +
" -Drmi.registry.port=" + REGISTRY_PORT +
"" ;
testImplVM = new JavaVM("TestImpl", options, ""); testImplVM = new JavaVM("TestImpl", options, "");
testImplVM.start(); testImplVM.start();
...@@ -112,7 +115,7 @@ public class DGCDeadLock implements Runnable { ...@@ -112,7 +115,7 @@ public class DGCDeadLock implements Runnable {
// create a test client // create a test client
Test foo = (Test) Naming.lookup("rmi://:" + Test foo = (Test) Naming.lookup("rmi://:" +
TestLibrary.REGISTRY_PORT + REGISTRY_PORT +
"/Foo"); "/Foo");
echo = foo.echo("Hello world"); echo = foo.echo("Hello world");
System.err.println("Test object created."); System.err.println("Test object created.");
...@@ -131,7 +134,7 @@ public class DGCDeadLock implements Runnable { ...@@ -131,7 +134,7 @@ public class DGCDeadLock implements Runnable {
//import "Bar" //import "Bar"
Test bar = (Test) Naming.lookup("rmi://:" + Test bar = (Test) Naming.lookup("rmi://:" +
TestLibrary.REGISTRY_PORT + REGISTRY_PORT +
"/Bar"); "/Bar");
/* infinite loop to show the liveness of Client, /* infinite loop to show the liveness of Client,
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -36,7 +36,6 @@ import java.rmi.server.*; ...@@ -36,7 +36,6 @@ import java.rmi.server.*;
public class TestImpl extends UnicastRemoteObject public class TestImpl extends UnicastRemoteObject
implements Test { implements Test {
static Thread locker = null; static Thread locker = null;
static TestImpl foo = null; static TestImpl foo = null;
static TestImpl bar = null; static TestImpl bar = null;
...@@ -57,20 +56,21 @@ public class TestImpl extends UnicastRemoteObject ...@@ -57,20 +56,21 @@ public class TestImpl extends UnicastRemoteObject
Registry registry = null; Registry registry = null;
try { try {
int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));
registry = java.rmi.registry.LocateRegistry. registry = java.rmi.registry.LocateRegistry.
createRegistry(TestLibrary.REGISTRY_PORT); createRegistry(registryPort);
//export "Foo" //export "Foo"
foo = new TestImpl(); foo = new TestImpl();
Naming.rebind("rmi://:" + Naming.rebind("rmi://:" +
TestLibrary.REGISTRY_PORT registryPort
+ "/Foo", foo); + "/Foo", foo);
try { try {
//export "Bar" after leases have been expired. //export "Bar" after leases have been expired.
bar = new TestImpl(); bar = new TestImpl();
Naming.rebind("rmi://localhost:" + Naming.rebind("rmi://localhost:" +
TestLibrary.REGISTRY_PORT registryPort
+ "/Bar", bar); + "/Bar", bar);
} catch (Exception e) { } catch (Exception e) {
throw new RemoteException(e.getMessage()); throw new RemoteException(e.getMessage());
......
/* /*
* Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
* java.rmi.ConnectException or ConnectIOException, not a MarshalException. * java.rmi.ConnectException or ConnectIOException, not a MarshalException.
* @author Peter Jones * @author Peter Jones
* *
* @build HandshakeFailure * @library ../../testlibrary
* @build HandshakeFailure TestLibrary
* @run main/othervm HandshakeFailure * @run main/othervm HandshakeFailure
*/ */
...@@ -44,7 +45,7 @@ import java.rmi.registry.Registry; ...@@ -44,7 +45,7 @@ import java.rmi.registry.Registry;
public class HandshakeFailure { public class HandshakeFailure {
private static final int PORT = 2020; private static final int PORT = TestLibrary.getUnusedRandomPort();
private static final int TIMEOUT = 10000; private static final int TIMEOUT = 10000;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
......
/* /*
* Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
* this point (because no data for the invocation has yet been written). * this point (because no data for the invocation has yet been written).
* @author Peter Jones * @author Peter Jones
* *
* @build HandshakeTimeout * @library ../../testlibrary
* @build HandshakeTimeout TestLibrary
* @run main/othervm HandshakeTimeout * @run main/othervm HandshakeTimeout
*/ */
...@@ -46,7 +47,7 @@ import java.rmi.registry.Registry; ...@@ -46,7 +47,7 @@ import java.rmi.registry.Registry;
public class HandshakeTimeout { public class HandshakeTimeout {
private static final int PORT = 2020; private static final int PORT = TestLibrary.getUnusedRandomPort();
private static final int TIMEOUT = 10000; private static final int TIMEOUT = 10000;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
......
/* /*
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* @author Dana Burns * @author Dana Burns
* *
* @library ../../testlibrary * @library ../../testlibrary
* @build HttpSocketTest HttpSocketTest_Stub * @build HttpSocketTest HttpSocketTest_Stub TestLibrary
* @run main/othervm/policy=security.policy HttpSocketTest * @run main/othervm/policy=security.policy HttpSocketTest
*/ */
...@@ -56,10 +56,7 @@ interface MyRemoteInterface extends Remote { ...@@ -56,10 +56,7 @@ interface MyRemoteInterface extends Remote {
public class HttpSocketTest extends UnicastRemoteObject public class HttpSocketTest extends UnicastRemoteObject
implements MyRemoteInterface implements MyRemoteInterface
{ {
private static final String NAME = "HttpSocketTest"; private static final String NAME = "HttpSocketTest";
private static final String REGNAME =
"//:" + TestLibrary.REGISTRY_PORT + "/" + NAME;
public HttpSocketTest() throws RemoteException{} public HttpSocketTest() throws RemoteException{}
...@@ -76,21 +73,20 @@ public class HttpSocketTest extends UnicastRemoteObject ...@@ -76,21 +73,20 @@ public class HttpSocketTest extends UnicastRemoteObject
// Set the socket factory. // Set the socket factory.
System.err.println("installing socket factory"); System.err.println("installing socket factory");
RMISocketFactory.setSocketFactory(new RMIHttpToPortSocketFactory()); RMISocketFactory.setSocketFactory(new RMIHttpToPortSocketFactory());
int registryPort = -1;
try { try {
System.err.println("Starting registry"); System.err.println("Starting registry");
registry = LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); registry = TestLibrary.createRegistryOnUnusedPort();
registryPort = TestLibrary.getRegistryPort(registry);
} catch (Exception e) { } catch (Exception e) {
TestLibrary.bomb(e); TestLibrary.bomb(e);
} }
try { try {
registry.rebind( NAME, new HttpSocketTest() ); registry.rebind( NAME, new HttpSocketTest() );
MyRemoteInterface httpTest = MyRemoteInterface httpTest =
(MyRemoteInterface)Naming.lookup( REGNAME ); (MyRemoteInterface)Naming.lookup("//:" + registryPort + "/" + NAME);
httpTest.setRemoteObject( new HttpSocketTest() ); httpTest.setRemoteObject( new HttpSocketTest() );
Remote r = httpTest.getRemoteObject(); Remote r = httpTest.getRemoteObject();
......
...@@ -4,6 +4,10 @@ grant codeBase "file:${java.home}/lib/ext/*" { ...@@ -4,6 +4,10 @@ grant codeBase "file:${java.home}/lib/ext/*" {
grant { grant {
permission java.net.SocketPermission "*:1024-", "accept,connect,listen"; permission java.net.SocketPermission "*:1024-", "accept,connect,listen";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.proxy"; permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.proxy";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp";
permission java.lang.RuntimePermission "setFactory"; permission java.lang.RuntimePermission "setFactory";
}; };
/* /*
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
* should become unreachable too (through the RMI implementation). * should become unreachable too (through the RMI implementation).
* @author Peter Jones * @author Peter Jones
* *
* @library ../../testlibrary
* @build TestLibrary
* @run main/othervm -Dsun.rmi.transport.connectionTimeout=2000 * @run main/othervm -Dsun.rmi.transport.connectionTimeout=2000
* PinClientSocketFactory * PinClientSocketFactory
*/ */
...@@ -56,7 +58,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -56,7 +58,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public class PinClientSocketFactory { public class PinClientSocketFactory {
private static final int PORT = 2345; private static final int PORT = TestLibrary.getUnusedRandomPort();
private static final int SESSIONS = 50; private static final int SESSIONS = 50;
public interface Factory extends Remote { public interface Factory extends Remote {
......
...@@ -78,10 +78,15 @@ public class PinLastArguments { ...@@ -78,10 +78,15 @@ public class PinLastArguments {
} }
impl = null; impl = null;
System.gc(); // Might require multiple calls to System.gc() for weak-references
// processing to be complete. If the weak-reference is not cleared as
if (ref.get() != null) { // expected we will hang here until timed out by the test harness.
throw new Error("TEST FAILED: impl not garbage collected"); while (true) {
System.gc();
Thread.sleep(20);
if (ref.get() == null) {
break;
}
} }
System.err.println("TEST PASSED"); System.err.println("TEST PASSED");
......
/* /*
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
* procedure (which sleeps 10 seconds after 10 rapid failures). * procedure (which sleeps 10 seconds after 10 rapid failures).
* @author Peter Jones * @author Peter Jones
* *
* @build RapidExportUnexport * @library ../../testlibrary
* @build TestLibrary RapidExportUnexport
* @run main/othervm RapidExportUnexport * @run main/othervm RapidExportUnexport
*/ */
...@@ -39,9 +40,7 @@ import java.rmi.Remote; ...@@ -39,9 +40,7 @@ import java.rmi.Remote;
import java.rmi.server.UnicastRemoteObject; import java.rmi.server.UnicastRemoteObject;
public class RapidExportUnexport { public class RapidExportUnexport {
private static final int PORT = TestLibrary.getUnusedRandomPort();
private static final int PORT = 2055;
private static final int REPS = 100; private static final int REPS = 100;
private static final long TIMEOUT = 60000; private static final long TIMEOUT = 60000;
......
/* /*
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
* continue to work because existing applications might depend on it. * continue to work because existing applications might depend on it.
* @author Peter Jones * @author Peter Jones
* *
* @build ReuseDefaultPort * @library ../../testlibrary
* @build ReuseDefaultPort TestLibrary
* @run main/othervm ReuseDefaultPort * @run main/othervm ReuseDefaultPort
*/ */
...@@ -48,7 +49,7 @@ import java.rmi.server.UnicastRemoteObject; ...@@ -48,7 +49,7 @@ import java.rmi.server.UnicastRemoteObject;
public class ReuseDefaultPort implements Remote { public class ReuseDefaultPort implements Remote {
private static final int PORT = 2223; private static final int PORT = TestLibrary.getUnusedRandomPort();
private ReuseDefaultPort() { } private ReuseDefaultPort() { }
......
/* /*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -22,36 +23,72 @@ ...@@ -22,36 +23,72 @@
* questions. * questions.
*/ */
/* /* @test
* * @bug 7160252
* (C) Copyright IBM Corp. 1999 All Rights Reserved. * @summary Checks if events are delivered to a listener
* Copyright 1997 The Open Group Research Institute. All rights reserved. * when a child node is added or removed
*/ */
package sun.security.krb5; import java.util.prefs.*;
import java.net.InetAddress; public class AddNodeChangeListener {
import java.net.UnknownHostException;
public class ServiceName extends PrincipalName { private static boolean failed = false;
private static Preferences userRoot, N2;
private static NodeChangeListenerAdd ncla;
public ServiceName(String name, int type) throws RealmException { public static void main(String[] args)
super(name, type); throws BackingStoreException, InterruptedException
{
userRoot = Preferences.userRoot();
ncla = new NodeChangeListenerAdd();
userRoot.addNodeChangeListener(ncla);
//Should initiate a node added event
addNode();
// Should not initiate a node added event
addNode();
//Should initate a child removed event
removeNode();
} if (failed)
public ServiceName(String name) throws RealmException { throw new RuntimeException("Failed");
this(name, PrincipalName.KRB_NT_UNKNOWN);
} }
public ServiceName(String name, String realm) throws RealmException { private static void addNode()
this(name, PrincipalName.KRB_NT_UNKNOWN); throws BackingStoreException, InterruptedException
setRealm(realm); {
N2 = userRoot.node("N2");
userRoot.flush();
Thread.sleep(3000);
if (ncla.getAddNumber() != 1)
failed = true;
} }
public ServiceName (String service, String instance, String realm) private static void removeNode()
throws KrbException throws BackingStoreException, InterruptedException
{ {
super(service, instance, realm, PrincipalName.KRB_NT_SRV_INST); N2.removeNode();
userRoot.flush();
Thread.sleep(3000);
if (ncla.getAddNumber() != 0)
failed = true;
} }
} private static class NodeChangeListenerAdd implements NodeChangeListener {
private int totalNode = 0;
@Override
public void childAdded(NodeChangeEvent evt) {
totalNode++;
}
@Override
public void childRemoved(NodeChangeEvent evt) {
totalNode--;
}
public int getAddNumber(){
return totalNode;
}
}
}
...@@ -75,7 +75,7 @@ public class StrCodingBenchmark { ...@@ -75,7 +75,7 @@ public class StrCodingBenchmark {
return nanoss; return nanoss;
} }
public static void time(Job ... jobs) throws Throwable { public static long[] time(Job ... jobs) throws Throwable {
long[] warmup = time0(jobs); // Warm up run long[] warmup = time0(jobs); // Warm up run
long[] nanoss = time0(jobs); // Real timing run long[] nanoss = time0(jobs); // Real timing run
...@@ -110,6 +110,7 @@ public class StrCodingBenchmark { ...@@ -110,6 +110,7 @@ public class StrCodingBenchmark {
// Print out absolute and relative times, calibrated against first job // Print out absolute and relative times, calibrated against first job
for (int i = 0; i < jobs.length; i++) for (int i = 0; i < jobs.length; i++)
System.out.printf(format, jobs[i].name(), milliss[i], ratios[i]); System.out.printf(format, jobs[i].name(), milliss[i], ratios[i]);
return milliss;
} }
public static Job[] filter(Pattern filter, Job[] jobs) { public static Job[] filter(Pattern filter, Job[] jobs) {
......
/*
* Copyright (c) 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.
*/
import java.util.*;
import java.nio.*;
import java.nio.charset.*;
import java.util.concurrent.*;
import java.util.regex.Pattern;
public class StrCodingBenchmarkDB extends StrCodingBenchmark {
public static void main(String[] args) throws Throwable {
final int itrs = Integer.getInteger("iterations", 100000);
//final int itrs = Integer.getInteger("iterations", 12);
final int size = Integer.getInteger("size", 2048);
final int subsize = Integer.getInteger("subsize", 128);
final int maxchar = Integer.getInteger("maxchar", 128);
final String regex = System.getProperty("filter");
final Pattern filter = (regex == null) ? null : Pattern.compile(regex);
final boolean useSecurityManager = Boolean.getBoolean("SecurityManager");
if (useSecurityManager)
System.setSecurityManager(new PermissiveSecurityManger());
final Random rnd = new Random();
String[] csns = new String[] {
"Big5",
"Johab",
"EUC_CN",
"EUC_KR",
"MS932",
"MS936",
"MS949",
"MS950",
"GBK",
"Big5_HKSCS",
"Big5_HKSCS_2001",
"Big5_Solaris",
"MS950_HKSCS",
"MS950_HKSCS_XP",
"IBM1364",
"IBM1381",
"IBM1383",
"IBM930",
"IBM933",
"IBM935",
"IBM937",
"IBM939",
"IBM942",
"IBM943",
"IBM948",
"IBM949",
"IBM950",
"IBM970",
};
ArrayList<long[]> sum = new ArrayList<>();
for (final String csn : csns) {
final Charset cs = Charset.forName(csn);
List<Integer> cps = new ArrayList<>(0x4000);
int off = 0;
int cp = 0;
int n = 0;
CharsetEncoder enc = cs.newEncoder();
while (cp < 0x10000 && n < cps.size()) {
if (enc.canEncode((char)cp)) {
cps.add(cp);
n++;
}
cp++;
}
Collections.shuffle(cps);
char[] ca = new char[cps.size()];
for (int i = 0; i < cps.size(); i++)
ca[i] = (char)(int)cps.get(i);
System.out.printf("%n--------%s---------%n", csn);
for (int sz = 8; sz <= 2048; sz *= 2) {
System.out.printf(" [len=%d]%n", sz);
final char[] chars = Arrays.copyOf(ca, sz);
final String str = new String(chars);
final byte[] bs = str.getBytes(cs);
Job[] jobs = {
new Job("String decode: csn") {
public void work() throws Throwable {
for (int i = 0; i < itrs; i++)
new String(bs, csn);
}},
new Job("String decode: cs") {
public void work() throws Throwable {
for (int i = 0; i < itrs; i++)
new String(bs, cs);
}},
new Job("String encode: csn") {
public void work() throws Throwable {
for (int i = 0; i < itrs; i++)
str.getBytes(csn);
}},
new Job("String encode: cs") {
public void work() throws Throwable {
for (int i = 0; i < itrs; i++)
str.getBytes(cs);
}},
};
sum.add(time(jobs));
}
}
}
}
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
*/ */
/* @test /* @test
@bug 6636323 6636319 7040220 7096080 @bug 6636323 6636319 7040220 7096080 7183053
@summary Test if StringCoding and NIO result have the same de/encoding result @summary Test if StringCoding and NIO result have the same de/encoding result
* @run main/othervm/timeout=2000 TestStringCoding * @run main/othervm/timeout=2000 TestStringCoding
*/ */
...@@ -70,11 +70,62 @@ public class TestStringCoding { ...@@ -70,11 +70,62 @@ public class TestStringCoding {
} }
test(cs, Arrays.copyOf(bmpCA, clen), Arrays.copyOf(sbBA, blen)); test(cs, Arrays.copyOf(bmpCA, clen), Arrays.copyOf(sbBA, blen));
} }
testMixed(cs);
System.out.println("done!"); System.out.println("done!");
} }
} }
} }
static void testMixed(Charset cs) throws Throwable {
CharsetDecoder dec = cs.newDecoder()
.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE);
CharsetEncoder enc = cs.newEncoder()
.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE);
List<Integer> cps = new ArrayList<>(0x10000);
int off = 0;
int cp = 0;
while (cp < 0x10000) {
if (enc.canEncode((char)cp)) {
cps.add(cp);
}
cp++;
}
Collections.shuffle(cps);
char[] bmpCA = new char[cps.size()];
for (int i = 0; i < cps.size(); i++)
bmpCA[i] = (char)(int)cps.get(i);
String bmpStr = new String(bmpCA);
//getBytes(csn);
byte[] bmpBA = bmpStr.getBytes(cs.name());
ByteBuffer bf = enc.reset().encode(CharBuffer.wrap(bmpCA));
byte[] baNIO = new byte[bf.limit()];
bf.get(baNIO, 0, baNIO.length);
if (!Arrays.equals(bmpBA, baNIO)) {
throw new RuntimeException("getBytes(csn) failed -> " + cs.name());
}
//getBytes(cs);
bmpBA = bmpStr.getBytes(cs);
if (!Arrays.equals(bmpBA, baNIO))
throw new RuntimeException("getBytes(cs) failed -> " + cs.name());
//new String(csn);
String strSC = new String(bmpBA, cs.name());
String strNIO = dec.reset().decode(ByteBuffer.wrap(bmpBA)).toString();
if(!strNIO.equals(strSC)) {
throw new RuntimeException("new String(csn) failed -> " + cs.name());
}
//new String(cs);
strSC = new String(bmpBA, cs);
if (!strNIO.equals(strSC))
throw new RuntimeException("new String(cs) failed -> " + cs.name());
}
static void test(Charset cs, char[] bmpCA, byte[] sbBA) throws Throwable { static void test(Charset cs, char[] bmpCA, byte[] sbBA) throws Throwable {
String bmpStr = new String(bmpCA); String bmpStr = new String(bmpCA);
CharsetDecoder dec = cs.newDecoder() CharsetDecoder dec = cs.newDecoder()
...@@ -100,6 +151,7 @@ public class TestStringCoding { ...@@ -100,6 +151,7 @@ public class TestStringCoding {
//new String(csn); //new String(csn);
String strSC = new String(sbBA, cs.name()); String strSC = new String(sbBA, cs.name());
String strNIO = dec.reset().decode(ByteBuffer.wrap(sbBA)).toString(); String strNIO = dec.reset().decode(ByteBuffer.wrap(sbBA)).toString();
if(!strNIO.equals(strSC)) if(!strNIO.equals(strSC))
throw new RuntimeException("new String(csn) failed -> " + cs.name()); throw new RuntimeException("new String(csn) failed -> " + cs.name());
...@@ -112,7 +164,7 @@ public class TestStringCoding { ...@@ -112,7 +164,7 @@ public class TestStringCoding {
if (enc instanceof sun.nio.cs.ArrayEncoder && if (enc instanceof sun.nio.cs.ArrayEncoder &&
cs.contains(Charset.forName("ASCII"))) { cs.contains(Charset.forName("ASCII"))) {
if (cs.name().equals("UTF-8") || // utf8 handles surrogates if (cs.name().equals("UTF-8") || // utf8 handles surrogates
cs.name().equals("CESU-8")) // utf8 handles surrogates cs.name().equals("CESU-8")) // utf8 handles surrogates
return; return;
enc.replaceWith(new byte[] { (byte)'A'}); enc.replaceWith(new byte[] { (byte)'A'});
sun.nio.cs.ArrayEncoder cae = (sun.nio.cs.ArrayEncoder)enc; sun.nio.cs.ArrayEncoder cae = (sun.nio.cs.ArrayEncoder)enc;
...@@ -137,12 +189,16 @@ public class TestStringCoding { ...@@ -137,12 +189,16 @@ public class TestStringCoding {
cs.name()))) cs.name())))
throw new RuntimeException("encode3(surrogates) failed -> " throw new RuntimeException("encode3(surrogates) failed -> "
+ cs.name()); + cs.name());
/* sun.nio.cs.ArrayDeEncoder works on the assumption that the
invoker (StringCoder) allocates enough output buf, utf8
and double-byte coder does not check the output buffer limit.
ba = new byte[str.length() - 1]; ba = new byte[str.length() - 1];
n = cae.encode(str.toCharArray(), 0, str.length(), ba); n = cae.encode(str.toCharArray(), 0, str.length(), ba);
if (n != 7 || !"abABABc".equals(new String(ba, 0, n, if (n != 7 || !"abABABc".equals(new String(ba, 0, n, cs.name()))) {
cs.name())))
throw new RuntimeException("encode4(surrogates) failed -> " throw new RuntimeException("encode4(surrogates) failed -> "
+ cs.name()); + cs.name());
}
*/
} }
} }
......
/* /*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,6 +25,7 @@ import java.rmi.RemoteException; ...@@ -25,6 +25,7 @@ import java.rmi.RemoteException;
import java.rmi.Naming; import java.rmi.Naming;
import java.rmi.server.UnicastRemoteObject; import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry; import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Random; import java.util.Random;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
...@@ -249,11 +250,12 @@ public class AppleUserImpl ...@@ -249,11 +250,12 @@ public class AppleUserImpl
} }
synchronized (user) { synchronized (user) {
int port = -1;
// create new registry and bind new AppleUserImpl in registry // create new registry and bind new AppleUserImpl in registry
try { try {
LocateRegistry.createRegistry(1099); //TestLibrary.REGISTRY_PORT); Registry registry = TestLibrary.createRegistryOnUnusedPort();
Naming.rebind("rmi://localhost:1099/AppleUser",user); port = TestLibrary.getRegistryPort(registry);
//TestLibrary.REGISTRY_PORT + "/AppleUser", user); Naming.rebind("rmi://localhost:" + port + "/AppleUser",user);
} catch (RemoteException e) { } catch (RemoteException e) {
//TestLibrary.bomb("Failed to bind AppleUser", e); //TestLibrary.bomb("Failed to bind AppleUser", e);
} catch (java.net.MalformedURLException e) { } catch (java.net.MalformedURLException e) {
...@@ -263,10 +265,9 @@ public class AppleUserImpl ...@@ -263,10 +265,9 @@ public class AppleUserImpl
// start the other server if available // start the other server if available
try { try {
Class app = Class.forName("ApplicationServer"); Class app = Class.forName("ApplicationServer");
server = new Thread((Runnable) app.newInstance()); java.lang.reflect.Constructor appConstructor =
logger.log(Level.INFO, "Starting application server " + app.getDeclaredConstructor(new Class[] {Integer.TYPE});
"in same process"); server = new Thread((Runnable) appConstructor.newInstance(port));
server.start();
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// assume the other server is running in a separate process // assume the other server is running in a separate process
logger.log(Level.INFO, "Application server must be " + logger.log(Level.INFO, "Application server must be " +
......
# #
# Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
# @summary This test verifies that the new implementation of rmic # @summary This test verifies that the new implementation of rmic
# generates equivalent classes as the old implementation, for a set # generates equivalent classes as the old implementation, for a set
# of sample input classes. # of sample input classes.
# @library ../../../../../java/rmi/testlibrary
# @build TestLibrary
# @author Peter Jones # @author Peter Jones
# #
# @build AgentServerImpl # @build AgentServerImpl
......
/* /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -90,7 +90,6 @@ public class NoConsoleOutput { ...@@ -90,7 +90,6 @@ public class NoConsoleOutput {
} }
public static class DoRMIStuff { public static class DoRMIStuff {
private static final int PORT = 2020;
private interface Foo extends Remote { private interface Foo extends Remote {
Object echo(Object obj) throws RemoteException; Object echo(Object obj) throws RemoteException;
} }
...@@ -99,8 +98,9 @@ public class NoConsoleOutput { ...@@ -99,8 +98,9 @@ public class NoConsoleOutput {
public Object echo(Object obj) { return obj; } public Object echo(Object obj) { return obj; }
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
LocateRegistry.createRegistry(PORT); Registry registry = TestLibrary.createRegistryOnUnusedPort();
Registry reg = LocateRegistry.getRegistry("", PORT); int registryPort = TestLibrary.getRegistryPort(registry);
Registry reg = LocateRegistry.getRegistry("", registryPort);
FooImpl fooimpl = new FooImpl(); FooImpl fooimpl = new FooImpl();
UnicastRemoteObject.exportObject(fooimpl, 0); UnicastRemoteObject.exportObject(fooimpl, 0);
reg.rebind("foo", fooimpl); reg.rebind("foo", fooimpl);
......
/* /*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -77,8 +77,9 @@ import java.rmi.registry.Registry; ...@@ -77,8 +77,9 @@ import java.rmi.registry.Registry;
* logger output is non-null. * logger output is non-null.
*/ */
public class CheckLogging { public class CheckLogging {
private static final String LOCATION = private static int REGISTRY_PORT = -1;
"rmi://localhost:" + TestLibrary.REGISTRY_PORT + "/"; private static String LOCATION;
private static final ByteArrayOutputStream clientCallOut = private static final ByteArrayOutputStream clientCallOut =
new ByteArrayOutputStream(); new ByteArrayOutputStream();
...@@ -100,7 +101,9 @@ public class CheckLogging { ...@@ -100,7 +101,9 @@ public class CheckLogging {
private static Registry registry; private static Registry registry;
static { static {
try { try {
registry = LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); registry = TestLibrary.createRegistryOnUnusedPort();
REGISTRY_PORT = TestLibrary.getRegistryPort(registry);
LOCATION = "rmi://localhost:" + REGISTRY_PORT + "/";
} catch (Exception e) { } catch (Exception e) {
TestLibrary.bomb("could not create registry"); TestLibrary.bomb("could not create registry");
} }
......
/* /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
* @bug 4290727 * @bug 4290727
* @summary Verify that ConnectException will trigger HTTP fallback if * @summary Verify that ConnectException will trigger HTTP fallback if
* sun.rmi.transport.proxy.eagerHttpFallback system property is set. * sun.rmi.transport.proxy.eagerHttpFallback system property is set.
* @library ../../../../java/rmi/testlibrary
* @build TestLibrary
* @run main/othervm EagerHttpFallback * @run main/othervm EagerHttpFallback
*/ */
...@@ -33,8 +35,8 @@ import java.rmi.registry.*; ...@@ -33,8 +35,8 @@ import java.rmi.registry.*;
public class EagerHttpFallback { public class EagerHttpFallback {
static final int INITIAL_PORT = 7070; static final int INITIAL_PORT = TestLibrary.getUnusedRandomPort();
static final int FALLBACK_PORT = 7071; static final int FALLBACK_PORT = TestLibrary.getUnusedRandomPort();
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.setProperty("http.proxyHost", "127.0.0.1"); System.setProperty("http.proxyHost", "127.0.0.1");
......
/* /*
* Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -58,7 +58,7 @@ import java.rmi.registry.*; ...@@ -58,7 +58,7 @@ import java.rmi.registry.*;
import java.rmi.server.*; import java.rmi.server.*;
public class DeadCachedConnection { public class DeadCachedConnection {
static public final int regport = 17340; static public final int regport = TestLibrary.getUnusedRandomPort();
static public void main(String[] argv) static public void main(String[] argv)
throws Exception { throws Exception {
......
...@@ -606,9 +606,8 @@ public class KDC { ...@@ -606,9 +606,8 @@ public class KDC {
TGSReq tgsReq = new TGSReq(in); TGSReq tgsReq = new TGSReq(in);
PrincipalName service = tgsReq.reqBody.sname; PrincipalName service = tgsReq.reqBody.sname;
if (options.containsKey(KDC.Option.RESP_NT)) { if (options.containsKey(KDC.Option.RESP_NT)) {
service = new PrincipalName(service.getNameStrings(), service = new PrincipalName((int)options.get(KDC.Option.RESP_NT),
(int)options.get(KDC.Option.RESP_NT)); service.getNameStrings(), service.getRealm());
service.setRealm(service.getRealm());
} }
try { try {
System.out.println(realm + "> " + tgsReq.reqBody.cname + System.out.println(realm + "> " + tgsReq.reqBody.cname +
...@@ -632,7 +631,6 @@ public class KDC { ...@@ -632,7 +631,6 @@ public class KDC {
EncryptedData ed = apReq.authenticator; EncryptedData ed = apReq.authenticator;
tkt = apReq.ticket; tkt = apReq.ticket;
int te = tkt.encPart.getEType(); int te = tkt.encPart.getEType();
tkt.sname.setRealm(tkt.realm);
EncryptionKey kkey = keyForUser(tkt.sname, te, true); EncryptionKey kkey = keyForUser(tkt.sname, te, true);
byte[] bb = tkt.encPart.decrypt(kkey, KeyUsage.KU_TICKET); byte[] bb = tkt.encPart.decrypt(kkey, KeyUsage.KU_TICKET);
DerInputStream derIn = new DerInputStream(bb); DerInputStream derIn = new DerInputStream(bb);
...@@ -693,7 +691,6 @@ public class KDC { ...@@ -693,7 +691,6 @@ public class KDC {
EncTicketPart enc = new EncTicketPart( EncTicketPart enc = new EncTicketPart(
tFlags, tFlags,
key, key,
etp.crealm,
etp.cname, etp.cname,
new TransitedEncoding(1, new byte[0]), // TODO new TransitedEncoding(1, new byte[0]), // TODO
new KerberosTime(new Date()), new KerberosTime(new Date()),
...@@ -709,7 +706,6 @@ public class KDC { ...@@ -709,7 +706,6 @@ public class KDC {
throw new KrbException(Krb5.KDC_ERR_SUMTYPE_NOSUPP); // TODO throw new KrbException(Krb5.KDC_ERR_SUMTYPE_NOSUPP); // TODO
} }
Ticket t = new Ticket( Ticket t = new Ticket(
body.crealm,
service, service,
new EncryptedData(skey, enc.asn1Encode(), KeyUsage.KU_TICKET) new EncryptedData(skey, enc.asn1Encode(), KeyUsage.KU_TICKET)
); );
...@@ -725,7 +721,6 @@ public class KDC { ...@@ -725,7 +721,6 @@ public class KDC {
new KerberosTime(new Date()), new KerberosTime(new Date()),
body.from, body.from,
till, body.rtime, till, body.rtime,
body.crealm,
service, service,
body.addresses != null // always set caddr body.addresses != null // always set caddr
? body.addresses ? body.addresses
...@@ -734,7 +729,6 @@ public class KDC { ...@@ -734,7 +729,6 @@ public class KDC {
); );
EncryptedData edata = new EncryptedData(ckey, enc_part.asn1Encode(), KeyUsage.KU_ENC_TGS_REP_PART_SESSKEY); EncryptedData edata = new EncryptedData(ckey, enc_part.asn1Encode(), KeyUsage.KU_ENC_TGS_REP_PART_SESSKEY);
TGSRep tgsRep = new TGSRep(null, TGSRep tgsRep = new TGSRep(null,
etp.crealm,
etp.cname, etp.cname,
t, t,
edata); edata);
...@@ -756,8 +750,8 @@ public class KDC { ...@@ -756,8 +750,8 @@ public class KDC {
new KerberosTime(new Date()), new KerberosTime(new Date()),
0, 0,
ke.returnCode(), ke.returnCode(),
body.crealm, body.cname, body.cname,
new Realm(getRealm()), service, service,
KrbException.errorMessage(ke.returnCode()), KrbException.errorMessage(ke.returnCode()),
null); null);
} }
...@@ -780,7 +774,6 @@ public class KDC { ...@@ -780,7 +774,6 @@ public class KDC {
if (options.containsKey(KDC.Option.RESP_NT)) { if (options.containsKey(KDC.Option.RESP_NT)) {
service = new PrincipalName(service.getNameStrings(), service = new PrincipalName(service.getNameStrings(),
(int)options.get(KDC.Option.RESP_NT)); (int)options.get(KDC.Option.RESP_NT));
service.setRealm(service.getRealm());
} }
try { try {
System.out.println(realm + "> " + asReq.reqBody.cname + System.out.println(realm + "> " + asReq.reqBody.cname +
...@@ -788,7 +781,6 @@ public class KDC { ...@@ -788,7 +781,6 @@ public class KDC {
service); service);
KDCReqBody body = asReq.reqBody; KDCReqBody body = asReq.reqBody;
body.cname.setRealm(getRealm());
eTypes = KDCReqBodyDotEType(body); eTypes = KDCReqBodyDotEType(body);
int eType = eTypes[0]; int eType = eTypes[0];
...@@ -971,7 +963,6 @@ public class KDC { ...@@ -971,7 +963,6 @@ public class KDC {
EncTicketPart enc = new EncTicketPart( EncTicketPart enc = new EncTicketPart(
tFlags, tFlags,
key, key,
body.crealm,
body.cname, body.cname,
new TransitedEncoding(1, new byte[0]), new TransitedEncoding(1, new byte[0]),
new KerberosTime(new Date()), new KerberosTime(new Date()),
...@@ -980,7 +971,6 @@ public class KDC { ...@@ -980,7 +971,6 @@ public class KDC {
body.addresses, body.addresses,
null); null);
Ticket t = new Ticket( Ticket t = new Ticket(
body.crealm,
service, service,
new EncryptedData(skey, enc.asn1Encode(), KeyUsage.KU_TICKET) new EncryptedData(skey, enc.asn1Encode(), KeyUsage.KU_TICKET)
); );
...@@ -996,14 +986,12 @@ public class KDC { ...@@ -996,14 +986,12 @@ public class KDC {
new KerberosTime(new Date()), new KerberosTime(new Date()),
body.from, body.from,
till, body.rtime, till, body.rtime,
body.crealm,
service, service,
body.addresses body.addresses
); );
EncryptedData edata = new EncryptedData(ckey, enc_part.asn1Encode(), KeyUsage.KU_ENC_AS_REP_PART); EncryptedData edata = new EncryptedData(ckey, enc_part.asn1Encode(), KeyUsage.KU_ENC_AS_REP_PART);
ASRep asRep = new ASRep( ASRep asRep = new ASRep(
outPAs.toArray(new PAData[outPAs.size()]), outPAs.toArray(new PAData[outPAs.size()]),
body.crealm,
body.cname, body.cname,
t, t,
edata); edata);
...@@ -1024,7 +1012,6 @@ public class KDC { ...@@ -1024,7 +1012,6 @@ public class KDC {
asRep.encKDCRepPart = enc_part; asRep.encKDCRepPart = enc_part;
sun.security.krb5.internal.ccache.Credentials credentials = sun.security.krb5.internal.ccache.Credentials credentials =
new sun.security.krb5.internal.ccache.Credentials(asRep); new sun.security.krb5.internal.ccache.Credentials(asRep);
asReq.reqBody.cname.setRealm(getRealm());
CredentialsCache cache = CredentialsCache cache =
CredentialsCache.create(asReq.reqBody.cname, ccache); CredentialsCache.create(asReq.reqBody.cname, ccache);
if (cache == null) { if (cache == null) {
...@@ -1059,8 +1046,8 @@ public class KDC { ...@@ -1059,8 +1046,8 @@ public class KDC {
new KerberosTime(new Date()), new KerberosTime(new Date()),
0, 0,
ke.returnCode(), ke.returnCode(),
body.crealm, body.cname, body.cname,
new Realm(getRealm()), service, service,
KrbException.errorMessage(ke.returnCode()), KrbException.errorMessage(ke.returnCode()),
eData); eData);
} }
......
/*
* Copyright (c) 2012, 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 6966259
* @summary Make PrincipalName and Realm immutable
* @run main/othervm Constructors
*/
import java.util.Arrays;
import sun.security.krb5.*;
public class Constructors {
public static void main(String[] args) throws Exception {
int type;
boolean testNoDefaultDomain;
// Part 1: on format
// Good ones
type = PrincipalName.KRB_NT_UNKNOWN;
checkName("a", type, "R", "R", "a");
checkName("a@R2", type, "R", "R", "a");
checkName("a/b", type, "R", "R", "a", "b");
checkName("a/b@R2", type, "R", "R", "a", "b");
checkName("a/b/c", type, "R", "R", "a", "b", "c");
checkName("a/b/c@R2", type, "R", "R", "a", "b", "c");
// Weird ones
checkName("a\\/b", type, "R", "R", "a/b");
checkName("a\\/b\\/c", type, "R", "R", "a/b/c");
checkName("a\\/b\\@R2", type, "R", "R", "a/b@R2");
// Bad ones
checkName("a", type, "", null);
checkName("a/", type, "R", null);
checkName("/a", type, "R", null);
checkName("a//b", type, "R", null);
checkName("a@", type, null, null);
type = PrincipalName.KRB_NT_SRV_HST;
// Part 2: on realm choices
// When there is no default realm
System.setProperty("java.security.krb5.conf",
System.getProperty("test.src", ".") + "/empty.conf");
Config.refresh();
// A Windows client login to AD always has a default realm
try {
Realm r = Realm.getDefault();
System.out.println("testNoDefaultDomain = false. Realm is " + r);
testNoDefaultDomain = false;
} catch (RealmException re) {
// Great. This is what we expected
testNoDefaultDomain = true;
}
if (testNoDefaultDomain) {
type = PrincipalName.KRB_NT_UNKNOWN;
checkName("a", type, "R1", "R1", "a"); // arg
checkName("a@R1", type, null, "R1", "a"); // or r in name
checkName("a@R2", type, "R1", "R1", "a"); // arg over r
checkName("a", type, null, null); // fail if none
checkName("a/b@R1", type, null, "R1", "a", "b");
type = PrincipalName.KRB_NT_SRV_HST;
// Let's pray "b.h" won't be canonicalized
checkName("a/b.h", type, "R1", "R1", "a", "b.h"); // arg
checkName("a/b.h@R1", type, null, "R1", "a", "b.h"); // or r in name
checkName("a/b.h@R1", type, "R2", "R2", "a", "b.h"); // arg over r
checkName("a/b.h", type, null, null); // fail if none
}
// When there is default realm
System.setProperty("java.security.krb5.conf",
System.getProperty("test.src", ".") + "/krb5.conf");
Config.refresh();
type = PrincipalName.KRB_NT_UNKNOWN;
checkName("a", type, "R1", "R1", "a"); // arg
checkName("a@R1", type, null, "R1", "a"); // or r in name
checkName("a@R2", type, "R1", "R1", "a"); // arg over r
checkName("a", type, null, "R", "a"); // default
checkName("a/b", type, null, "R", "a", "b");
type = PrincipalName.KRB_NT_SRV_HST;
checkName("a/b.h3", type, "R1", "R1", "a", "b.h3"); // arg
checkName("a/b.h@R1", type, null, "R1", "a", "b.h"); // or r in name
checkName("a/b.h3@R2", type, "R1", "R1", "a", "b.h3"); // arg over r
checkName("a/b.h2", type, "R1", "R1", "a", "b.h2"); // arg over map
checkName("a/b.h2@R1", type, null, "R1", "a", "b.h2"); // r over map
checkName("a/b.h2", type, null, "R2", "a", "b.h2"); // map
checkName("a/b.h", type, null, "R", "a", "b.h"); // default
}
// Check if the creation matches the expected output.
// Note: realm == null means creation failure
static void checkName(String n, int t, String s,
String realm, String... parts)
throws Exception {
PrincipalName pn = null;
try {
pn = new PrincipalName(n, t, s);
} catch (Exception e) {
if (realm == null) {
return; // This is expected
} else {
throw e;
}
}
if (!pn.getRealmAsString().equals(realm)
|| !Arrays.equals(pn.getNameStrings(), parts)) {
throw new Exception(pn.toString() + " vs "
+ Arrays.toString(parts) + "@" + realm);
}
}
}
[libdefaults]
dns_fallback = false
[libdefaults]
default_realm = R
[realms]
R = {
kdc = kdc
}
[domain_realm]
.h2 = R2
...@@ -27,7 +27,9 @@ ...@@ -27,7 +27,9 @@
# @test # @test
# @bug 7106773 # @bug 7106773
# @summary 512 bits RSA key cannot work with SHA384 and SHA512 # @summary 512 bits RSA key cannot work with SHA384 and SHA512
# @run shell ShortRSAKey1024.sh # @run shell ShortRSAKey1024.sh 1024
# @run shell ShortRSAKey1024.sh 768
# @run shell ShortRSAKey1024.sh 512
# set a few environment variables so that the shell-script can run stand-alone # set a few environment variables so that the shell-script can run stand-alone
# in the source directory # in the source directory
...@@ -55,6 +57,8 @@ case "$OS" in ...@@ -55,6 +57,8 @@ case "$OS" in
;; ;;
esac esac
BITS=$1
case "$OS" in case "$OS" in
Windows* | CYGWIN* ) Windows* | CYGWIN* )
...@@ -63,9 +67,10 @@ case "$OS" in ...@@ -63,9 +67,10 @@ case "$OS" in
-genkeypair \ -genkeypair \
-storetype Windows-My \ -storetype Windows-My \
-keyalg RSA \ -keyalg RSA \
-alias 7106773.1024 \ -alias 7106773.$BITS \
-keysize 1024 \ -keysize $BITS \
-dname "cn=localhost,c=US" \ -dname "cn=localhost,c=US" \
-debug \
-noprompt -noprompt
if [ "$?" -ne "0" ]; then if [ "$?" -ne "0" ]; then
...@@ -77,7 +82,7 @@ case "$OS" in ...@@ -77,7 +82,7 @@ case "$OS" in
echo "Running the test..." echo "Running the test..."
${TESTJAVA}${FS}bin${FS}javac -d . \ ${TESTJAVA}${FS}bin${FS}javac -d . \
${TESTSRC}${FS}ShortRSAKeyWithinTLS.java ${TESTSRC}${FS}ShortRSAKeyWithinTLS.java
${TESTJAVA}${FS}bin${FS}java ShortRSAKeyWithinTLS 7106773.1024 1024 \ ${TESTJAVA}${FS}bin${FS}java ShortRSAKeyWithinTLS 7106773.$BITS $BITS \
TLSv1.2 TLS_DHE_RSA_WITH_AES_128_CBC_SHA TLSv1.2 TLS_DHE_RSA_WITH_AES_128_CBC_SHA
rc=$? rc=$?
...@@ -87,7 +92,8 @@ case "$OS" in ...@@ -87,7 +92,8 @@ case "$OS" in
${TESTJAVA}${FS}bin${FS}keytool \ ${TESTJAVA}${FS}bin${FS}keytool \
-delete \ -delete \
-storetype Windows-My \ -storetype Windows-My \
-alias 7106773.1024 -debug \
-alias 7106773.$BITS
echo "Done". echo "Done".
exit $rc exit $rc
......
#!/bin/sh
#
# Copyright (c) 2012, 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 7106773
# @summary 512 bits RSA key cannot work with SHA384 and SHA512
# @run shell ShortRSAKey512.sh
# set a few environment variables so that the shell-script can run stand-alone
# in the source directory
if [ "${TESTSRC}" = "" ] ; then
TESTSRC="."
fi
if [ "${TESTCLASSES}" = "" ] ; then
TESTCLASSES="."
fi
if [ "${TESTJAVA}" = "" ] ; then
echo "TESTJAVA not set. Test cannot execute."
echo "FAILED!!!"
exit 1
fi
OS=`uname -s`
case "$OS" in
SunOS | Linux | Darwin | CYGWIN* )
FS="/"
;;
Windows_* )
FS="\\"
;;
esac
case "$OS" in
Windows* | CYGWIN* )
echo "Creating a temporary RSA keypair in the Windows-My store..."
${TESTJAVA}${FS}bin${FS}keytool \
-genkeypair \
-storetype Windows-My \
-keyalg RSA \
-alias 7106773.512 \
-keysize 512 \
-dname "cn=localhost,c=US" \
-noprompt
if [ "$?" -ne "0" ]; then
echo "Unable to generate key pair in Windows-My keystore"
exit 1
fi
echo
echo "Running the test..."
${TESTJAVA}${FS}bin${FS}javac -d . \
${TESTSRC}${FS}ShortRSAKeyWithinTLS.java
${TESTJAVA}${FS}bin${FS}java ShortRSAKeyWithinTLS 7106773.512 512 \
TLSv1.2 TLS_DHE_RSA_WITH_AES_128_CBC_SHA
rc=$?
echo
echo "Removing the temporary RSA keypair from the Windows-My store..."
${TESTJAVA}${FS}bin${FS}keytool \
-delete \
-storetype Windows-My \
-alias 7106773.512
echo "Done".
exit $rc
;;
* )
echo "This test is not intended for '$OS' - passing test"
exit 0
;;
esac
#!/bin/sh
#
# Copyright (c) 2012, 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 7106773
# @summary 512 bits RSA key cannot work with SHA384 and SHA512
# @run shell ShortRSAKey768.sh
# set a few environment variables so that the shell-script can run stand-alone
# in the source directory
if [ "${TESTSRC}" = "" ] ; then
TESTSRC="."
fi
if [ "${TESTCLASSES}" = "" ] ; then
TESTCLASSES="."
fi
if [ "${TESTJAVA}" = "" ] ; then
echo "TESTJAVA not set. Test cannot execute."
echo "FAILED!!!"
exit 1
fi
OS=`uname -s`
case "$OS" in
SunOS | Linux | Darwin | CYGWIN* )
FS="/"
;;
Windows_* )
FS="\\"
;;
esac
case "$OS" in
Windows* | CYGWIN* )
echo "Creating a temporary RSA keypair in the Windows-My store..."
${TESTJAVA}${FS}bin${FS}keytool \
-genkeypair \
-storetype Windows-My \
-keyalg RSA \
-alias 7106773.768 \
-keysize 768 \
-dname "cn=localhost,c=US" \
-noprompt
if [ "$?" -ne "0" ]; then
echo "Unable to generate key pair in Windows-My keystore"
exit 1
fi
echo
echo "Running the test..."
${TESTJAVA}${FS}bin${FS}javac -d . \
${TESTSRC}${FS}ShortRSAKeyWithinTLS.java
${TESTJAVA}${FS}bin${FS}java ShortRSAKeyWithinTLS 7106773.768 768 \
TLSv1.2 TLS_DHE_RSA_WITH_AES_128_CBC_SHA
rc=$?
echo
echo "Removing the temporary RSA keypair from the Windows-My store..."
${TESTJAVA}${FS}bin${FS}keytool \
-delete \
-storetype Windows-My \
-alias 7106773.768
echo "Done".
exit $rc
;;
* )
echo "This test is not intended for '$OS' - passing test"
exit 0
;;
esac
...@@ -245,6 +245,10 @@ public abstract class PKCS11Test { ...@@ -245,6 +245,10 @@ public abstract class PKCS11Test {
osMap.put("SunOS-amd64-64", "/usr/lib/mps/64/"); osMap.put("SunOS-amd64-64", "/usr/lib/mps/64/");
osMap.put("Linux-i386-32", "/usr/lib/"); osMap.put("Linux-i386-32", "/usr/lib/");
osMap.put("Linux-amd64-64", "/usr/lib64/"); osMap.put("Linux-amd64-64", "/usr/lib64/");
osMap.put("Windows-x86-32",
PKCS11_BASE + "/nss/lib/windows-i586/".replace('/', SEP));
osMap.put("Windows-amd64-64",
PKCS11_BASE + "/nss/lib/windows-amd64/".replace('/', SEP));
} }
private final static char[] hexDigits = "0123456789abcdef".toCharArray(); private final static char[] hexDigits = "0123456789abcdef".toCharArray();
......
1390c8a35c667e05e542 nss-3.13.1.tar.gz
d8e7ee9f9f1e0bfa2ea8b72d25727634fea130a6 nss-3.13.1.tar.gz
...@@ -71,7 +71,7 @@ case "$OS" in ...@@ -71,7 +71,7 @@ case "$OS" in
i[3-6]86 ) i[3-6]86 )
PF="linux-i586" PF="linux-i586"
;; ;;
amd64* ) amd64* | x86_64 )
PF="linux-amd64" PF="linux-amd64"
;; ;;
* ) * )
...@@ -97,15 +97,29 @@ case "$OS" in ...@@ -97,15 +97,29 @@ case "$OS" in
;; ;;
esac esac
echo "==================================================="
echo "Try to set ALT_JAVA_RE_JDK if you see timeout error"
echo "==================================================="
# the test code # the test code
${TESTJAVA}${FS}bin${FS}javac -target 1.4 -source 1.4 \ ${TESTJAVA}${FS}bin${FS}javac -target 1.4 -source 1.4 \
-d . ${TESTSRC}${FS}SerialTest.java || exit 10 -d . ${TESTSRC}${FS}SerialTest.java || exit 10
# You can set ALT_JAVA_RE_JDK to another location that contains the
# binaries for older JDK releases. You can set it to a non-existent
# directory to skip the interop tests between different versions.
if [ "$ALT_JAVA_RE_JDK" = "" ]; then
JAVA_RE_JDK=/java/re/j2se
else
JAVA_RE_JDK=$ALT_JAVA_RE_JDK
fi
OLDJAVA=" OLDJAVA="
/java/re/j2se/1.6.0/latest/binaries/${PF} $JAVA_RE_JDK/1.6.0/latest/binaries/${PF}
/java/re/j2se/1.5.0/latest/binaries/${PF} $JAVA_RE_JDK/1.5.0/latest/binaries/${PF}
/java/re/j2se/1.4.2/latest/binaries/${PF} $JAVA_RE_JDK/1.4.2/latest/binaries/${PF}
" "
SMALL=" SMALL="
......
/*
* Copyright (c) 2012, 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.ArrayList;
import java.util.List;
/*
* @test
* @bug 7184145
* @summary tests repacking of a simple named jarfile.
* @compile -XDignore.symbol.file Utils.java RepackTest.java
* @run main RepackTest
* @author ksrini
*/
public class RepackTest {
public static void main(String... args) throws Exception {
testRepack();
}
/*
* there are two cases we need to test, where the file in question is
* orpaned, ie. without a parent ie. not qualified by a parent path
* relative nor absolute
* case 1: src and dest are the same
* case 2: src and dest are different
*/
static void testRepack() throws IOException {
// make a copy of the test specimen to local directory
File testFile = new File("src_tools.jar");
Utils.copyFile(Utils.locateJar("golden.jar"), testFile);
List<String> cmdsList = new ArrayList<>();
// case 1:
cmdsList.add(Utils.getPack200Cmd());
cmdsList.add("--repack");
cmdsList.add(testFile.getName());
Utils.runExec(cmdsList);
// case 2:
File dstFile = new File("dst_tools.jar");
cmdsList.clear();
cmdsList.add(Utils.getPack200Cmd());
cmdsList.add("--repack");
cmdsList.add(dstFile.getName());
cmdsList.add(testFile.getName());
Utils.runExec(cmdsList);
// tidy up
testFile.delete();
dstFile.delete();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册