--- a/.hgtags Tue Oct 07 13:41:39 2008 -0400
+++ b/.hgtags Tue Oct 07 13:48:49 2008 -0400
@@ -8,3 +8,5 @@ b7474b739d13bacd9972f88ac91f6350b7b0be12
b7474b739d13bacd9972f88ac91f6350b7b0be12 jdk7-b31
c51121419e30eac5f0fbbce45ff1711c4ce0de28 jdk7-b32
fa4c0a6cdd25d97d4e6f5d7aa180bcbb0e0d56af jdk7-b33
+434055a0716ee44bca712ebca02fc04b20e6e288 jdk7-b34
+cf4894b78ceb966326e93bf221db0c2d14d59218 jdk7-b35
--- a/make/common/Defs.gmk Tue Oct 07 13:41:39 2008 -0400
+++ b/make/common/Defs.gmk Tue Oct 07 13:48:49 2008 -0400
@@ -451,7 +451,7 @@ vpath %.$(OBJECT_SUFFIX) $(OBJDIR)
# namely jni.h, jvm.h, and jni_utils.h, plus their platform-specific
# relatives.
#
-VPATH.h = $(PLATFORM_SRC)/javavm/export$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/javavm/export$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/javavm/include$(CLASSPATH_SEPARATOR)$(PLATFORM_SRC)/javavm/include
+VPATH.h = $(PLATFORM_SRC)/javavm/export$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/javavm/export
vpath %.h $(VPATH.h)
#
--- a/make/common/shared/Defs-windows.gmk Tue Oct 07 13:41:39 2008 -0400
+++ b/make/common/shared/Defs-windows.gmk Tue Oct 07 13:48:49 2008 -0400
@@ -539,6 +539,8 @@ else
WSCRIPT :=$(call FileExists,$(_WSCRIPT1),$(_WSCRIPT2))
endif
WSCRIPT:=$(call AltCheckSpaces,WSCRIPT)
+# batch mode no modal dialogs on errors, please.
+WSCRIPT += -B
# CSCRIPT: path to cscript.exe (used in creating install bundles)
ifdef ALT_CSCRIPT
@@ -561,6 +563,10 @@ else
MSIVAL2 :=$(call FileExists,$(_MSIVAL2_1),$(_MSIVAL2_2))
endif
MSIVAL2:=$(call AltCheckSpaces,MSIVAL2)
+# suppress msival2 checks, as it hangs jprt builds
+ifdef SKIP_MSIVAL2
+ MSIVAL2 := $(ECHO)
+endif
# LOGOCUB: path to cub file for (used in validating install msi files)
ifdef ALT_LOGOCUB
--- a/make/docs/CORE_PKGS.gmk Tue Oct 07 13:41:39 2008 -0400
+++ b/make/docs/CORE_PKGS.gmk Tue Oct 07 13:48:49 2008 -0400
@@ -158,6 +158,7 @@ CORE_PKGS =
javax.management.event \
javax.management.loading \
javax.management.monitor \
+ javax.management.namespace \
javax.management.relation \
javax.management.openmbean \
javax.management.timer \
--- a/make/java/java/FILES_java.gmk Tue Oct 07 13:41:39 2008 -0400
+++ b/make/java/java/FILES_java.gmk Tue Oct 07 13:48:49 2008 -0400
@@ -449,6 +449,7 @@ JAVA_JAVA_java = \
sun/misc/JavaLangAccess.java \
sun/misc/JavaIOAccess.java \
sun/misc/JavaIODeleteOnExitAccess.java \
- sun/misc/JavaIOFileDescriptorAccess.java
+ sun/misc/JavaIOFileDescriptorAccess.java \
+ sun/misc/JavaNioAccess.java
FILES_java = $(JAVA_JAVA_java)
--- a/make/java/java/mapfile-vers Tue Oct 07 13:41:39 2008 -0400
+++ b/make/java/java/mapfile-vers Tue Oct 07 13:48:49 2008 -0400
@@ -222,8 +222,6 @@ SUNWprivate_1.1 {
Java_java_lang_UNIXProcess_waitForProcessExit;
Java_java_lang_UNIXProcess_forkAndExec;
Java_java_lang_UNIXProcess_destroyProcess;
- Java_java_nio_Bits_copyFromByteArray;
- Java_java_nio_Bits_copyToByteArray;
Java_java_nio_Bits_copyFromShortArray;
Java_java_nio_Bits_copyToShortArray;
Java_java_nio_Bits_copyFromIntArray;
--- a/make/java/jli/Makefile Tue Oct 07 13:41:39 2008 -0400
+++ b/make/java/jli/Makefile Tue Oct 07 13:48:49 2008 -0400
@@ -113,7 +113,11 @@ ifeq ($(PLATFORM), windows)
JAVALIB =
OTHER_LCF = -export:JLI_Launch \
-export:JLI_ManifestIterate \
- -export:JLI_SetTraceLauncher
+ -export:JLI_SetTraceLauncher \
+ -export:JLI_ReportErrorMessage \
+ -export:JLI_ReportErrorMessageSys \
+ -export:JLI_ReportMessage \
+ -export:JLI_ReportExceptionDescription
endif
--- a/make/java/jli/mapfile-vers Tue Oct 07 13:41:39 2008 -0400
+++ b/make/java/jli/mapfile-vers Tue Oct 07 13:48:49 2008 -0400
@@ -1,5 +1,5 @@
#
-# Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
+# Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,10 @@ SUNWprivate_1.1 {
JLI_Launch;
JLI_ManifestIterate;
JLI_SetTraceLauncher;
+ JLI_ReportErrorMessage;
+ JLI_ReportErrorMessageSys;
+ JLI_ReportMessage;
+ JLI_ReportExceptionDescription;
local:
*;
};
--- a/make/java/net/mapfile-vers Tue Oct 07 13:41:39 2008 -0400
+++ b/make/java/net/mapfile-vers Tue Oct 07 13:48:49 2008 -0400
@@ -57,7 +57,7 @@ SUNWprivate_1.1 {
Java_java_net_Inet6AddressImpl_isReachable0;
Java_java_net_NetworkInterface_init;
Java_java_net_NetworkInterface_getByName0;
- Java_java_net_NetworkInterface_getByIndex;
+ Java_java_net_NetworkInterface_getByIndex0;
Java_java_net_NetworkInterface_getByInetAddress0;
Java_java_net_NetworkInterface_getAll;
Java_java_net_NetworkInterface_isUp0;
--- a/make/java/nio/FILES_java.gmk Tue Oct 07 13:41:39 2008 -0400
+++ b/make/java/nio/FILES_java.gmk Tue Oct 07 13:48:49 2008 -0400
@@ -26,6 +26,7 @@ FILES_src = \
FILES_src = \
java/nio/Bits.java \
java/nio/Buffer.java \
+ java/nio/BufferPoolMXBean.java \
java/nio/ByteOrder.java \
java/nio/MappedByteBuffer.java \
java/nio/StringCharBuffer.java \
@@ -38,6 +39,9 @@ FILES_src = \
java/nio/channels/FileLock.java \
java/nio/channels/GatheringByteChannel.java \
java/nio/channels/InterruptibleChannel.java \
+ java/nio/channels/MembershipKey.java \
+ java/nio/channels/MulticastChannel.java \
+ java/nio/channels/NetworkChannel.java \
java/nio/channels/ReadableByteChannel.java \
java/nio/channels/ScatteringByteChannel.java \
java/nio/channels/SelectableChannel.java \
@@ -72,6 +76,7 @@ FILES_src = \
sun/nio/ch/DatagramSocketAdaptor.java \
sun/nio/ch/DefaultSelectorProvider.java \
sun/nio/ch/DirectBuffer.java \
+ sun/nio/ch/ExtendedSocketOption.java \
sun/nio/ch/FileChannelImpl.java \
sun/nio/ch/FileDispatcher.java \
sun/nio/ch/FileKey.java \
@@ -79,12 +84,14 @@ FILES_src = \
sun/nio/ch/IOUtil.java \
sun/nio/ch/IOStatus.java \
sun/nio/ch/IOVecWrapper.java \
+ sun/nio/ch/MembershipKeyImpl.java \
+ sun/nio/ch/MembershipRegistry.java \
sun/nio/ch/NativeDispatcher.java \
sun/nio/ch/NativeObject.java \
sun/nio/ch/NativeThread.java \
sun/nio/ch/NativeThreadSet.java \
sun/nio/ch/Net.java \
- sun/nio/ch/OptionAdaptor.java \
+ sun/nio/ch/OptionKey.java \
sun/nio/ch/PipeImpl.java \
sun/nio/ch/PollArrayWrapper.java \
sun/nio/ch/Reflect.java \
@@ -98,8 +105,7 @@ FILES_src = \
sun/nio/ch/SocketAdaptor.java \
sun/nio/ch/SocketChannelImpl.java \
sun/nio/ch/SocketDispatcher.java \
- sun/nio/ch/SocketOpts.java \
- sun/nio/ch/SocketOptsImpl.java \
+ sun/nio/ch/SocketOptionRegistry.java \
sun/nio/ch/SourceChannelImpl.java \
sun/nio/ch/Util.java \
\
@@ -239,6 +245,7 @@ FILES_gen_ex = \
java/nio/InvalidMarkException.java \
java/nio/ReadOnlyBufferException.java \
\
+ java/nio/channels/AlreadyBoundException.java \
java/nio/channels/AlreadyConnectedException.java \
java/nio/channels/AsynchronousCloseException.java \
java/nio/channels/ClosedByInterruptException.java \
@@ -257,14 +264,15 @@ FILES_gen_ex = \
java/nio/channels/UnresolvedAddressException.java \
java/nio/channels/UnsupportedAddressTypeException.java \
\
- sun/nio/ch/AlreadyBoundException.java \
- \
java/nio/charset/CharacterCodingException.java \
java/nio/charset/IllegalCharsetNameException.java \
java/nio/charset/UnsupportedCharsetException.java
FILES_gen_csp = sun/nio/cs/StandardCharsets.java
-FILES_gen = $(FILES_gen_coder) $(FILES_gen_buffer) $(FILES_gen_ex) $(FILES_gen_csp)
+FILES_gen_sor = sun/nio/ch/SocketOptionRegistry.java
+
+FILES_gen = $(FILES_gen_coder) $(FILES_gen_buffer) $(FILES_gen_ex) \
+ $(FILES_gen_csp) $(FILES_gen_sor)
FILES_java = $(FILES_src) $(FILES_gen)
--- a/make/java/nio/Makefile Tue Oct 07 13:41:39 2008 -0400
+++ b/make/java/nio/Makefile Tue Oct 07 13:48:49 2008 -0400
@@ -56,18 +56,18 @@ FILES_java += \
sun/nio/ch/DevPollSelectorProvider.java \
sun/nio/ch/InheritedChannel.java \
sun/nio/ch/PollSelectorProvider.java \
- sun/nio/ch/PollSelectorImpl.java
+ sun/nio/ch/PollSelectorImpl.java
FILES_c += \
DevPollArrayWrapper.c \
InheritedChannel.c \
- PollArrayWrapper.c \
- NativeThread.c
+ NativeThread.c \
+ PollArrayWrapper.c
FILES_export += \
sun/nio/ch/DevPollArrayWrapper.java \
sun/nio/ch/InheritedChannel.java \
- sun/nio/ch/NativeThread.java
+ sun/nio/ch/NativeThread.java
endif # PLATFORM = solaris
ifeq ($(PLATFORM), windows)
@@ -94,14 +94,14 @@ FILES_java += \
FILES_c += \
EPollArrayWrapper.c \
- PollArrayWrapper.c \
InheritedChannel.c \
- NativeThread.c
+ NativeThread.c \
+ PollArrayWrapper.c
FILES_export += \
sun/nio/ch/EPollArrayWrapper.java \
sun/nio/ch/InheritedChannel.java \
- sun/nio/ch/NativeThread.java
+ sun/nio/ch/NativeThread.java
endif # PLATFORM = linux
# Find platform-specific C source files
@@ -618,12 +618,6 @@ GEN_EX_CMD = NAWK="$(NAWK)" SH="$(SH)" $
@$(RM) $@.temp
$(GEN_EX_CMD) $(BUF_SRC)/exceptions $(BUF_GEN)
-$(SCH_GEN)/%Exception.java: genExceptions.sh $(SCH_SRC)/exceptions
- $(prep-target)
- @$(RM) $@.temp
- $(GEN_EX_CMD) $(SCH_SRC)/exceptions $(SCH_GEN)
-
-
#
# Generated charset-provider classes
#
@@ -638,4 +632,29 @@ HASHER_JARFILE = $(BUILDTOOLJARDIR)/hash
HASHER="$(BOOT_JAVA_CMD) -jar $(HASHER_JARFILE)" \
$(SH) -e genCharsetProvider.sh $(SCS_SRC)/standard-charsets $(SCS_GEN)
+#
+# Generated channel implementation classes.
+# C source is compiled in TEMPDIR to avoid turds left by Windows compilers.
+#
+
+GENSOR_SRC = $(SHARE_SRC)/native/sun/nio/ch/genSocketOptionRegistry.c
+
+GENSOR_EXE = $(TEMPDIR)/genSocketOptionRegistry$(EXE_SUFFIX)
+
+SOR_COPYRIGHT_YEARS = $(shell $(CAT) $(GENSOR_SRC) | \
+ $(NAWK) '/^.*Copyright.*Sun/ { print $$3 }')
+
+$(TEMPDIR)/$(GENSOR_SRC) : $(GENSOR_SRC)
+ $(install-file)
+
+$(GENSOR_EXE) : $(TEMPDIR)/$(GENSOR_SRC)
+ $(prep-target)
+ ($(CD) $(TEMPDIR); $(CC) $(CPPFLAGS) $(LDDFLAGS) \
+ -o genSocketOptionRegistry$(EXE_SUFFIX) $(GENSOR_SRC))
+
+$(SCH_GEN)/SocketOptionRegistry.java: $(GENSOR_EXE)
+ $(prep-target)
+ NAWK="$(NAWK)" SH="$(SH)" $(SH) -e addNotices.sh $(SOR_COPYRIGHT_YEARS) > $@
+ $(GENSOR_EXE) >> $@
+
.PHONY: sources
--- a/make/java/nio/mapfile-linux Tue Oct 07 13:41:39 2008 -0400
+++ b/make/java/nio/mapfile-linux Tue Oct 07 13:48:49 2008 -0400
@@ -1,3 +1,27 @@
+#
+# Copyright 2001-2008 Sun Microsystems, Inc. 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. Sun designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Sun in the LICENSE file that accompanied this code.
+#
+# 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
SUNWprivate_1.1 {
global:
@@ -18,6 +42,8 @@ SUNWprivate_1.1 {
Java_sun_nio_ch_EPollArrayWrapper_fdLimit;
Java_sun_nio_ch_EPollArrayWrapper_init;
Java_sun_nio_ch_EPollArrayWrapper_interrupt;
+ Java_sun_nio_ch_EPollArrayWrapper_offsetofData;
+ Java_sun_nio_ch_EPollArrayWrapper_sizeofEPollEvent;
Java_sun_nio_ch_FileChannelImpl_close0;
Java_sun_nio_ch_FileChannelImpl_force0;
Java_sun_nio_ch_FileChannelImpl_initIDs;
@@ -59,20 +85,29 @@ SUNWprivate_1.1 {
Java_sun_nio_ch_NativeThread_init;
Java_sun_nio_ch_NativeThread_signal;
Java_sun_nio_ch_Net_socket0;
- Java_sun_nio_ch_Net_bind;
- Java_sun_nio_ch_Net_connect;
+ Java_sun_nio_ch_Net_bind0;
+ Java_sun_nio_ch_Net_connect0;
+ Java_sun_nio_ch_Net_listen;
Java_sun_nio_ch_Net_localPort;
Java_sun_nio_ch_Net_localInetAddress;
Java_sun_nio_ch_Net_getIntOption0;
Java_sun_nio_ch_Net_setIntOption0;
Java_sun_nio_ch_Net_initIDs;
+ Java_sun_nio_ch_Net_isIPv6Available0;
+ Java_sun_nio_ch_Net_joinOrDrop4;
+ Java_sun_nio_ch_Net_blockOrUnblock4;
+ Java_sun_nio_ch_Net_joinOrDrop6;
+ Java_sun_nio_ch_Net_blockOrUnblock6;
+ Java_sun_nio_ch_Net_setInterface4;
+ Java_sun_nio_ch_Net_getInterface4;
+ Java_sun_nio_ch_Net_setInterface6;
+ Java_sun_nio_ch_Net_getInterface6;
+ Java_sun_nio_ch_Net_shutdown;
Java_sun_nio_ch_PollArrayWrapper_interrupt;
Java_sun_nio_ch_PollArrayWrapper_poll0;
Java_sun_nio_ch_ServerSocketChannelImpl_accept0;
Java_sun_nio_ch_ServerSocketChannelImpl_initIDs;
- Java_sun_nio_ch_ServerSocketChannelImpl_listen;
Java_sun_nio_ch_SocketChannelImpl_checkConnect;
- Java_sun_nio_ch_SocketChannelImpl_shutdown;
local:
*;
--- a/make/java/nio/mapfile-solaris Tue Oct 07 13:41:39 2008 -0400
+++ b/make/java/nio/mapfile-solaris Tue Oct 07 13:48:49 2008 -0400
@@ -1,3 +1,27 @@
+#
+# Copyright 2001-2008 Sun Microsystems, Inc. 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. Sun designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Sun in the LICENSE file that accompanied this code.
+#
+# 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
SUNWprivate_1.1 {
global:
@@ -59,20 +83,29 @@ SUNWprivate_1.1 {
Java_sun_nio_ch_NativeThread_init;
Java_sun_nio_ch_NativeThread_signal;
Java_sun_nio_ch_Net_socket0;
- Java_sun_nio_ch_Net_bind;
- Java_sun_nio_ch_Net_connect;
+ Java_sun_nio_ch_Net_bind0;
+ Java_sun_nio_ch_Net_connect0;
+ Java_sun_nio_ch_Net_listen;
Java_sun_nio_ch_Net_localPort;
Java_sun_nio_ch_Net_localInetAddress;
Java_sun_nio_ch_Net_getIntOption0;
Java_sun_nio_ch_Net_setIntOption0;
Java_sun_nio_ch_Net_initIDs;
+ Java_sun_nio_ch_Net_isIPv6Available0;
+ Java_sun_nio_ch_Net_joinOrDrop4;
+ Java_sun_nio_ch_Net_blockOrUnblock4;
+ Java_sun_nio_ch_Net_joinOrDrop6;
+ Java_sun_nio_ch_Net_blockOrUnblock6;
+ Java_sun_nio_ch_Net_setInterface4;
+ Java_sun_nio_ch_Net_getInterface4;
+ Java_sun_nio_ch_Net_setInterface6;
+ Java_sun_nio_ch_Net_getInterface6;
+ Java_sun_nio_ch_Net_shutdown;
Java_sun_nio_ch_PollArrayWrapper_interrupt;
Java_sun_nio_ch_PollArrayWrapper_poll0;
Java_sun_nio_ch_ServerSocketChannelImpl_accept0;
Java_sun_nio_ch_ServerSocketChannelImpl_initIDs;
- Java_sun_nio_ch_ServerSocketChannelImpl_listen;
Java_sun_nio_ch_SocketChannelImpl_checkConnect;
- Java_sun_nio_ch_SocketChannelImpl_shutdown;
local:
*;
--- a/make/java/verify/Makefile Tue Oct 07 13:41:39 2008 -0400
+++ b/make/java/verify/Makefile Tue Oct 07 13:48:49 2008 -0400
@@ -1,5 +1,5 @@
#
-# Copyright 1999-2005 Sun Microsystems, Inc. All Rights Reserved.
+# Copyright 1999-2008 Sun Microsystems, Inc. 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
@@ -53,12 +53,6 @@ FILES_c = \
check_format.c
#
-# libverify.so needs these 2 header files (opcodes.h opcodes.length)
-# from the VM.
-#
-CPPFLAGS += -I$(SHARE_SRC)/javavm/include
-
-#
# Targets.
#
ifeq ($(PLATFORM), solaris)
--- a/make/jprt.properties Tue Oct 07 13:41:39 2008 -0400
+++ b/make/jprt.properties Tue Oct 07 13:48:49 2008 -0400
@@ -55,6 +55,5 @@ jprt.test.targets=*-*-*-jvm98
jprt.test.targets=*-*-*-jvm98
# Directories needed to build
-jprt.bundle.src.dirs=make src
jprt.bundle.exclude.src.dirs=build
--- a/make/mksample/nio/Makefile Tue Oct 07 13:41:39 2008 -0400
+++ b/make/mksample/nio/Makefile Tue Oct 07 13:48:49 2008 -0400
@@ -31,7 +31,7 @@ PRODUCT = java
PRODUCT = java
include $(BUILDDIR)/common/Defs.gmk
-SUBDIRS = server
+SUBDIRS = multicast server
all build clean clobber::
$(SUBDIRS-loop)
--- a/make/netbeans/awt2d/README Tue Oct 07 13:41:39 2008 -0400
+++ b/make/netbeans/awt2d/README Tue Oct 07 13:48:49 2008 -0400
@@ -145,7 +145,6 @@ Notes on using CND (C/C++ pack) with thi
(a somewhat complete list of awt and 2d native directories on windows):
../../src/share/javavm/export;
- ../../src/share/javavm/include;
../../src/share/native/common;
../../src/share/native/sun/awt/debug;
../../src/share/native/sun/awt/image/cvutils;
--- a/make/sun/net/spi/Makefile Tue Oct 07 13:41:39 2008 -0400
+++ b/make/sun/net/spi/Makefile Tue Oct 07 13:48:49 2008 -0400
@@ -23,10 +23,6 @@
# have any questions.
#
-#
-# Makefile for building com/sun
-#
-
BUILDDIR = ../../..
include $(BUILDDIR)/common/Defs.gmk
--- a/make/sun/net/spi/nameservice/Makefile Tue Oct 07 13:41:39 2008 -0400
+++ b/make/sun/net/spi/nameservice/Makefile Tue Oct 07 13:48:49 2008 -0400
@@ -23,10 +23,6 @@
# have any questions.
#
-#
-# Makefile for building com/sun
-#
-
BUILDDIR = ../../../..
include $(BUILDDIR)/common/Defs.gmk
--- a/make/sun/net/spi/nameservice/dns/Makefile Tue Oct 07 13:41:39 2008 -0400
+++ b/make/sun/net/spi/nameservice/dns/Makefile Tue Oct 07 13:48:49 2008 -0400
@@ -24,7 +24,7 @@
#
#
-# Makefile for building JNDI service provider toolkit
+# Makefile for building JNDI DNS name service provider
#
BUILDDIR = ../../../../..
--- a/make/tools/GenerateCharacter/check_class.c.template Tue Oct 07 13:41:39 2008 -0400
+++ b/make/tools/GenerateCharacter/check_class.c.template Tue Oct 07 13:48:49 2008 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,6 @@
#include "bool.h"
#include "utf.h"
#include "tree.h"
-#include "sys_api.h"
extern bool_t verify_class_codes(ClassClass *cb);
--- a/src/share/back/debugDispatch.c Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/back/debugDispatch.c Tue Oct 07 13:48:49 2008 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1998-2008 Sun Microsystems, Inc. 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
@@ -41,7 +41,6 @@
#include "ArrayReferenceImpl.h"
#include "EventRequestImpl.h"
#include "StackFrameImpl.h"
-#include "typedefs.h"
static void **l1Array;
--- a/src/share/back/error_messages.c Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/back/error_messages.c Tue Oct 07 13:48:49 2008 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -48,7 +48,6 @@
#include "util.h"
#include "proc_md.h"
-#include "typedefs.h"
/* Maximim length of a message */
#define MAX_MESSAGE_LEN MAXPATHLEN*2+512
--- a/src/share/back/inStream.c Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/back/inStream.c Tue Oct 07 13:48:49 2008 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -30,7 +30,6 @@
#include "bag.h"
#include "commonRef.h"
#include "FrameID.h"
-#include "typedefs.h"
#define INITIAL_REF_ALLOC 50
#define SMALLEST(a, b) ((a) < (b)) ? (a) : (b)
--- a/src/share/back/outStream.h Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/back/outStream.h Tue Oct 07 13:48:49 2008 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1998-2008 Sun Microsystems, Inc. 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
@@ -25,8 +25,6 @@
#ifndef JDWP_OUTSTREAM_H
#define JDWP_OUTSTREAM_H
-
-#include "typedefs.h"
#include "transport.h"
#include "FrameID.h"
--- a/src/share/bin/emessages.h Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/bin/emessages.h Tue Oct 07 13:48:49 2008 -0400
@@ -25,8 +25,8 @@
/*
* This file primarily consists of all the error and warning messages, that
- * are used in ReportErrorMessage. All message must be defined here, in order
- * to help in I18N/L10N the messages.
+ * are used in JLI_ReportErrorMessage. All message must be defined here, in
+ * order to help with localizing the messages.
*/
#ifndef _EMESSAGES_H
--- a/src/share/bin/java.c Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/bin/java.c Tue Oct 07 13:48:49 2008 -0400
@@ -148,7 +148,7 @@ static jboolean IsWildCardEnabled();
static jboolean IsWildCardEnabled();
#define ARG_CHECK(n, f, a) if (n < 1) { \
- ReportErrorMessage(f, a); \
+ JLI_ReportErrorMessage(f, a); \
printUsage = JNI_TRUE; \
*pret = 1; \
return JNI_TRUE; \
@@ -326,15 +326,15 @@ JavaMain(void * _args)
start = CounterGet();
if (!InitializeJVM(&vm, &env, &ifn)) {
- ReportErrorMessage(JVM_ERROR1);
+ JLI_ReportErrorMessage(JVM_ERROR1);
exit(1);
}
if (printVersion || showVersion) {
PrintJavaVersion(env, showVersion);
if ((*env)->ExceptionOccurred(env)) {
- ReportExceptionDescription(env);
- ReportErrorMessage(JNI_ERROR);
+ JLI_ReportExceptionDescription(env);
+ JLI_ReportErrorMessage(JNI_ERROR);
goto leave;
}
if (printVersion) {
@@ -347,8 +347,8 @@ JavaMain(void * _args)
if (printXUsage || printUsage || (jarfile == 0 && classname == 0)) {
PrintUsage(env, printXUsage);
if ((*env)->ExceptionOccurred(env)) {
- ReportExceptionDescription(env);
- ReportErrorMessage(JNI_ERROR);
+ JLI_ReportExceptionDescription(env);
+ JLI_ReportErrorMessage(JNI_ERROR);
ret=1;
}
goto leave;
@@ -397,43 +397,43 @@ JavaMain(void * _args)
if (jarfile != 0) {
mainClassName = GetMainClassName(env, jarfile);
if ((*env)->ExceptionOccurred(env)) {
- ReportExceptionDescription(env);
- ReportErrorMessage(JNI_ERROR);
+ JLI_ReportExceptionDescription(env);
+ JLI_ReportErrorMessage(JNI_ERROR);
goto leave;
}
if (mainClassName == NULL) {
- ReportErrorMessage(JAR_ERROR1,jarfile, GEN_ERROR);
+ JLI_ReportErrorMessage(JAR_ERROR1,jarfile, GEN_ERROR);
goto leave;
}
classname = (char *)(*env)->GetStringUTFChars(env, mainClassName, 0);
if (classname == NULL) {
- ReportExceptionDescription(env);
- ReportErrorMessage(JNI_ERROR);
+ JLI_ReportExceptionDescription(env);
+ JLI_ReportErrorMessage(JNI_ERROR);
goto leave;
}
mainClass = LoadClass(env, classname);
if(mainClass == NULL) { /* exception occured */
- ReportExceptionDescription(env);
- ReportErrorMessage(CLS_ERROR1, classname);
+ JLI_ReportExceptionDescription(env);
+ JLI_ReportErrorMessage(CLS_ERROR1, classname);
goto leave;
}
(*env)->ReleaseStringUTFChars(env, mainClassName, classname);
} else {
mainClassName = NewPlatformString(env, classname);
if (mainClassName == NULL) {
- ReportErrorMessage(CLS_ERROR2, classname, GEN_ERROR);
+ JLI_ReportErrorMessage(CLS_ERROR2, classname, GEN_ERROR);
goto leave;
}
classname = (char *)(*env)->GetStringUTFChars(env, mainClassName, 0);
if (classname == NULL) {
- ReportExceptionDescription(env);
- ReportErrorMessage(JNI_ERROR);
+ JLI_ReportExceptionDescription(env);
+ JLI_ReportErrorMessage(JNI_ERROR);
goto leave;
}
mainClass = LoadClass(env, classname);
if(mainClass == NULL) { /* exception occured */
- ReportExceptionDescription(env);
- ReportErrorMessage(CLS_ERROR1, classname);
+ JLI_ReportExceptionDescription(env);
+ JLI_ReportErrorMessage(CLS_ERROR1, classname);
goto leave;
}
(*env)->ReleaseStringUTFChars(env, mainClassName, classname);
@@ -444,10 +444,10 @@ JavaMain(void * _args)
"([Ljava/lang/String;)V");
if (mainID == NULL) {
if ((*env)->ExceptionOccurred(env)) {
- ReportExceptionDescription(env);
- ReportErrorMessage(JNI_ERROR);
+ JLI_ReportExceptionDescription(env);
+ JLI_ReportErrorMessage(JNI_ERROR);
} else {
- ReportErrorMessage(CLS_ERROR3);
+ JLI_ReportErrorMessage(CLS_ERROR3);
}
goto leave;
}
@@ -459,8 +459,8 @@ JavaMain(void * _args)
mainID, JNI_TRUE);
if( obj == NULL) { /* exception occurred */
- ReportExceptionDescription(env);
- ReportErrorMessage(JNI_ERROR);
+ JLI_ReportExceptionDescription(env);
+ JLI_ReportErrorMessage(JNI_ERROR);
goto leave;
}
@@ -469,14 +469,14 @@ JavaMain(void * _args)
(*env)->GetObjectClass(env, obj),
"getModifiers", "()I");
if ((*env)->ExceptionOccurred(env)) {
- ReportExceptionDescription(env);
- ReportErrorMessage(JNI_ERROR);
+ JLI_ReportExceptionDescription(env);
+ JLI_ReportErrorMessage(JNI_ERROR);
goto leave;
}
mods = (*env)->CallIntMethod(env, obj, mid);
if ((mods & 1) == 0) { /* if (!Modifier.isPublic(mods)) ... */
- ReportErrorMessage(CLS_ERROR4);
+ JLI_ReportErrorMessage(CLS_ERROR4);
goto leave;
}
}
@@ -484,8 +484,8 @@ JavaMain(void * _args)
/* Build argument array */
mainArgs = NewPlatformStringArray(env, argv, argc);
if (mainArgs == NULL) {
- ReportExceptionDescription(env);
- ReportErrorMessage(JNI_ERROR);
+ JLI_ReportExceptionDescription(env);
+ JLI_ReportErrorMessage(JNI_ERROR);
goto leave;
}
@@ -506,7 +506,7 @@ JavaMain(void * _args)
* launcher's return code except by calling System.exit.
*/
if ((*vm)->DetachCurrentThread(vm) != 0) {
- ReportErrorMessage(JVM_ERROR2);
+ JLI_ReportErrorMessage(JVM_ERROR2);
ret = 1;
goto leave;
}
@@ -635,7 +635,7 @@ CheckJvmType(int *pargc, char ***argv, j
if (loopCount > knownVMsCount) {
if (!speculative) {
- ReportErrorMessage(CFG_ERROR1);
+ JLI_ReportErrorMessage(CFG_ERROR1);
exit(1);
} else {
return "ERROR";
@@ -645,7 +645,7 @@ CheckJvmType(int *pargc, char ***argv, j
if (nextIdx < 0) {
if (!speculative) {
- ReportErrorMessage(CFG_ERROR2, knownVMs[jvmidx].alias);
+ JLI_ReportErrorMessage(CFG_ERROR2, knownVMs[jvmidx].alias);
exit(1);
} else {
return "ERROR";
@@ -660,7 +660,7 @@ CheckJvmType(int *pargc, char ***argv, j
switch (knownVMs[jvmidx].flag) {
case VM_WARN:
if (!speculative) {
- ReportErrorMessage(CFG_WARN1, jvmtype, knownVMs[0].name + 1);
+ JLI_ReportErrorMessage(CFG_WARN1, jvmtype, knownVMs[0].name + 1);
}
/* fall through */
case VM_IGNORE:
@@ -670,7 +670,7 @@ CheckJvmType(int *pargc, char ***argv, j
break;
case VM_ERROR:
if (!speculative) {
- ReportErrorMessage(CFG_ERROR3, jvmtype);
+ JLI_ReportErrorMessage(CFG_ERROR3, jvmtype);
exit(1);
} else {
return "ERROR";
@@ -879,9 +879,9 @@ SelectVersion(int argc, char **argv, cha
if (jarflag && operand) {
if ((res = JLI_ParseManifest(operand, &info)) != 0) {
if (res == -1)
- ReportErrorMessage(JAR_ERROR2, operand);
+ JLI_ReportErrorMessage(JAR_ERROR2, operand);
else
- ReportErrorMessage(JAR_ERROR3, operand);
+ JLI_ReportErrorMessage(JAR_ERROR3, operand);
exit(1);
}
@@ -948,7 +948,7 @@ SelectVersion(int argc, char **argv, cha
* Check for correct syntax of the version specification (JSR 56).
*/
if (!JLI_ValidVersionString(info.jre_version)) {
- ReportErrorMessage(SPC_ERROR1, info.jre_version);
+ JLI_ReportErrorMessage(SPC_ERROR1, info.jre_version);
exit(1);
}
@@ -970,7 +970,7 @@ SelectVersion(int argc, char **argv, cha
JLI_MemFree(new_argv);
return;
} else {
- ReportErrorMessage(CFG_ERROR4, info.jre_version);
+ JLI_ReportErrorMessage(CFG_ERROR4, info.jre_version);
exit(1);
}
}
@@ -1040,7 +1040,7 @@ ParseArguments(int *pargc, char ***pargv
* command line options.
*/
} else if (JLI_StrCmp(arg, "-fullversion") == 0) {
- ReportMessage("%s full version \"%s\"", _launcher_name, GetFullVersion());
+ JLI_ReportMessage("%s full version \"%s\"", _launcher_name, GetFullVersion());
return JNI_FALSE;
} else if (JLI_StrCmp(arg, "-verbosegc") == 0) {
AddOption("-verbose:gc", NULL);
@@ -1080,7 +1080,7 @@ ParseArguments(int *pargc, char ***pargv
JLI_StrCmp(arg, "-cs") == 0 ||
JLI_StrCmp(arg, "-noasyncgc") == 0) {
/* No longer supported */
- ReportErrorMessage(ARG_WARN, arg);
+ JLI_ReportErrorMessage(ARG_WARN, arg);
} else if (JLI_StrCCmp(arg, "-version:") == 0 ||
JLI_StrCmp(arg, "-no-jre-restrict-search") == 0 ||
JLI_StrCmp(arg, "-jre-restrict-search") == 0 ||
@@ -1143,12 +1143,12 @@ InitializeJVM(JavaVM **pvm, JNIEnv **pen
#define NULL_CHECK0(e) if ((e) == 0) { \
- ReportErrorMessage(JNI_ERROR); \
+ JLI_ReportErrorMessage(JNI_ERROR); \
return 0; \
}
#define NULL_CHECK(e) if ((e) == 0) { \
- ReportErrorMessage(JNI_ERROR); \
+ JLI_ReportErrorMessage(JNI_ERROR); \
return; \
}
@@ -1351,7 +1351,7 @@ TranslateApplicationArgs(int jargc, cons
char *arg = argv[i];
if (arg[0] == '-' && arg[1] == 'J') {
if (arg[2] == '\0') {
- ReportErrorMessage(ARG_ERROR3);
+ JLI_ReportErrorMessage(ARG_ERROR3);
exit(1);
}
*nargv++ = arg + 2;
@@ -1418,7 +1418,7 @@ AddApplicationOptions(int cpathc, const
}
if (!GetApplicationHome(home, sizeof(home))) {
- ReportErrorMessage(CFG_ERROR5);
+ JLI_ReportErrorMessage(CFG_ERROR5);
return JNI_FALSE;
}
@@ -1691,7 +1691,7 @@ ReadKnownVMs(const char *jrepath, const
jvmCfg = fopen(jvmCfgName, "r");
if (jvmCfg == NULL) {
if (!speculative) {
- ReportErrorMessage(CFG_ERROR6, jvmCfgName);
+ JLI_ReportErrorMessage(CFG_ERROR6, jvmCfgName);
exit(1);
} else {
return -1;
@@ -1703,7 +1703,7 @@ ReadKnownVMs(const char *jrepath, const
if (line[0] == '#')
continue;
if (line[0] != '-') {
- ReportErrorMessage(CFG_WARN2, lineno, jvmCfgName);
+ JLI_ReportErrorMessage(CFG_WARN2, lineno, jvmCfgName);
}
if (cnt >= knownVMsLimit) {
GrowKnownVMs(cnt);
@@ -1711,13 +1711,13 @@ ReadKnownVMs(const char *jrepath, const
line[JLI_StrLen(line)-1] = '\0'; /* remove trailing newline */
tmpPtr = line + JLI_StrCSpn(line, whiteSpace);
if (*tmpPtr == 0) {
- ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
+ JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
} else {
/* Null-terminate this string for JLI_StringDup below */
*tmpPtr++ = 0;
tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);
if (*tmpPtr == 0) {
- ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
+ JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
} else {
if (!JLI_StrCCmp(tmpPtr, "KNOWN")) {
vmType = VM_KNOWN;
@@ -1727,7 +1727,7 @@ ReadKnownVMs(const char *jrepath, const
tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);
}
if (*tmpPtr == 0) {
- ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
+ JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
} else {
/* Null terminate altVMName */
altVMName = tmpPtr;
@@ -1747,7 +1747,7 @@ ReadKnownVMs(const char *jrepath, const
tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);
}
if (*tmpPtr == 0) {
- ReportErrorMessage(CFG_WARN4, lineno, jvmCfgName);
+ JLI_ReportErrorMessage(CFG_WARN4, lineno, jvmCfgName);
} else {
/* Null terminate server class VM name */
serverClassVMName = tmpPtr;
@@ -1756,7 +1756,7 @@ ReadKnownVMs(const char *jrepath, const
vmType = VM_IF_SERVER_CLASS;
}
} else {
- ReportErrorMessage(CFG_WARN5, lineno, &jvmCfgName[0]);
+ JLI_ReportErrorMessage(CFG_WARN5, lineno, &jvmCfgName[0]);
vmType = VM_KNOWN;
}
}
@@ -2019,7 +2019,7 @@ RemovableOption(char * option)
* A utility procedure to always print to stderr
*/
void
-ReportMessage(const char* fmt, ...)
+JLI_ReportMessage(const char* fmt, ...)
{
va_list vl;
va_start(vl, fmt);
--- a/src/share/bin/java.h Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/bin/java.h Tue Oct 07 13:48:49 2008 -0400
@@ -121,24 +121,20 @@ void CreateExecutionEnvironment(int *_ar
char jvmpath[],
jint so_jvmpath,
char **original_argv);
+/* Reports an error message to stderr or a window as appropriate. */
+void JLI_ReportErrorMessage(const char * message, ...);
+
+/* Reports a system error message to stderr or a window */
+void JLI_ReportErrorMessageSys(const char * message, ...);
+
+/* Reports an error message only to stderr. */
+void JLI_ReportMessage(const char * message, ...);
/*
- * Report an error message to stderr or a window as appropriate.
- */
-void ReportErrorMessage(const char * message, ...);
-void ReportErrorMessageSys(const char * format, ...);
-
-/*
- * Report an error message only to stderr.
- */
-void ReportMessage(const char * message, ...);
-
-/*
- * Report an exception which terminates the vm to stderr or a window
+ * Reports an exception which terminates the vm to stderr or a window
* as appropriate.
*/
-void ReportExceptionDescription(JNIEnv * env);
-
+void JLI_ReportExceptionDescription(JNIEnv * env);
void PrintMachineDependentOptions();
const char *jlong_format_specifier();
--- a/src/share/classes/com/sun/jmx/defaults/JmxProperties.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/defaults/JmxProperties.java Tue Oct 07 13:48:49 2008 -0400
@@ -177,6 +177,18 @@ public class JmxProperties {
"javax.management.relation";
/**
+ * Logger name for Namespaces.
+ */
+ public static final String NAMESPACE_LOGGER_NAME =
+ "javax.management.namespace";
+
+ /**
+ * Logger name for Namespaces.
+ */
+ public static final Logger NAMESPACE_LOGGER =
+ Logger.getLogger(NAMESPACE_LOGGER_NAME);
+
+ /**
* Logger for Relation Service.
*/
public static final Logger RELATION_LOGGER =
--- a/src/share/classes/com/sun/jmx/event/LeaseManager.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/event/LeaseManager.java Tue Oct 07 13:48:49 2008 -0400
@@ -27,7 +27,6 @@ package com.sun.jmx.event;
import com.sun.jmx.remote.util.ClassLogger;
import java.util.concurrent.Executors;
-import java.util.concurrent.FutureTask;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -115,6 +114,7 @@ public class LeaseManager {
scheduled = null;
}
callback.run();
+ executor.shutdown();
}
}
@@ -131,6 +131,13 @@ public class LeaseManager {
logger.trace("stop", "canceling lease");
scheduled.cancel(false);
scheduled = null;
+ try {
+ executor.shutdown();
+ } catch (SecurityException e) {
+ // OK: caller doesn't have RuntimePermission("modifyThread")
+ // which is unlikely in reality but triggers a test failure otherwise
+ logger.trace("stop", "exception from executor.shutdown", e);
+ }
}
private final Runnable callback;
@@ -138,7 +145,7 @@ public class LeaseManager {
private final ScheduledExecutorService executor
= Executors.newScheduledThreadPool(1,
- new DaemonThreadFactory("LeaseManager"));
+ new DaemonThreadFactory("JMX LeaseManager %d"));
private static final ClassLogger logger =
new ClassLogger("javax.management.event", "LeaseManager");
--- a/src/share/classes/com/sun/jmx/event/RepeatedSingletonJob.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/event/RepeatedSingletonJob.java Tue Oct 07 13:48:49 2008 -0400
@@ -95,7 +95,9 @@ public abstract class RepeatedSingletonJ
executor.execute(this);
} catch (RejectedExecutionException e) {
logger.warning(
- "setEventReceiver", "Executor threw exception", e);
+ "execute",
+ "Executor threw exception (" + this.getClass().getName() + ")",
+ e);
throw new RejectedExecutionException(
"Executor.execute threw exception -" +
"should not be possible", e);
--- a/src/share/classes/com/sun/jmx/interceptor/DefaultMBeanServerInterceptor.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/interceptor/DefaultMBeanServerInterceptor.java Tue Oct 07 13:48:49 2008 -0400
@@ -25,33 +25,49 @@
package com.sun.jmx.interceptor;
-// java import
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.WeakHashMap;
+
+// JMX RI
+import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER;
+import com.sun.jmx.mbeanserver.DynamicMBean2;
+import com.sun.jmx.mbeanserver.Introspector;
+import com.sun.jmx.mbeanserver.MBeanInjector;
+import com.sun.jmx.mbeanserver.MBeanInstantiator;
+import com.sun.jmx.mbeanserver.ModifiableClassLoaderRepository;
+import com.sun.jmx.mbeanserver.NamedObject;
+import com.sun.jmx.mbeanserver.NotifySupport;
+import com.sun.jmx.mbeanserver.Repository;
+import com.sun.jmx.mbeanserver.Repository.RegistrationContext;
+import com.sun.jmx.mbeanserver.Util;
+import com.sun.jmx.remote.util.EnvHelp;
+
import java.lang.ref.WeakReference;
import java.security.AccessControlContext;
+import java.security.AccessController;
import java.security.Permission;
+import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.logging.Level;
// JMX import
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.DynamicMBean;
+import javax.management.DynamicWrapperMBean;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.InvalidAttributeValueException;
import javax.management.JMRuntimeException;
import javax.management.ListenerNotFoundException;
-import javax.management.MalformedObjectNameException;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanPermission;
@@ -64,6 +80,7 @@ import javax.management.NotCompliantMBea
import javax.management.NotCompliantMBeanException;
import javax.management.Notification;
import javax.management.NotificationBroadcaster;
+import javax.management.NotificationBroadcasterSupport;
import javax.management.NotificationEmitter;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
@@ -75,22 +92,7 @@ import javax.management.RuntimeErrorExce
import javax.management.RuntimeErrorException;
import javax.management.RuntimeMBeanException;
import javax.management.RuntimeOperationsException;
-
-// JMX RI
-import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER;
-import com.sun.jmx.mbeanserver.DynamicMBean2;
-import com.sun.jmx.mbeanserver.ModifiableClassLoaderRepository;
-import com.sun.jmx.mbeanserver.MBeanInstantiator;
-import com.sun.jmx.mbeanserver.Repository;
-import com.sun.jmx.mbeanserver.NamedObject;
-import com.sun.jmx.mbeanserver.Introspector;
-import com.sun.jmx.mbeanserver.MBeanInjector;
-import com.sun.jmx.mbeanserver.NotifySupport;
-import com.sun.jmx.mbeanserver.Repository.RegistrationContext;
-import com.sun.jmx.mbeanserver.Util;
-import com.sun.jmx.remote.util.EnvHelp;
-import javax.management.DynamicWrapperMBean;
-import javax.management.NotificationBroadcasterSupport;
+import javax.management.namespace.JMXNamespace;
/**
* This is the default class for MBean manipulation on the agent side. It
@@ -113,7 +115,8 @@ import javax.management.NotificationBroa
*
* @since 1.5
*/
-public class DefaultMBeanServerInterceptor implements MBeanServerInterceptor {
+public class DefaultMBeanServerInterceptor
+ extends MBeanServerInterceptorSupport {
/** The MBeanInstantiator object used by the
* DefaultMBeanServerInterceptor */
@@ -123,7 +126,7 @@ public class DefaultMBeanServerIntercept
* DefaultMBeanServerInterceptor */
private transient MBeanServer server = null;
- /** The MBean server object taht associated to the
+ /** The MBean server delegate object that is associated to the
* DefaultMBeanServerInterceptor */
private final transient MBeanServerDelegate delegate;
@@ -138,13 +141,15 @@ public class DefaultMBeanServerIntercept
new WeakHashMap<ListenerWrapper,
WeakReference<ListenerWrapper>>();
+ private final NamespaceDispatchInterceptor dispatcher;
+
/** The default domain of the object names */
private final String domain;
- /** True if the repository perform queries, false otherwise */
- private boolean queryByRepo;
-
- /** The sequence number identifyng the notifications sent */
+ /** The mbeanServerName */
+ private final String mbeanServerName;
+
+ /** The sequence number identifying the notifications sent */
// Now sequence number is handled by MBeanServerDelegate.
// private int sequenceNumber=0;
@@ -162,11 +167,13 @@ public class DefaultMBeanServerIntercept
* @param instantiator The MBeanInstantiator that will be used to
* instantiate MBeans and take care of class loading issues.
* @param repository The repository to use for this MBeanServer.
+ * @param dispatcher The dispatcher used by this MBeanServer
*/
public DefaultMBeanServerInterceptor(MBeanServer outer,
MBeanServerDelegate delegate,
MBeanInstantiator instantiator,
- Repository repository) {
+ Repository repository,
+ NamespaceDispatchInterceptor dispatcher) {
if (outer == null) throw new
IllegalArgumentException("outer MBeanServer cannot be null");
if (delegate == null) throw new
@@ -181,6 +188,8 @@ public class DefaultMBeanServerIntercept
this.instantiator = instantiator;
this.repository = repository;
this.domain = repository.getDefaultDomain();
+ this.dispatcher = dispatcher;
+ this.mbeanServerName = Util.getMBeanServerSecurityName(delegate);
}
public ObjectInstance createMBean(String className, ObjectName name)
@@ -259,8 +268,8 @@ public class DefaultMBeanServerIntercept
name = nonDefaultDomain(name);
}
- checkMBeanPermission(className, null, null, "instantiate");
- checkMBeanPermission(className, null, name, "registerMBean");
+ checkMBeanPermission(mbeanServerName,className, null, null, "instantiate");
+ checkMBeanPermission(mbeanServerName,className, null, name, "registerMBean");
/* Load the appropriate class. */
if (withDefaultLoaderRepository) {
@@ -324,7 +333,7 @@ public class DefaultMBeanServerIntercept
final String infoClassName = getNewMBeanClassName(object);
- checkMBeanPermission(infoClassName, null, name, "registerMBean");
+ checkMBeanPermission(mbeanServerName,infoClassName, null, name, "registerMBean");
checkMBeanTrustPermission(theClass);
return registerObject(infoClassName, object, name);
@@ -433,7 +442,8 @@ public class DefaultMBeanServerIntercept
DynamicMBean instance = getMBean(name);
// may throw InstanceNotFoundException
- checkMBeanPermission(instance, null, name, "unregisterMBean");
+ checkMBeanPermission(mbeanServerName, instance, null, name,
+ "unregisterMBean");
if (instance instanceof MBeanRegistration)
preDeregisterInvoke((MBeanRegistration) instance);
@@ -467,7 +477,8 @@ public class DefaultMBeanServerIntercept
name = nonDefaultDomain(name);
DynamicMBean instance = getMBean(name);
- checkMBeanPermission(instance, null, name, "getObjectInstance");
+ checkMBeanPermission(mbeanServerName,
+ instance, null, name, "getObjectInstance");
final String className = getClassName(instance);
@@ -479,7 +490,7 @@ public class DefaultMBeanServerIntercept
if (sm != null) {
// Check if the caller has the right to invoke 'queryMBeans'
//
- checkMBeanPermission((String) null, null, null, "queryMBeans");
+ checkMBeanPermission(mbeanServerName,(String) null, null, null, "queryMBeans");
// Perform query without "query".
//
@@ -492,7 +503,7 @@ public class DefaultMBeanServerIntercept
new HashSet<ObjectInstance>(list.size());
for (ObjectInstance oi : list) {
try {
- checkMBeanPermission(oi.getClassName(), null,
+ checkMBeanPermission(mbeanServerName,oi.getClassName(), null,
oi.getObjectName(), "queryMBeans");
allowedList.add(oi);
} catch (SecurityException e) {
@@ -516,11 +527,6 @@ public class DefaultMBeanServerIntercept
//
Set<NamedObject> list = repository.query(name, query);
- if (queryByRepo) {
- // The repository performs the filtering
- query = null;
- }
-
return (objectInstancesFromFilteredNamedObjects(list, query));
}
@@ -530,7 +536,7 @@ public class DefaultMBeanServerIntercept
if (sm != null) {
// Check if the caller has the right to invoke 'queryNames'
//
- checkMBeanPermission((String) null, null, null, "queryNames");
+ checkMBeanPermission(mbeanServerName,(String) null, null, null, "queryNames");
// Perform query without "query".
//
@@ -543,7 +549,7 @@ public class DefaultMBeanServerIntercept
new HashSet<ObjectInstance>(list.size());
for (ObjectInstance oi : list) {
try {
- checkMBeanPermission(oi.getClassName(), null,
+ checkMBeanPermission(mbeanServerName, oi.getClassName(), null,
oi.getObjectName(), "queryNames");
allowedList.add(oi);
} catch (SecurityException e) {
@@ -572,11 +578,6 @@ public class DefaultMBeanServerIntercept
//
Set<NamedObject> list = repository.query(name, query);
- if (queryByRepo) {
- // The repository performs the filtering
- query = null;
- }
-
return (objectNamesFromFilteredNamedObjects(list, query));
}
@@ -589,8 +590,8 @@ public class DefaultMBeanServerIntercept
name = nonDefaultDomain(name);
-// /* Permission check */
-// checkMBeanPermission(null, null, name, "isRegistered");
+ /* No Permission check */
+ // isRegistered is always unchecked as per JMX spec.
return (repository.contains(name));
}
@@ -600,7 +601,7 @@ public class DefaultMBeanServerIntercept
if (sm != null) {
// Check if the caller has the right to invoke 'getDomains'
//
- checkMBeanPermission((String) null, null, null, "getDomains");
+ checkMBeanPermission(mbeanServerName, (String) null, null, null, "getDomains");
// Return domains
//
@@ -612,8 +613,8 @@ public class DefaultMBeanServerIntercept
List<String> result = new ArrayList<String>(domains.length);
for (int i = 0; i < domains.length; i++) {
try {
- ObjectName domain = Util.newObjectName(domains[i] + ":x=x");
- checkMBeanPermission((String) null, null, domain, "getDomains");
+ ObjectName dom = ObjectName.valueOf(domains[i] + ":x=x");
+ checkMBeanPermission(mbeanServerName, (String) null, null, dom, "getDomains");
result.add(domains[i]);
} catch (SecurityException e) {
// OK: Do not add this domain to the list
@@ -657,7 +658,8 @@ public class DefaultMBeanServerIntercept
}
final DynamicMBean instance = getMBean(name);
- checkMBeanPermission(instance, attribute, name, "getAttribute");
+ checkMBeanPermission(mbeanServerName, instance, attribute,
+ name, "getAttribute");
try {
return instance.getAttribute(attribute);
@@ -702,7 +704,7 @@ public class DefaultMBeanServerIntercept
// Check if the caller has the right to invoke 'getAttribute'
//
- checkMBeanPermission(classname, null, name, "getAttribute");
+ checkMBeanPermission(mbeanServerName, classname, null, name, "getAttribute");
// Check if the caller has the right to invoke 'getAttribute'
// on each specific attribute
@@ -711,14 +713,15 @@ public class DefaultMBeanServerIntercept
new ArrayList<String>(attributes.length);
for (String attr : attributes) {
try {
- checkMBeanPermission(classname, attr,
+ checkMBeanPermission(mbeanServerName, classname, attr,
name, "getAttribute");
allowedList.add(attr);
} catch (SecurityException e) {
// OK: Do not add this attribute to the list
}
}
- allowedAttributes = allowedList.toArray(new String[0]);
+ allowedAttributes =
+ allowedList.toArray(new String[allowedList.size()]);
}
try {
@@ -756,7 +759,7 @@ public class DefaultMBeanServerIntercept
}
DynamicMBean instance = getMBean(name);
- checkMBeanPermission(instance, attribute.getName(),
+ checkMBeanPermission(mbeanServerName, instance, attribute.getName(),
name, "setAttribute");
try {
@@ -799,7 +802,7 @@ public class DefaultMBeanServerIntercept
// Check if the caller has the right to invoke 'setAttribute'
//
- checkMBeanPermission(classname, null, name, "setAttribute");
+ checkMBeanPermission(mbeanServerName, classname, null, name, "setAttribute");
// Check if the caller has the right to invoke 'setAttribute'
// on each specific attribute
@@ -808,7 +811,7 @@ public class DefaultMBeanServerIntercept
for (Iterator i = attributes.iterator(); i.hasNext();) {
try {
Attribute attribute = (Attribute) i.next();
- checkMBeanPermission(classname, attribute.getName(),
+ checkMBeanPermission(mbeanServerName, classname, attribute.getName(),
name, "setAttribute");
allowedAttributes.add(attribute);
} catch (SecurityException e) {
@@ -832,7 +835,8 @@ public class DefaultMBeanServerIntercept
name = nonDefaultDomain(name);
DynamicMBean instance = getMBean(name);
- checkMBeanPermission(instance, operationName, name, "invoke");
+ checkMBeanPermission(mbeanServerName, instance, operationName,
+ name, "invoke");
try {
return instance.invoke(operationName, params, signature);
} catch (Throwable t) {
@@ -934,8 +938,7 @@ public class DefaultMBeanServerIntercept
"registerMBean", "ObjectName = " + name);
}
- ObjectName logicalName = name;
- logicalName = preRegister(mbean, server, name);
+ ObjectName logicalName = preRegister(mbean, server, name);
// preRegister returned successfully, so from this point on we
// must call postRegister(false) if there is any problem.
@@ -961,16 +964,17 @@ public class DefaultMBeanServerIntercept
if (logicalName != name && logicalName != null) {
logicalName =
- ObjectName.getInstance(nonDefaultDomain(logicalName));
- }
-
- checkMBeanPermission(classname, null, logicalName, "registerMBean");
+ ObjectName.getInstance(nonDefaultDomain(logicalName));
+ }
+
+ checkMBeanPermission(mbeanServerName, classname, null, logicalName,
+ "registerMBean");
if (logicalName == null) {
final RuntimeException wrapped =
- new IllegalArgumentException("No object name specified");
+ new IllegalArgumentException("No object name specified");
throw new RuntimeOperationsException(wrapped,
- "Exception occurred trying to register the MBean");
+ "Exception occurred trying to register the MBean");
}
final Object resource = getResource(mbean);
@@ -987,13 +991,15 @@ public class DefaultMBeanServerIntercept
//
context = registerWithRepository(resource, mbean, logicalName);
+
registerFailed = false;
registered = true;
+
} finally {
try {
postRegister(logicalName, mbean, registered, registerFailed);
} finally {
- if (registered) context.done();
+ if (registered && context!=null) context.done();
}
}
return new ObjectInstance(logicalName, classname);
@@ -1001,20 +1007,19 @@ public class DefaultMBeanServerIntercept
private static void throwMBeanRegistrationException(Throwable t, String where)
throws MBeanRegistrationException {
- try {
- throw t;
- } catch (RuntimeException e) {
- throw new RuntimeMBeanException(
- e, "RuntimeException thrown " + where);
- } catch (Error er) {
- throw new RuntimeErrorException(er, "Error thrown " + where);
- } catch (MBeanRegistrationException r) {
- throw r;
- } catch (Exception ex) {
- throw new MBeanRegistrationException(ex, "Exception thrown " + where);
- } catch (Throwable t1) {
- throw new RuntimeException(t); // neither Error nor Exception??
- }
+ if (t instanceof RuntimeException) {
+ throw new RuntimeMBeanException((RuntimeException)t,
+ "RuntimeException thrown " + where);
+ } else if (t instanceof Error) {
+ throw new RuntimeErrorException((Error)t,
+ "Error thrown " + where);
+ } else if (t instanceof MBeanRegistrationException) {
+ throw (MBeanRegistrationException)t;
+ } else if (t instanceof Exception) {
+ throw new MBeanRegistrationException((Exception)t,
+ "Exception thrown " + where);
+ } else // neither Error nor Exception??
+ throw new RuntimeException(t);
}
private static ObjectName preRegister(
@@ -1164,7 +1169,7 @@ public class DefaultMBeanServerIntercept
if one is supplied where it shouldn't be). */
final String completeName = domain + name;
- return Util.newObjectName(completeName);
+ return ObjectName.valueOf(completeName);
}
public String getDefaultDomain() {
@@ -1230,7 +1235,8 @@ public class DefaultMBeanServerIntercept
}
DynamicMBean instance = getMBean(name);
- checkMBeanPermission(instance, null, name, "addNotificationListener");
+ checkMBeanPermission(mbeanServerName, instance, null,
+ name, "addNotificationListener");
NotificationBroadcaster broadcaster =
getNotificationBroadcaster(name, instance,
@@ -1367,7 +1373,7 @@ public class DefaultMBeanServerIntercept
}
DynamicMBean instance = getMBean(name);
- checkMBeanPermission(instance, null, name,
+ checkMBeanPermission(mbeanServerName, instance, null, name,
"removeNotificationListener");
/* We could simplify the code by assigning broadcaster after
@@ -1438,7 +1444,7 @@ public class DefaultMBeanServerIntercept
throw new JMRuntimeException("MBean " + name +
"has no MBeanInfo");
- checkMBeanPermission(mbi.getClassName(), null, name, "getMBeanInfo");
+ checkMBeanPermission(mbeanServerName, mbi.getClassName(), null, name, "getMBeanInfo");
return mbi;
}
@@ -1446,8 +1452,9 @@ public class DefaultMBeanServerIntercept
public boolean isInstanceOf(ObjectName name, String className)
throws InstanceNotFoundException {
- DynamicMBean instance = getMBean(name);
- checkMBeanPermission(instance, null, name, "isInstanceOf");
+ final DynamicMBean instance = getMBean(name);
+ checkMBeanPermission(mbeanServerName,
+ instance, null, name, "isInstanceOf");
try {
Object resource = getResource(instance);
@@ -1498,7 +1505,8 @@ public class DefaultMBeanServerIntercept
throws InstanceNotFoundException {
DynamicMBean instance = getMBean(mbeanName);
- checkMBeanPermission(instance, null, mbeanName, "getClassLoaderFor");
+ checkMBeanPermission(mbeanServerName, instance, null, mbeanName,
+ "getClassLoaderFor");
return getResourceLoader(instance);
}
@@ -1513,12 +1521,13 @@ public class DefaultMBeanServerIntercept
throws InstanceNotFoundException {
if (loaderName == null) {
- checkMBeanPermission((String) null, null, null, "getClassLoader");
+ checkMBeanPermission(mbeanServerName, (String) null, null, null, "getClassLoader");
return server.getClass().getClassLoader();
}
DynamicMBean instance = getMBean(loaderName);
- checkMBeanPermission(instance, null, loaderName, "getClassLoader");
+ checkMBeanPermission(mbeanServerName, instance, null, loaderName,
+ "getClassLoader");
Object resource = getResource(instance);
@@ -1568,7 +1577,7 @@ public class DefaultMBeanServerIntercept
}
} else {
// Access the filter
- MBeanServer oldServer = QueryEval.getMBeanServer();
+ final MBeanServer oldServer = QueryEval.getMBeanServer();
query.setMBeanServer(server);
try {
for (NamedObject no : list) {
@@ -1817,26 +1826,30 @@ public class DefaultMBeanServerIntercept
return mbean.getMBeanInfo().getClassName();
}
- private static void checkMBeanPermission(DynamicMBean mbean,
+ private static void checkMBeanPermission(String mbeanServerName,
+ DynamicMBean mbean,
String member,
ObjectName objectName,
String actions) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
- checkMBeanPermission(safeGetClassName(mbean),
+ checkMBeanPermission(mbeanServerName,
+ safeGetClassName(mbean),
member,
objectName,
actions);
}
}
- private static void checkMBeanPermission(String classname,
+ private static void checkMBeanPermission(String mbeanServerName,
+ String classname,
String member,
ObjectName objectName,
String actions) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
- Permission perm = new MBeanPermission(classname,
+ Permission perm = new MBeanPermission(mbeanServerName,
+ classname,
member,
objectName,
actions);
@@ -1902,6 +1915,12 @@ public class DefaultMBeanServerIntercept
throws InstanceAlreadyExistsException,
MBeanRegistrationException {
+ // this will throw an exception if the pair (resource, logicalName)
+ // violates namespace conventions - for instance, if logicalName
+ // ends with // but resource is not a JMXNamespace.
+ //
+ checkResourceObjectNameConstraints(resource, logicalName);
+
// Creates a registration context, if needed.
//
final ResourceContext context =
@@ -1965,6 +1984,57 @@ public class DefaultMBeanServerIntercept
sendNotification(MBeanServerNotification.UNREGISTRATION_NOTIFICATION,
logicalName);
return context;
+ }
+
+
+ /**
+ * Checks that the ObjectName is legal with regards to the
+ * type of the MBean resource.
+ * If the MBean name is domain:type=JMXDomain, the
+ * MBean must be a JMXDomain.
+ * If the MBean name is namespace//:type=JMXNamespace, the
+ * MBean must be a JMXNamespace.
+ * If the MBean is a JMXDomain, its name
+ * must be domain:type=JMXDomain.
+ * If the MBean is a JMXNamespace, its name
+ * must be namespace//:type=JMXNamespace.
+ */
+ private void checkResourceObjectNameConstraints(Object resource,
+ ObjectName logicalName)
+ throws MBeanRegistrationException {
+ try {
+ dispatcher.checkLocallyRegistrable(resource, logicalName);
+ } catch (Throwable x) {
+ DefaultMBeanServerInterceptor.throwMBeanRegistrationException(x, "validating ObjectName");
+ }
+ }
+
+ /**
+ * Registers a JMXNamespace with the dispatcher.
+ * This method is called by the ResourceContext from within the
+ * repository lock.
+ * @param namespace The JMXNamespace
+ * @param logicalName The JMXNamespaceMBean ObjectName
+ * @param postQueue A queue that will be processed after postRegister.
+ */
+ private void addJMXNamespace(JMXNamespace namespace,
+ final ObjectName logicalName,
+ final Queue<Runnable> postQueue) {
+ dispatcher.addInterceptorFor(logicalName, namespace, postQueue);
+ }
+
+ /**
+ * Unregisters a JMXNamespace from the dispatcher.
+ * This method is called by the ResourceContext from within the
+ * repository lock.
+ * @param namespace The JMXNamespace
+ * @param logicalName The JMXNamespaceMBean ObjectName
+ * @param postQueue A queue that will be processed after postDeregister.
+ */
+ private void removeJMXNamespace(JMXNamespace namespace,
+ final ObjectName logicalName,
+ final Queue<Runnable> postQueue) {
+ dispatcher.removeInterceptorFor(logicalName, namespace, postQueue);
}
/**
@@ -2020,6 +2090,52 @@ public class DefaultMBeanServerIntercept
}
}
+
+ /**
+ * Creates a ResourceContext for a JMXNamespace MBean.
+ * The resource context makes it possible to add the JMXNamespace to
+ * (ResourceContext.registering) or resp. remove the JMXNamespace from
+ * (ResourceContext.unregistered) the NamespaceDispatchInterceptor
+ * when the associated MBean is added to or resp. removed from the
+ * repository.
+ * Note: JMXDomains are special sub classes of JMXNamespaces and
+ * are also handled by this object.
+ *
+ * @param namespace The JMXNamespace MBean being registered or
+ * unregistered.
+ * @param logicalName The name of the JMXNamespace MBean.
+ * @return a ResourceContext that takes in charge the addition or removal
+ * of the namespace to or from the NamespaceDispatchInterceptor.
+ */
+ private ResourceContext createJMXNamespaceContext(
+ final JMXNamespace namespace,
+ final ObjectName logicalName) {
+ final Queue<Runnable> doneTaskQueue = new LinkedList<Runnable>();
+ return new ResourceContext() {
+
+ public void registering() {
+ addJMXNamespace(namespace, logicalName, doneTaskQueue);
+ }
+
+ public void unregistered() {
+ removeJMXNamespace(namespace, logicalName,
+ doneTaskQueue);
+ }
+
+ public void done() {
+ for (Runnable r : doneTaskQueue) {
+ try {
+ r.run();
+ } catch (RuntimeException x) {
+ MBEANSERVER_LOGGER.log(Level.FINE,
+ "Failed to process post queue for "+
+ logicalName, x);
+ }
+ }
+ }
+ };
+ }
+
/**
* Creates a ResourceContext for a ClassLoader MBean.
* The resource context makes it possible to add the ClassLoader to
@@ -2065,10 +2181,16 @@ public class DefaultMBeanServerIntercept
*/
private ResourceContext makeResourceContextFor(Object resource,
ObjectName logicalName) {
+ if (resource instanceof JMXNamespace) {
+ return createJMXNamespaceContext((JMXNamespace) resource,
+ logicalName);
+ }
if (resource instanceof ClassLoader) {
return createClassLoaderContext((ClassLoader) resource,
logicalName);
}
return ResourceContext.NONE;
}
+
+
}
--- a/src/share/classes/com/sun/jmx/interceptor/MBeanServerInterceptor.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/interceptor/MBeanServerInterceptor.java Tue Oct 07 13:48:49 2008 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2002-2008 Sun Microsystems, Inc. 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
@@ -25,35 +25,14 @@
package com.sun.jmx.interceptor;
-import java.util.Set;
-// RI import
-import javax.management.DynamicMBean;
-import javax.management.AttributeNotFoundException;
+import java.io.ObjectInputStream;
+import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.OperationsException;
import javax.management.ReflectionException;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanInfo;
-import javax.management.QueryExp;
-import javax.management.NotificationListener;
-import javax.management.NotificationFilter;
-import javax.management.ListenerNotFoundException;
-import javax.management.IntrospectionException;
-import javax.management.OperationsException;
-import javax.management.MBeanNotificationInfo;
-import javax.management.JMRuntimeException;
-import javax.management.InstanceNotFoundException;
-import javax.management.NotCompliantMBeanException;
-import javax.management.MBeanRegistrationException;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InvalidAttributeValueException;
-import javax.management.ObjectName;
-import javax.management.ObjectInstance;
-import javax.management.Attribute;
-import javax.management.AttributeList;
-import javax.management.RuntimeOperationsException;
-import javax.management.MBeanServerConnection;
-import javax.management.MBeanServerDelegate;
import javax.management.loading.ClassLoaderRepository;
/**
@@ -85,618 +64,67 @@ import javax.management.loading.ClassLoa
*
* @since 1.5
*/
-public interface MBeanServerInterceptor extends MBeanServerConnection {
+public interface MBeanServerInterceptor extends MBeanServer {
/**
- * Instantiates and registers an MBean in the MBean server. The
- * MBean server will use its {@link
- * javax.management.loading.ClassLoaderRepository Default Loader
- * Repository} to load the class of the MBean. An object name is
- * associated to the MBean. If the object name given is null, the
- * MBean must provide its own name by implementing the {@link
- * javax.management.MBeanRegistration MBeanRegistration} interface
- * and returning the name from the {@link
- * javax.management.MBeanRegistration#preRegister preRegister} method.
- *
- * @param className The class name of the MBean to be instantiated.
- * @param name The object name of the MBean. May be null.
- * @param params An array containing the parameters of the
- * constructor to be invoked.
- * @param signature An array containing the signature of the
- * constructor to be invoked.
- *
- * @return An <CODE>ObjectInstance</CODE>, containing the
- * <CODE>ObjectName</CODE> and the Java class name of the newly
- * instantiated MBean.
- *
- * @exception ReflectionException Wraps a
- * <CODE>java.lang.ClassNotFoundException</CODE> or a
- * <CODE>java.lang.Exception</CODE> that occurred when trying to
- * invoke the MBean's constructor.
- * @exception InstanceAlreadyExistsException The MBean is already
- * under the control of the MBean server.
- * @exception MBeanRegistrationException The
- * <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE>
- * interface) method of the MBean has thrown an exception. The
- * MBean will not be registered.
- * @exception MBeanException The constructor of the MBean has
- * thrown an exception
- * @exception RuntimeOperationsException Wraps a
- * <CODE>java.lang.IllegalArgumentException</CODE>: The className
- * passed in parameter is null, the <CODE>ObjectName</CODE> passed
- * in parameter contains a pattern or no <CODE>ObjectName</CODE>
- * is specified for the MBean.
+ * This method should never be called.
+ * Usually hrows UnsupportedOperationException.
*/
- public ObjectInstance createMBean(String className, ObjectName name,
- Object params[], String signature[])
- throws ReflectionException, InstanceAlreadyExistsException,
- MBeanRegistrationException, MBeanException,
- NotCompliantMBeanException;
+ public Object instantiate(String className)
+ throws ReflectionException, MBeanException;
+ /**
+ * This method should never be called.
+ * Usually throws UnsupportedOperationException.
+ */
+ public Object instantiate(String className, ObjectName loaderName)
+ throws ReflectionException, MBeanException,
+ InstanceNotFoundException;
+ /**
+ * This method should never be called.
+ * Usually throws UnsupportedOperationException.
+ */
+ public Object instantiate(String className, Object[] params,
+ String[] signature) throws ReflectionException, MBeanException;
/**
- * Instantiates and registers an MBean in the MBean server. The
- * class loader to be used is identified by its object name. An
- * object name is associated to the MBean. If the object name of
- * the loader is not specified, the ClassLoader that loaded the
- * MBean server will be used. If the MBean object name given is
- * null, the MBean must provide its own name by implementing the
- * {@link javax.management.MBeanRegistration MBeanRegistration}
- * interface and returning the name from the {@link
- * javax.management.MBeanRegistration#preRegister preRegister} method.
- *
- * @param className The class name of the MBean to be instantiated.
- * @param name The object name of the MBean. May be null.
- * @param params An array containing the parameters of the
- * constructor to be invoked.
- * @param signature An array containing the signature of the
- * constructor to be invoked.
- * @param loaderName The object name of the class loader to be used.
- *
- * @return An <CODE>ObjectInstance</CODE>, containing the
- * <CODE>ObjectName</CODE> and the Java class name of the newly
- * instantiated MBean.
- *
- * @exception ReflectionException Wraps a
- * <CODE>java.lang.ClassNotFoundException</CODE> or a
- * <CODE>java.lang.Exception</CODE> that occurred when trying to
- * invoke the MBean's constructor.
- * @exception InstanceAlreadyExistsException The MBean is already
- * under the control of the MBean server.
- * @exception MBeanRegistrationException The
- * <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE>
- * interface) method of the MBean has thrown an exception. The
- * MBean will not be registered.
- * @exception MBeanException The constructor of the MBean has
- * thrown an exception
- * @exception InstanceNotFoundException The specified class loader
- * is not registered in the MBean server.
- * @exception RuntimeOperationsException Wraps a
- * <CODE>java.lang.IllegalArgumentException</CODE>: The className
- * passed in parameter is null, the <CODE>ObjectName</CODE> passed
- * in parameter contains a pattern or no <CODE>ObjectName</CODE>
- * is specified for the MBean.
- *
+ * This method should never be called.
+ * Usually throws UnsupportedOperationException.
*/
- public ObjectInstance createMBean(String className, ObjectName name,
- ObjectName loaderName, Object params[],
- String signature[])
- throws ReflectionException, InstanceAlreadyExistsException,
- MBeanRegistrationException, MBeanException,
- NotCompliantMBeanException, InstanceNotFoundException;
+ public Object instantiate(String className, ObjectName loaderName,
+ Object[] params, String[] signature)
+ throws ReflectionException, MBeanException,
+ InstanceNotFoundException;
/**
- * Registers a pre-existing object as an MBean with the MBean
- * server. If the object name given is null, the MBean must
- * provide its own name by implementing the {@link
- * javax.management.MBeanRegistration MBeanRegistration} interface
- * and returning the name from the {@link
- * javax.management.MBeanRegistration#preRegister preRegister} method.
- *
- * @param object The MBean to be registered as an MBean.
- * @param name The object name of the MBean. May be null.
- *
- * @return The <CODE>ObjectInstance</CODE> for the MBean that has
- * been registered.
- *
- * @exception InstanceAlreadyExistsException The MBean is already
- * under the control of the MBean server.
- * @exception MBeanRegistrationException The
- * <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE>
- * interface) method of the MBean has thrown an exception. The
- * MBean will not be registered.
- * @exception NotCompliantMBeanException This object is not a JMX
- * compliant MBean
- * @exception RuntimeOperationsException Wraps a
- * <CODE>java.lang.IllegalArgumentException</CODE>: The object
- * passed in parameter is null or no object name is specified.
+ * This method should never be called.
+ * Usually throws UnsupportedOperationException.
*/
- public ObjectInstance registerMBean(Object object, ObjectName name)
- throws InstanceAlreadyExistsException, MBeanRegistrationException,
- NotCompliantMBeanException;
+ @Deprecated
+ public ObjectInputStream deserialize(ObjectName name, byte[] data)
+ throws InstanceNotFoundException, OperationsException;
/**
- * Unregisters an MBean from the MBean server. The MBean is
- * identified by its object name. Once the method has been
- * invoked, the MBean may no longer be accessed by its object
- * name.
- *
- * @param name The object name of the MBean to be unregistered.
- *
- * @exception InstanceNotFoundException The MBean specified is not
- * registered in the MBean server.
- * @exception MBeanRegistrationException The preDeregister
- * ((<CODE>MBeanRegistration</CODE> interface) method of the MBean
- * has thrown an exception.
- * @exception RuntimeOperationsException Wraps a
- * <CODE>java.lang.IllegalArgumentException</CODE>: The object
- * name in parameter is null or the MBean you are when trying to
- * unregister is the {@link javax.management.MBeanServerDelegate
- * MBeanServerDelegate} MBean.
- *
+ * This method should never be called.
+ * Usually throws UnsupportedOperationException.
*/
- public void unregisterMBean(ObjectName name)
- throws InstanceNotFoundException, MBeanRegistrationException;
+ @Deprecated
+ public ObjectInputStream deserialize(String className, byte[] data)
+ throws OperationsException, ReflectionException;
/**
- * Gets the <CODE>ObjectInstance</CODE> for a given MBean
- * registered with the MBean server.
- *
- * @param name The object name of the MBean.
- *
- * @return The <CODE>ObjectInstance</CODE> associated to the MBean
- * specified by <VAR>name</VAR>.
- *
- * @exception InstanceNotFoundException The MBean specified is not
- * registered in the MBean server.
+ * This method should never be called.
+ * Usually hrows UnsupportedOperationException.
*/
- public ObjectInstance getObjectInstance(ObjectName name)
- throws InstanceNotFoundException;
+ @Deprecated
+ public ObjectInputStream deserialize(String className,
+ ObjectName loaderName, byte[] data)
+ throws InstanceNotFoundException, OperationsException,
+ ReflectionException;
/**
- * Gets MBeans controlled by the MBean server. This method allows
- * any of the following to be obtained: All MBeans, a set of
- * MBeans specified by pattern matching on the
- * <CODE>ObjectName</CODE> and/or a Query expression, a specific
- * MBean. When the object name is null or no domain and key
- * properties are specified, all objects are to be selected (and
- * filtered if a query is specified). It returns the set of
- * <CODE>ObjectInstance</CODE> objects (containing the
- * <CODE>ObjectName</CODE> and the Java Class name) for the
- * selected MBeans.
- *
- * @param name The object name pattern identifying the MBeans to
- * be retrieved. If null or no domain and key properties are
- * specified, all the MBeans registered will be retrieved.
- * @param query The query expression to be applied for selecting
- * MBeans. If null no query expression will be applied for
- * selecting MBeans.
- *
- * @return A set containing the <CODE>ObjectInstance</CODE>
- * objects for the selected MBeans. If no MBean satisfies the
- * query an empty list is returned.
+ * This method should never be called.
+ * Usually throws UnsupportedOperationException.
*/
- public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query);
-
- /**
- * Gets the names of MBeans controlled by the MBean server. This
- * method enables any of the following to be obtained: The names
- * of all MBeans, the names of a set of MBeans specified by
- * pattern matching on the <CODE>ObjectName</CODE> and/or a Query
- * expression, a specific MBean name (equivalent to testing
- * whether an MBean is registered). When the object name is null
- * or no domain and key properties are specified, all objects are
- * selected (and filtered if a query is specified). It returns the
- * set of ObjectNames for the MBeans selected.
- *
- * @param name The object name pattern identifying the MBean names
- * to be retrieved. If null oror no domain and key properties are
- * specified, the name of all registered MBeans will be retrieved.
- * @param query The query expression to be applied for selecting
- * MBeans. If null no query expression will be applied for
- * selecting MBeans.
- *
- * @return A set containing the ObjectNames for the MBeans
- * selected. If no MBean satisfies the query, an empty list is
- * returned.
- */
- public Set<ObjectName> queryNames(ObjectName name, QueryExp query);
-
- /**
- * Checks whether an MBean, identified by its object name, is
- * already registered with the MBean server.
- *
- * @param name The object name of the MBean to be checked.
- *
- * @return True if the MBean is already registered in the MBean
- * server, false otherwise.
- *
- * @exception RuntimeOperationsException Wraps a
- * <CODE>java.lang.IllegalArgumentException</CODE>: The object
- * name in parameter is null.
- */
- public boolean isRegistered(ObjectName name);
-
- /**
- * Returns the number of MBeans registered in the MBean server.
- */
- public Integer getMBeanCount();
-
- /**
- * Gets the value of a specific attribute of a named MBean. The MBean
- * is identified by its object name.
- *
- * @param name The object name of the MBean from which the
- * attribute is to be retrieved.
- * @param attribute A String specifying the name of the attribute
- * to be retrieved.
- *
- * @return The value of the retrieved attribute.
- *
- * @exception AttributeNotFoundException The attribute specified
- * is not accessible in the MBean.
- * @exception MBeanException Wraps an exception thrown by the
- * MBean's getter.
- * @exception InstanceNotFoundException The MBean specified is not
- * registered in the MBean server.
- * @exception ReflectionException Wraps a
- * <CODE>java.lang.Exception</CODE> thrown when trying to invoke
- * the setter.
- * @exception RuntimeOperationsException Wraps a
- * <CODE>java.lang.IllegalArgumentException</CODE>: The object
- * name in parameter is null or the attribute in parameter is
- * null.
- */
- public Object getAttribute(ObjectName name, String attribute)
- throws MBeanException, AttributeNotFoundException,
- InstanceNotFoundException, ReflectionException;
-
- /**
- * Enables the values of several attributes of a named MBean. The MBean
- * is identified by its object name.
- *
- * @param name The object name of the MBean from which the
- * attributes are retrieved.
- * @param attributes A list of the attributes to be retrieved.
- *
- * @return The list of the retrieved attributes.
- *
- * @exception InstanceNotFoundException The MBean specified is not
- * registered in the MBean server.
- * @exception ReflectionException An exception occurred when
- * trying to invoke the getAttributes method of a Dynamic MBean.
- * @exception RuntimeOperationsException Wrap a
- * <CODE>java.lang.IllegalArgumentException</CODE>: The object
- * name in parameter is null or attributes in parameter is null.
- */
- public AttributeList getAttributes(ObjectName name, String[] attributes)
- throws InstanceNotFoundException, ReflectionException;
-
- /**
- * Sets the value of a specific attribute of a named MBean. The MBean
- * is identified by its object name.
- *
- * @param name The name of the MBean within which the attribute is
- * to be set.
- * @param attribute The identification of the attribute to be set
- * and the value it is to be set to.
- *
- * @exception InstanceNotFoundException The MBean specified is not
- * registered in the MBean server.
- * @exception AttributeNotFoundException The attribute specified
- * is not accessible in the MBean.
- * @exception InvalidAttributeValueException The value specified
- * for the attribute is not valid.
- * @exception MBeanException Wraps an exception thrown by the
- * MBean's setter.
- * @exception ReflectionException Wraps a
- * <CODE>java.lang.Exception</CODE> thrown when trying to invoke
- * the setter.
- * @exception RuntimeOperationsException Wraps a
- * <CODE>java.lang.IllegalArgumentException</CODE>: The object
- * name in parameter is null or the attribute in parameter is
- * null.
- */
- public void setAttribute(ObjectName name, Attribute attribute)
- throws InstanceNotFoundException, AttributeNotFoundException,
- InvalidAttributeValueException, MBeanException,
- ReflectionException;
-
-
-
- /**
- * Sets the values of several attributes of a named MBean. The MBean is
- * identified by its object name.
- *
- * @param name The object name of the MBean within which the
- * attributes are to be set.
- * @param attributes A list of attributes: The identification of
- * the attributes to be set and the values they are to be set to.
- *
- * @return The list of attributes that were set, with their new
- * values.
- *
- * @exception InstanceNotFoundException The MBean specified is not
- * registered in the MBean server.
- * @exception ReflectionException An exception occurred when
- * trying to invoke the getAttributes method of a Dynamic MBean.
- * @exception RuntimeOperationsException Wraps a
- * <CODE>java.lang.IllegalArgumentException</CODE>: The object
- * name in parameter is null or attributes in parameter is null.
- */
- public AttributeList setAttributes(ObjectName name,
- AttributeList attributes)
- throws InstanceNotFoundException, ReflectionException;
-
- /**
- * Invokes an operation on an MBean.
- *
- * @param name The object name of the MBean on which the method is
- * to be invoked.
- * @param operationName The name of the operation to be invoked.
- * @param params An array containing the parameters to be set when
- * the operation is invoked
- * @param signature An array containing the signature of the
- * operation. The class objects will be loaded using the same
- * class loader as the one used for loading the MBean on which the
- * operation was invoked.
- *
- * @return The object returned by the operation, which represents
- * the result ofinvoking the operation on the MBean specified.
- *
- * @exception InstanceNotFoundException The MBean specified is not
- * registered in the MBean server.
- * @exception MBeanException Wraps an exception thrown by the
- * MBean's invoked method.
- * @exception ReflectionException Wraps a
- * <CODE>java.lang.Exception</CODE> thrown while trying to invoke
- * the method.
- */
- public Object invoke(ObjectName name, String operationName,
- Object params[], String signature[])
- throws InstanceNotFoundException, MBeanException,
- ReflectionException;
-
- /**
- * Returns the default domain used for naming the MBean.
- * The default domain name is used as the domain part in the ObjectName
- * of MBeans if no domain is specified by the user.
- */
- public String getDefaultDomain();
-
- /**
- * Returns the list of domains in which any MBean is currently
- * registered.
- */
- public String[] getDomains();
-
- /**
- * <p>Adds a listener to a registered MBean.</p>
- *
- * <P> A notification emitted by an MBean will be forwarded by the
- * MBeanServer to the listener. If the source of the notification
- * is a reference to an MBean object, the MBean server will replace it
- * by that MBean's ObjectName. Otherwise the source is unchanged.
- *
- * @param name The name of the MBean on which the listener should
- * be added.
- * @param listener The listener object which will handle the
- * notifications emitted by the registered MBean.
- * @param filter The filter object. If filter is null, no
- * filtering will be performed before handling notifications.
- * @param handback The context to be sent to the listener when a
- * notification is emitted.
- *
- * @exception InstanceNotFoundException The MBean name provided
- * does not match any of the registered MBeans.
- */
- public void addNotificationListener(ObjectName name,
- NotificationListener listener,
- NotificationFilter filter,
- Object handback)
- throws InstanceNotFoundException;
-
-
- /**
- * <p>Adds a listener to a registered MBean.</p>
- *
- * <p>A notification emitted by an MBean will be forwarded by the
- * MBeanServer to the listener. If the source of the notification
- * is a reference to an MBean object, the MBean server will
- * replace it by that MBean's ObjectName. Otherwise the source is
- * unchanged.</p>
- *
- * <p>The listener object that receives notifications is the one
- * that is registered with the given name at the time this method
- * is called. Even if it is subsequently unregistered, it will
- * continue to receive notifications.</p>
- *
- * @param name The name of the MBean on which the listener should
- * be added.
- * @param listener The object name of the listener which will
- * handle the notifications emitted by the registered MBean.
- * @param filter The filter object. If filter is null, no
- * filtering will be performed before handling notifications.
- * @param handback The context to be sent to the listener when a
- * notification is emitted.
- *
- * @exception InstanceNotFoundException The MBean name of the
- * notification listener or of the notification broadcaster does
- * not match any of the registered MBeans.
- * @exception RuntimeOperationsException Wraps an {@link
- * IllegalArgumentException}. The MBean named by
- * <code>listener</code> exists but does not implement the {@link
- * NotificationListener} interface.
- * @exception IOException A communication problem occurred when
- * talking to the MBean server.
- */
- public void addNotificationListener(ObjectName name,
- ObjectName listener,
- NotificationFilter filter,
- Object handback)
- throws InstanceNotFoundException;
-
- /**
- * Removes a listener from a registered MBean.
- *
- * <P> If the listener is registered more than once, perhaps with
- * different filters or callbacks, this method will remove all
- * those registrations.
- *
- * @param name The name of the MBean on which the listener should
- * be removed.
- * @param listener The object name of the listener to be removed.
- *
- * @exception InstanceNotFoundException The MBean name provided
- * does not match any of the registered MBeans.
- * @exception ListenerNotFoundException The listener is not
- * registered in the MBean.
- */
- public void removeNotificationListener(ObjectName name,
- ObjectName listener)
- throws InstanceNotFoundException, ListenerNotFoundException;
-
- /**
- * <p>Removes a listener from a registered MBean.</p>
- *
- * <p>The MBean must have a listener that exactly matches the
- * given <code>listener</code>, <code>filter</code>, and
- * <code>handback</code> parameters. If there is more than one
- * such listener, only one is removed.</p>
- *
- * <p>The <code>filter</code> and <code>handback</code> parameters
- * may be null if and only if they are null in a listener to be
- * removed.</p>
- *
- * @param name The name of the MBean on which the listener should
- * be removed.
- * @param listener A listener that was previously added to this
- * MBean.
- * @param filter The filter that was specified when the listener
- * was added.
- * @param handback The handback that was specified when the
- * listener was added.
- *
- * @exception InstanceNotFoundException The MBean name provided
- * does not match any of the registered MBeans.
- * @exception ListenerNotFoundException The listener is not
- * registered in the MBean, or it is not registered with the given
- * filter and handback.
- */
- public void removeNotificationListener(ObjectName name,
- ObjectName listener,
- NotificationFilter filter,
- Object handback)
- throws InstanceNotFoundException, ListenerNotFoundException;
-
-
- /**
- * <p>Removes a listener from a registered MBean.</p>
- *
- * <P> If the listener is registered more than once, perhaps with
- * different filters or callbacks, this method will remove all
- * those registrations.
- *
- * @param name The name of the MBean on which the listener should
- * be removed.
- * @param listener The listener object which will handle the
- * notifications emitted by the registered MBean.
- *
- * @exception InstanceNotFoundException The MBean name provided
- * does not match any of the registered MBeans.
- * @exception ListenerNotFoundException The listener is not
- * registered in the MBean.
- */
- public void removeNotificationListener(ObjectName name,
- NotificationListener listener)
- throws InstanceNotFoundException, ListenerNotFoundException;
-
- /**
- * <p>Removes a listener from a registered MBean.</p>
- *
- * <p>The MBean must have a listener that exactly matches the
- * given <code>listener</code>, <code>filter</code>, and
- * <code>handback</code> parameters. If there is more than one
- * such listener, only one is removed.</p>
- *
- * <p>The <code>filter</code> and <code>handback</code> parameters
- * may be null if and only if they are null in a listener to be
- * removed.</p>
- *
- * @param name The name of the MBean on which the listener should
- * be removed.
- * @param listener A listener that was previously added to this
- * MBean.
- * @param filter The filter that was specified when the listener
- * was added.
- * @param handback The handback that was specified when the
- * listener was added.
- *
- * @exception InstanceNotFoundException The MBean name provided
- * does not match any of the registered MBeans.
- * @exception ListenerNotFoundException The listener is not
- * registered in the MBean, or it is not registered with the given
- * filter and handback.
- */
- public void removeNotificationListener(ObjectName name,
- NotificationListener listener,
- NotificationFilter filter,
- Object handback)
- throws InstanceNotFoundException, ListenerNotFoundException;
-
- /**
- * This method discovers the attributes and operations that an
- * MBean exposes for management.
- *
- * @param name The name of the MBean to analyze
- *
- * @return An instance of <CODE>MBeanInfo</CODE> allowing the
- * retrieval of all attributes and operations of this MBean.
- *
- * @exception IntrospectionException An exception occurred during
- * introspection.
- * @exception InstanceNotFoundException The MBean specified was
- * not found.
- * @exception ReflectionException An exception occurred when
- * trying to invoke the getMBeanInfo of a Dynamic MBean.
- */
- public MBeanInfo getMBeanInfo(ObjectName name)
- throws InstanceNotFoundException, IntrospectionException,
- ReflectionException;
-
-
- /**
- * Returns true if the MBean specified is an instance of the
- * specified class, false otherwise.
- *
- * @param name The <CODE>ObjectName</CODE> of the MBean.
- * @param className The name of the class.
- *
- * @return true if the MBean specified is an instance of the
- * specified class, false otherwise.
- *
- * @exception InstanceNotFoundException The MBean specified is not
- * registered in the MBean server.
- */
- public boolean isInstanceOf(ObjectName name, String className)
- throws InstanceNotFoundException;
-
- /**
- * <p>Return the {@link java.lang.ClassLoader} that was used for
- * loading the class of the named MBean.
- * @param mbeanName The ObjectName of the MBean.
- * @return The ClassLoader used for that MBean.
- * @exception InstanceNotFoundException if the named MBean is not found.
- */
- public ClassLoader getClassLoaderFor(ObjectName mbeanName)
- throws InstanceNotFoundException;
-
- /**
- * <p>Return the named {@link java.lang.ClassLoader}.
- * @param loaderName The ObjectName of the ClassLoader.
- * @return The named ClassLoader.
- * @exception InstanceNotFoundException if the named ClassLoader is
- * not found.
- */
- public ClassLoader getClassLoader(ObjectName loaderName)
- throws InstanceNotFoundException;
+ public ClassLoaderRepository getClassLoaderRepository();
}
+
--- a/src/share/classes/com/sun/jmx/interceptor/SingleMBeanForwarder.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/interceptor/SingleMBeanForwarder.java Tue Oct 07 13:48:49 2008 -0400
@@ -51,6 +51,8 @@ import javax.management.ObjectName;
import javax.management.ObjectName;
import javax.management.QueryExp;
import javax.management.ReflectionException;
+import javax.management.namespace.JMXNamespaces;
+import javax.management.namespace.MBeanServerSupport;
import javax.management.remote.IdentityMBeanServerForwarder;
public class SingleMBeanForwarder extends IdentityMBeanServerForwarder {
@@ -285,14 +287,14 @@ public class SingleMBeanForwarder extend
if (!pattern.apply(mbeanName))
return false;
-// final String dompat = pattern.getDomain();
-// if (!dompat.contains(JMXNamespaces.NAMESPACE_SEPARATOR))
-// return true; // We already checked that patterns apply.
-//
-// if (mbeanName.getDomain().endsWith(JMXNamespaces.NAMESPACE_SEPARATOR)) {
-// // only matches if pattern ends with //
-// return dompat.endsWith(JMXNamespaces.NAMESPACE_SEPARATOR);
-// }
+ final String dompat = pattern.getDomain();
+ if (!dompat.contains(JMXNamespaces.NAMESPACE_SEPARATOR))
+ return true; // We already checked that patterns apply.
+
+ if (mbeanName.getDomain().endsWith(JMXNamespaces.NAMESPACE_SEPARATOR)) {
+ // only matches if pattern ends with //
+ return dompat.endsWith(JMXNamespaces.NAMESPACE_SEPARATOR);
+ }
// should not come here, unless mbeanName contains a // in the
// middle of its domain, which would be weird.
--- a/src/share/classes/com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java Tue Oct 07 13:48:49 2008 -0400
@@ -1172,10 +1172,10 @@ public class DefaultMXBeanMappingFactory
final Class<ConstructorProperties> propertyNamesClass = ConstructorProperties.class;
Class targetClass = getTargetClass();
- Constructor[] constrs = targetClass.getConstructors();
+ Constructor<?>[] constrs = targetClass.getConstructors();
// Applicable if and only if there are any annotated constructors
- List<Constructor> annotatedConstrList = newList();
+ List<Constructor<?>> annotatedConstrList = newList();
for (Constructor<?> constr : constrs) {
if (Modifier.isPublic(constr.getModifiers())
&& constr.getAnnotation(propertyNamesClass) != null)
@@ -1206,7 +1206,7 @@ public class DefaultMXBeanMappingFactory
// Also remember the set of properties in that constructor
// so we can test unambiguity.
Set<BitSet> getterIndexSets = newSet();
- for (Constructor constr : annotatedConstrList) {
+ for (Constructor<?> constr : annotatedConstrList) {
String[] propertyNames =
constr.getAnnotation(propertyNamesClass).value();
@@ -1363,10 +1363,10 @@ public class DefaultMXBeanMappingFactory
}
private static class Constr {
- final Constructor constructor;
+ final Constructor<?> constructor;
final int[] paramIndexes;
final BitSet presentParams;
- Constr(Constructor constructor, int[] paramIndexes,
+ Constr(Constructor<?> constructor, int[] paramIndexes,
BitSet presentParams) {
this.constructor = constructor;
this.paramIndexes = paramIndexes;
--- a/src/share/classes/com/sun/jmx/mbeanserver/JmxMBeanServer.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/mbeanserver/JmxMBeanServer.java Tue Oct 07 13:48:49 2008 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1999-2008 Sun Microsystems, Inc. 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
@@ -25,43 +25,41 @@
package com.sun.jmx.mbeanserver;
-import java.util.Iterator;
-import java.util.logging.Level;
-import java.util.Set;
+import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER;
+import com.sun.jmx.interceptor.NamespaceDispatchInterceptor;
+
import java.io.ObjectInputStream;
import java.security.AccessController;
import java.security.Permission;
import java.security.PrivilegedExceptionAction;
-
-// RI import
-import javax.management.MBeanPermission;
-import javax.management.AttributeNotFoundException;
-import javax.management.MBeanException;
-import javax.management.ReflectionException;
-import javax.management.MBeanInfo;
-import javax.management.QueryExp;
-import javax.management.NotificationListener;
-import javax.management.NotificationFilter;
-import javax.management.ListenerNotFoundException;
-import javax.management.IntrospectionException;
-import javax.management.OperationsException;
-import javax.management.InstanceNotFoundException;
-import javax.management.NotCompliantMBeanException;
-import javax.management.MBeanRegistrationException;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InvalidAttributeValueException;
-import javax.management.ObjectName;
-import javax.management.ObjectInstance;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.logging.Level;
+
import javax.management.Attribute;
import javax.management.AttributeList;
-import javax.management.RuntimeOperationsException;
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.IntrospectionException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanPermission;
+import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MBeanServerDelegate;
+import javax.management.NotCompliantMBeanException;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import javax.management.OperationsException;
+import javax.management.QueryExp;
+import javax.management.ReflectionException;
+import javax.management.RuntimeOperationsException;
import javax.management.loading.ClassLoaderRepository;
-
-import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER;
-import com.sun.jmx.interceptor.DefaultMBeanServerInterceptor;
-import com.sun.jmx.interceptor.MBeanServerInterceptor;
/**
* This is the base class for MBean manipulation on the agent side. It
@@ -102,15 +100,14 @@ public final class JmxMBeanServer
/** true if interceptors are enabled **/
private final boolean interceptorsEnabled;
- /** Revisit: transient ??? **/
- private final transient MBeanServer outerShell;
-
- /** Revisit: transient ??? **/
- private transient MBeanServerInterceptor mbsInterceptor = null;
-
- /** Revisit: transient ??? **/
+ private final MBeanServer outerShell;
+
+ private volatile MBeanServer mbsInterceptor = null;
+
/** The MBeanServerDelegate object representing the MBean Server */
- private final transient MBeanServerDelegate mBeanServerDelegateObject;
+ private final MBeanServerDelegate mBeanServerDelegateObject;
+
+ private final String mbeanServerName;
/**
* <b>Package:</b> Creates an MBeanServer with the
@@ -243,9 +240,10 @@ public final class JmxMBeanServer
final Repository repository = new Repository(domain,fairLock);
this.mbsInterceptor =
- new DefaultMBeanServerInterceptor(outer, delegate, instantiator,
+ new NamespaceDispatchInterceptor(outer, delegate, instantiator,
repository);
this.interceptorsEnabled = interceptors;
+ this.mbeanServerName = Util.getMBeanServerSecurityName(delegate);
initialize();
}
@@ -941,7 +939,8 @@ public final class JmxMBeanServer
throws ReflectionException, MBeanException {
/* Permission check */
- checkMBeanPermission(className, null, null, "instantiate");
+ checkMBeanPermission(mbeanServerName, className, null, null,
+ "instantiate");
return instantiator.instantiate(className);
}
@@ -978,7 +977,8 @@ public final class JmxMBeanServer
InstanceNotFoundException {
/* Permission check */
- checkMBeanPermission(className, null, null, "instantiate");
+ checkMBeanPermission(mbeanServerName, className, null,
+ null, "instantiate");
ClassLoader myLoader = outerShell.getClass().getClassLoader();
return instantiator.instantiate(className, loaderName, myLoader);
@@ -1016,7 +1016,8 @@ public final class JmxMBeanServer
throws ReflectionException, MBeanException {
/* Permission check */
- checkMBeanPermission(className, null, null, "instantiate");
+ checkMBeanPermission(mbeanServerName, className, null, null,
+ "instantiate");
ClassLoader myLoader = outerShell.getClass().getClassLoader();
return instantiator.instantiate(className, params, signature,
@@ -1059,7 +1060,8 @@ public final class JmxMBeanServer
InstanceNotFoundException {
/* Permission check */
- checkMBeanPermission(className, null, null, "instantiate");
+ checkMBeanPermission(mbeanServerName, className, null,
+ null, "instantiate");
ClassLoader myLoader = outerShell.getClass().getClassLoader();
return instantiator.instantiate(className,loaderName,params,signature,
@@ -1236,7 +1238,7 @@ public final class JmxMBeanServer
"Unexpected exception occurred", e);
}
throw new
- IllegalStateException("Can't register delegate.");
+ IllegalStateException("Can't register delegate.",e);
}
@@ -1278,7 +1280,7 @@ public final class JmxMBeanServer
* are not enabled on this object.
* @see #interceptorsEnabled
**/
- public synchronized MBeanServerInterceptor getMBeanServerInterceptor() {
+ public synchronized MBeanServer getMBeanServerInterceptor() {
if (interceptorsEnabled) return mbsInterceptor;
else throw new UnsupportedOperationException(
"MBeanServerInterceptors are disabled.");
@@ -1292,7 +1294,7 @@ public final class JmxMBeanServer
* @see #interceptorsEnabled
**/
public synchronized void
- setMBeanServerInterceptor(MBeanServerInterceptor interceptor) {
+ setMBeanServerInterceptor(MBeanServer interceptor) {
if (!interceptorsEnabled) throw new UnsupportedOperationException(
"MBeanServerInterceptors are disabled.");
if (interceptor == null) throw new
@@ -1330,7 +1332,8 @@ public final class JmxMBeanServer
**/
public ClassLoaderRepository getClassLoaderRepository() {
/* Permission check */
- checkMBeanPermission(null, null, null, "getClassLoaderRepository");
+ checkMBeanPermission(mbeanServerName, null, null,
+ null, "getClassLoaderRepository");
return secureClr;
}
@@ -1484,14 +1487,16 @@ public final class JmxMBeanServer
// SECURITY CHECKS
//----------------
- private static void checkMBeanPermission(String classname,
+ private static void checkMBeanPermission(String serverName,
+ String classname,
String member,
ObjectName objectName,
String actions)
throws SecurityException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
- Permission perm = new MBeanPermission(classname,
+ Permission perm = new MBeanPermission(serverName,
+ classname,
member,
objectName,
actions);
--- a/src/share/classes/com/sun/jmx/mbeanserver/MBeanIntrospector.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/mbeanserver/MBeanIntrospector.java Tue Oct 07 13:48:49 2008 -0400
@@ -623,7 +623,7 @@ abstract class MBeanIntrospector<M> {
}
private static MBeanConstructorInfo[] findConstructors(Class<?> c) {
- Constructor[] cons = c.getConstructors();
+ Constructor<?>[] cons = c.getConstructors();
MBeanConstructorInfo[] mbc = new MBeanConstructorInfo[cons.length];
for (int i = 0; i < cons.length; i++) {
String descr = "Public constructor of the MBean";
--- a/src/share/classes/com/sun/jmx/mbeanserver/MXBeanLookup.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/mbeanserver/MXBeanLookup.java Tue Oct 07 13:48:49 2008 -0400
@@ -224,7 +224,7 @@ public abstract class MXBeanLookup {
throws InvalidObjectException {
String domain = prefix + name.getDomain();
try {
- name = switchDomain(domain, name);
+ name = name.withDomain(domain);
} catch (MalformedObjectNameException e) {
throw EnvHelp.initCause(
new InvalidObjectException(e.getMessage()), e);
@@ -242,7 +242,7 @@ public abstract class MXBeanLookup {
"Proxy's name does not start with " + prefix + ": " + name);
}
try {
- name = switchDomain(domain.substring(prefix.length()), name);
+ name = name.withDomain(domain.substring(prefix.length()));
} catch (MalformedObjectNameException e) {
throw EnvHelp.initCause(new OpenDataException(e.getMessage()), e);
}
@@ -269,14 +269,6 @@ public abstract class MXBeanLookup {
currentLookup.set(lookup);
}
- // Method temporarily added until we have ObjectName.switchDomain in the
- // public API. Note that this method DOES NOT PRESERVE the order of
- // keys in the ObjectName so it must not be used in the final release.
- static ObjectName switchDomain(String domain, ObjectName name)
- throws MalformedObjectNameException {
- return new ObjectName(domain, name.getKeyPropertyList());
- }
-
private static final ThreadLocal<MXBeanLookup> currentLookup =
new ThreadLocal<MXBeanLookup>();
--- a/src/share/classes/com/sun/jmx/mbeanserver/Repository.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/mbeanserver/Repository.java Tue Oct 07 13:48:49 2008 -0400
@@ -45,7 +45,6 @@ import javax.management.RuntimeOperation
import javax.management.RuntimeOperationsException;
/**
- * The RepositorySupport implements the Repository interface.
* This repository does not support persistency.
*
* @since 1.5
@@ -197,9 +196,9 @@ public class Repository {
if (isPropertyValuePattern &&
pattern.isPropertyValuePattern(keys[i])) {
// wildmatch key property values
- final char[] val_pattern = values[i].toCharArray();
- final char[] val_string = v.toCharArray();
- if (wildmatch(val_string,val_pattern))
+ // values[i] is the pattern;
+ // v is the string
+ if (Util.wildmatch(v,values[i]))
continue;
else
return false;
@@ -236,86 +235,6 @@ public class Repository {
}
}
- /** Match a string against a shell-style pattern. The only pattern
- characters recognised are <code>?</code>, standing for any one
- character, and <code>*</code>, standing for any string of
- characters, including the empty string.
-
- @param str the string to match, as a character array.
- @param pat the pattern to match the string against, as a
- character array.
-
- @return true if and only if the string matches the pattern.
- */
- /* The algorithm is a classical one. We advance pointers in
- parallel through str and pat. If we encounter a star in pat,
- we remember its position and continue advancing. If at any
- stage we get a mismatch between str and pat, we look to see if
- there is a remembered star. If not, we fail. If so, we
- retreat pat to just past that star and str to the position
- after the last one we tried, and we let the match advance
- again.
-
- Even though there is only one remembered star position, the
- algorithm works when there are several stars in the pattern.
- When we encounter the second star, we forget the first one.
- This is OK, because if we get to the second star in A*B*C
- (where A etc are arbitrary strings), we have already seen AXB.
- We're therefore setting up a match of *C against the remainder
- of the string, which will match if that remainder looks like
- YC, so the whole string looks like AXBYC.
- */
- public static boolean wildmatch(char[] str, char[] pat) {
- int stri; // index in str
- int pati; // index in pat
- int starstri; // index for backtrack if "*" attempt fails
- int starpati; // index for backtrack if "*" attempt fails, +1
- final int strlen = str.length;
- final int patlen = pat.length;
-
- stri = pati = 0;
- starstri = starpati = -1;
-
- /* On each pass through this loop, we either advance pati,
- or we backtrack pati and advance starstri. Since starstri
- is only ever assigned from pati, the loop must terminate. */
- while (true) {
- if (pati < patlen) {
- final char patc = pat[pati];
- switch (patc) {
- case '?':
- if (stri == strlen)
- break;
- stri++;
- pati++;
- continue;
- case '*':
- pati++;
- starpati = pati;
- starstri = stri;
- continue;
- default:
- if (stri < strlen && str[stri] == patc) {
- stri++;
- pati++;
- continue;
- }
- break;
- }
- } else if (stri == strlen)
- return true;
-
- // Mismatched, can we backtrack to a "*"?
- if (starpati < 0 || starstri == strlen)
- return false;
-
- // Retry the match one position later in str
- pati = starpati;
- starstri++;
- stri = starstri;
- }
- }
-
private void addNewDomMoi(final DynamicMBean object,
final String dom,
final ObjectName name,
@@ -370,7 +289,7 @@ public class Repository {
if (name.isPattern()) return null;
// Extract the domain name.
- String dom= name.getDomain().intern();
+ String dom = name.getDomain().intern();
// Default domain case
if (dom.length() == 0) {
@@ -477,10 +396,10 @@ public class Repository {
// Set domain to default if domain is empty and not already set
if (dom.length() == 0)
- name = Util.newObjectName(domain + name.toString());
+ name = ObjectName.valueOf(domain + name.toString());
// Do we have default domain ?
- if (dom == domain) {
+ if (dom == domain) { // ES: OK (dom & domain are interned)
to_default_domain = true;
dom = domain;
} else {
@@ -652,10 +571,9 @@ public class Repository {
}
// Pattern matching in the domain name (*, ?)
- char[] dom2Match = name.getDomain().toCharArray();
+ final String dom2Match = name.getDomain();
for (String dom : domainTb.keySet()) {
- char[] theDom = dom.toCharArray();
- if (wildmatch(theDom, dom2Match)) {
+ if (Util.wildpathmatch(dom, dom2Match)) {
final Map<String,NamedObject> moiTb = domainTb.get(dom);
if (allNames)
result.addAll(moiTb.values());
@@ -726,7 +644,7 @@ public class Repository {
// need to reinstantiate a hashtable because of possible
// big buckets array size inside table, never cleared,
// thus the new !
- if (dom == domain)
+ if (dom == domain) // ES: OK dom and domain are interned.
domainTb.put(domain, new HashMap<String,NamedObject>());
}
--- a/src/share/classes/com/sun/jmx/mbeanserver/SunJmxMBeanServer.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/mbeanserver/SunJmxMBeanServer.java Tue Oct 07 13:48:49 2008 -0400
@@ -28,17 +28,16 @@ import javax.management.MBeanServer;
import javax.management.MBeanServer;
import javax.management.MBeanServerDelegate;
-import com.sun.jmx.interceptor.MBeanServerInterceptor;
/**
- * Extends the MBeanServer and MBeanServerInterceptor interface to
+ * Extends the MBeanServer interface to
* provide methods for getting the MetaData and MBeanServerInstantiator
* objects associated with an MBeanServer.
*
* @since 1.5
*/
public interface SunJmxMBeanServer
- extends MBeanServerInterceptor, MBeanServer {
+ extends MBeanServer {
/**
* Return the MBeanInstantiator associated to this MBeanServer.
@@ -68,7 +67,7 @@ public interface SunJmxMBeanServer
* are not enabled on this object.
* @see #interceptorsEnabled
**/
- public MBeanServerInterceptor getMBeanServerInterceptor();
+ public MBeanServer getMBeanServerInterceptor();
/**
* Set the MBeanServerInterceptor.
@@ -77,7 +76,7 @@ public interface SunJmxMBeanServer
* are not enabled on this object.
* @see #interceptorsEnabled
**/
- public void setMBeanServerInterceptor(MBeanServerInterceptor interceptor);
+ public void setMBeanServerInterceptor(MBeanServer interceptor);
/**
* <p>Return the MBeanServerDelegate representing the MBeanServer.
--- a/src/share/classes/com/sun/jmx/mbeanserver/Util.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/mbeanserver/Util.java Tue Oct 07 13:48:49 2008 -0400
@@ -25,6 +25,8 @@
package com.sun.jmx.mbeanserver;
+import com.sun.jmx.defaults.JmxProperties;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -42,11 +44,23 @@ import java.util.TreeMap;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.WeakHashMap;
+import java.util.logging.Level;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerDelegate;
+import javax.management.MBeanServerFactory;
import javax.management.MalformedObjectNameException;
+import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.loading.ClassLoaderRepository;
+import static javax.management.namespace.JMXNamespaces.NAMESPACE_SEPARATOR;
public class Util {
+ private final static int NAMESPACE_SEPARATOR_LENGTH =
+ NAMESPACE_SEPARATOR.length();
+ public final static char[] ILLEGAL_MBEANSERVER_NAME_CHARS=";:*?".
+ toCharArray();
+
+
static <K, V> Map<K, V> newMap() {
return new HashMap<K, V>();
}
@@ -94,14 +108,6 @@ public class Util {
static <E> List<E> newList(Collection<E> c) {
return new ArrayList<E>(c);
- }
-
- public static ObjectName newObjectName(String s) {
- try {
- return new ObjectName(s);
- } catch (MalformedObjectNameException e) {
- throw new IllegalArgumentException(e);
- }
}
/* This method can be used by code that is deliberately violating the
@@ -145,6 +151,270 @@ public class Util {
return hash;
}
+ /** Match a part of a string against a shell-style pattern.
+ The only pattern characters recognized are <code>?</code>,
+ standing for any one character,
+ and <code>*</code>, standing for any string of
+ characters, including the empty string. For instance,
+ {@code wildmatch("sandwich","sa?d*ch",1,4,1,4)} will match
+ {@code "and"} against {@code "a?d"}.
+
+ @param str the string containing the sequence to match.
+ @param pat a string containing a pattern to match the sub string
+ against.
+ @param stri the index in the string at which matching should begin.
+ @param strend the index in the string at which the matching should
+ end.
+ @param pati the index in the pattern at which matching should begin.
+ @param patend the index in the pattern at which the matching should
+ end.
+
+ @return true if and only if the string matches the pattern.
+ */
+ /* The algorithm is a classical one. We advance pointers in
+ parallel through str and pat. If we encounter a star in pat,
+ we remember its position and continue advancing. If at any
+ stage we get a mismatch between str and pat, we look to see if
+ there is a remembered star. If not, we fail. If so, we
+ retreat pat to just past that star and str to the position
+ after the last one we tried, and we let the match advance
+ again.
+
+ Even though there is only one remembered star position, the
+ algorithm works when there are several stars in the pattern.
+ When we encounter the second star, we forget the first one.
+ This is OK, because if we get to the second star in A*B*C
+ (where A etc are arbitrary strings), we have already seen AXB.
+ We're therefore setting up a match of *C against the remainder
+ of the string, which will match if that remainder looks like
+ YC, so the whole string looks like AXBYC.
+ */
+ private static boolean wildmatch(final String str, final String pat,
+ int stri, final int strend, int pati, final int patend) {
+
+ // System.out.println("matching "+pat.substring(pati,patend)+
+ // " against "+str.substring(stri, strend));
+ int starstri; // index for backtrack if "*" attempt fails
+ int starpati; // index for backtrack if "*" attempt fails, +1
+
+ starstri = starpati = -1;
+
+ /* On each pass through this loop, we either advance pati,
+ or we backtrack pati and advance starstri. Since starstri
+ is only ever assigned from pati, the loop must terminate. */
+ while (true) {
+ if (pati < patend) {
+ final char patc = pat.charAt(pati);
+ switch (patc) {
+ case '?':
+ if (stri == strend)
+ break;
+ stri++;
+ pati++;
+ continue;
+ case '*':
+ pati++;
+ starpati = pati;
+ starstri = stri;
+ continue;
+ default:
+ if (stri < strend && str.charAt(stri) == patc) {
+ stri++;
+ pati++;
+ continue;
+ }
+ break;
+ }
+ } else if (stri == strend)
+ return true;
+
+ // Mismatched, can we backtrack to a "*"?
+ if (starpati < 0 || starstri == strend)
+ return false;
+
+ // Retry the match one position later in str
+ pati = starpati;
+ starstri++;
+ stri = starstri;
+ }
+ }
+
+ /** Match a string against a shell-style pattern. The only pattern
+ characters recognized are <code>?</code>, standing for any one
+ character, and <code>*</code>, standing for any string of
+ characters, including the empty string.
+
+ @param str the string to match.
+ @param pat the pattern to match the string against.
+
+ @return true if and only if the string matches the pattern.
+ */
+ public static boolean wildmatch(String str, String pat) {
+ return wildmatch(str,pat,0,str.length(),0,pat.length());
+ }
+
+ /**
+ * Matches a string against a pattern, as a name space path.
+ * This is a special matching where * and ?? don't match //.
+ * The string is split in sub-strings separated by //, and the
+ * pattern is split in sub-patterns separated by //. Each sub-string
+ * is matched against its corresponding sub-pattern.
+ * so <elt-1>//<elt2>//...//<elt-n> matches <pat-1>//<pat-2>//...//<pat-q>
+ * only if n==q and for ( i = 1 => n) elt-i matches pat-i.
+ *
+ * In addition, if we encounter a pattern element which is exactly
+ * **, it can match any number of path-elements - but it must match at
+ * least one element.
+ * When we encounter such a meta-wildcard, we remember its position
+ * and the position in the string path, and we advance both the pattern
+ * and the string. Later, if we encounter a mismatch in pattern & string,
+ * we rewind the position in pattern to just after the meta-wildcard,
+ * and we backtrack the string to i+1 element after the position
+ * we had when we first encountered the meta-wildcard, i being the
+ * position when we last backtracked the string.
+ *
+ * The backtracking logic is an adaptation of the logic in wildmatch
+ * above.
+ * See test/javax/mangement/ObjectName/ApplyWildcardTest.java
+ *
+ * Note: this thing is called 'wild' - and that's for a reason ;-)
+ **/
+ public static boolean wildpathmatch(String str, String pat) {
+ final int strlen = str.length();
+ final int patlen = pat.length();
+ int stri = 0;
+ int pati = 0;
+
+ int starstri; // index for backtrack if "**" attempt fails
+ int starpati; // index for backtrack if "**" attempt fails
+
+ starstri = starpati = -1;
+
+ while (true) {
+ // System.out.println("pati="+pati+", stri="+stri);
+ final int strend = str.indexOf(NAMESPACE_SEPARATOR, stri);
+ final int patend = pat.indexOf(NAMESPACE_SEPARATOR, pati);
+
+ // no // remaining in either string or pattern: simple wildmatch
+ // until end of string.
+ if (strend == -1 && patend == -1) {
+ // System.out.println("last sub pattern, last sub element...");
+ // System.out.println("wildmatch("+str.substring(stri,strlen)+
+ // ","+pat.substring(pati,patlen)+")");
+ return wildmatch(str,pat,stri,strlen,pati,patlen);
+ }
+
+ // no // remaining in string, but at least one remaining in
+ // pattern
+ // => no match
+ if (strend == -1) {
+ // System.out.println("pattern has more // than string...");
+ return false;
+ }
+
+ // strend is != -1, but patend might.
+ // detect wildcard **
+ if (patend == pati+2 && pat.charAt(pati)=='*' &&
+ pat.charAt(pati+1)=='*') {
+ // if we reach here we know that neither strend nor patend are
+ // equals to -1.
+ stri = strend + NAMESPACE_SEPARATOR_LENGTH;
+ pati = patend + NAMESPACE_SEPARATOR_LENGTH;
+ starpati = pati; // position just after **// in pattern
+ starstri = stri; // we eat 1 element in string, and remember
+ // the position for backtracking and eating
+ // one more element if needed.
+ // System.out.println("starpati="+pati);
+ continue;
+ }
+
+ // This is a bit hacky: * can match // when // is at the end
+ // of the string, so we include the // delimiter in the pattern
+ // matching. Either we're in the middle of the path, so including
+ // // both at the end of the pattern and at the end of the string
+ // has no effect - match(*//,dfsd//) is equivalent to match(*,dfsd)
+ // or we're at the end of the pattern path, in which case
+ // including // at the end of the string will have the desired
+ // effect (provided that we detect the end of matching correctly,
+ // see further on).
+ //
+ final int endpat =
+ ((patend > -1)?patend+NAMESPACE_SEPARATOR_LENGTH:patlen);
+ final int endstr =
+ ((strend > -1)?strend+NAMESPACE_SEPARATOR_LENGTH:strlen);
+
+ // if we reach the end of the pattern, or if elt-i & pat-i
+ // don't match, we have a mismatch.
+
+ // Note: we know that strend != -1, therefore patend==-1
+ // indicates a mismatch unless pattern can match
+ // a // at the end, and strend+2=strlen.
+ // System.out.println("wildmatch("+str.substring(stri,endstr)+","+
+ // pat.substring(pati,endpat)+")");
+ if (!wildmatch(str,pat,stri,endstr,pati,endpat)) {
+
+ // System.out.println("nomatch");
+ // if we have a mismatch and didn't encounter any meta-wildcard,
+ // we return false. String & pattern don't match.
+ if (starpati < 0) return false;
+
+ // If we reach here, we had a meta-wildcard.
+ // We need to backtrack to the wildcard, and make it eat an
+ // additional string element.
+ //
+ stri = str.indexOf(NAMESPACE_SEPARATOR, starstri);
+ // System.out.println("eating one additional element? "+stri);
+
+ // If there's no more elements to eat, string and pattern
+ // don't match => return false.
+ if (stri == -1) return false;
+
+ // Backtrack to where we were when we last matched against
+ // the meta-wildcard, make it eat an additional path element,
+ // remember the new positions, and continue from there...
+ //
+ stri = stri + NAMESPACE_SEPARATOR_LENGTH;
+ starstri = stri;
+ pati = starpati;
+ // System.out.println("skiping to stri="+stri);
+ continue;
+ }
+
+ // Here we know that strend > -1 but we can have patend == -1.
+ //
+ // So if we reach here, we know pat-i+//? has matched
+ // elt-i+//
+ //
+ // If patend==-1, we know that there was no delimiter
+ // at the end of the pattern, that we are at the last pattern,
+ // and therefore that pat-i has matched elt-i+//
+ //
+ // In that case we can consider that we have a match only if
+ // elt-i is also the last path element in the string, which is
+ // equivalent to saying that strend+2==strlen.
+ //
+ if (patend == -1 && starpati == -1)
+ return (strend+NAMESPACE_SEPARATOR_LENGTH==strlen);
+
+ // patend != -1, or starpati > -1 so there remains something
+ // to match.
+
+ // go to next pair: elt-(i+1) pat-(i+1);
+ stri = strend + NAMESPACE_SEPARATOR_LENGTH;
+ pati = (patend==-1)?pati:(patend + NAMESPACE_SEPARATOR_LENGTH);
+ }
+ }
+
+ /**
+ * Returns true if the ObjectName's {@code domain} is selected by the
+ * given {@code pattern}.
+ */
+ public static boolean isDomainSelected(String domain, String pattern) {
+ if (domain == null || pattern == null)
+ throw new IllegalArgumentException("null");
+ return Util.wildpathmatch(domain,pattern);
+ }
+
/**
* Filters a set of ObjectName according to a given pattern.
*
@@ -167,6 +437,34 @@ public class Util {
return res;
}
+
+ /**
+ * Filters a set of ObjectInstance according to a given pattern.
+ *
+ * @param pattern the pattern that the returned names must match.
+ * @param all the set of instances to filter.
+ * @return a set of ObjectInstance from which non matching instances
+ * have been removed.
+ */
+ public static Set<ObjectInstance>
+ filterMatchingInstances(ObjectName pattern,
+ Set<ObjectInstance> all) {
+ // If no pattern, just return all names
+ if (pattern == null
+ || all.isEmpty()
+ || ObjectName.WILDCARD.equals(pattern))
+ return all;
+
+ // If there's a pattern, do the matching.
+ final Set<ObjectInstance> res = equivalentEmptySet(all);
+ for (ObjectInstance n : all) {
+ if (n == null) continue;
+ if (pattern.apply(n.getObjectName()))
+ res.add(n);
+ }
+ return res;
+ }
+
/**
* An abstract ClassLoaderRepository that contains a single class loader.
**/
@@ -214,6 +512,160 @@ public class Util {
public static ClassLoaderRepository getSingleClassLoaderRepository(
final ClassLoader loader) {
return new SingleClassLoaderRepository(loader);
+ }
+
+ /**
+ * Returns the name of the given MBeanServer that should be put in a
+ * permission you need.
+ * This corresponds to the
+ * {@code *[;mbeanServerName=<mbeanServerName>[;*]]} property
+ * embedded in the MBeanServerId attribute of the
+ * server's {@link MBeanServerDelegate}.
+ *
+ * @param server The MBean server
+ * @return the name of the MBeanServer, or "*" if the name couldn't be
+ * obtained, or {@value MBeanServerFactory#DEFAULT_MBEANSERVER_NAME}
+ * if there was no name.
+ */
+ public static String getMBeanServerSecurityName(MBeanServer server) {
+ final String notfound = "*";
+ try {
+ final String mbeanServerId = (String)
+ server.getAttribute(MBeanServerDelegate.DELEGATE_NAME,
+ "MBeanServerId");
+ final String found = extractMBeanServerName(mbeanServerId);
+ if (found.length()==0)
+ return MBeanServerFactory.DEFAULT_MBEANSERVER_NAME;
+ return found;
+ } catch (Exception x) {
+ logshort("Failed to retrieve MBeanServerName for server, " +
+ "using \"*\"",x);
+ return notfound;
+ }
+ }
+
+ /**
+ * Returns the name of the MBeanServer embedded in the given
+ * mbeanServerId. If the given mbeanServerId doesn't contain any name,
+ * an empty String is returned.
+ * The MBeanServerId is expected to be of the form:
+ * {@code *[;mbeanServerName=<mbeanServerName>[;*]]}
+ * @param mbeanServerId The MBean server ID
+ * @return the name of the MBeanServer if found, or "" if the name was
+ * not present in the mbeanServerId.
+ */
+ public static String extractMBeanServerName(String mbeanServerId) {
+ if (mbeanServerId==null) return "";
+ final String beginMarker=";mbeanServerName=";
+ final String endMarker=";";
+ final int found = mbeanServerId.indexOf(beginMarker);
+ if (found < 0) return "";
+ final int start = found + beginMarker.length();
+ final int stop = mbeanServerId.indexOf(endMarker, start);
+ return mbeanServerId.substring(start,
+ (stop < 0 ? mbeanServerId.length() : stop));
+ }
+
+ /**
+ * Insert the given mbeanServerName into the given mbeanServerId.
+ * If mbeanServerName is null, empty, or equals to "-", the returned
+ * mbeanServerId will not contain any mbeanServerName.
+ * @param mbeanServerId The mbeanServerId in which to insert
+ * mbeanServerName
+ * @param mbeanServerName The mbeanServerName
+ * @return an mbeanServerId containing the given mbeanServerName
+ * @throws IllegalArgumentException if mbeanServerId already contains
+ * a different name, or if the given mbeanServerName is not valid.
+ */
+ public static String insertMBeanServerName(String mbeanServerId,
+ String mbeanServerName) {
+ final String found = extractMBeanServerName(mbeanServerId);
+ if (found.length() > 0 &&
+ found.equals(checkServerName(mbeanServerName)))
+ return mbeanServerId;
+ if (found.length() > 0 && !isMBeanServerNameUndefined(found))
+ throw new IllegalArgumentException(
+ "MBeanServerName already defined");
+ if (isMBeanServerNameUndefined(mbeanServerName))
+ return mbeanServerId;
+ final String beginMarker=";mbeanServerName=";
+ return mbeanServerId+beginMarker+checkServerName(mbeanServerName);
+ }
+
+ /**
+ * Returns true if the given mbeanServerName corresponds to an
+ * undefined MBeanServerName.
+ * The mbeanServerName is considered undefined if it is one of:
+ * {@code null} or {@value MBeanServerFactory#DEFAULT_MBEANSERVER_NAME}.
+ * @param mbeanServerName The mbeanServerName, as returned by
+ * {@link #extractMBeanServerName(String)}.
+ * @return true if the given name corresponds to one of the forms that
+ * denotes an undefined MBeanServerName.
+ */
+ public static boolean isMBeanServerNameUndefined(String mbeanServerName) {
+ return mbeanServerName == null ||
+ MBeanServerFactory.DEFAULT_MBEANSERVER_NAME.equals(mbeanServerName);
+ }
+ /**
+ * Check that the provided mbeanServername is syntactically valid.
+ * @param mbeanServerName An mbeanServerName, or {@code null}.
+ * @return mbeanServerName, or {@value
+ * MBeanServerFactory#DEFAULT_MBEANSERVER_NAME} if {@code mbeanServerName}
+ * is {@code null}.
+ * @throws IllegalArgumentException if mbeanServerName contains illegal
+ * characters, or is empty, or is {@code "-"}.
+ * Illegal characters are {@link #ILLEGAL_MBEANSERVER_NAME_CHARS}.
+ */
+ public static String checkServerName(String mbeanServerName) {
+ if ("".equals(mbeanServerName))
+ throw new IllegalArgumentException(
+ "\"\" is not a valid MBean server name");
+ if ("-".equals(mbeanServerName))
+ throw new IllegalArgumentException(
+ "\"-\" is not a valid MBean server name");
+ if (isMBeanServerNameUndefined(mbeanServerName))
+ return MBeanServerFactory.DEFAULT_MBEANSERVER_NAME;
+ for (char c : ILLEGAL_MBEANSERVER_NAME_CHARS) {
+ if (mbeanServerName.indexOf(c) >= 0)
+ throw new IllegalArgumentException(
+ "invalid character in MBeanServer name: "+c);
+ }
+ return mbeanServerName;
+ }
+
+ /**
+ * Get the MBeanServer name that should be put in a permission you need.
+ *
+ * @param delegate The MBeanServerDelegate
+ * @return The MBeanServer name - or {@value
+ * MBeanServerFactory#DEFAULT_MBEANSERVER_NAME} if there was no name.
+ */
+ public static String getMBeanServerSecurityName(
+ MBeanServerDelegate delegate) {
+ try {
+ final String serverName = delegate.getMBeanServerName();
+ if (isMBeanServerNameUndefined(serverName))
+ return MBeanServerFactory.DEFAULT_MBEANSERVER_NAME;
+ return serverName;
+ } catch (Exception x) {
+ logshort("Failed to retrieve MBeanServerName from delegate, " +
+ "using \"*\"",x);
+ return "*";
+ }
+ }
+
+ // Log the exception and its causes without logging the stack trace.
+ // Use with care - it is usually preferable to log the whole stack trace!
+ // We don't want to log the whole stack trace here: logshort() is
+ // called in those cases where the exception might not be abnormal.
+ private static void logshort(String msg, Throwable t) {
+ if (JmxProperties.MISC_LOGGER.isLoggable(Level.FINE)) {
+ StringBuilder toprint = new StringBuilder(msg);
+ do {
+ toprint.append("\nCaused By: ").append(String.valueOf(t));
+ } while ((t=t.getCause())!=null);
+ JmxProperties.MISC_LOGGER.fine(toprint.toString());
+ }
}
public static <T> Set<T> cloneSet(Set<T> set) {
@@ -232,10 +684,19 @@ public class Util {
@SuppressWarnings("unchecked")
SortedSet<T> sset = (SortedSet<T>) set;
set = new TreeSet<T>(sset.comparator());
- } else if (set != null) {
- set = new HashSet<T>(set.size());
} else
set = new HashSet<T>();
return set;
}
+
+ // This exception is used when wrapping a class that throws IOException
+ // in a class that doesn't.
+ // The typical example for this are JMXNamespaces, when the sub
+ // MBeanServer can be remote.
+ //
+ public static RuntimeException newRuntimeIOException(IOException io) {
+ final String msg = "Communication failed with underlying resource: "+
+ io.getMessage();
+ return new RuntimeException(msg,io);
+ }
}
--- a/src/share/classes/com/sun/jmx/remote/internal/ClientCommunicatorAdmin.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/remote/internal/ClientCommunicatorAdmin.java Tue Oct 07 13:48:49 2008 -0400
@@ -32,13 +32,15 @@ import com.sun.jmx.remote.util.EnvHelp;
import com.sun.jmx.remote.util.EnvHelp;
public abstract class ClientCommunicatorAdmin {
+ private static volatile long threadNo = 1;
+
public ClientCommunicatorAdmin(long period) {
this.period = period;
if (period > 0) {
checker = new Checker();
- Thread t = new Thread(checker);
+ Thread t = new Thread(checker, "JMX client heartbeat " + ++threadNo);
t.setDaemon(true);
t.start();
} else
--- a/src/share/classes/com/sun/jmx/remote/internal/ServerNotifForwarder.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/remote/internal/ServerNotifForwarder.java Tue Oct 07 13:48:49 2008 -0400
@@ -57,6 +57,7 @@ import javax.security.auth.Subject;
public class ServerNotifForwarder {
+
public ServerNotifForwarder(MBeanServer mbeanServer,
Map env,
NotificationBuffer notifBuffer,
@@ -85,7 +86,8 @@ public class ServerNotifForwarder {
// Explicitly check MBeanPermission for addNotificationListener
//
- checkMBeanPermission(name, "addNotificationListener");
+ checkMBeanPermission(getMBeanServerName(),
+ mbeanServer, name, "addNotificationListener");
if (notificationAccessController != null) {
notificationAccessController.addNotificationListener(
connectionId, name, getSubject());
@@ -155,7 +157,8 @@ public class ServerNotifForwarder {
// Explicitly check MBeanPermission for removeNotificationListener
//
- checkMBeanPermission(name, "removeNotificationListener");
+ checkMBeanPermission(getMBeanServerName(),
+ mbeanServer, name, "removeNotificationListener");
if (notificationAccessController != null) {
notificationAccessController.removeNotificationListener(
connectionId, name, getSubject());
@@ -330,13 +333,7 @@ public class ServerNotifForwarder {
* Explicitly check the MBeanPermission for
* the current access control context.
*/
- private void checkMBeanPermission(final ObjectName name,
- final String actions)
- throws InstanceNotFoundException, SecurityException {
- checkMBeanPermission(mbeanServer, name, actions);
- }
-
- public static void checkMBeanPermission(
+ public static void checkMBeanPermission(String serverName,
final MBeanServer mbs, final ObjectName name, final String actions)
throws InstanceNotFoundException, SecurityException {
SecurityManager sm = System.getSecurityManager();
@@ -355,7 +352,9 @@ public class ServerNotifForwarder {
throw (InstanceNotFoundException) extractException(e);
}
String classname = oi.getClassName();
- MBeanPermission perm = new MBeanPermission(classname,
+ MBeanPermission perm = new MBeanPermission(
+ serverName,
+ classname,
null,
name,
actions);
@@ -370,8 +369,8 @@ public class ServerNotifForwarder {
TargetedNotification tn) {
try {
if (checkNotificationEmission) {
- checkMBeanPermission(
- name, "addNotificationListener");
+ checkMBeanPermission(getMBeanServerName(),
+ mbeanServer, name, "addNotificationListener");
}
if (notificationAccessController != null) {
notificationAccessController.fetchNotification(
@@ -433,11 +432,27 @@ public class ServerNotifForwarder {
}
}
+ private String getMBeanServerName() {
+ if (mbeanServerName != null) return mbeanServerName;
+ else return (mbeanServerName = getMBeanServerName(mbeanServer));
+ }
+
+ private static String getMBeanServerName(final MBeanServer server) {
+ final PrivilegedAction<String> action = new PrivilegedAction<String>() {
+ public String run() {
+ return Util.getMBeanServerSecurityName(server);
+ }
+ };
+ return AccessController.doPrivileged(action);
+ }
+
+
//------------------
// PRIVATE VARIABLES
//------------------
private MBeanServer mbeanServer;
+ private volatile String mbeanServerName;
private final String connectionId;
--- a/src/share/classes/com/sun/jmx/remote/util/EventClientConnection.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/jmx/remote/util/EventClientConnection.java Tue Oct 07 13:48:49 2008 -0400
@@ -25,6 +25,7 @@
package com.sun.jmx.remote.util;
+import com.sun.jmx.defaults.JmxProperties;
import com.sun.jmx.event.EventClientFactory;
import java.lang.reflect.InvocationHandler;
@@ -45,6 +46,7 @@ import javax.management.ObjectName;
import javax.management.ObjectName;
import javax.management.event.EventClient;
import javax.management.event.EventClientDelegate;
+import javax.management.namespace.JMXNamespaces;
/**
* Class EventClientConnection - a {@link Proxy} that wraps an
@@ -63,12 +65,10 @@ public class EventClientConnection imple
/**
* A logger for this class.
**/
- private static final Logger LOG =
- Logger.getLogger(EventClientConnection.class.getName());
-
- private static final String NAMESPACE_SEPARATOR = "//";
+ private static final Logger LOG = JmxProperties.NOTIFICATION_LOGGER;
+
private static final int NAMESPACE_SEPARATOR_LENGTH =
- NAMESPACE_SEPARATOR.length();
+ JMXNamespaces.NAMESPACE_SEPARATOR.length();
/**
* Creates a new {@code EventClientConnection}.
@@ -212,9 +212,9 @@ public class EventClientConnection imple
}
final ObjectName mbean = (ObjectName) args[0];
- final EventClient client = getEventClient();
-
- // Fails if client is null AND the MBean we try to listen to is
+ final EventClient evtClient = getEventClient();
+
+ // Fails if evtClient is null AND the MBean we try to listen to is
// in a subnamespace. We fail here because we know this will not
// work.
//
@@ -222,15 +222,15 @@ public class EventClientConnection imple
// earlier agent (JDK 1.6 or earlier), then the EventClient will
// be null (we can't use the event service with earlier JDKs).
//
- // In principle a null client indicates that the remote VM is of
+ // In principle a null evtClient indicates that the remote VM is of
// an earlier version, in which case it shouldn't contain any namespace.
//
- // So having a null client AND an MBean contained in a namespace is
+ // So having a null evtClient AND an MBean contained in a namespace is
// clearly an error case.
//
- if (client == null) {
+ if (evtClient == null) {
final String domain = mbean.getDomain();
- final int index = domain.indexOf(NAMESPACE_SEPARATOR);
+ final int index = domain.indexOf(JMXNamespaces.NAMESPACE_SEPARATOR);
if (index > -1 && index <
(domain.length()-NAMESPACE_SEPARATOR_LENGTH)) {
throw new UnsupportedOperationException(method.getName()+
@@ -256,9 +256,9 @@ public class EventClientConnection imple
final NotificationFilter filter = (NotificationFilter) args[2];
final Object handback = args[3];
- if (client != null) {
+ if (evtClient != null) {
// general case
- client.addNotificationListener(mbean,listener,filter,handback);
+ evtClient.addNotificationListener(mbean,listener,filter,handback);
} else {
// deprecated case. Only works for mbean in local namespace.
connection.addNotificationListener(mbean,listener,filter,
@@ -274,9 +274,9 @@ public class EventClientConnection imple
switch (nargs) {
case 2:
- if (client != null) {
+ if (evtClient != null) {
// general case
- client.removeNotificationListener(mbean,listener);
+ evtClient.removeNotificationListener(mbean,listener);
} else {
// deprecated case. Only works for mbean in local namespace.
connection.removeNotificationListener(mbean, listener);
@@ -286,8 +286,8 @@ public class EventClientConnection imple
case 4:
NotificationFilter filter = (NotificationFilter) args[2];
Object handback = args[3];
- if (client != null) {
- client.removeNotificationListener(mbean,
+ if (evtClient != null) {
+ evtClient.removeNotificationListener(mbean,
listener,
filter,
handback);
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/Init.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/org/apache/xml/internal/security/Init.java Tue Oct 07 13:48:49 2008 -0400
@@ -20,12 +20,9 @@
*/
package com.sun.org.apache.xml.internal.security;
-
-
import java.io.InputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
-
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -51,7 +48,7 @@ import org.w3c.dom.Node;
* done by calling {@link Init#init} which should be done in any static block
* of the files of this library. We ensure that this call is only executed once.
*
- * @author $Author: raul $
+ * @author $Author: mullan $
*/
public final class Init {
@@ -113,20 +110,19 @@ public final class Init {
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
-
// We don't allow users to override the Apache XML Security
// configuration in the JRE. Users should use the standard security
// provider mechanism instead if implementing their own
// transform or canonicalization algorithms.
- // String cfile = System.getProperty("com.sun.org.apache.xml.internal.security.resource.config");
- // InputStream is =
- // Class.forName("com.sun.org.apache.xml.internal.security.Init")
- // .getResourceAsStream(cfile != null ? cfile : "resource/config.xml");
+ // InputStream is = Class.forName("com.sun.org.apache.xml.internal.security.Init").getResourceAsStream("resource/config.xml");
InputStream is = (InputStream) AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
+// String cfile = System.getProperty
+// ("com.sun.org.apache.xml.internal.security.resource.config");
return getClass().getResourceAsStream
- ("resource/config.xml");
+// (cfile != null ? cfile : "resource/config.xml");
+ ("resource/config.xml");
}
});
@@ -167,7 +163,7 @@ public final class Init {
//
// if (tag.equals("ResourceBundles")){
// XX_configure_i18n_start = System.currentTimeMillis();
-// Element resource=(Element)el;
+// Element resource=(Element)el;
// /* configure internationalization */
// Attr langAttr = resource.getAttributeNode("defaultLanguageCode");
// Attr countryAttr = resource.getAttributeNode("defaultCountryCode");
@@ -202,11 +198,11 @@ public final class Init {
if (currMeth.getDeclaringClass().getName()
.equals(JAVACLASS)) {
- log.log(java.util.logging.Level.FINE, currMeth.getDeclaringClass().toString());
+ log.log(java.util.logging.Level.FINE, currMeth.getDe claringClass().toString());
}
}*/
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Canonicalizer.register(" + URI + ", "
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Canonicalizer.register(" + URI + ", "
+ JAVACLASS + ")");
Canonicalizer.register(URI, JAVACLASS);
} catch (ClassNotFoundException e) {
@@ -233,9 +229,8 @@ public final class Init {
"JAVACLASS");
try {
Class.forName(JAVACLASS);
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Transform.register(" + URI + ", " + JAVACLASS
- + ")");
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Transform.register(" + URI + ", " + JAVACLASS + ")");
Transform.register(URI, JAVACLASS);
} catch (ClassNotFoundException e) {
Object exArgs[] = { URI, JAVACLASS };
@@ -284,12 +279,11 @@ public final class Init {
//
// if (currMeth.getDeclaringClass().getName()
// .equals(JAVACLASS)) {
-// log.log(java.util.logging.Level.FINE, currMeth.getDeclaringClass().toString());
+// log.log(java.util.logging.Level.FINE, currMeth.getDe claringClass().toString());
// }
// }
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "SignatureAlgorithm.register(" + URI + ", "
- + JAVACLASS + ")");
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "SignatureAlgorithm.register(" + URI + ", " + JAVACLASS + ")");
SignatureAlgorithm.register(URI, JAVACLASS);
} catch (ClassNotFoundException e) {
Object exArgs[] = { URI, JAVACLASS };
@@ -320,13 +314,11 @@ public final class Init {
"DESCRIPTION");
if ((Description != null) && (Description.length() > 0)) {
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS + ": "
- + Description);
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS + ": " + Description);
} else {
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS
- + ": For unknown purposes");
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS + ": For unknown purposes");
}
try {
ResourceResolver.register(JAVACLASS);
@@ -359,13 +351,11 @@ public final class Init {
"DESCRIPTION");
if ((Description != null) && (Description.length() > 0)) {
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS + ": "
- + Description);
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS + ": " + Description);
} else {
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS
- + ": For unknown purposes");
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS + ": For unknown purposes");
}
KeyResolver.register(JAVACLASS);
@@ -376,8 +366,8 @@ public final class Init {
if (tag.equals("PrefixMappings")){
XX_configure_reg_prefixes_start = System.currentTimeMillis();
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Now I try to bind prefixes:");
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Now I try to bind prefixes:");
Element[] nl = XMLUtils.selectNodes(el.getFirstChild(), CONF_NS,"PrefixMapping");
@@ -386,8 +376,8 @@ public final class Init {
"namespace");
String prefix = nl[i].getAttributeNS(null,
"prefix");
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Now I try to bind " + prefix + " to " + namespace);
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Now I try to bind " + prefix + " to " + namespace);
com.sun.org.apache.xml.internal.security.utils.ElementProxy
.setDefaultPrefix(namespace, prefix);
}
@@ -398,19 +388,19 @@ public final class Init {
long XX_init_end = System.currentTimeMillis();
//J-
- if (true) {
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "XX_init " + ((int)(XX_init_end - XX_init_start)) + " ms");
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_prng " + ((int)(XX_prng_end - XX_prng_start)) + " ms");
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_parsing " + ((int)(XX_parsing_end - XX_parsing_start)) + " ms");
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_i18n " + ((int)(XX_configure_i18n_end- XX_configure_i18n_start)) + " ms");
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_c14n " + ((int)(XX_configure_reg_c14n_end- XX_configure_reg_c14n_start)) + " ms");
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_jcemapper " + ((int)(XX_configure_reg_jcemapper_end- XX_configure_reg_jcemapper_start)) + " ms");
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_keyInfo " + ((int)(XX_configure_reg_keyInfo_end- XX_configure_reg_keyInfo_start)) + " ms");
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_keyResolver " + ((int)(XX_configure_reg_keyResolver_end- XX_configure_reg_keyResolver_start)) + " ms");
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_prefixes " + ((int)(XX_configure_reg_prefixes_end- XX_configure_reg_prefixes_start)) + " ms");
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_resourceresolver " + ((int)(XX_configure_reg_resourceresolver_end- XX_configure_reg_resourceresolver_start)) + " ms");
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_sigalgos " + ((int)(XX_configure_reg_sigalgos_end- XX_configure_reg_sigalgos_start)) + " ms");
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_transforms " + ((int)(XX_configure_reg_transforms_end- XX_configure_reg_transforms_start)) + " ms");
+ if (log.isLoggable(java.util.logging.Level.FINE)) {
+ log.log(java.util.logging.Level.FINE, "XX_init " + ((int)(XX_init_end - XX_init_start)) + " ms");
+ log.log(java.util.logging.Level.FINE, " XX_prng " + ((int)(XX_prng_end - XX_prng_start)) + " ms");
+ log.log(java.util.logging.Level.FINE, " XX_parsing " + ((int)(XX_parsing_end - XX_parsing_start)) + " ms");
+ log.log(java.util.logging.Level.FINE, " XX_configure_i18n " + ((int)(XX_configure_i18n_end- XX_configure_i18n_start)) + " ms");
+ log.log(java.util.logging.Level.FINE, " XX_configure_reg_c14n " + ((int)(XX_configure_reg_c14n_end- XX_configure_reg_c14n_start)) + " ms");
+ log.log(java.util.logging.Level.FINE, " XX_configure_reg_jcemapper " + ((int)(XX_configure_reg_jcemapper_end- XX_configure_reg_jcemapper_start)) + " ms");
+ log.log(java.util.logging.Level.FINE, " XX_configure_reg_keyInfo " + ((int)(XX_configure_reg_keyInfo_end- XX_configure_reg_keyInfo_start)) + " ms");
+ log.log(java.util.logging.Level.FINE, " XX_configure_reg_keyResolver " + ((int)(XX_configure_reg_keyResolver_end- XX_configure_reg_keyResolver_start)) + " ms");
+ log.log(java.util.logging.Level.FINE, " XX_configure_reg_prefixes " + ((int)(XX_configure_reg_prefixes_end- XX_configure_reg_prefixes_start)) + " ms");
+ log.log(java.util.logging.Level.FINE, " XX_configure_reg_resourceresolver " + ((int)(XX_configure_reg_resourceresolver_end- XX_configure_reg_resourceresolver_start)) + " ms");
+ log.log(java.util.logging.Level.FINE, " XX_configure_reg_sigalgos " + ((int)(XX_configure_reg_sigalgos_end- XX_configure_reg_sigalgos_start)) + " ms");
+ log.log(java.util.logging.Level.FINE, " XX_configure_reg_transforms " + ((int)(XX_configure_reg_transforms_end- XX_configure_reg_transforms_start)) + " ms");
}
} catch (Exception e) {
log.log(java.util.logging.Level.SEVERE, "Bad: ", e);
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/Algorithm.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/Algorithm.java Tue Oct 07 13:48:49 2008 -0400
@@ -24,7 +24,7 @@ package com.sun.org.apache.xml.internal.
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Constants;
-import com.sun.org.apache.xml.internal.security.utils.ElementProxy;
+import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -33,11 +33,7 @@ import org.w3c.dom.Element;
* The Algorithm class which stores the Algorithm URI as a string.
*
*/
-public abstract class Algorithm extends ElementProxy {
-
- /** {@link java.util.logging} logging facility */
- static java.util.logging.Logger log =
- java.util.logging.Logger.getLogger(Algorithm.class.getName());
+public abstract class Algorithm extends SignatureElementProxy {
/**
*
@@ -79,7 +75,7 @@ public abstract class Algorithm extends
*/
protected void setAlgorithmURI(String algorithmURI) {
- if ((this._state == MODE_CREATE) && (algorithmURI != null)) {
+ if ( (algorithmURI != null)) {
this._constructionElement.setAttributeNS(null, Constants._ATT_ALGORITHM,
algorithmURI);
}
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/JCEMapper.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/JCEMapper.java Tue Oct 07 13:48:49 2008 -0400
@@ -35,7 +35,7 @@ import org.w3c.dom.Element;
/**
* This class maps algorithm identifier URIs to JAVA JCE class names.
*
- * @author $Author: raul $
+ * @author $Author: mullan $
*/
public class JCEMapper {
@@ -45,9 +45,9 @@ public class JCEMapper {
- private static Map uriToJCEName = new HashMap();
+ private static Map uriToJCEName;
- private static Map algorithmsMap = new HashMap();
+ private static Map algorithmsMap;
private static String providerName = null;
/**
@@ -63,6 +63,8 @@ public class JCEMapper {
static void loadAlgorithms( Element algorithmsEl) {
Element[] algorithms = XMLUtils.selectNodes(algorithmsEl.getFirstChild(),Init.CONF_NS,"Algorithm");
+ uriToJCEName = new HashMap( algorithms.length * 2);
+ algorithmsMap = new HashMap( algorithms.length * 2);
for (int i = 0 ;i < algorithms.length ;i ++) {
Element el = algorithms[i];
String id = el.getAttribute("URI");
@@ -70,6 +72,7 @@ public class JCEMapper {
uriToJCEName.put(id, jceName);
algorithmsMap.put(id, new Algorithm(el));
}
+
}
static Algorithm getAlgorithmMapping(String algoURI) {
@@ -84,8 +87,8 @@ public class JCEMapper {
*
*/
public static String translateURItoJCEID(String AlgorithmURI) {
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Request for URI " + AlgorithmURI);
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Request for URI " + AlgorithmURI);
String jceName = (String) uriToJCEName.get(AlgorithmURI);
return jceName;
@@ -100,8 +103,8 @@ public class JCEMapper {
*
*/
public static String getAlgorithmClassFromURI(String AlgorithmURI) {
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Request for URI " + AlgorithmURI);
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Request for URI " + AlgorithmURI);
return ((Algorithm) algorithmsMap.get(AlgorithmURI)).algorithmClass;
}
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/MessageDigestAlgorithm.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/MessageDigestAlgorithm.java Tue Oct 07 13:48:49 2008 -0400
@@ -20,10 +20,10 @@
*/
package com.sun.org.apache.xml.internal.security.algorithms;
-
-
import java.security.MessageDigest;
import java.security.NoSuchProviderException;
+import java.util.HashMap;
+import java.util.Map;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import com.sun.org.apache.xml.internal.security.utils.Constants;
@@ -40,11 +40,6 @@ import org.w3c.dom.Document;
*
*/
public class MessageDigestAlgorithm extends Algorithm {
-
- /** {@link java.util.logging} logging facility */
- static java.util.logging.Logger log =
- java.util.logging.Logger.getLogger(
- MessageDigestAlgorithm.class.getName());
/** Message Digest - NOT RECOMMENDED MD5*/
public static final String ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5 = Constants.MoreAlgorithmsSpecNS + "md5";
@@ -76,6 +71,12 @@ public class MessageDigestAlgorithm exte
this.algorithm = messageDigest;
}
+ static ThreadLocal instances=new ThreadLocal() {
+ protected Object initialValue() {
+ return new HashMap();
+ };
+ };
+
/**
* Factory method for constructing a message digest algorithm by name.
*
@@ -86,8 +87,15 @@ public class MessageDigestAlgorithm exte
*/
public static MessageDigestAlgorithm getInstance(
Document doc, String algorithmURI) throws XMLSignatureException {
-
- String algorithmID = JCEMapper.translateURItoJCEID(algorithmURI);
+ MessageDigest md = getDigestInstance(algorithmURI);
+ return new MessageDigestAlgorithm(doc, md, algorithmURI);
+ }
+
+private static MessageDigest getDigestInstance(String algorithmURI) throws XMLSignatureException {
+ MessageDigest result=(MessageDigest) ((Map)instances.get()).get(algorithmURI);
+ if (result!=null)
+ return result;
+ String algorithmID = JCEMapper.translateURItoJCEID(algorithmURI);
if (algorithmID == null) {
Object[] exArgs = { algorithmURI };
@@ -113,8 +121,9 @@ public class MessageDigestAlgorithm exte
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
}
- return new MessageDigestAlgorithm(doc, md, algorithmURI);
- }
+ ((Map)instances.get()).put(algorithmURI, md);
+ return md;
+}
/**
* Returns the actual {@link java.security.MessageDigest} algorithm object
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/SignatureAlgorithm.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/SignatureAlgorithm.java Tue Oct 07 13:48:49 2008 -0400
@@ -25,6 +25,7 @@ import java.security.SecureRandom;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import java.util.HashMap;
+import java.util.Map;
import com.sun.org.apache.xml.internal.security.algorithms.implementations.IntegrityHmac;
import com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException;
@@ -52,8 +53,34 @@ public class SignatureAlgorithm extends
/** All available algorithm classes are registered here */
static HashMap _algorithmHash = null;
+ static ThreadLocal instancesSigning=new ThreadLocal() {
+ protected Object initialValue() {
+ return new HashMap();
+ };
+ };
+
+ static ThreadLocal instancesVerify=new ThreadLocal() {
+ protected Object initialValue() {
+ return new HashMap();
+ };
+ };
+
+ static ThreadLocal keysSigning=new ThreadLocal() {
+ protected Object initialValue() {
+ return new HashMap();
+ };
+ };
+ static ThreadLocal keysVerify=new ThreadLocal() {
+ protected Object initialValue() {
+ return new HashMap();
+ };
+ };
+// boolean isForSigning=false;
+
/** Field _signatureAlgorithm */
protected SignatureAlgorithmSpi _signatureAlgorithm = null;
+
+ private String algorithmURI;
/**
* Constructor SignatureAlgorithm
@@ -64,18 +91,49 @@ public class SignatureAlgorithm extends
*/
public SignatureAlgorithm(Document doc, String algorithmURI)
throws XMLSecurityException {
-
super(doc, algorithmURI);
-
- try {
+ this.algorithmURI = algorithmURI;
+ }
+
+
+ private void initializeAlgorithm(boolean isForSigning) throws XMLSignatureException {
+ if (_signatureAlgorithm!=null) {
+ return;
+ }
+ _signatureAlgorithm=isForSigning ? getInstanceForSigning(algorithmURI) : getInstanceForVerify(algorithmURI);
+ this._signatureAlgorithm
+ .engineGetContextFromElement(this._constructionElement);
+ }
+ private static SignatureAlgorithmSpi getInstanceForSigning(String algorithmURI) throws XMLSignatureException {
+ SignatureAlgorithmSpi result=(SignatureAlgorithmSpi) ((Map)instancesSigning.get()).get(algorithmURI);
+ if (result!=null) {
+ result.reset();
+ return result;
+ }
+ result=buildSigner(algorithmURI, result);
+ ((Map)instancesSigning.get()).put(algorithmURI,result);
+ return result;
+ }
+ private static SignatureAlgorithmSpi getInstanceForVerify(String algorithmURI) throws XMLSignatureException {
+ SignatureAlgorithmSpi result=(SignatureAlgorithmSpi) ((Map)instancesVerify.get()).get(algorithmURI);
+ if (result!=null) {
+ result.reset();
+ return result;
+ }
+ result=buildSigner(algorithmURI, result);
+ ((Map)instancesVerify.get()).put(algorithmURI,result);
+ return result;
+ }
+
+ private static SignatureAlgorithmSpi buildSigner(String algorithmURI, SignatureAlgorithmSpi result) throws XMLSignatureException {
+ try {
Class implementingClass =
SignatureAlgorithm.getImplementingClass(algorithmURI);
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Create URI \"" + algorithmURI + "\" class \""
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Create URI \"" + algorithmURI + "\" class \""
+ implementingClass + "\"");
-
- this._signatureAlgorithm =
- (SignatureAlgorithmSpi) implementingClass.newInstance();
+ result=(SignatureAlgorithmSpi) implementingClass.newInstance();
+ return result;
} catch (IllegalAccessException ex) {
Object exArgs[] = { algorithmURI, ex.getMessage() };
@@ -92,7 +150,7 @@ public class SignatureAlgorithm extends
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
ex);
}
- }
+}
/**
* Constructor SignatureAlgorithm
@@ -107,7 +165,8 @@ public class SignatureAlgorithm extends
throws XMLSecurityException {
this(doc, algorithmURI);
-
+ this.algorithmURI=algorithmURI;
+ initializeAlgorithm(true);
this._signatureAlgorithm.engineSetHMACOutputLength(HMACOutputLength);
((IntegrityHmac)this._signatureAlgorithm)
.engineAddContextToElement(this._constructionElement);
@@ -124,37 +183,7 @@ public class SignatureAlgorithm extends
throws XMLSecurityException {
super(element, BaseURI);
-
- String algorithmURI = this.getURI();
-
- try {
- Class implementingClass =
- SignatureAlgorithm.getImplementingClass(algorithmURI);
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Create URI \"" + algorithmURI + "\" class \""
- + implementingClass + "\"");
-
- this._signatureAlgorithm =
- (SignatureAlgorithmSpi) implementingClass.newInstance();
-
- this._signatureAlgorithm
- .engineGetContextFromElement(this._constructionElement);
- } catch (IllegalAccessException ex) {
- Object exArgs[] = { algorithmURI, ex.getMessage() };
-
- throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
- ex);
- } catch (InstantiationException ex) {
- Object exArgs[] = { algorithmURI, ex.getMessage() };
-
- throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
- ex);
- } catch (NullPointerException ex) {
- Object exArgs[] = { algorithmURI, ex.getMessage() };
-
- throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
- ex);
- }
+ algorithmURI = this.getURI();
}
/**
@@ -175,7 +204,12 @@ public class SignatureAlgorithm extends
* @return the result of the {@link java.security.Signature#getAlgorithm} method
*/
public String getJCEAlgorithmString() {
- return this._signatureAlgorithm.engineGetJCEAlgorithmString();
+ try {
+ return getInstanceForVerify(algorithmURI).engineGetJCEAlgorithmString();
+ } catch (XMLSignatureException e) {
+ //Ignore.
+ return null;
+ }
}
/**
@@ -184,7 +218,11 @@ public class SignatureAlgorithm extends
* @return The Provider of this Signature Alogrithm
*/
public String getJCEProviderName() {
- return this._signatureAlgorithm.engineGetJCEProviderName();
+ try {
+ return getInstanceForVerify(algorithmURI).engineGetJCEProviderName();
+ } catch (XMLSignatureException e) {
+ return null;
+ }
}
/**
@@ -231,7 +269,13 @@ public class SignatureAlgorithm extends
* @throws XMLSignatureException
*/
public void initSign(Key signingKey) throws XMLSignatureException {
- this._signatureAlgorithm.engineInitSign(signingKey);
+ initializeAlgorithm(true);
+ Map map=(Map)keysSigning.get();
+ if (map.get(this.algorithmURI)==signingKey) {
+ return;
+ }
+ map.put(this.algorithmURI,signingKey);
+ this._signatureAlgorithm.engineInitSign(signingKey);
}
/**
@@ -244,6 +288,7 @@ public class SignatureAlgorithm extends
*/
public void initSign(Key signingKey, SecureRandom secureRandom)
throws XMLSignatureException {
+ initializeAlgorithm(true);
this._signatureAlgorithm.engineInitSign(signingKey, secureRandom);
}
@@ -258,6 +303,7 @@ public class SignatureAlgorithm extends
public void initSign(
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
throws XMLSignatureException {
+ initializeAlgorithm(true);
this._signatureAlgorithm.engineInitSign(signingKey,
algorithmParameterSpec);
}
@@ -282,7 +328,13 @@ public class SignatureAlgorithm extends
* @throws XMLSignatureException
*/
public void initVerify(Key verificationKey) throws XMLSignatureException {
- this._signatureAlgorithm.engineInitVerify(verificationKey);
+ initializeAlgorithm(false);
+ Map map=(Map)keysVerify.get();
+ if (map.get(this.algorithmURI)==verificationKey) {
+ return;
+ }
+ map.put(this.algorithmURI,verificationKey);
+ this._signatureAlgorithm.engineInitVerify(verificationKey);
}
/**
@@ -320,7 +372,7 @@ public class SignatureAlgorithm extends
.getLogger(SignatureAlgorithm.class.getName());
}
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Init() called");
+ log.log(java.util.logging.Level.FINE, "Init() called");
if (!SignatureAlgorithm._alreadyInitialized) {
SignatureAlgorithm._algorithmHash = new HashMap(10);
@@ -340,8 +392,8 @@ public class SignatureAlgorithm extends
throws AlgorithmAlreadyRegisteredException,XMLSignatureException {
{
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Try to register " + algorithmURI + " " + implementingClass);
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Try to register " + algorithmURI + " " + implementingClass);
// are we already registered?
Class registeredClassClass =
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/SignatureAlgorithmSpi.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/SignatureAlgorithmSpi.java Tue Oct 07 13:48:49 2008 -0400
@@ -20,26 +20,19 @@
*/
package com.sun.org.apache.xml.internal.security.algorithms;
-
-
import java.security.Key;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
-import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
*
- * @author $Author: raul $
+ * @author $Author: mullan $
*/
public abstract class SignatureAlgorithmSpi {
-
- /** {@link java.util.logging} logging facility */
- static java.util.logging.Logger log =
- java.util.logging.Logger.getLogger(SignatureAlgorithmSpi.class.getName());
/**
* Returns the URI representation of <code>Transformation algorithm</code>
@@ -167,20 +160,6 @@ public abstract class SignatureAlgorithm
protected abstract void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException;
- /** Field _doc */
- Document _doc = null;
-
- /**
- * Method engineSetDocument
- *
- * @param doc
- */
- protected void engineSetDocument(Document doc) {
- this._doc = doc;
- }
-
- /** Field _constructionElement */
- Element _constructionElement = null;
/**
* Method engineGetContextFromElement
@@ -188,7 +167,6 @@ public abstract class SignatureAlgorithm
* @param element
*/
protected void engineGetContextFromElement(Element element) {
- this._constructionElement = element;
}
/**
@@ -199,4 +177,7 @@ public abstract class SignatureAlgorithm
*/
protected abstract void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException;
+
+ public void reset() {
+ }
}
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/implementations/IntegrityHmac.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/implementations/IntegrityHmac.java Tue Oct 07 13:48:49 2008 -0400
@@ -45,7 +45,7 @@ import org.w3c.dom.Text;
/**
*
- * @author $Author: raul $
+ * @author $Author: mullan $
*/
public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
@@ -74,8 +74,8 @@ public abstract class IntegrityHmac exte
public IntegrityHmac() throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Created IntegrityHmacSHA1 using " + algorithmID);
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Created IntegrityHmacSHA1 using " + algorithmID);
try {
this._macAlgorithm = Mac.getInstance(algorithmID);
@@ -97,6 +97,10 @@ public abstract class IntegrityHmac exte
protected void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException {
throw new XMLSignatureException("empty");
+ }
+
+ public void reset() {
+ _HMACOutputLength=0;
}
/**
@@ -145,7 +149,20 @@ public abstract class IntegrityHmac exte
try {
this._macAlgorithm.init(secretKey);
} catch (InvalidKeyException ex) {
- throw new XMLSignatureException("empty", ex);
+ // reinstantiate Mac object to work around bug in JDK
+ // see: http://bugs.sun.com/view_bug.do?bug_id=4953555
+ Mac mac = this._macAlgorithm;
+ try {
+ this._macAlgorithm = Mac.getInstance
+ (_macAlgorithm.getAlgorithm());
+ } catch (Exception e) {
+ // this shouldn't occur, but if it does, restore previous Mac
+ if (log.isLoggable(java.util.logging.Level.FINE)) {
+ log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Mac:" + e);
+ }
+ this._macAlgorithm = mac;
+ }
+ throw new XMLSignatureException("empty", ex);
}
}
@@ -323,7 +340,7 @@ public abstract class IntegrityHmac exte
*/
protected String engineGetJCEAlgorithmString() {
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "engineGetJCEAlgorithmString()");
+ log.log(java.util.logging.Level.FINE, "engineGetJCEAlgorithmString()");
return this._macAlgorithm.getAlgorithm();
}
@@ -397,7 +414,8 @@ public abstract class IntegrityHmac exte
/**
* Class IntegrityHmacSHA1
*
- * @author $Author: raul $
+ * @author $Author: mullan $
+ * @version $Revision: 1.5 $
*/
public static class IntegrityHmacSHA1 extends IntegrityHmac {
@@ -423,7 +441,8 @@ public abstract class IntegrityHmac exte
/**
* Class IntegrityHmacSHA256
*
- * @author $Author: raul $
+ * @author $Author: mullan $
+ * @version $Revision: 1.5 $
*/
public static class IntegrityHmacSHA256 extends IntegrityHmac {
@@ -449,7 +468,8 @@ public abstract class IntegrityHmac exte
/**
* Class IntegrityHmacSHA384
*
- * @author $Author: raul $
+ * @author $Author: mullan $
+ * @version $Revision: 1.5 $
*/
public static class IntegrityHmacSHA384 extends IntegrityHmac {
@@ -475,7 +495,8 @@ public abstract class IntegrityHmac exte
/**
* Class IntegrityHmacSHA512
*
- * @author $Author: raul $
+ * @author $Author: mullan $
+ * @version $Revision: 1.5 $
*/
public static class IntegrityHmacSHA512 extends IntegrityHmac {
@@ -501,7 +522,8 @@ public abstract class IntegrityHmac exte
/**
* Class IntegrityHmacRIPEMD160
*
- * @author $Author: raul $
+ * @author $Author: mullan $
+ * @version $Revision: 1.5 $
*/
public static class IntegrityHmacRIPEMD160 extends IntegrityHmac {
@@ -527,7 +549,8 @@ public abstract class IntegrityHmac exte
/**
* Class IntegrityHmacMD5
*
- * @author $Author: raul $
+ * @author $Author: mullan $
+ * @version $Revision: 1.5 $
*/
public static class IntegrityHmacMD5 extends IntegrityHmac {
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/implementations/SignatureBaseRSA.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/implementations/SignatureBaseRSA.java Tue Oct 07 13:48:49 2008 -0400
@@ -3,7 +3,7 @@
* DO NOT REMOVE OR ALTER!
*/
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2007 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,8 +19,6 @@
*
*/
package com.sun.org.apache.xml.internal.security.algorithms.implementations;
-
-
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
@@ -38,329 +36,344 @@ import com.sun.org.apache.xml.internal.s
import com.sun.org.apache.xml.internal.security.signature.XMLSignature;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
-
/**
*
- * @author $Author: raul $
+ * @author $Author: mullan $
*/
public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
- /** {@link java.util.logging} logging facility */
+ /** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
- java.util.logging.Logger.getLogger(SignatureBaseRSA.class.getName());
-
- /** @inheritDoc */
- public abstract String engineGetURI();
-
- /** Field algorithm */
- private java.security.Signature _signatureAlgorithm = null;
-
- /**
- * Constructor SignatureRSA
- *
- * @throws XMLSignatureException
- */
- public SignatureBaseRSA() throws XMLSignatureException {
-
- String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
-
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Created SignatureDSA using " + algorithmID);
- String provider=JCEMapper.getProviderId();
- try {
- if (provider==null) {
+ java.util.logging.Logger.getLogger
+ (SignatureBaseRSA.class.getName());
+
+ /** @inheritDoc */
+ public abstract String engineGetURI();
+
+ /** Field algorithm */
+ private java.security.Signature _signatureAlgorithm = null;
+
+ /**
+ * Constructor SignatureRSA
+ *
+ * @throws XMLSignatureException
+ */
+ public SignatureBaseRSA() throws XMLSignatureException {
+
+ String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
+
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Created SignatureRSA using " + algorithmID);
+ String provider=JCEMapper.getProviderId();
+ try {
+ if (provider==null) {
this._signatureAlgorithm = Signature.getInstance(algorithmID);
- } else {
+ } else {
this._signatureAlgorithm = Signature.getInstance(algorithmID,provider);
- }
- } catch (java.security.NoSuchAlgorithmException ex) {
- Object[] exArgs = { algorithmID,
- ex.getLocalizedMessage() };
-
- throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
- } catch (NoSuchProviderException ex) {
- Object[] exArgs = { algorithmID,
- ex.getLocalizedMessage() };
-
- throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
- }
- }
-
- /** @inheritDoc */
- protected void engineSetParameter(AlgorithmParameterSpec params)
- throws XMLSignatureException {
-
- try {
- this._signatureAlgorithm.setParameter(params);
- } catch (InvalidAlgorithmParameterException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- protected boolean engineVerify(byte[] signature)
- throws XMLSignatureException {
-
- try {
- return this._signatureAlgorithm.verify(signature);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
-
- if (!(publicKey instanceof PublicKey)) {
- String supplied = publicKey.getClass().getName();
- String needed = PublicKey.class.getName();
- Object exArgs[] = { supplied, needed };
-
- throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
- exArgs);
- }
-
- try {
- this._signatureAlgorithm.initVerify((PublicKey) publicKey);
- } catch (InvalidKeyException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- protected byte[] engineSign() throws XMLSignatureException {
-
- try {
- return this._signatureAlgorithm.sign();
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
- throws XMLSignatureException {
-
- if (!(privateKey instanceof PrivateKey)) {
- String supplied = privateKey.getClass().getName();
- String needed = PrivateKey.class.getName();
- Object exArgs[] = { supplied, needed };
-
- throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
- exArgs);
- }
-
- try {
- this._signatureAlgorithm.initSign((PrivateKey) privateKey,
- secureRandom);
- } catch (InvalidKeyException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- protected void engineInitSign(Key privateKey) throws XMLSignatureException {
-
- if (!(privateKey instanceof PrivateKey)) {
- String supplied = privateKey.getClass().getName();
- String needed = PrivateKey.class.getName();
- Object exArgs[] = { supplied, needed };
-
- throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
- exArgs);
- }
-
- try {
- this._signatureAlgorithm.initSign((PrivateKey) privateKey);
- } catch (InvalidKeyException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- protected void engineUpdate(byte[] input) throws XMLSignatureException {
-
- try {
- this._signatureAlgorithm.update(input);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- protected void engineUpdate(byte input) throws XMLSignatureException {
-
- try {
- this._signatureAlgorithm.update(input);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- protected void engineUpdate(byte buf[], int offset, int len)
- throws XMLSignatureException {
-
- try {
- this._signatureAlgorithm.update(buf, offset, len);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- protected String engineGetJCEAlgorithmString() {
- return this._signatureAlgorithm.getAlgorithm();
- }
-
- /** @inheritDoc */
- protected String engineGetJCEProviderName() {
- return this._signatureAlgorithm.getProvider().getName();
- }
-
- /** @inheritDoc */
- protected void engineSetHMACOutputLength(int HMACOutputLength)
- throws XMLSignatureException {
- throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
- }
-
- /** @inheritDoc */
- protected void engineInitSign(
- Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
- throws XMLSignatureException {
- throw new XMLSignatureException(
- "algorithms.CannotUseAlgorithmParameterSpecOnRSA");
- }
-
- /**
- * Class SignatureRSASHA1
- *
- * @author $Author: raul $
- */
- public static class SignatureRSASHA1 extends SignatureBaseRSA {
-
- /**
- * Constructor SignatureRSASHA1
- *
- * @throws XMLSignatureException
- */
- public SignatureRSASHA1() throws XMLSignatureException {
- super();
- }
-
- /** @inheritDoc */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1;
- }
- }
-
- /**
- * Class SignatureRSASHA256
- *
- * @author $Author: raul $
- */
- public static class SignatureRSASHA256 extends SignatureBaseRSA {
-
- /**
- * Constructor SignatureRSASHA256
- *
- * @throws XMLSignatureException
- */
- public SignatureRSASHA256() throws XMLSignatureException {
- super();
- }
-
- /** @inheritDoc */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256;
- }
- }
-
- /**
- * Class SignatureRSASHA384
- *
- * @author $Author: raul $
- */
- public static class SignatureRSASHA384 extends SignatureBaseRSA {
-
- /**
- * Constructor SignatureRSASHA384
- *
- * @throws XMLSignatureException
- */
- public SignatureRSASHA384() throws XMLSignatureException {
- super();
- }
-
- /** @inheritDoc */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA384;
- }
- }
-
- /**
- * Class SignatureRSASHA512
- *
- * @author $Author: raul $
- */
- public static class SignatureRSASHA512 extends SignatureBaseRSA {
-
- /**
- * Constructor SignatureRSASHA512
- *
- * @throws XMLSignatureException
- */
- public SignatureRSASHA512() throws XMLSignatureException {
- super();
- }
-
- /** @inheritDoc */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512;
- }
- }
-
- /**
- * Class SignatureRSARIPEMD160
- *
- * @author $Author: raul $
- */
- public static class SignatureRSARIPEMD160 extends SignatureBaseRSA {
-
- /**
- * Constructor SignatureRSARIPEMD160
- *
- * @throws XMLSignatureException
- */
- public SignatureRSARIPEMD160() throws XMLSignatureException {
- super();
- }
-
- /** @inheritDoc */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_SIGNATURE_RSA_RIPEMD160;
- }
- }
-
- /**
- * Class SignatureRSAMD5
- *
- * @author $Author: raul $
- */
- public static class SignatureRSAMD5 extends SignatureBaseRSA {
-
- /**
- * Constructor SignatureRSAMD5
- *
- * @throws XMLSignatureException
- */
- public SignatureRSAMD5() throws XMLSignatureException {
- super();
- }
-
- /** @inheritDoc */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_SIGNATURE_NOT_RECOMMENDED_RSA_MD5;
- }
- }
+ }
+ } catch (java.security.NoSuchAlgorithmException ex) {
+ Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
+
+ throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
+ } catch (NoSuchProviderException ex) {
+ Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
+
+ throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
+ }
+ }
+
+ /** @inheritDoc */
+ protected void engineSetParameter(AlgorithmParameterSpec params)
+ throws XMLSignatureException {
+
+ try {
+ this._signatureAlgorithm.setParameter(params);
+ } catch (InvalidAlgorithmParameterException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @inheritDoc */
+ protected boolean engineVerify(byte[] signature)
+ throws XMLSignatureException {
+
+ try {
+ return this._signatureAlgorithm.verify(signature);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @inheritDoc */
+ protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
+
+ if (!(publicKey instanceof PublicKey)) {
+ String supplied = publicKey.getClass().getName();
+ String needed = PublicKey.class.getName();
+ Object exArgs[] = { supplied, needed };
+
+ throw new XMLSignatureException
+ ("algorithms.WrongKeyForThisOperation", exArgs);
+ }
+
+ try {
+ this._signatureAlgorithm.initVerify((PublicKey) publicKey);
+ } catch (InvalidKeyException ex) {
+ // reinstantiate Signature object to work around bug in JDK
+ // see: http://bugs.sun.com/view_bug.do?bug_id=4953555
+ Signature sig = this._signatureAlgorithm;
+ try {
+ this._signatureAlgorithm = Signature.getInstance
+ (_signatureAlgorithm.getAlgorithm());
+ } catch (Exception e) {
+ // this shouldn't occur, but if it does, restore previous
+ // Signature
+ if (log.isLoggable(java.util.logging.Level.FINE)) {
+ log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
+ }
+ this._signatureAlgorithm = sig;
+ }
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @inheritDoc */
+ protected byte[] engineSign() throws XMLSignatureException {
+ try {
+ return this._signatureAlgorithm.sign();
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @inheritDoc */
+ protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
+ throws XMLSignatureException {
+
+ if (!(privateKey instanceof PrivateKey)) {
+ String supplied = privateKey.getClass().getName();
+ String needed = PrivateKey.class.getName();
+ Object exArgs[] = { supplied, needed };
+
+ throw new XMLSignatureException
+ ("algorithms.WrongKeyForThisOperation", exArgs);
+ }
+
+ try {
+ this._signatureAlgorithm.initSign
+ ((PrivateKey) privateKey, secureRandom);
+ } catch (InvalidKeyException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @inheritDoc */
+ protected void engineInitSign(Key privateKey) throws XMLSignatureException {
+
+ if (!(privateKey instanceof PrivateKey)) {
+ String supplied = privateKey.getClass().getName();
+ String needed = PrivateKey.class.getName();
+ Object exArgs[] = { supplied, needed };
+
+ throw new XMLSignatureException
+ ("algorithms.WrongKeyForThisOperation", exArgs);
+ }
+
+ try {
+ this._signatureAlgorithm.initSign((PrivateKey) privateKey);
+ } catch (InvalidKeyException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @inheritDoc */
+ protected void engineUpdate(byte[] input) throws XMLSignatureException {
+ try {
+ this._signatureAlgorithm.update(input);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @inheritDoc */
+ protected void engineUpdate(byte input) throws XMLSignatureException {
+ try {
+ this._signatureAlgorithm.update(input);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @inheritDoc */
+ protected void engineUpdate(byte buf[], int offset, int len)
+ throws XMLSignatureException {
+ try {
+ this._signatureAlgorithm.update(buf, offset, len);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @inheritDoc */
+ protected String engineGetJCEAlgorithmString() {
+ return this._signatureAlgorithm.getAlgorithm();
+ }
+
+ /** @inheritDoc */
+ protected String engineGetJCEProviderName() {
+ return this._signatureAlgorithm.getProvider().getName();
+ }
+
+ /** @inheritDoc */
+ protected void engineSetHMACOutputLength(int HMACOutputLength)
+ throws XMLSignatureException {
+ throw new XMLSignatureException
+ ("algorithms.HMACOutputLengthOnlyForHMAC");
+ }
+
+ /** @inheritDoc */
+ protected void engineInitSign(
+ Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
+ throws XMLSignatureException {
+ throw new XMLSignatureException(
+ "algorithms.CannotUseAlgorithmParameterSpecOnRSA");
+ }
+
+ /**
+ * Class SignatureRSASHA1
+ *
+ * @author $Author: mullan $
+ * @version $Revision: 1.5 $
+ */
+ public static class SignatureRSASHA1 extends SignatureBaseRSA {
+
+ /**
+ * Constructor SignatureRSASHA1
+ *
+ * @throws XMLSignatureException
+ */
+ public SignatureRSASHA1() throws XMLSignatureException {
+ super();
+ }
+
+ /** @inheritDoc */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1;
+ }
+ }
+
+ /**
+ * Class SignatureRSASHA256
+ *
+ * @author $Author: mullan $
+ * @version $Revision: 1.5 $
+ */
+ public static class SignatureRSASHA256 extends SignatureBaseRSA {
+
+ /**
+ * Constructor SignatureRSASHA256
+ *
+ * @throws XMLSignatureException
+ */
+ public SignatureRSASHA256() throws XMLSignatureException {
+ super();
+ }
+
+ /** @inheritDoc */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256;
+ }
+ }
+
+ /**
+ * Class SignatureRSASHA384
+ *
+ * @author $Author: mullan $
+ * @version $Revision: 1.5 $
+ */
+ public static class SignatureRSASHA384 extends SignatureBaseRSA {
+
+ /**
+ * Constructor SignatureRSASHA384
+ *
+ * @throws XMLSignatureException
+ */
+ public SignatureRSASHA384() throws XMLSignatureException {
+ super();
+ }
+
+ /** @inheritDoc */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA384;
+ }
+ }
+
+ /**
+ * Class SignatureRSASHA512
+ *
+ * @author $Author: mullan $
+ * @version $Revision: 1.5 $
+ */
+ public static class SignatureRSASHA512 extends SignatureBaseRSA {
+
+ /**
+ * Constructor SignatureRSASHA512
+ *
+ * @throws XMLSignatureException
+ */
+ public SignatureRSASHA512() throws XMLSignatureException {
+ super();
+ }
+
+ /** @inheritDoc */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512;
+ }
+ }
+
+ /**
+ * Class SignatureRSARIPEMD160
+ *
+ * @author $Author: mullan $
+ * @version $Revision: 1.5 $
+ */
+ public static class SignatureRSARIPEMD160 extends SignatureBaseRSA {
+
+ /**
+ * Constructor SignatureRSARIPEMD160
+ *
+ * @throws XMLSignatureException
+ */
+ public SignatureRSARIPEMD160() throws XMLSignatureException {
+ super();
+ }
+
+ /** @inheritDoc */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_SIGNATURE_RSA_RIPEMD160;
+ }
+ }
+
+ /**
+ * Class SignatureRSAMD5
+ *
+ * @author $Author: mullan $
+ * @version $Revision: 1.5 $
+ */
+ public static class SignatureRSAMD5 extends SignatureBaseRSA {
+
+ /**
+ * Constructor SignatureRSAMD5
+ *
+ * @throws XMLSignatureException
+ */
+ public SignatureRSAMD5() throws XMLSignatureException {
+ super();
+ }
+
+ /** @inheritDoc */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_SIGNATURE_NOT_RECOMMENDED_RSA_MD5;
+ }
+ }
}
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/implementations/SignatureDSA.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/org/apache/xml/internal/security/algorithms/implementations/SignatureDSA.java Tue Oct 07 13:48:49 2008 -0400
@@ -19,8 +19,6 @@
*
*/
package com.sun.org.apache.xml.internal.security.algorithms.implementations;
-
-
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
@@ -39,342 +37,359 @@ import com.sun.org.apache.xml.internal.s
import com.sun.org.apache.xml.internal.security.utils.Base64;
import com.sun.org.apache.xml.internal.security.utils.Constants;
-
/**
*
- * @author $Author: vishal $
+ * @author $Author: mullan $
*/
public class SignatureDSA extends SignatureAlgorithmSpi {
- /** {@link java.util.logging} logging facility */
+ /** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(SignatureDSA.class.getName());
- /** Field _URI */
- public static final String _URI = Constants.SignatureSpecNS + "dsa-sha1";
-
- /** Field algorithm */
- private java.security.Signature _signatureAlgorithm = null;
-
- /**
- * Method engineGetURI
- *
- * @inheritDoc
- */
- protected String engineGetURI() {
- return SignatureDSA._URI;
- }
-
- /**
- * Constructor SignatureDSA
- *
- * @throws XMLSignatureException
- */
- public SignatureDSA() throws XMLSignatureException {
-
- String algorithmID = JCEMapper.translateURItoJCEID(SignatureDSA._URI);
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Created SignatureDSA using " + algorithmID);
-
- try {
- this._signatureAlgorithm = Signature.getInstance(algorithmID);
- } catch (java.security.NoSuchAlgorithmException ex) {
- Object[] exArgs = { algorithmID,
- ex.getLocalizedMessage() };
-
- throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
- }
- }
-
- /**
- * @inheritDoc
- */
- protected void engineSetParameter(AlgorithmParameterSpec params)
+ /** Field _URI */
+ public static final String _URI = Constants.SignatureSpecNS + "dsa-sha1";
+
+ /** Field algorithm */
+ private java.security.Signature _signatureAlgorithm = null;
+
+ /**
+ * Method engineGetURI
+ *
+ * @inheritDoc
+ */
+ protected String engineGetURI() {
+ return SignatureDSA._URI;
+ }
+
+ /**
+ * Constructor SignatureDSA
+ *
+ * @throws XMLSignatureException
+ */
+ public SignatureDSA() throws XMLSignatureException {
+
+ String algorithmID = JCEMapper.translateURItoJCEID(SignatureDSA._URI);
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Created SignatureDSA using " + algorithmID);
+
+ String provider = JCEMapper.getProviderId();
+ try {
+ if (provider == null) {
+ this._signatureAlgorithm = Signature.getInstance(algorithmID);
+ } else {
+ this._signatureAlgorithm =
+ Signature.getInstance(algorithmID, provider);
+ }
+ } catch (java.security.NoSuchAlgorithmException ex) {
+ Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
+ throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
+ } catch (java.security.NoSuchProviderException ex) {
+ Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
+ throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ protected void engineSetParameter(AlgorithmParameterSpec params)
+ throws XMLSignatureException {
+
+ try {
+ this._signatureAlgorithm.setParameter(params);
+ } catch (InvalidAlgorithmParameterException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ protected boolean engineVerify(byte[] signature)
throws XMLSignatureException {
- try {
- this._signatureAlgorithm.setParameter(params);
- } catch (InvalidAlgorithmParameterException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * @inheritDoc
- */
- protected boolean engineVerify(byte[] signature)
+ try {
+ if (log.isLoggable(java.util.logging.Level.FINE))
+ log.log(java.util.logging.Level.FINE, "Called DSA.verify() on " + Base64.encode(signature));
+
+ byte[] jcebytes = SignatureDSA.convertXMLDSIGtoASN1(signature);
+
+ return this._signatureAlgorithm.verify(jcebytes);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ } catch (IOException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
+
+ if (!(publicKey instanceof PublicKey)) {
+ String supplied = publicKey.getClass().getName();
+ String needed = PublicKey.class.getName();
+ Object exArgs[] = { supplied, needed };
+
+ throw new XMLSignatureException
+ ("algorithms.WrongKeyForThisOperation", exArgs);
+ }
+
+ try {
+ this._signatureAlgorithm.initVerify((PublicKey) publicKey);
+ } catch (InvalidKeyException ex) {
+ // reinstantiate Signature object to work around bug in JDK
+ // see: http://bugs.sun.com/view_bug.do?bug_id=4953555
+ Signature sig = this._signatureAlgorithm;
+ try {
+ this._signatureAlgorithm = Signature.getInstance
+ (_signatureAlgorithm.getAlgorithm());
+ } catch (Exception e) {
+ // this shouldn't occur, but if it does, restore previous
+ // Signature
+ if (log.isLoggable(java.util.logging.Level.FINE)) {
+ log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
+ }
+ this._signatureAlgorithm = sig;
+ }
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ protected byte[] engineSign() throws XMLSignatureException {
+
+ try {
+ byte jcebytes[] = this._signatureAlgorithm.sign();
+
+ return SignatureDSA.convertASN1toXMLDSIG(jcebytes);
+ } catch (IOException ex) {
+ throw new XMLSignatureException("empty", ex);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
throws XMLSignatureException {
- try {
- if (true)
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Called DSA.verify() on " + Base64.encode(signature));
-
- byte[] jcebytes = SignatureDSA.convertXMLDSIGtoASN1(signature);
-
- return this._signatureAlgorithm.verify(jcebytes);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- } catch (IOException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * @inheritDoc
- */
- protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
-
- if (!(publicKey instanceof PublicKey)) {
- String supplied = publicKey.getClass().getName();
- String needed = PublicKey.class.getName();
- Object exArgs[] = { supplied, needed };
-
- throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
- exArgs);
- }
-
- try {
- this._signatureAlgorithm.initVerify((PublicKey) publicKey);
- } catch (InvalidKeyException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * @inheritDoc
- */
- protected byte[] engineSign() throws XMLSignatureException {
-
- try {
- byte jcebytes[] = this._signatureAlgorithm.sign();
-
- return SignatureDSA.convertASN1toXMLDSIG(jcebytes);
- } catch (IOException ex) {
- throw new XMLSignatureException("empty", ex);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * @inheritDoc
- */
- protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
- throws XMLSignatureException {
-
- if (!(privateKey instanceof PrivateKey)) {
- String supplied = privateKey.getClass().getName();
- String needed = PrivateKey.class.getName();
- Object exArgs[] = { supplied, needed };
-
- throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
- exArgs);
- }
-
- try {
- this._signatureAlgorithm.initSign((PrivateKey) privateKey,
+ if (!(privateKey instanceof PrivateKey)) {
+ String supplied = privateKey.getClass().getName();
+ String needed = PrivateKey.class.getName();
+ Object exArgs[] = { supplied, needed };
+
+ throw new XMLSignatureException
+ ("algorithms.WrongKeyForThisOperation", exArgs);
+ }
+
+ try {
+ this._signatureAlgorithm.initSign((PrivateKey) privateKey,
secureRandom);
- } catch (InvalidKeyException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * @inheritDoc
- */
- protected void engineInitSign(Key privateKey) throws XMLSignatureException {
-
- if (!(privateKey instanceof PrivateKey)) {
- String supplied = privateKey.getClass().getName();
- String needed = PrivateKey.class.getName();
- Object exArgs[] = { supplied, needed };
-
- throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
- exArgs);
- }
-
- try {
- this._signatureAlgorithm.initSign((PrivateKey) privateKey);
- } catch (InvalidKeyException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * @inheritDoc
- */
- protected void engineUpdate(byte[] input) throws XMLSignatureException {
-
- try {
- this._signatureAlgorithm.update(input);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * @inheritDoc
- */
- protected void engineUpdate(byte input) throws XMLSignatureException {
-
- try {
- this._signatureAlgorithm.update(input);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * @inheritDoc
- */
- protected void engineUpdate(byte buf[], int offset, int len)
- throws XMLSignatureException {
-
- try {
- this._signatureAlgorithm.update(buf, offset, len);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * Method engineGetJCEAlgorithmString
- *
- * @inheritDoc
- */
- protected String engineGetJCEAlgorithmString() {
- return this._signatureAlgorithm.getAlgorithm();
- }
-
- /**
- * Method engineGetJCEProviderName
- *
- * @inheritDoc
- */
- protected String engineGetJCEProviderName() {
- return this._signatureAlgorithm.getProvider().getName();
- }
-
-
- /**
- * Converts an ASN.1 DSA value to a XML Signature DSA Value.
- *
- * The JAVA JCE DSA Signature algorithm creates ASN.1 encoded (r,s) value
- * pairs; the XML Signature requires the core BigInteger values.
- *
- * @param asn1Bytes
- * @return the decode bytes
- *
- * @throws IOException
- * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
- */
- private static byte[] convertASN1toXMLDSIG(byte asn1Bytes[])
+ } catch (InvalidKeyException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ protected void engineInitSign(Key privateKey) throws XMLSignatureException {
+
+ if (!(privateKey instanceof PrivateKey)) {
+ String supplied = privateKey.getClass().getName();
+ String needed = PrivateKey.class.getName();
+ Object exArgs[] = { supplied, needed };
+
+ throw new XMLSignatureException
+ ("algorithms.WrongKeyForThisOperation", exArgs);
+ }
+
+ try {
+ this._signatureAlgorithm.initSign((PrivateKey) privateKey);
+ } catch (InvalidKeyException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ protected void engineUpdate(byte[] input) throws XMLSignatureException {
+ try {
+ this._signatureAlgorithm.update(input);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ protected void engineUpdate(byte input) throws XMLSignatureException {
+ try {
+ this._signatureAlgorithm.update(input);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ protected void engineUpdate(byte buf[], int offset, int len)
+ throws XMLSignatureException {
+ try {
+ this._signatureAlgorithm.update(buf, offset, len);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * Method engineGetJCEAlgorithmString
+ *
+ * @inheritDoc
+ */
+ protected String engineGetJCEAlgorithmString() {
+ return this._signatureAlgorithm.getAlgorithm();
+ }
+
+ /**
+ * Method engineGetJCEProviderName
+ *
+ * @inheritDoc
+ */
+ protected String engineGetJCEProviderName() {
+ return this._signatureAlgorithm.getProvider().getName();
+ }
+
+ /**
+ * Converts an ASN.1 DSA value to a XML Signature DSA Value.
+ *
+ * The JAVA JCE DSA Signature algorithm creates ASN.1 encoded (r,s) value
+ * pairs; the XML Signature requires the core BigInteger values.
+ *
+ * @param asn1Bytes
+ * @return the decode bytes
+ *
+ * @throws IOException
+ * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
+ */
+ private static byte[] convertASN1toXMLDSIG(byte asn1Bytes[])
throws IOException {
- byte rLength = asn1Bytes[3];
- int i;
-
- for (i = rLength; (i > 0) && (asn1Bytes[(4 + rLength) - i] == 0); i--);
-
- byte sLength = asn1Bytes[5 + rLength];
- int j;
-
- for (j = sLength;
+ byte rLength = asn1Bytes[3];
+ int i;
+
+ for (i = rLength; (i > 0) && (asn1Bytes[(4 + rLength) - i] == 0); i--);
+
+ byte sLength = asn1Bytes[5 + rLength];
+ int j;
+
+ for (j = sLength;
(j > 0) && (asn1Bytes[(6 + rLength + sLength) - j] == 0); j--);
- if ((asn1Bytes[0] != 48) || (asn1Bytes[1] != asn1Bytes.length - 2)
+ if ((asn1Bytes[0] != 48) || (asn1Bytes[1] != asn1Bytes.length - 2)
|| (asn1Bytes[2] != 2) || (i > 20)
|| (asn1Bytes[4 + rLength] != 2) || (j > 20)) {
- throw new IOException("Invalid ASN.1 format of DSA signature");
- }
- byte xmldsigBytes[] = new byte[40];
-
- System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 20 - i,
+ throw new IOException("Invalid ASN.1 format of DSA signature");
+ }
+ byte xmldsigBytes[] = new byte[40];
+
+ System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 20 - i,
i);
- System.arraycopy(asn1Bytes, (6 + rLength + sLength) - j, xmldsigBytes,
+ System.arraycopy(asn1Bytes, (6 + rLength + sLength) - j, xmldsigBytes,
40 - j, j);
- return xmldsigBytes;
- }
-
- /**
- * Converts a XML Signature DSA Value to an ASN.1 DSA value.
- *
- * The JAVA JCE DSA Signature algorithm creates ASN.1 encoded (r,s) value
- * pairs; the XML Signature requires the core BigInteger values.
- *
- * @param xmldsigBytes
- * @return the encoded ASN.1 bytes
- *
- * @throws IOException
- * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
- */
- private static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[])
+ return xmldsigBytes;
+ }
+
+ /**
+ * Converts a XML Signature DSA Value to an ASN.1 DSA value.
+ *
+ * The JAVA JCE DSA Signature algorithm creates ASN.1 encoded (r,s) value
+ * pairs; the XML Signature requires the core BigInteger values.
+ *
+ * @param xmldsigBytes
+ * @return the encoded ASN.1 bytes
+ *
+ * @throws IOException
+ * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
+ */
+ private static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[])
throws IOException {
- if (xmldsigBytes.length != 40) {
- throw new IOException("Invalid XMLDSIG format of DSA signature");
- }
-
- int i;
-
- for (i = 20; (i > 0) && (xmldsigBytes[20 - i] == 0); i--);
-
- int j = i;
-
- if (xmldsigBytes[20 - i] < 0) {
+ if (xmldsigBytes.length != 40) {
+ throw new IOException("Invalid XMLDSIG format of DSA signature");
+ }
+
+ int i;
+
+ for (i = 20; (i > 0) && (xmldsigBytes[20 - i] == 0); i--);
+
+ int j = i;
+
+ if (xmldsigBytes[20 - i] < 0) {
j += 1;
- }
-
- int k;
-
- for (k = 20; (k > 0) && (xmldsigBytes[40 - k] == 0); k--);
-
- int l = k;
-
- if (xmldsigBytes[40 - k] < 0) {
- l += 1;
- }
-
- byte asn1Bytes[] = new byte[6 + j + l];
-
- asn1Bytes[0] = 48;
- asn1Bytes[1] = (byte) (4 + j + l);
- asn1Bytes[2] = 2;
- asn1Bytes[3] = (byte) j;
-
- System.arraycopy(xmldsigBytes, 20 - i, asn1Bytes, (4 + j) - i, i);
-
- asn1Bytes[4 + j] = 2;
- asn1Bytes[5 + j] = (byte) l;
-
- System.arraycopy(xmldsigBytes, 40 - k, asn1Bytes, (6 + j + l) - k, k);
-
- return asn1Bytes;
- }
-
- /**
- * Method engineSetHMACOutputLength
- *
- * @param HMACOutputLength
- * @throws XMLSignatureException
- */
- protected void engineSetHMACOutputLength(int HMACOutputLength)
- throws XMLSignatureException {
- throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
- }
-
- /**
- * Method engineInitSign
- *
- * @param signingKey
- * @param algorithmParameterSpec
- * @throws XMLSignatureException
- */
- protected void engineInitSign(
- Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
- throws XMLSignatureException {
- throw new XMLSignatureException(
- "algorithms.CannotUseAlgorithmParameterSpecOnDSA");
- }
+ }
+
+ int k;
+
+ for (k = 20; (k > 0) && (xmldsigBytes[40 - k] == 0); k--);
+
+ int l = k;
+
+ if (xmldsigBytes[40 - k] < 0) {
+ l += 1;
+ }
+
+ byte asn1Bytes[] = new byte[6 + j + l];
+
+ asn1Bytes[0] = 48;
+ asn1Bytes[1] = (byte) (4 + j + l);
+ asn1Bytes[2] = 2;
+ asn1Bytes[3] = (byte) j;
+
+ System.arraycopy(xmldsigBytes, 20 - i, asn1Bytes, (4 + j) - i, i);
+
+ asn1Bytes[4 + j] = 2;
+ asn1Bytes[5 + j] = (byte) l;
+
+ System.arraycopy(xmldsigBytes, 40 - k, asn1Bytes, (6 + j + l) - k, k);
+
+ return asn1Bytes;
+ }
+
+ /**
+ * Method engineSetHMACOutputLength
+ *
+ * @param HMACOutputLength
+ * @throws XMLSignatureException
+ */
+ protected void engineSetHMACOutputLength(int HMACOutputLength)
+ throws XMLSignatureException {
+ throw new XMLSignatureException(
+ "algorithms.HMACOutputLengthOnlyForHMAC");
+ }
+
+ /**
+ * Method engineInitSign
+ *
+ * @param signingKey
+ * @param algorithmParameterSpec
+ * @throws XMLSignatureException
+ */
+ protected void engineInitSign(
+ Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
+ throws XMLSignatureException {
+ throw new XMLSignatureException(
+ "algorithms.CannotUseAlgorithmParameterSpecOnDSA");
+ }
}
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/CanonicalizationException.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/CanonicalizationException.java Tue Oct 07 13:48:49 2008 -0400
@@ -2,7 +2,6 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
-
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/Canonicalizer.java Tue Oct 07 13:41:39 2008 -0400
+++ b/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/Canonicalizer.java Tue Oct 07 13:48:49 2008 -0400
@@ -3,7 +3,7 @@
* DO NOT REMOVE OR ALTER!
*/
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2008 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,8 +20,6 @@
*/
package com.sun.org.apache.xml.internal.security.c14n;
-
-
import java.io.ByteArrayInputStream;
import java.io.OutputStream;
import java.util.HashMap;
@@ -37,318 +35,326 @@ import org.w3c.dom.NodeList;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
-
/**
- *
*
* @author Christian Geuer-Pollmann
*/
public class Canonicalizer {
- //J-
- /** The output encoding of canonicalized data */
- public static final String ENCODING = "UTF8";
-
-
- /**
- * XPath Expresion for selecting every node and continuos comments joined in only one node
- */
- public static final String XPATH_C14N_WITH_COMMENTS_SINGLE_NODE = "(.//. | .//@* | .//namespace::*)";
-
-
- /**
+ /** The output encoding of canonicalized data */
+ public static final String ENCODING = "UTF8";
+
+ /**
+ * XPath Expresion for selecting every node and continuous comments joined
+ * in only one node
+ */
+ public static final String XPATH_C14N_WITH_COMMENTS_SINGLE_NODE =
+ "(.//. | .//@* | .//namespace::*)";
+
+ /**
* The URL defined in XML-SEC Rec for inclusive c14n <b>without</b> comments.
*/
- public static final String ALGO_ID_C14N_OMIT_COMMENTS = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
- /**
- * The URL defined in XML-SEC Rec for inclusive c14n <b>with</b> comments.
- */
- public static final String ALGO_ID_C14N_WITH_COMMENTS = ALGO_ID_C14N_OMIT_COMMENTS + "#WithComments";
- /**
- * The URL defined in XML-SEC Rec for exclusive c14n <b>without</b> comments.
- */
- public static final String ALGO_ID_C14N_EXCL_OMIT_COMMENTS = "http://www.w3.org/2001/10/xml-exc-c14n#";
- /**
- * The URL defined in XML-SEC Rec for exclusive c14n <b>with</b> comments.
- */
- public static final String ALGO_ID_C14N_EXCL_WITH_COMMENTS = ALGO_ID_C14N_EXCL_OMIT_COMMENTS + "WithComments";
-
- static boolean _alreadyInitialized = false;
- static Map _canonicalizerHash = null;
-
- protected CanonicalizerSpi canonicalizerSpi = null;
- //J+
-
- /**
- * Method init
- *
- */
- public static void init() {
-
- if (!Canonicalizer._alreadyInitialized) {
- Canonicalizer._canonicalizerHash = new HashMap(10);
- Canonicalizer._alreadyInitialized = true;
- }
- }
-
- /**
- * Constructor Canonicalizer
- *
- * @param algorithmURI
- * @throws InvalidCanonicalizerException
- */
- private Canonicalizer(String algorithmURI)
+ public static final String ALGO_ID_C14N_OMIT_COMMENTS =
+ "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
+ /**
+ * The URL defined in XML-SEC Rec for inclusive c14n <b>with</b> comments.
+ */
+ public static final String ALGO_ID_C14N_WITH_COMMENTS =
+ ALGO_ID_C14N_OMIT_COMMENTS + "#WithComments";
+ /**
+ * The URL defined in XML-SEC Rec for exclusive c14n <b>without</b> comments.
+ */
+ public static final String ALGO_ID_C14N_EXCL_OMIT_COMMENTS =
+ "http://www.w3.org/2001/10/xml-exc-c14n#";
+ /**
+ * The URL defined in XML-SEC Rec for exclusive c14n <b>with</b> comments.
+ */
+ public static final String ALGO_ID_C14N_EXCL_WITH_COMMENTS =
+ ALGO_ID_C14N_EXCL_OMIT_COMMENTS + "WithComments";
+ /**
+ * The URI for inclusive c14n 1.1 <b>without</b> comments.
+ */
+ public static final String ALGO_ID_C14N11_OMIT_COMMENTS =
+ "http://www.w3.org/2006/12/xml-c14n11";
+ /**
+ * The URI for inclusive c14n 1.1 <b>with</b> comments.
+ */
+ public static final String ALGO_ID_C14N11_WITH_COMMENTS =
+ ALGO_ID_C14N11_OMIT_COMMENTS + "#WithComments";
+
+ static boolean _alreadyInitialized = false;
+ static Map _canonicalizerHash = null;
+
+ protected CanonicalizerSpi canonicalizerSpi = null;
+
+ /**
+ * Method init
+ *
+ */
+ public static void init() {
+
+ if (!Canonicalizer._alreadyInitialized) {
+ Canonicalizer._canonicalizerHash = new HashMap(10);
+ Canonicalizer._alreadyInitialized = true;
+ }
+ }
+
+ /**
+ * Constructor Canonicalizer
+ *
+ * @param algorithmURI
+ * @throws InvalidCanonicalizerException
+ */
+ private Canonicalizer(String algorithmURI)
throws InvalidCanonicalizerException {
- try {
- Class implementingClass = getImplementingClass(algorithmURI);
-
- this.canonicalizerSpi =
- (CanonicalizerSpi) implementingClass.newInstance();
- this.canonicalizerSpi.reset=true;
- } catch (Exception e) {
- Object exArgs[] = { algorithmURI };
-
- throw new InvalidCanonicalizerException(
- "signature.Canonicalizer.UnknownCanonicalizer", exArgs);
- }
- }
-
- /**
- * Method getInstance
- *
- * @param algorithmURI
- * @return a Conicicalizer instance ready for the job
- * @throws InvalidCanonicalizerException
- */
- public static final Canonicalizer getInstance(String algorithmURI)
+ try {
+ Class implementingClass = getImplementingClass(algorithmURI);
+
+ this.canonicalizerSpi =
+ (CanonicalizerSpi) implementingClass.newInstance();
+ this.canonicalizerSpi.reset=true;
+ } catch (Exception e) {
+ Object exArgs[] = { algorithmURI };
+
+ throw new InvalidCanonicalizerException(
+ "signature.Canonicalizer.UnknownCanonicalizer", exArgs);
+ }
+ }
+
+ /**
+ * Method getInstance
+ *
+ * @param algorithmURI
+ * @return a Conicicalizer instance ready for the job
+ * @throws InvalidCanonicalizerException
+ */
+ public static final Canonicalizer getInstance(String algorithmURI)
throws InvalidCanonicalizerException {
- Canonicalizer c14nizer = new Canonicalizer(algorithmURI);
-
- return c14nizer;
- }
-
- /**
- * Method register
- *
- * @param algorithmURI
- * @param implementingClass
- * @throws AlgorithmAlreadyRegisteredException
- */
- public static void register(String algorithmURI, String implementingClass)
+ Canonicalizer c14nizer = new Canonicalizer(algorithmURI);
+
+ return c14nizer;
+ }
+
+ /**
+ * Method register
+ *
+ * @param algorithmURI
+ * @param implementingClass
+ * @throws AlgorithmAlreadyRegisteredException
+ */
+ public static void register(String algorithmURI, String implementingClass)
throws AlgorithmAlreadyRegisteredException {
- // check whether URI is already registered
- Class registeredClass = getImplementingClass(algorithmURI);
-
- if (registeredClass != null) {
- Object exArgs[] = { algorithmURI, registeredClass };
-
- throw new AlgorithmAlreadyRegisteredException(
- "algorithm.alreadyRegistered", exArgs);
- }
-
- try {
- _canonicalizerHash.put(algorithmURI, Class.forName(implementingClass));
+ // check whether URI is already registered
+ Class registeredClass = getImplementingClass(algorithmURI);
+
+ if (registeredClass != null) {
+ Object exArgs[] = { algorithmURI, registeredClass };
+
+ throw new AlgorithmAlreadyRegisteredException(
+ "algorithm.alreadyRegistered", exArgs);
+ }
+
+ try {
+ _canonicalizerHash.put(algorithmURI, Class.forName(implementingClass));
} catch (ClassNotFoundException e) {
- throw new RuntimeException("c14n class not found");
- }
- }
-
- /**
- * Method getURI
- *
- * @return the URI defined for this c14n instance.
- */
- public final String getURI() {
- return this.canonicalizerSpi.engineGetURI();
- }
-
- /**
- * Method getIncludeComments
- *
- * @return true if the c14n respect the comments.
- */
- public boolean getIncludeComments() {
- return this.canonicalizerSpi.engineGetIncludeComments();
- }
-
- /**
- * This method tries to canonicalize the given bytes. It's possible to even
- * canonicalize non-wellformed sequences if they are well-formed after being
- * wrapped with a <CODE>>a<...>/a<</CODE>.
- *
- * @param inputBytes
- * @return the result of the conicalization.
- * @throws CanonicalizationException
- * @throws java.io.IOException
- * @throws javax.xml.parsers.ParserConfigurationException
- * @throws org.xml.sax.SAXException
- */
- public byte[] canonicalize(byte[] inputBytes)
+ throw new RuntimeException("c14n class not found");
+ }
+ }
+
+ /**
+ * Method getURI
+ *
+ * @return the URI defined for this c14n instance.
+ */
+ public final String getURI() {
+ return this.canonicalizerSpi.engineGetURI();
+ }
+
+ /**
+ * Method getIncludeComments
+ *
+ * @return true if the c14n respect the comments.
+ */
+ public boolean getIncludeComments() {
+ return this.canonicalizerSpi.engineGetIncludeComments();
+ }
+
+ /**
+ * This method tries to canonicalize the given bytes. It's possible to even
+ * canonicalize non-wellformed sequences if they are well-formed after being
+ * wrapped with a <CODE>>a<...>/a<</CODE>.
+ *
+ * @param inputBytes
+ * @return the result of the conicalization.
+ * @throws CanonicalizationException
+ * @throws java.io.IOException
+ * @throws javax.xml.parsers.ParserConfigurationException
+ * @throws org.xml.sax.SAXException
+ */
+ public byte[] canonicalize(byte[] inputBytes)
throws javax.xml.parsers.ParserConfigurationException,
java.io.IOException, org.xml.sax.SAXException,
CanonicalizationException {
- ByteArrayInputStream bais = new ByteArrayInputStream(inputBytes);
- InputSource in = new InputSource(bais);
- DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
-
- dfactory.setNamespaceAware(true);
-
- // needs to validate for ID attribute nomalization
- dfactory.setValidating(true);
-
- DocumentBuilder db = dfactory.newDocumentBuilder();
-
- /*
- * for some of the test vectors from the specification,
- * there has to be a validatin parser for ID attributes, default
- * attribute values, NMTOKENS, etc.
- * Unfortunaltely, the test vectors do use different DTDs or
- * even no DTD. So Xerces 1.3.1 fires many warnings about using
- * ErrorHandlers.
- *
- * Text from the spec:
- *
- * The input octet stream MUST contain a well-formed XML document,
- * but the input need not be validated. However, the attribute
- * value normalization and entity reference resolution MUST be
- * performed in accordance with the behaviors of a validating
- * XML processor. As well, nodes for default attributes (declared
- * in the ATTLIST with an AttValue but not specified) are created
- * in each element. Thus, the declarations in the document type
- * declaration are used to help create the canonical form, even
- * though the document type declaration is not retained in the
- * canonical form.
- *
- */
- db.setErrorHandler(new com.sun.org.apache.xml.internal.security.utils
- .IgnoreAllErrorHandler());
-
- Document document = db.parse(in);
- byte result[] = this.canonicalizeSubtree(document);
-
- return result;
- }
-
- /**
- * Canonicalizes the subtree rooted by <CODE>node</CODE>.
- *
- * @param node The node to canicalize
- * @return the result of the c14n.
- *
- * @throws CanonicalizationException
- */
- public byte[] canonicalizeSubtree(Node node)
- throws CanonicalizationException {
- return this.canonicalizerSpi.engineCanonicalizeSubTree(node);
- }
-
- /**
- * Canonicalizes the subtree rooted by <CODE>node</CODE>.
- *
- * @param node
- * @param inclusiveNamespaces
- * @return the result of the c14n.
- * @throws CanonicalizationException
- */
- public byte[] canonicalizeSubtree(Node node, String inclusiveNamespaces)
- throws CanonicalizationException {
- return this.canonicalizerSpi.engineCanonicalizeSubTree(node,
+ ByteArrayInputStream bais = new ByteArrayInputStream(inputBytes);
+ InputSource in = new InputSource(bais);
+ DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
+
+ dfactory.setNamespaceAware(true);
+
+ // needs to validate for ID attribute nomalization
+ dfactory.setValidating(true);
+
+ DocumentBuilder db = dfactory.newDocumentBuilder();
+