[rhq] Branch 'release-3.0.1' - modules/enterprise
by mazz
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
New commits:
commit 5821f5de67f88ef148f86697bda01a06d964c89c
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jan 5 12:37:07 2012 -0500
fix the log message - we want to see the resource Ids so we need to convert the array to a string
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java
index 5c83563..ab3ed4d 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java
@@ -22,6 +22,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -842,7 +843,7 @@ public class MeasurementScheduleManagerBean implements MeasurementScheduleManage
}
}
} catch (Throwable t) {
- log.warn("problem creating schedules for resourceIds [" + resourceIds + "]", t);
+ log.warn("problem creating schedules for resourceIds [" + Arrays.toString(resourceIds) + "]", t);
}
return;
@@ -1341,4 +1342,4 @@ public class MeasurementScheduleManagerBean implements MeasurementScheduleManage
// }
// }
-}
\ No newline at end of file
+}
12 years, 5 months
[rhq] modules/enterprise
by mazz
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
New commits:
commit 08a2a27a85319bf47e512780f678e532229381c8
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jan 5 12:37:07 2012 -0500
fix the log message - we want to see the resource Ids so we need to convert the array to a string
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java
index e5df592..5b6b048 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java
@@ -23,6 +23,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -1008,7 +1009,7 @@ public class MeasurementScheduleManagerBean implements MeasurementScheduleManage
}
}
} catch (Throwable t) {
- log.warn("problem creating schedules for resourceIds [" + resourceIds + "]", t);
+ log.warn("problem creating schedules for resourceIds [" + Arrays.toString(resourceIds) + "]", t);
}
return;
12 years, 5 months
[rhq] modules/plugins
by lkrejci
modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit cf293cb3baf9e3d3447c16db0c181735d12c12e9
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Thu Jan 5 13:58:08 2012 +0100
[BZ 746113] - increasing the maximum wait time for the tomcat start/stop
scripts from 1s to 120s.
diff --git a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java
index f1e78f4..e9002f8 100644
--- a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java
+++ b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java
@@ -403,7 +403,7 @@ public class TomcatServerOperationsDelegate {
private void initProcessExecution(ProcessExecution processExecution) {
processExecution.setCaptureOutput(true);
- processExecution.setWaitForCompletion(1000L); // 1 second // TODO: Should we wait longer than one second?
+ processExecution.setWaitForCompletion(120000L); // 120 seconds - that should be safe? // TODO: make this configurable
processExecution.setKillOnTimeout(false);
}
12 years, 5 months
[rhq] Branch 'release-3.0.1' - modules/plugins
by lkrejci
modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit 6ef135fd2bbf36b77f82bfbeea8fb7f0f48c0409
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Thu Jan 5 13:58:08 2012 +0100
[BZ 746113] - increasing the maximum wait time for the tomcat start/stop
scripts from 1s to 120s.
diff --git a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java
index b0f3f7c..0f05866 100644
--- a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java
+++ b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java
@@ -402,7 +402,7 @@ public class TomcatServerOperationsDelegate {
private void initProcessExecution(ProcessExecution processExecution) {
processExecution.setCaptureOutput(true);
- processExecution.setWaitForCompletion(1000L); // 1 second // TODO: Should we wait longer than one second?
+ processExecution.setWaitForCompletion(120000L); // 120 seconds - that should be safe? // TODO: make this configurable
processExecution.setKillOnTimeout(false);
}
12 years, 5 months
[rhq] 2 commits - modules/enterprise modules/plugins
by Heiko W. Rupp
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/util/MeasurementDataManagerUtility.java | 14 +++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/MetricHandlerBean.java | 9 ++-
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java | 29 +++++++---
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java | 5 +
4 files changed, 40 insertions(+), 17 deletions(-)
New commits:
commit aa4ec7d05bb38856a664ba6996255780db44f3d2
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Jan 4 21:56:48 2012 +0100
BZ 770967 - the port expression may now also have a ${} expression.
BZ 766284 - Detect managed AS7 in domain mode
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
index 78b1543..0e58078 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
@@ -158,7 +158,8 @@ public class AbstractBaseDiscovery {
if (portString!=null && !portString.isEmpty()) {
- hp.port = Integer.valueOf(portString);
+ String tmp = replaceDollarExpression(portString,commandLine);
+ hp.port = Integer.valueOf(tmp);
}
else
hp.port = 9990; // Fallback to default
@@ -197,15 +198,24 @@ public class AbstractBaseDiscovery {
* -D jboss.bind.address.management
* or
* -b management
- * to find the management port
+ * to find the management addresss
*/
String ret=null;
for (String line: commandLine) {
- if (line.contains("-bmanagement") || line.contains("jboss.bind.address.management")) {
- ret = line.substring(line.indexOf("=")+1);
- break;
+ if (expression.contains("address")) {
+ if (line.contains("-bmanagement") || line.contains("jboss.bind.address.management")) {
+ ret = line.substring(line.indexOf("=")+1);
+ break;
+ }
}
+ else if (expression.contains("port")) {
+ if (line.contains(expression)) {
+ ret = line.substring(line.indexOf("=")+1);
+ break;
+ }
+ }
+
}
if (ret==null)
ret = fallback;
@@ -269,12 +279,17 @@ public class AbstractBaseDiscovery {
if (hostXml==null)
throw new IllegalArgumentException(CALL_READ_STANDALONE_OR_HOST_XML_FIRST);
- // TODO make realm variable
String fileName = obtainXmlPropertyViaXPath("//security-realms/security-realm[@name='" + realm + "']/authentication/properties/@path");
String relDir = obtainXmlPropertyViaXPath("//security-realms/security-realm[@name='" + realm + "']/authentication/properties/@relative-to");
+ String dmode;
+ if (mode==AS7Mode.STANDALONE)
+ dmode="server";
+ else
+ dmode="domain";
+
String fullName ;
- if (relDir.equals("jboss.server.config.dir"))
+ if (relDir.equals("jboss." + dmode + ".config.dir"))
fullName = baseDir + File.separator + mode.getBaseDir() + File.separator + "configuration" + File.separator + fileName;
else
fullName = relDir + File.separator + fileName;
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
index 3e90588..53afe21 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
@@ -35,6 +35,7 @@ import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.pluginapi.event.log.LogFileEventResourceComponentHelper;
import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
import org.rhq.core.pluginapi.inventory.ProcessScanResult;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
import org.rhq.core.system.ProcessInfo;
import org.rhq.modules.plugins.jbossas7.json.Address;
@@ -49,7 +50,7 @@ import org.rhq.modules.plugins.jbossas7.json.ReadResource;
* @author Heiko W. Rupp
*/
@SuppressWarnings("unused")
-public class ManagedASDiscovery extends AbstractBaseDiscovery
+public class ManagedASDiscovery extends AbstractBaseDiscovery implements ResourceDiscoveryComponent
{
@@ -144,7 +145,7 @@ public class ManagedASDiscovery extends AbstractBaseDiscovery
Address theAddress = new Address("server-group", serverGroup);
Operation op = new ReadResource(theAddress);
ComplexResult res = (ComplexResult) dcConnection.execute(op, true);
- if (res.isSuccess()) {
+ if (res!=null && res.isSuccess()) {
if (res.getResult().containsKey("socket-binding-group")) {
String sbg = (String) res.getResult().get("socket-binding-group");
commit 51d8b4632a497bdbdfe2ae154aafbf2631411452
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Jan 4 15:32:40 2012 +0100
Allow to submit a 'now' value - otherwise the 7days case will always be served from the 1h table as the Handler's now is some ms earlier than the utilities now.
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/util/MeasurementDataManagerUtility.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/util/MeasurementDataManagerUtility.java
index 0dfe0bb..f43820f 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/util/MeasurementDataManagerUtility.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/util/MeasurementDataManagerUtility.java
@@ -447,12 +447,12 @@ public class MeasurementDataManagerUtility {
return tables;
}
- /**
+ /**
* The raw tables starting at the specified index. Can be useful for getting the tables in a necessary time order (like
* oldest data first.
- *
- * @param startIndex >= 0. If >= TABLE_COUNT normalized via modulo.
- * @return Array of raw table names starting with the table with the specified index.
+ *
+ * @param startIndex >= 0. If >= TABLE_COUNT normalized via modulo.
+ * @return Array of raw table names starting with the table with the specified index.
*/
public static String[] getAllRawTables(int startIndex) {
String[] tables = new String[TABLE_COUNT];
@@ -465,9 +465,13 @@ public class MeasurementDataManagerUtility {
}
public static String[] getTables(long beginTime, long endTime) {
+ return getTables(beginTime, endTime, System.currentTimeMillis());
+ }
+
+ public static String[] getTables(long beginTime, long endTime, long now) {
List<String> tables = new ArrayList<String>();
- long now = System.currentTimeMillis();
+
if ((now - RAW_PURGE) < beginTime) {
int startIndex = getTableIndex(beginTime);
int endIndex = getTableIndex(endTime);
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/MetricHandlerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/MetricHandlerBean.java
index a772ab4..71a6a45 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/MetricHandlerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/MetricHandlerBean.java
@@ -407,14 +407,15 @@ public class MetricHandlerBean extends AbstractRestBean implements MetricHandle
MediaType mediaType = headers.getAcceptableMediaTypes().get(0);
+ long now = System.currentTimeMillis();
if (endTime==0)
- endTime = System.currentTimeMillis();
+ endTime = now;
if (startTime==0)
startTime = endTime - EIGHT_HOURS;
if (duration>0) // overrides start time
startTime = endTime - duration*1000L; // duration is in seconds
- if (startTime < System.currentTimeMillis()-7L*86400*1000)
+ if (startTime < now -7L*86400*1000)
throw new IllegalArgumentException("Start time is older than 7 days");
// Check if the schedule exists
@@ -425,6 +426,7 @@ public class MetricHandlerBean extends AbstractRestBean implements MetricHandle
so.startTime = startTime;
so.endTime = endTime;
so.mediaType = mediaType;
+ so.now = now-1; // pass this so that the for the 7days case is still handled from raw tables.
return so;
@@ -484,12 +486,13 @@ public class MetricHandlerBean extends AbstractRestBean implements MetricHandle
int scheduleId;
long startTime;
long endTime;
+ long now;
MediaType mediaType;
@Override
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
- String[] tables = MeasurementDataManagerUtility.getTables(startTime,endTime);
+ String[] tables = MeasurementDataManagerUtility.getTables(startTime,endTime,now);
StringBuilder sb = new StringBuilder();
for (int i = 0 ; i < tables.length ; i ++) {
sb.append("SELECT time_stamp,value FROM ");
12 years, 5 months
[rhq] modules/enterprise
by mazz
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/ResourceTypeTreeNodeBuilder.java | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
New commits:
commit d757cd72c10213f8888699095f7e5a1932427970
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Jan 4 17:27:03 2012 -0500
[BZ 759481] fix the NPE that occurred when quick clicking between the template screens
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/ResourceTypeTreeNodeBuilder.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/ResourceTypeTreeNodeBuilder.java
index afb7b31..72563c2 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/ResourceTypeTreeNodeBuilder.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/ResourceTypeTreeNodeBuilder.java
@@ -25,6 +25,7 @@ import java.util.Set;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridRecord;
+import com.smartgwt.client.widgets.tree.Tree;
import com.smartgwt.client.widgets.tree.TreeGrid;
import com.smartgwt.client.widgets.tree.TreeNode;
@@ -118,8 +119,7 @@ public abstract class ResourceTypeTreeNodeBuilder {
boolean isPlatform = (parentType.getCategory() == ResourceCategory.PLATFORM && isEmpty(parentType
.getParentResourceTypes()));
if (!isPlatform || !gotPlatform) {
- treeNodes
- .add(getTreeNodeInstance(composite, String.valueOf(parentType.getId())));
+ treeNodes.add(getTreeNodeInstance(composite, String.valueOf(parentType.getId())));
}
if (isPlatform) {
gotPlatform = true;
@@ -132,7 +132,11 @@ public abstract class ResourceTypeTreeNodeBuilder {
platformsGrid.setData(platformsRecords.toArray(new ListGridRecord[platformsRecords.size()]));
platformServicesGrid.setData(platformServicesRecords
.toArray(new ListGridRecord[platformServicesRecords.size()]));
- serversGrid.getTree().linkNodes(treeNodes.toArray(new TreeNode[treeNodes.size()]));
+ Tree tree = serversGrid.getTree();
+ if (tree != null) {
+ TreeNode[] treeNodeArray = treeNodes.toArray(new TreeNode[treeNodes.size()]);
+ tree.linkNodes(treeNodeArray);
+ }
}
@Override
12 years, 5 months
[rhq] modules/core
by Jay Shaughnessy
modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/DriftTemplateMapDatabaseUpgradeTask.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit 04000903b57864003ee41a86e013ddcc39ec4789
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Wed Jan 4 14:22:00 2012 -0500
[Bug 751778 - Upgrade from rhq4.1.0 to rhq4.2.0 fails with error : relation "rhq_drift_def_template" does not exist]
Fix query syntax for Oracle compatibility
diff --git a/modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/DriftTemplateMapDatabaseUpgradeTask.java b/modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/DriftTemplateMapDatabaseUpgradeTask.java
index 95d9ef7..386bd2a 100644
--- a/modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/DriftTemplateMapDatabaseUpgradeTask.java
+++ b/modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/DriftTemplateMapDatabaseUpgradeTask.java
@@ -74,7 +74,7 @@ public class DriftTemplateMapDatabaseUpgradeTask implements DatabaseUpgradeTask
+ " from RHQ_DRIFT_DEF_TEMPLATE dt" //
+ " join RHQ_RESOURCE_TYPE rt on dt.RESOURCE_TYPE_ID = rt.ID" //
+ " join RHQ_RESOURCE res on rt.ID = res.RESOURCE_TYPE_ID" //
- + " and dd.RESOURCE_ID = res.ID" //
+ + " where dd.RESOURCE_ID = res.ID" //
+ " )" //
+ " where dd.DRIFT_DEF_TEMPLATE_ID is null";
12 years, 5 months
[rhq] .classpath
by Jay Shaughnessy
.classpath | 1 +
1 file changed, 1 insertion(+)
New commits:
commit 0db0f28f90897d71b3c992d802e58dc091ff2b7e
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Wed Jan 4 10:31:51 2012 -0500
add jboss-sasl jar (as-7 plugin dep) to eclipse build path
diff --git a/.classpath b/.classpath
index 24fb54d..9eaf31b 100644
--- a/.classpath
+++ b/.classpath
@@ -124,6 +124,7 @@
<classpathentry exported="true" kind="var" path="M2_REPO/org/jboss/resteasy/resteasy-jaxrs/2.2.1.GA/resteasy-jaxrs-2.2.1.GA.jar"/>
<classpathentry exported="true" kind="var" path="M2_REPO/org/jboss/resteasy/resteasy-jettison-provider/2.2.1.GA/resteasy-jettison-provider-2.2.1.GA.jar"/>
<classpathentry exported="true" kind="var" path="M2_REPO/org/jboss/resteasy/jaxrs-api/2.2.1.GA/jaxrs-api-2.2.1.GA.jar"/>
+ <classpathentry exported="true" kind="var" path="M2_REPO/org/jboss/sasl/jboss-sasl/1.0.0.Beta9/jboss-sasl-1.0.0.Beta9.jar"/>
<classpathentry kind="src" path="modules/common/ant-bundle/src/main/java"/>
<classpathentry kind="src" path="modules/enterprise/server/itests/src/test/java"/>
<classpathentry kind="src" path="modules/enterprise/server/plugins/drift-mongodb/src/main/java"/>
12 years, 5 months
[rhq] modules/enterprise
by lkrejci
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/AccessCheckingContextDecorator.java | 237 ---------
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/AccessCheckingInitialContextFactoryBuilder.java | 89 ++-
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/AccessCheckingInitialContextFactoryDecorator.java | 60 --
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/DecoratingInitialContextFactory.java | 63 ++
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/URLPreferringContext.java | 105 ----
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/URLPreferringInitialContextFactoryDecorator.java | 52 --
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingContextDecorator.java | 254 ++++++++++
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingDirContextDecorator.java | 187 +++++++
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingEventContextDecorator.java | 69 ++
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingEventDirContextDecorator.java | 96 +++
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingLdapContextDecorator.java | 85 +++
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/ContextDecorator.java | 33 +
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/ContextDecoratorPicker.java | 162 ++++++
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringContextDecorator.java | 212 ++++++++
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringContextDecoratorHelper.java | 76 ++
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringDirContextDecorator.java | 185 +++++++
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringEventContextDecorator.java | 81 +++
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringEventDirContextDecorator.java | 104 ++++
modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringLdapContextDecorator.java | 94 +++
modules/enterprise/server/itests/pom.xml | 6
20 files changed, 1779 insertions(+), 471 deletions(-)
New commits:
commit 51fbaef6a41e324118e069b7b5b8915526c2dc34
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Jan 4 14:15:57 2012 +0100
Adding support for Ldap, Dir, Event and EventDir contexts in addition to
the normal JNDI contexts in our JNDI security wrappers. This should unbreak
the LDAP support in the RHQ server.
Fixed enterprise/server/itests tests.
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/AccessCheckingContextDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/AccessCheckingContextDecorator.java
deleted file mode 100644
index df42afe..0000000
--- a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/AccessCheckingContextDecorator.java
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program 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 for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-package org.rhq.jndi;
-
-import java.util.Arrays;
-import java.util.Hashtable;
-import java.util.List;
-
-import javax.naming.Binding;
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NameClassPair;
-import javax.naming.NameParser;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-
-/**
- * This is the "meat" of the RHQ's secured JNDI access. This {@link Context} decorator
- * applied security checks in each method (lookups, (un)bindings, etc).
- * <p>
- * The security check consists of checking if the current callstack has the {@link AllowRhqServerInternalsAccessPermission}.
- * <p>
- * This decorator applies the security check on any JNDI name without a scheme and
- * on any name that has a scheme listed in the {@link #checkedSchemes} list supplied
- * in the constructor.
- *
- * @author Lukas Krejci
- */
-public class AccessCheckingContextDecorator implements Context {
-
- private static final AllowRhqServerInternalsAccessPermission PERM = new AllowRhqServerInternalsAccessPermission();
- private Context original;
- private List<String> checkedSchemes;
-
- public AccessCheckingContextDecorator(Context original, String... checkedSchemes) {
- this.original = original;
- this.checkedSchemes = Arrays.asList(checkedSchemes);
- }
-
- private static void check() {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) sm.checkPermission(PERM);
- }
-
- private void checkScheme(String scheme) {
- if (scheme == null || checkedSchemes.contains(scheme)) {
- check();
- }
- }
-
- private void check(String name) {
- checkScheme(getURLScheme(name));
- }
-
- private void check(Name name) {
- if (name.size() == 0) {
- check();
- } else {
- String first = name.get(0);
- checkScheme(getURLScheme(first));
- }
- }
-
- public Object lookup(Name name) throws NamingException {
- check(name);
- return original.lookup(name);
- }
-
- public Object lookup(String name) throws NamingException {
- check(name);
- return original.lookup(name);
- }
-
- public void bind(Name name, Object obj) throws NamingException {
- check(name);
- original.bind(name, obj);
- }
-
- public void bind(String name, Object obj) throws NamingException {
- check(name);
- original.bind(name, obj);
- }
-
- public void rebind(Name name, Object obj) throws NamingException {
- check(name);
- original.rebind(name, obj);
- }
-
- public void rebind(String name, Object obj) throws NamingException {
- check(name);
- original.rebind(name, obj);
- }
-
- public void unbind(Name name) throws NamingException {
- check(name);
- original.unbind(name);
- }
-
- public void unbind(String name) throws NamingException {
- check(name);
- original.unbind(name);
- }
-
- public void rename(Name oldName, Name newName) throws NamingException {
- check(oldName);
- check(newName);
- original.rename(oldName, newName);
- }
-
- public void rename(String oldName, String newName) throws NamingException {
- check(oldName);
- check(newName);
- original.rename(oldName, newName);
- }
-
- public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
- check(name);
- return original.list(name);
- }
-
- public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
- check(name);
- return original.list(name);
- }
-
- public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
- check(name);
- return original.listBindings(name);
- }
-
- public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
- check(name);
- return original.listBindings(name);
- }
-
- public void destroySubcontext(Name name) throws NamingException {
- check(name);
- original.destroySubcontext(name);
- }
-
- public void destroySubcontext(String name) throws NamingException {
- check(name);
- original.destroySubcontext(name);
- }
-
- public Context createSubcontext(Name name) throws NamingException {
- check(name);
- return original.createSubcontext(name);
- }
-
- public Context createSubcontext(String name) throws NamingException {
- check(name);
- return original.createSubcontext(name);
- }
-
- public Object lookupLink(Name name) throws NamingException {
- check(name);
- return original.lookupLink(name);
- }
-
- public Object lookupLink(String name) throws NamingException {
- check(name);
- return original.lookupLink(name);
- }
-
- public NameParser getNameParser(Name name) throws NamingException {
- check(name);
- return original.getNameParser(name);
- }
-
- public NameParser getNameParser(String name) throws NamingException {
- check(name);
- return original.getNameParser(name);
- }
-
- public Name composeName(Name name, Name prefix) throws NamingException {
- check(name);
- return original.composeName(name, prefix);
- }
-
- public String composeName(String name, String prefix) throws NamingException {
- check(name);
- return original.composeName(name, prefix);
- }
-
- public Object addToEnvironment(String propName, Object propVal) throws NamingException {
- check();
- return original.addToEnvironment(propName, propVal);
- }
-
- public Object removeFromEnvironment(String propName) throws NamingException {
- check();
- return original.removeFromEnvironment(propName);
- }
-
- public Hashtable<?, ?> getEnvironment() throws NamingException {
- check();
- return original.getEnvironment();
- }
-
- public void close() throws NamingException {
- check();
- original.close();
- }
-
- public String getNameInNamespace() throws NamingException {
- check();
- return original.getNameInNamespace();
- }
-
- //copied from InitialContext
- private static String getURLScheme(String str) {
- int colon_posn = str.indexOf(':');
- int slash_posn = str.indexOf('/');
-
- if (colon_posn > 0 && (slash_posn == -1 || colon_posn < slash_posn))
- return str.substring(0, colon_posn);
- return null;
- }
-}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/AccessCheckingInitialContextFactoryBuilder.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/AccessCheckingInitialContextFactoryBuilder.java
index e529347..60e9bf6 100644
--- a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/AccessCheckingInitialContextFactoryBuilder.java
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/AccessCheckingInitialContextFactoryBuilder.java
@@ -27,6 +27,7 @@ import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
@@ -43,6 +44,18 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jnp.interfaces.NamingContextFactory;
+import org.rhq.jndi.context.AccessCheckingContextDecorator;
+import org.rhq.jndi.context.AccessCheckingDirContextDecorator;
+import org.rhq.jndi.context.AccessCheckingEventContextDecorator;
+import org.rhq.jndi.context.AccessCheckingEventDirContextDecorator;
+import org.rhq.jndi.context.AccessCheckingLdapContextDecorator;
+import org.rhq.jndi.context.ContextDecoratorPicker;
+import org.rhq.jndi.context.URLPreferringContextDecorator;
+import org.rhq.jndi.context.URLPreferringDirContextDecorator;
+import org.rhq.jndi.context.URLPreferringEventContextDecorator;
+import org.rhq.jndi.context.URLPreferringEventDirContextDecorator;
+import org.rhq.jndi.context.URLPreferringLdapContextDecorator;
+
/**
* This initial context factory builder is installed early on during the RHQ server startup
* and is later on used for obtaining the {@link Context}s for all JNDI lookups in the
@@ -67,7 +80,7 @@ import org.jnp.interfaces.NamingContextFactory;
*/
public class AccessCheckingInitialContextFactoryBuilder implements InitialContextFactoryBuilder {
private static final Log LOG = LogFactory.getLog(AccessCheckingInitialContextFactoryBuilder.class);
-
+
/**
* The list of JNDI name schemes that should be checked for security permissions
* (in addition to the names with no scheme).
@@ -79,14 +92,14 @@ public class AccessCheckingInitialContextFactoryBuilder implements InitialContex
private static final Set<InetAddress> SERVER_BIND_IPS;
static {
SERVER_BIND_IPS = new HashSet<InetAddress>();
-
+
try {
String bindingAddressString = System.getProperty("jboss.bind.address");
InetAddress bindingAddress = InetAddress.getByName(bindingAddressString);
-
+
if (bindingAddress.isAnyLocalAddress()) {
Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
- while(ifaces.hasMoreElements()) {
+ while (ifaces.hasMoreElements()) {
NetworkInterface iface = ifaces.nextElement();
SERVER_BIND_IPS.addAll(Collections.list(iface.getInetAddresses()));
}
@@ -97,11 +110,12 @@ public class AccessCheckingInitialContextFactoryBuilder implements InitialContex
LOG.error("Could not obtain the list of local IPs", e);
} catch (UnknownHostException e) {
LOG.error("Failed to get the binding address of the RHQ server.", e);
- }
+ }
}
-
- private static final int JNP_PORT = Integer.parseInt(System.getProperty("rhq.server.startup.namingservice.port", "2099"));
-
+
+ private static final int JNP_PORT = Integer.parseInt(System.getProperty("rhq.server.startup.namingservice.port",
+ "2099"));
+
/**
* This is the default initial context factory that is returned when no other is
* configured using the environment variables.
@@ -147,31 +161,72 @@ public class AccessCheckingInitialContextFactoryBuilder implements InitialContex
});
}
- private static InitialContextFactory createSecureWrapper(InitialContextFactory factory, Hashtable<?, ?> environment) {
+ private static InitialContextFactory
+ createSecureWrapper(InitialContextFactory factory, Hashtable<?, ?> environment) {
String providerUrl = (String) environment.get(Context.PROVIDER_URL);
-
+
if (providerUrl == null) {
- return new AccessCheckingInitialContextFactoryDecorator(factory, CHECKED_SCHEMES);
+ return getAccessCheckingFactory(factory);
} else {
try {
URI uri = new URI(providerUrl);
InetAddress providerHost = InetAddress.getByName(uri.getHost());
-
+
//check if we are accessing the RHQ server through some remoting
//interface.
- if (uri.getPort() == JNP_PORT && SERVER_BIND_IPS.contains(providerHost)) {
- return new AccessCheckingInitialContextFactoryDecorator(factory, CHECKED_SCHEMES);
+ if (uri.getPort() == JNP_PORT && SERVER_BIND_IPS.contains(providerHost)) {
+ return getAccessCheckingFactory(factory);
} else {
- return new URLPreferringInitialContextFactoryDecorator(factory);
+ return getURLPreferringFactory(factory);
}
} catch (URISyntaxException e) {
- return new AccessCheckingInitialContextFactoryDecorator(factory, CHECKED_SCHEMES);
+ return getAccessCheckingFactory(factory);
} catch (UnknownHostException e) {
//let the factory deal with the unknown host...
//this most probably shouldn't be secured because localhost addresses
//should be resolvable.
- return new URLPreferringInitialContextFactoryDecorator(factory);
+ return getURLPreferringFactory(factory);
}
}
}
+
+ private static InitialContextFactory getAccessCheckingFactory(InitialContextFactory original) {
+ return new DecoratingInitialContextFactory(original, Arrays.asList(
+ getURLPreferringDecoratorPicker(), getAccessCheckingDecoratorPicker()));
+ }
+
+ private static InitialContextFactory getURLPreferringFactory(InitialContextFactory original) {
+ return new DecoratingInitialContextFactory(original, Arrays.asList(
+ getURLPreferringDecoratorPicker()));
+ }
+
+ private static ContextDecoratorPicker getAccessCheckingDecoratorPicker() {
+ ContextDecoratorPicker ret = new ContextDecoratorPicker();
+
+ ret.setConstructorParameters(new Object[] { CHECKED_SCHEMES });
+ ret.setConstructorParameterTypes(new Class<?>[] { String[].class });
+
+ ret.getPossibleDecorators().add(AccessCheckingContextDecorator.class);
+ ret.getPossibleDecorators().add(AccessCheckingDirContextDecorator.class);
+ ret.getPossibleDecorators().add(AccessCheckingEventContextDecorator.class);
+ ret.getPossibleDecorators().add(AccessCheckingEventDirContextDecorator.class);
+ ret.getPossibleDecorators().add(AccessCheckingLdapContextDecorator.class);
+
+ return ret;
+ }
+
+ private static ContextDecoratorPicker getURLPreferringDecoratorPicker() {
+ ContextDecoratorPicker ret = new ContextDecoratorPicker();
+
+ ret.setConstructorParameters(null);
+ ret.setConstructorParameterTypes(null);
+
+ ret.getPossibleDecorators().add(URLPreferringContextDecorator.class);
+ ret.getPossibleDecorators().add(URLPreferringDirContextDecorator.class);
+ ret.getPossibleDecorators().add(URLPreferringEventContextDecorator.class);
+ ret.getPossibleDecorators().add(URLPreferringEventDirContextDecorator.class);
+ ret.getPossibleDecorators().add(URLPreferringLdapContextDecorator.class);
+
+ return ret;
+ }
}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/AccessCheckingInitialContextFactoryDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/AccessCheckingInitialContextFactoryDecorator.java
deleted file mode 100644
index b23935f..0000000
--- a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/AccessCheckingInitialContextFactoryDecorator.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program 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 for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-package org.rhq.jndi;
-
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.spi.InitialContextFactory;
-
-/**
- * A decorator of an {@link InitialContextFactory} that adds the security checking
- * machinery to the returned initial contexts.
- *
- * @author Lukas Krejci
- */
-public class AccessCheckingInitialContextFactoryDecorator extends URLPreferringInitialContextFactoryDecorator {
-
- private final String[] checkedSchemes;
-
- /**
- * @param factory the factory to wrap
- * @param checkedSchemes the list of JNDI name schemes to check for permissions
- * @see AccessCheckingContextDecorator
- */
- public AccessCheckingInitialContextFactoryDecorator(InitialContextFactory factory, String... checkedSchemes) {
- super(factory);
- this.checkedSchemes = checkedSchemes;
- }
-
- /**
- * @param environment the environment variables for the return {@link Context} to use
- *
- * @return the initial context returned by the decorated factory wrapped in
- * {@link URLPreferringContext} and {@link AccessCheckingContextDecorator} in that
- * order.
- */
- @Override
- public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
- return new AccessCheckingContextDecorator(super.getInitialContext(environment), checkedSchemes);
- }
-
-}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/DecoratingInitialContextFactory.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/DecoratingInitialContextFactory.java
new file mode 100644
index 0000000..2414c98
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/DecoratingInitialContextFactory.java
@@ -0,0 +1,63 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi;
+
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+
+import org.rhq.jndi.context.ContextDecoratorPicker;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public class DecoratingInitialContextFactory implements InitialContextFactory {
+
+ private List<ContextDecoratorPicker> pickers;
+ private InitialContextFactory factory;
+
+ public DecoratingInitialContextFactory(InitialContextFactory factory, List<ContextDecoratorPicker> decoratorPickers) {
+ this.factory = factory;
+ this.pickers = decoratorPickers;
+ }
+
+ public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
+ Context ctx = factory.getInitialContext(environment);
+
+ try {
+ for(ContextDecoratorPicker picker : pickers) {
+ ctx = picker.wrapInAppropriateDecorator(ctx);
+ }
+ } catch (IllegalArgumentException e) {
+ NamingException ex = new NamingException();
+ ex.initCause(ex);
+
+ throw e;
+ }
+
+ return ctx;
+ }
+
+}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/URLPreferringContext.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/URLPreferringContext.java
deleted file mode 100644
index c6456a2..0000000
--- a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/URLPreferringContext.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program 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 for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-package org.rhq.jndi;
-
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.Name;
-import javax.naming.NamingException;
-import javax.naming.spi.InitialContextFactory;
-import javax.naming.spi.NamingManager;
-
-/**
- * This is a modification of the default {@link InitialContext} class that
- * ignores the initial context factory builder when constructing the default
- * context to use in lookups etc.
- * <p>
- * This is important because RHQ server has its own initial context factory
- * builder that creates factories that in turn create contexts. If the default
- * {@link InitialContext} implementation was used, we'd never be able to lookup
- * scheme-based names because the default implementation of the {@link InitialContext}
- * always uses the default context of the builder if one is installed no matter
- * the scheme in the name.
- * <p>
- * The {@link AccessCheckingInitialContextFactoryBuilder} wraps the context returned
- * by the factory in an instance of this class and thus is restoring the original
- * intended behavior of the {@link InitialContext}. It looks at the name being looked
- * up (bound or whatever) and prefers to use the URL context factories if the name
- * contains the scheme (as does the {@link InitialContext} if no builder is installed).
- * If the name doesn't contain a scheme, the provided default context factory is used to
- * look up the name.
- *
- * @author Lukas Krejci
- */
-public class URLPreferringContext extends InitialContext {
-
- public URLPreferringContext(InitialContextFactory defaultContextFactory) throws NamingException {
- super(true);
- this.defaultInitCtx = defaultContextFactory.getInitialContext(null);
- this.gotDefault = true;
- init(null);
- }
-
- public URLPreferringContext(Hashtable<?, ?> environment, InitialContextFactory defaultContextFactory) throws NamingException {
- super(true);
- this.defaultInitCtx = defaultContextFactory.getInitialContext(environment);
- this.gotDefault = true;
- init(environment);
- }
-
- @Override
- protected Context getURLOrDefaultInitCtx(Name name) throws NamingException {
- if (name.size() > 0) {
- String first = name.get(0);
- String scheme = getURLScheme(first);
- if (scheme != null) {
- Context ctx = NamingManager.getURLContext(scheme, myProps);
- if (ctx != null) {
- return ctx;
- }
- }
- }
- return getDefaultInitCtx();
- }
-
- @Override
- protected Context getURLOrDefaultInitCtx(String name) throws NamingException {
- String scheme = getURLScheme(name);
- if (scheme != null) {
- Context ctx = NamingManager.getURLContext(scheme, myProps);
- if (ctx != null) {
- return ctx;
- }
- }
- return getDefaultInitCtx();
- }
-
- //copied from InitialContext
- private static String getURLScheme(String str) {
- int colon_posn = str.indexOf(':');
- int slash_posn = str.indexOf('/');
-
- if (colon_posn > 0 && (slash_posn == -1 || colon_posn < slash_posn))
- return str.substring(0, colon_posn);
- return null;
- }
-}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/URLPreferringInitialContextFactoryDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/URLPreferringInitialContextFactoryDecorator.java
deleted file mode 100644
index 609e98c..0000000
--- a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/URLPreferringInitialContextFactoryDecorator.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program 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 for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-package org.rhq.jndi;
-
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.spi.InitialContextFactory;
-
-/**
- * A decorator of an {@link InitialContextFactory} that returns an {@link URLPreferringContext}
- * backed by the wrapped initial context factory.
- * <p>
- * This is to support contexts that don't need to be secured, yet we need to make sure to
- * re-enable lookup of scheme-based names.
- *
- * @author Lukas Krejci
- */
-public class URLPreferringInitialContextFactoryDecorator implements InitialContextFactory {
-
- private final InitialContextFactory factory;
-
- public URLPreferringInitialContextFactoryDecorator(InitialContextFactory factory) {
- this.factory = factory;
- }
-
- public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
- return new URLPreferringContext(environment, getFactory());
- }
-
- protected InitialContextFactory getFactory() {
- return factory;
- }
-}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingContextDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingContextDecorator.java
new file mode 100644
index 0000000..6bfec7e
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingContextDecorator.java
@@ -0,0 +1,254 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi.context;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+import org.rhq.jndi.AllowRhqServerInternalsAccessPermission;
+
+/**
+ * This is the "meat" of the RHQ's secured JNDI access. This {@link Context} decorator
+ * applied security checks in each method (lookups, (un)bindings, etc).
+ * <p>
+ * The security check consists of checking if the current callstack has the {@link AllowRhqServerInternalsAccessPermission}.
+ * <p>
+ * This decorator applies the security check on any JNDI name without a scheme and
+ * on any name that has a scheme listed in the {@link #checkedSchemes} list supplied
+ * in the constructor.
+ *
+ * @author Lukas Krejci
+ */
+public class AccessCheckingContextDecorator implements Context, ContextDecorator, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final AllowRhqServerInternalsAccessPermission PERM = new AllowRhqServerInternalsAccessPermission();
+ private Context original;
+ private List<String> checkedSchemes;
+
+ public AccessCheckingContextDecorator(String... checkedSchemes) {
+ this.checkedSchemes = Arrays.asList(checkedSchemes);
+ }
+
+ public AccessCheckingContextDecorator(Context original, String... checkedSchemes) {
+ this.original = original;
+ this.checkedSchemes = Arrays.asList(checkedSchemes);
+ }
+
+ public void init(Context ctx) {
+ this.original = ctx;
+ }
+
+ protected Context getOriginal() {
+ return original;
+ }
+
+ protected static void check() {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) sm.checkPermission(PERM);
+ }
+
+ private void checkScheme(String scheme) {
+ if (scheme == null || checkedSchemes.contains(scheme)) {
+ check();
+ }
+ }
+
+ protected void check(String name) {
+ checkScheme(getURLScheme(name));
+ }
+
+ protected void check(Name name) {
+ if (name.size() == 0) {
+ check();
+ } else {
+ String first = name.get(0);
+ checkScheme(getURLScheme(first));
+ }
+ }
+
+ public Object lookup(Name name) throws NamingException {
+ check(name);
+ return original.lookup(name);
+ }
+
+ public Object lookup(String name) throws NamingException {
+ check(name);
+ return original.lookup(name);
+ }
+
+ public void bind(Name name, Object obj) throws NamingException {
+ check(name);
+ original.bind(name, obj);
+ }
+
+ public void bind(String name, Object obj) throws NamingException {
+ check(name);
+ original.bind(name, obj);
+ }
+
+ public void rebind(Name name, Object obj) throws NamingException {
+ check(name);
+ original.rebind(name, obj);
+ }
+
+ public void rebind(String name, Object obj) throws NamingException {
+ check(name);
+ original.rebind(name, obj);
+ }
+
+ public void unbind(Name name) throws NamingException {
+ check(name);
+ original.unbind(name);
+ }
+
+ public void unbind(String name) throws NamingException {
+ check(name);
+ original.unbind(name);
+ }
+
+ public void rename(Name oldName, Name newName) throws NamingException {
+ check(oldName);
+ check(newName);
+ original.rename(oldName, newName);
+ }
+
+ public void rename(String oldName, String newName) throws NamingException {
+ check(oldName);
+ check(newName);
+ original.rename(oldName, newName);
+ }
+
+ public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
+ check(name);
+ return original.list(name);
+ }
+
+ public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
+ check(name);
+ return original.list(name);
+ }
+
+ public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
+ check(name);
+ return original.listBindings(name);
+ }
+
+ public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
+ check(name);
+ return original.listBindings(name);
+ }
+
+ public void destroySubcontext(Name name) throws NamingException {
+ check(name);
+ original.destroySubcontext(name);
+ }
+
+ public void destroySubcontext(String name) throws NamingException {
+ check(name);
+ original.destroySubcontext(name);
+ }
+
+ public Context createSubcontext(Name name) throws NamingException {
+ check(name);
+ return original.createSubcontext(name);
+ }
+
+ public Context createSubcontext(String name) throws NamingException {
+ check(name);
+ return original.createSubcontext(name);
+ }
+
+ public Object lookupLink(Name name) throws NamingException {
+ check(name);
+ return original.lookupLink(name);
+ }
+
+ public Object lookupLink(String name) throws NamingException {
+ check(name);
+ return original.lookupLink(name);
+ }
+
+ public NameParser getNameParser(Name name) throws NamingException {
+ check(name);
+ return original.getNameParser(name);
+ }
+
+ public NameParser getNameParser(String name) throws NamingException {
+ check(name);
+ return original.getNameParser(name);
+ }
+
+ public Name composeName(Name name, Name prefix) throws NamingException {
+ check(name);
+ return original.composeName(name, prefix);
+ }
+
+ public String composeName(String name, String prefix) throws NamingException {
+ check(name);
+ return original.composeName(name, prefix);
+ }
+
+ public Object addToEnvironment(String propName, Object propVal) throws NamingException {
+ check();
+ return original.addToEnvironment(propName, propVal);
+ }
+
+ public Object removeFromEnvironment(String propName) throws NamingException {
+ check();
+ return original.removeFromEnvironment(propName);
+ }
+
+ public Hashtable<?, ?> getEnvironment() throws NamingException {
+ check();
+ return original.getEnvironment();
+ }
+
+ public void close() throws NamingException {
+ check();
+ original.close();
+ }
+
+ public String getNameInNamespace() throws NamingException {
+ check();
+ return original.getNameInNamespace();
+ }
+
+ //copied from InitialContext
+ private static String getURLScheme(String str) {
+ int colon_posn = str.indexOf(':');
+ int slash_posn = str.indexOf('/');
+
+ if (colon_posn > 0 && (slash_posn == -1 || colon_posn < slash_posn))
+ return str.substring(0, colon_posn);
+ return null;
+ }
+}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingDirContextDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingDirContextDecorator.java
new file mode 100644
index 0000000..1614180
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingDirContextDecorator.java
@@ -0,0 +1,187 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi.context;
+
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+/**
+ * A decorator of {@link DirContext}.
+ *
+ * @author Lukas Krejci
+ */
+public class AccessCheckingDirContextDecorator extends AccessCheckingContextDecorator implements DirContext {
+
+ private static final long serialVersionUID = 1L;
+
+ public AccessCheckingDirContextDecorator(String... checkedSchemes) {
+ super(checkedSchemes);
+ }
+
+ public AccessCheckingDirContextDecorator(DirContext original, String... checkedSchemes) {
+ super(original, checkedSchemes);
+ }
+
+ @Override
+ protected DirContext getOriginal() {
+ return (DirContext) super.getOriginal();
+ }
+
+ public Attributes getAttributes(Name name) throws NamingException {
+ check(name);
+ return getOriginal().getAttributes(name);
+ }
+
+ public Attributes getAttributes(String name) throws NamingException {
+ check(name);
+ return getOriginal().getAttributes(name);
+ }
+
+ public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
+ check(name);
+ return getOriginal().getAttributes(name, attrIds);
+ }
+
+ public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
+ check(name);
+ return getOriginal().getAttributes(name, attrIds);
+ }
+
+ public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
+ check(name);
+ getOriginal().modifyAttributes(name, mod_op, attrs);
+ }
+
+ public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
+ check(name);
+ getOriginal().modifyAttributes(name, mod_op, attrs);
+ }
+
+ public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
+ check(name);
+ getOriginal().modifyAttributes(name, mods);
+ }
+
+ public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
+ check(name);
+ getOriginal().modifyAttributes(name, mods);
+ }
+
+ public void bind(Name name, Object obj, Attributes attrs) throws NamingException {
+ check(name);
+ getOriginal().bind(name, obj, attrs);
+ }
+
+ public void bind(String name, Object obj, Attributes attrs) throws NamingException {
+ check(name);
+ getOriginal().bind(name, obj, attrs);
+ }
+
+ public void rebind(Name name, Object obj, Attributes attrs) throws NamingException {
+ check(name);
+ getOriginal().rebind(name, obj, attrs);
+ }
+
+ public void rebind(String name, Object obj, Attributes attrs) throws NamingException {
+ check(name);
+ getOriginal().rebind(name, obj, attrs);
+ }
+
+ public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
+ check(name);
+ return getOriginal().createSubcontext(name, attrs);
+ }
+
+ public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
+ check(name);
+ return getOriginal().createSubcontext(name, attrs);
+ }
+
+ public DirContext getSchema(Name name) throws NamingException {
+ check(name);
+ return getOriginal().getSchema(name);
+ }
+
+ public DirContext getSchema(String name) throws NamingException {
+ check(name);
+ return getOriginal().getSchema(name);
+ }
+
+ public DirContext getSchemaClassDefinition(Name name) throws NamingException {
+ check(name);
+ return getOriginal().getSchemaClassDefinition(name);
+ }
+
+ public DirContext getSchemaClassDefinition(String name) throws NamingException {
+ check(name);
+ return getOriginal().getSchema(name);
+ }
+
+ public NamingEnumeration<SearchResult>
+ search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
+ check(name);
+ return getOriginal().search(name, matchingAttributes, attributesToReturn);
+ }
+
+ public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes,
+ String[] attributesToReturn) throws NamingException {
+ check(name);
+ return getOriginal().search(name, matchingAttributes, attributesToReturn);
+ }
+
+ public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes) throws NamingException {
+ check(name);
+ return getOriginal().search(name, matchingAttributes);
+ }
+
+ public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes) throws NamingException {
+ check(name);
+ return getOriginal().search(name, matchingAttributes);
+ }
+
+ public NamingEnumeration<SearchResult> search(Name name, String filter, SearchControls cons) throws NamingException {
+ check(name);
+ return getOriginal().search(name, filter, cons);
+ }
+
+ public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls cons)
+ throws NamingException {
+ check(name);
+ return getOriginal().search(name, filter, cons);
+ }
+
+ public NamingEnumeration<SearchResult>
+ search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
+ check(name);
+ return getOriginal().search(name, filterExpr, filterArgs, cons);
+ }
+
+ public NamingEnumeration<SearchResult> search(String name, String filterExpr, Object[] filterArgs,
+ SearchControls cons) throws NamingException {
+ check(name);
+ return getOriginal().search(name, filterExpr, filterArgs, cons);
+ }
+}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingEventContextDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingEventContextDecorator.java
new file mode 100644
index 0000000..67a9527
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingEventContextDecorator.java
@@ -0,0 +1,69 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi.context;
+
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.event.EventContext;
+import javax.naming.event.NamingListener;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public class AccessCheckingEventContextDecorator extends AccessCheckingContextDecorator implements EventContext {
+
+ private static final long serialVersionUID = 1L;
+
+ public AccessCheckingEventContextDecorator(String... checkedSchemes) {
+ super(checkedSchemes);
+ }
+
+ public AccessCheckingEventContextDecorator(EventContext original, String... checkedSchemes) {
+ super(original, checkedSchemes);
+ }
+
+ @Override
+ protected EventContext getOriginal() {
+ return (EventContext) super.getOriginal();
+ }
+
+ public void addNamingListener(Name target, int scope, NamingListener l) throws NamingException {
+ check(target);
+ getOriginal().addNamingListener(target, scope, l);
+ }
+
+ public void addNamingListener(String target, int scope, NamingListener l) throws NamingException {
+ check(target);
+ getOriginal().addNamingListener(target, scope, l);
+ }
+
+ public void removeNamingListener(NamingListener l) throws NamingException {
+ check();
+ getOriginal().removeNamingListener(l);
+ }
+
+ public boolean targetMustExist() throws NamingException {
+ check();
+ return getOriginal().targetMustExist();
+ }
+
+}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingEventDirContextDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingEventDirContextDecorator.java
new file mode 100644
index 0000000..ed7a848
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingEventDirContextDecorator.java
@@ -0,0 +1,96 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi.context;
+
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.directory.SearchControls;
+import javax.naming.event.EventDirContext;
+import javax.naming.event.NamingListener;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public class AccessCheckingEventDirContextDecorator extends AccessCheckingDirContextDecorator implements
+ EventDirContext {
+
+ private static final long serialVersionUID = 1L;
+
+ public AccessCheckingEventDirContextDecorator(String... checkedSchemes) {
+ super(checkedSchemes);
+ }
+
+ public AccessCheckingEventDirContextDecorator(EventDirContext original, String... checkedSchemes) {
+ super(original, checkedSchemes);
+ }
+
+ @Override
+ protected EventDirContext getOriginal() {
+ return (EventDirContext) super.getOriginal();
+ }
+
+ public void addNamingListener(Name target, int scope, NamingListener l) throws NamingException {
+ check(target);
+ getOriginal().addNamingListener(target, scope, l);
+ }
+
+ public void addNamingListener(String target, int scope, NamingListener l) throws NamingException {
+ check(target);
+ getOriginal().addNamingListener(target, scope, l);
+ }
+
+ public void removeNamingListener(NamingListener l) throws NamingException {
+ check();
+ getOriginal().removeNamingListener(l);
+ }
+
+ public boolean targetMustExist() throws NamingException {
+ check();
+ return getOriginal().targetMustExist();
+ }
+
+ public void addNamingListener(Name target, String filter, SearchControls ctls, NamingListener l)
+ throws NamingException {
+ check(target);
+ getOriginal().addNamingListener(target, filter, ctls, l);
+ }
+
+ public void addNamingListener(String target, String filter, SearchControls ctls, NamingListener l)
+ throws NamingException {
+ check(target);
+ getOriginal().addNamingListener(target, filter, ctls, l);
+ }
+
+ public void
+ addNamingListener(Name target, String filter, Object[] filterArgs, SearchControls ctls, NamingListener l)
+ throws NamingException {
+ check(target);
+ getOriginal().addNamingListener(target, filter, filterArgs, ctls, l);
+ }
+
+ public void addNamingListener(String target, String filter, Object[] filterArgs, SearchControls ctls,
+ NamingListener l) throws NamingException {
+ check(target);
+ getOriginal().addNamingListener(target, filter, filterArgs, ctls, l);
+ }
+
+}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingLdapContextDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingLdapContextDecorator.java
new file mode 100644
index 0000000..e361db8
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/AccessCheckingLdapContextDecorator.java
@@ -0,0 +1,85 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi.context;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.ExtendedRequest;
+import javax.naming.ldap.ExtendedResponse;
+import javax.naming.ldap.LdapContext;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public class AccessCheckingLdapContextDecorator extends AccessCheckingDirContextDecorator implements LdapContext {
+
+ private static final long serialVersionUID = 1L;
+
+ public AccessCheckingLdapContextDecorator(String... checkedSchemes) {
+ super(checkedSchemes);
+ }
+
+ public AccessCheckingLdapContextDecorator(LdapContext original, String... checkedSchemes) {
+ super(original, checkedSchemes);
+ }
+
+ @Override
+ protected LdapContext getOriginal() {
+ return (LdapContext) super.getOriginal();
+ }
+
+ public ExtendedResponse extendedOperation(ExtendedRequest request) throws NamingException {
+ check();
+ return getOriginal().extendedOperation(request);
+ }
+
+ public LdapContext newInstance(Control[] requestControls) throws NamingException {
+ check();
+ return getOriginal().newInstance(requestControls);
+ }
+
+ public void reconnect(Control[] connCtls) throws NamingException {
+ check();
+ getOriginal().reconnect(connCtls);
+ }
+
+ public Control[] getConnectControls() throws NamingException {
+ check();
+ return getOriginal().getConnectControls();
+ }
+
+ public void setRequestControls(Control[] requestControls) throws NamingException {
+ check();
+ getOriginal().setRequestControls(requestControls);
+ }
+
+ public Control[] getRequestControls() throws NamingException {
+ check();
+ return getOriginal().getRequestControls();
+ }
+
+ public Control[] getResponseControls() throws NamingException {
+ check();
+ return getOriginal().getResponseControls();
+ }
+
+}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/ContextDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/ContextDecorator.java
new file mode 100644
index 0000000..5755ebd
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/ContextDecorator.java
@@ -0,0 +1,33 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi.context;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public interface ContextDecorator extends Context {
+
+ void init(Context context) throws NamingException;
+}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/ContextDecoratorPicker.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/ContextDecoratorPicker.java
new file mode 100644
index 0000000..a088aa2
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/ContextDecoratorPicker.java
@@ -0,0 +1,162 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi.context;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+/**
+ * @author Lukas Krejci
+ */
+public class ContextDecoratorPicker {
+
+ private Set<Class<? extends ContextDecorator>> possibleDecorators = new HashSet<Class<? extends ContextDecorator>>();
+ private Class<?>[] constructorParameterTypes;
+ private Object[] constructorParameters;
+
+ public ContextDecoratorPicker() {
+ }
+
+ public ContextDecoratorPicker(Collection<? extends Class<? extends ContextDecorator>> c) {
+ possibleDecorators.addAll(c);
+ }
+
+ public Set<Class<? extends ContextDecorator>> getPossibleDecorators() {
+ return possibleDecorators;
+ }
+
+ public Class<?>[] getConstructorParameterTypes() {
+ return constructorParameterTypes;
+ }
+
+ public void setConstructorParameterTypes(Class<?>[] constructorParameterTypes) {
+ this.constructorParameterTypes = constructorParameterTypes;
+ }
+
+ public Object[] getConstructorParameters() {
+ return constructorParameters;
+ }
+
+ public void setConstructorParameters(Object[] constructorParameters) {
+ this.constructorParameters = constructorParameters;
+ }
+
+ public Context wrapInAppropriateDecorator(Context context) throws NamingException {
+ Class<? extends ContextDecorator> cls = getMatchByInterfaces(context, possibleDecorators);
+
+ if (cls == null) {
+ throw new IllegalArgumentException("Could not find a matching context decorator for " + context.getClass() + " in " + this);
+ }
+
+ Constructor<? extends ContextDecorator> ctor = null;
+ try {
+ ctor = cls.getConstructor(constructorParameterTypes);
+ ContextDecorator ctx = ctor.newInstance(constructorParameters);
+
+ ctx.init(context);
+
+ return ctx;
+ } catch (SecurityException e) {
+ throw new IllegalStateException("Could not instantiate a class through reflection.", e);
+ } catch (NoSuchMethodException e) {
+ throw new IllegalArgumentException(
+ "Could not construct a context decorator - unable to find a constructor with parameters "
+ + (constructorParameterTypes == null ? "[no parameters]" : Arrays.asList(constructorParameterTypes)) + " on class " + cls.getName(), e);
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Could not instantiate a context decorator " + cls + " using constructor " + ctor, e);
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException("Could not instantiate a context decorator " + cls + " using constructor " + ctor, e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException("Could not instantiate a context decorator " + cls + " using constructor " + ctor, e);
+ } catch (InvocationTargetException e) {
+ throw new IllegalArgumentException("Could not instantiate a context decorator " + cls + " using constructor " + ctor, e);
+ }
+ }
+
+ private static <T> Class<? extends T> getMatchByInterfaces(Object obj, Set<Class<? extends T>> classes) {
+ Set<Class<?>> ifaces = getAllImplementedInterfaces(obj.getClass());
+
+ Class<? extends T> match = null;
+ int maxMatchCnt = Integer.MIN_VALUE;
+
+ for(Class<? extends T> cls : classes) {
+ int cnt = getBestMatchByIfaces(cls, ifaces);
+ if (cnt > maxMatchCnt) {
+ maxMatchCnt = cnt;
+ match = cls;
+ }
+ }
+
+ return match;
+ }
+
+ private static int getBestMatchByIfaces(Class<?> cls, Set<Class<?>> ifaces) {
+ int ret = 0;
+
+ //count how many interfaces from the supplied array the class implements
+ for(Class<?> iface : ifaces) {
+ if (iface.isAssignableFrom(cls)) {
+ ++ret;
+ } else {
+ --ret;
+ }
+ }
+
+ //that's not all - to get the best possible match, we need to take into account
+ //the fact that the class might implement more than just the interfaces provided
+ Set<Class<?>> clsIfaces = getAllImplementedInterfaces(cls);
+
+ for(Class<?> clsIface : clsIfaces) {
+ if (!(ifaces.contains(clsIface))) {
+ --ret;
+ }
+ }
+
+ return ret;
+ }
+
+ private static Set<Class<?>> getAllImplementedInterfaces(Class<?> cls) {
+ HashSet<Class<?>> ret = new HashSet<Class<?>>();
+ getAllImplementedInterfaces(cls, ret);
+
+ return ret;
+ }
+
+ private static void getAllImplementedInterfaces(Class<?> cls, Set<Class<?>> output) {
+ Class<?>[] ifaces = cls.getInterfaces();
+
+ for(Class<?> iface : Arrays.asList(ifaces)) {
+ output.add(iface);
+ getAllImplementedInterfaces(iface, output);
+ }
+
+ if (cls.getSuperclass() != null) {
+ getAllImplementedInterfaces(cls.getSuperclass(), output);
+ }
+ }
+}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringContextDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringContextDecorator.java
new file mode 100644
index 0000000..20077de
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringContextDecorator.java
@@ -0,0 +1,212 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi.context;
+
+import java.io.Serializable;
+import java.util.Hashtable;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+import org.rhq.jndi.AccessCheckingInitialContextFactoryBuilder;
+
+/**
+ * This is a wrapper class around another {@link Context} implementation that
+ * prefers to use an URL context for some operation if the JNDI name contains
+ * a scheme rather than the original. This is the behavior of {@link InitialContext}
+ * which we need to restore in the contexts created by the {@link AccessCheckingInitialContextFactoryBuilder}
+ * (which an {@link InitialContext} uses exclusively if the builder is set).
+ * <p>
+ * This is important because RHQ server has its own initial context factory
+ * builder that creates factories that in turn create contexts. If the default
+ * {@link InitialContext} implementation was used, we'd never be able to lookup
+ * scheme-based names because the default implementation of the {@link InitialContext}
+ * always uses the default context of the builder if one is installed no matter
+ * the scheme in the name.
+ * <p>
+ * The {@link AccessCheckingInitialContextFactoryBuilder} wraps the context returned
+ * by the factory in an instance of this class and thus is restoring the original
+ * intended behavior of the {@link InitialContext}. It looks at the name being looked
+ * up (bound or whatever) and prefers to use the URL context factories if the name
+ * contains the scheme (as does the {@link InitialContext} if no builder is installed).
+ * If the name doesn't contain a scheme, the provided default context factory is used to
+ * look up the name.
+ *
+ * @author Lukas Krejci
+ */
+public class URLPreferringContextDecorator implements Context, ContextDecorator, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private Context original;
+
+ public URLPreferringContextDecorator() {
+
+ }
+
+ public URLPreferringContextDecorator(Context ctx) {
+ original = ctx;
+ }
+
+ public void init(Context context) {
+ original = context;
+ }
+
+ protected Context getOriginal() throws NamingException {
+ return original;
+ }
+
+ protected Context getURLOrDefaultInitCtx(Name name) throws NamingException {
+ @SuppressWarnings("unchecked")
+ Context urlContext = URLPreferringContextDecoratorHelper.getURLContext(name, (Hashtable<Object, Object>) getEnvironment());
+ return urlContext == null ? getOriginal() : urlContext;
+ }
+
+ protected Context getURLOrDefaultInitCtx(String name) throws NamingException {
+ @SuppressWarnings("unchecked")
+ Context urlContext = URLPreferringContextDecoratorHelper.getURLContext(name, (Hashtable<Object, Object>) getEnvironment());
+ return urlContext == null ? getOriginal() : urlContext;
+ }
+
+ public Object lookup(Name name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).lookup(name);
+ }
+
+ public Object lookup(String name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).lookup(name);
+ }
+
+ public void bind(Name name, Object obj) throws NamingException {
+ getURLOrDefaultInitCtx(name).bind(name, obj);
+ }
+
+ public void bind(String name, Object obj) throws NamingException {
+ getURLOrDefaultInitCtx(name).bind(name, obj);
+ }
+
+ public void rebind(Name name, Object obj) throws NamingException {
+ getURLOrDefaultInitCtx(name).rebind(name, obj);
+ }
+
+ public void rebind(String name, Object obj) throws NamingException {
+ getURLOrDefaultInitCtx(name).rebind(name, obj);
+ }
+
+ public void unbind(Name name) throws NamingException {
+ getURLOrDefaultInitCtx(name).unbind(name);
+ }
+
+ public void unbind(String name) throws NamingException {
+ getURLOrDefaultInitCtx(name).unbind(name);
+ }
+
+ public void rename(Name oldName, Name newName) throws NamingException {
+ getURLOrDefaultInitCtx(oldName).rename(oldName, newName);
+ }
+
+ public void rename(String oldName, String newName) throws NamingException {
+ getURLOrDefaultInitCtx(oldName).rename(oldName, newName);
+ }
+
+ public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).list(name);
+ }
+
+ public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).list(name);
+ }
+
+ public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).listBindings(name);
+ }
+
+ public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).listBindings(name);
+ }
+
+ public void destroySubcontext(Name name) throws NamingException {
+ getURLOrDefaultInitCtx(name).destroySubcontext(name);
+ }
+
+ public void destroySubcontext(String name) throws NamingException {
+ getURLOrDefaultInitCtx(name).destroySubcontext(name);
+ }
+
+ public Context createSubcontext(Name name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).createSubcontext(name);
+ }
+
+ public Context createSubcontext(String name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).createSubcontext(name);
+ }
+
+ public Object lookupLink(Name name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).lookupLink(name);
+ }
+
+ public Object lookupLink(String name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).lookupLink(name);
+ }
+
+ public NameParser getNameParser(Name name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).getNameParser(name);
+ }
+
+ public NameParser getNameParser(String name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).getNameParser(name);
+ }
+
+ public Name composeName(Name name, Name prefix) throws NamingException {
+ return getOriginal().composeName(name, prefix);
+ }
+
+ public String composeName(String name, String prefix) throws NamingException {
+ return getOriginal().composeName(name, prefix);
+ }
+
+ public Object addToEnvironment(String propName, Object propVal) throws NamingException {
+ return getOriginal().addToEnvironment(propName, propVal);
+ }
+
+ public Object removeFromEnvironment(String propName) throws NamingException {
+ return getOriginal().removeFromEnvironment(propName);
+ }
+
+ public Hashtable<?, ?> getEnvironment() throws NamingException {
+ return getOriginal().getEnvironment();
+ }
+
+ public void close() throws NamingException {
+ if (getOriginal() != null) {
+ getOriginal().close();
+ original = null;
+ }
+ }
+
+ public String getNameInNamespace() throws NamingException {
+ return getOriginal().getNameInNamespace();
+ }
+}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringContextDecoratorHelper.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringContextDecoratorHelper.java
new file mode 100644
index 0000000..6e7debc
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringContextDecoratorHelper.java
@@ -0,0 +1,76 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi.context;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.spi.NamingManager;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public class URLPreferringContextDecoratorHelper {
+
+ private URLPreferringContextDecoratorHelper() {
+
+ }
+
+ public static Context getURLContext(String name, Hashtable<Object, Object> env) throws NamingException {
+ String scheme = getURLScheme(name);
+ if (scheme != null) {
+ Context ctx = NamingManager.getURLContext(scheme, env);
+ if (ctx != null) {
+ return ctx;
+ }
+ }
+
+ return null;
+ }
+
+ public static Context getURLContext(Name name, Hashtable<Object, Object> env) throws NamingException {
+ if (name.size() > 0) {
+ String first = name.get(0);
+ String scheme = getURLScheme(first);
+ if (scheme != null) {
+ Context ctx = NamingManager.getURLContext(scheme, env);
+ if (ctx != null) {
+ return ctx;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ //copied from InitialContext
+ private static String getURLScheme(String str) {
+ int colon_posn = str.indexOf(':');
+ int slash_posn = str.indexOf('/');
+
+ if (colon_posn > 0 && (slash_posn == -1 || colon_posn < slash_posn))
+ return str.substring(0, colon_posn);
+ return null;
+ }
+}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringDirContextDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringDirContextDecorator.java
new file mode 100644
index 0000000..6a49942
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringDirContextDecorator.java
@@ -0,0 +1,185 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi.context;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
+import javax.naming.NotContextException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+/**
+ * Akin to {@link URLPreferringContextDecorator} this class implements the similar logic
+ * for {@link DirContext}s.
+ *
+ * @author Lukas Krejci
+ */
+public class URLPreferringDirContextDecorator extends URLPreferringContextDecorator implements DirContext {
+
+ private static final long serialVersionUID = 1L;
+
+ public URLPreferringDirContextDecorator() {
+ super(null);
+ }
+
+ public URLPreferringDirContextDecorator(DirContext ctx) {
+ super(ctx);
+ }
+
+ protected DirContext checkAndCast(Context ctx) throws NamingException {
+ if (!(ctx instanceof DirContext)) {
+ if (ctx == null) {
+ throw new NoInitialContextException();
+ } else {
+ throw new NotContextException(
+ "Not an instance of DirContext");
+ }
+ }
+
+ return (DirContext) ctx;
+ }
+
+ @Override
+ protected DirContext getURLOrDefaultInitCtx(Name name) throws NamingException {
+ Context ctx = super.getURLOrDefaultInitCtx(name);
+ return checkAndCast(ctx);
+ }
+
+ @Override
+ protected DirContext getURLOrDefaultInitCtx(String name) throws NamingException {
+ Context ctx = super.getURLOrDefaultInitCtx(name);
+ return checkAndCast(ctx);
+ }
+
+ public Attributes getAttributes(Name name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).getAttributes(name);
+ }
+
+ public Attributes getAttributes(String name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).getAttributes(name);
+ }
+
+ public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
+ return getURLOrDefaultInitCtx(name).getAttributes(name, attrIds);
+ }
+
+ public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
+ return getURLOrDefaultInitCtx(name).getAttributes(name, attrIds);
+ }
+
+ public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
+ getURLOrDefaultInitCtx(name).modifyAttributes(name, mod_op, attrs);
+ }
+
+ public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
+ getURLOrDefaultInitCtx(name).modifyAttributes(name, mod_op, attrs);
+ }
+
+ public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
+ getURLOrDefaultInitCtx(name).modifyAttributes(name, mods);
+ }
+
+ public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
+ getURLOrDefaultInitCtx(name).modifyAttributes(name, mods);
+ }
+
+ public void bind(Name name, Object obj, Attributes attrs) throws NamingException {
+ getURLOrDefaultInitCtx(name).bind(name, obj, attrs);
+ }
+
+ public void bind(String name, Object obj, Attributes attrs) throws NamingException {
+ getURLOrDefaultInitCtx(name).bind(name, obj, attrs);
+ }
+
+ public void rebind(Name name, Object obj, Attributes attrs) throws NamingException {
+ getURLOrDefaultInitCtx(name).rebind(name, obj, attrs);
+ }
+
+ public void rebind(String name, Object obj, Attributes attrs) throws NamingException {
+ getURLOrDefaultInitCtx(name).rebind(name, obj, attrs);
+ }
+
+ public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
+ return getURLOrDefaultInitCtx(name).createSubcontext(name, attrs);
+ }
+
+ public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
+ return getURLOrDefaultInitCtx(name).createSubcontext(name, attrs);
+ }
+
+ public DirContext getSchema(Name name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).getSchema(name);
+ }
+
+ public DirContext getSchema(String name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).getSchema(name);
+ }
+
+ public DirContext getSchemaClassDefinition(Name name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).getSchemaClassDefinition(name);
+ }
+
+ public DirContext getSchemaClassDefinition(String name) throws NamingException {
+ return getURLOrDefaultInitCtx(name).getSchemaClassDefinition(name);
+ }
+
+ public NamingEnumeration<SearchResult>
+ search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
+ return getURLOrDefaultInitCtx(name).search(name, matchingAttributes, attributesToReturn);
+ }
+
+ public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes,
+ String[] attributesToReturn) throws NamingException {
+ return getURLOrDefaultInitCtx(name).search(name, matchingAttributes, attributesToReturn);
+ }
+
+ public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes) throws NamingException {
+ return getURLOrDefaultInitCtx(name).search(name, matchingAttributes);
+ }
+
+ public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes) throws NamingException {
+ return getURLOrDefaultInitCtx(name).search(name, matchingAttributes);
+ }
+
+ public NamingEnumeration<SearchResult> search(Name name, String filter, SearchControls cons) throws NamingException {
+ return getURLOrDefaultInitCtx(name).search(name, filter, cons);
+ }
+
+ public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls cons)
+ throws NamingException {
+ return getURLOrDefaultInitCtx(name).search(name, filter, cons);
+ }
+
+ public NamingEnumeration<SearchResult>
+ search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
+ return getURLOrDefaultInitCtx(name).search(name, filterExpr, filterArgs, cons);
+ }
+
+ public NamingEnumeration<SearchResult> search(String name, String filterExpr, Object[] filterArgs,
+ SearchControls cons) throws NamingException {
+ return getURLOrDefaultInitCtx(name).search(name, filterExpr, filterArgs, cons);
+ }
+}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringEventContextDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringEventContextDecorator.java
new file mode 100644
index 0000000..e3298a0
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringEventContextDecorator.java
@@ -0,0 +1,81 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi.context;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
+import javax.naming.NotContextException;
+import javax.naming.event.EventContext;
+import javax.naming.event.NamingListener;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public class URLPreferringEventContextDecorator extends URLPreferringContextDecorator implements EventContext {
+
+ private static final long serialVersionUID = 1L;
+
+ public URLPreferringEventContextDecorator() {
+ super(null);
+ }
+
+ public URLPreferringEventContextDecorator(EventContext ctx) {
+ super(ctx);
+ }
+
+ protected EventContext checkAndCast(Context ctx) throws NamingException {
+ if (!(ctx instanceof EventContext)) {
+ if (ctx == null) {
+ throw new NoInitialContextException();
+ } else {
+ throw new NotContextException(
+ "Not an instance of EventContext");
+ }
+ }
+
+ return (EventContext) ctx;
+ }
+
+ @Override
+ protected EventContext getOriginal() throws NamingException {
+ return checkAndCast(super.getOriginal());
+ }
+
+ public void addNamingListener(Name target, int scope, NamingListener l) throws NamingException {
+ getOriginal().addNamingListener(target, scope, l);
+ }
+
+ public void addNamingListener(String target, int scope, NamingListener l) throws NamingException {
+ getOriginal().addNamingListener(target, scope, l);
+ }
+
+ public void removeNamingListener(NamingListener l) throws NamingException {
+ getOriginal().removeNamingListener(l);
+ }
+
+ public boolean targetMustExist() throws NamingException {
+ return getOriginal().targetMustExist();
+ }
+
+}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringEventDirContextDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringEventDirContextDecorator.java
new file mode 100644
index 0000000..4925297
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringEventDirContextDecorator.java
@@ -0,0 +1,104 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi.context;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
+import javax.naming.NotContextException;
+import javax.naming.directory.SearchControls;
+import javax.naming.event.EventDirContext;
+import javax.naming.event.NamingListener;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public class URLPreferringEventDirContextDecorator extends URLPreferringDirContextDecorator implements EventDirContext {
+
+ private static final long serialVersionUID = 1L;
+
+ public URLPreferringEventDirContextDecorator() {
+ super(null);
+ }
+
+ public URLPreferringEventDirContextDecorator(EventDirContext ctx) {
+ super(ctx);
+ }
+
+ @Override
+ protected EventDirContext checkAndCast(Context ctx) throws NamingException {
+ if (!(ctx instanceof EventDirContext)) {
+ if (ctx == null) {
+ throw new NoInitialContextException();
+ } else {
+ throw new NotContextException(
+ "Not an instance of EventDirContext");
+ }
+ }
+
+ return (EventDirContext) ctx;
+ }
+
+ @Override
+ protected EventDirContext getOriginal() throws NamingException {
+ return checkAndCast(super.getOriginal());
+ }
+
+ public void addNamingListener(Name target, int scope, NamingListener l) throws NamingException {
+ getOriginal().addNamingListener(target, scope, l);
+ }
+
+ public void addNamingListener(String target, int scope, NamingListener l) throws NamingException {
+ getOriginal().addNamingListener(target, scope, l);
+ }
+
+ public void removeNamingListener(NamingListener l) throws NamingException {
+ getOriginal().removeNamingListener(l);
+ }
+
+ public boolean targetMustExist() throws NamingException {
+ return getOriginal().targetMustExist();
+ }
+
+ public void addNamingListener(Name target, String filter, SearchControls ctls, NamingListener l)
+ throws NamingException {
+ getOriginal().addNamingListener(target, filter, ctls, l);
+ }
+
+ public void addNamingListener(String target, String filter, SearchControls ctls, NamingListener l)
+ throws NamingException {
+ getOriginal().addNamingListener(target, filter, ctls, l);
+ }
+
+ public void
+ addNamingListener(Name target, String filter, Object[] filterArgs, SearchControls ctls, NamingListener l)
+ throws NamingException {
+ getOriginal().addNamingListener(target, filter, filterArgs, ctls, l);
+ }
+
+ public void addNamingListener(String target, String filter, Object[] filterArgs, SearchControls ctls,
+ NamingListener l) throws NamingException {
+ getOriginal().addNamingListener(target, filter, filterArgs, ctls, l);
+ }
+
+}
diff --git a/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringLdapContextDecorator.java b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringLdapContextDecorator.java
new file mode 100644
index 0000000..c74df39
--- /dev/null
+++ b/modules/enterprise/server/container-lib/src/main/java/org/rhq/jndi/context/URLPreferringLdapContextDecorator.java
@@ -0,0 +1,94 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.jndi.context;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
+import javax.naming.NotContextException;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.ExtendedRequest;
+import javax.naming.ldap.ExtendedResponse;
+import javax.naming.ldap.LdapContext;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public class URLPreferringLdapContextDecorator extends URLPreferringDirContextDecorator implements LdapContext {
+
+ private static final long serialVersionUID = 1L;
+
+ public URLPreferringLdapContextDecorator() {
+ super(null);
+ }
+
+ public URLPreferringLdapContextDecorator(LdapContext original) {
+ super(original);
+ }
+
+ @Override
+ protected LdapContext checkAndCast(Context ctx) throws NamingException {
+ if (!(ctx instanceof LdapContext)) {
+ if (ctx == null) {
+ throw new NoInitialContextException();
+ } else {
+ throw new NotContextException("Not an instance of LdapContext");
+ }
+ }
+
+ return (LdapContext) ctx;
+ }
+
+ @Override
+ protected LdapContext getOriginal() throws NamingException {
+ return checkAndCast(super.getOriginal());
+ }
+
+ public ExtendedResponse extendedOperation(ExtendedRequest request) throws NamingException {
+ return getOriginal().extendedOperation(request);
+ }
+
+ public LdapContext newInstance(Control[] requestControls) throws NamingException {
+ return new URLPreferringLdapContextDecorator(getOriginal().newInstance(requestControls));
+ }
+
+ public void reconnect(Control[] connCtls) throws NamingException {
+ getOriginal().reconnect(connCtls);
+ }
+
+ public Control[] getConnectControls() throws NamingException {
+ return getOriginal().getConnectControls();
+ }
+
+ public void setRequestControls(Control[] requestControls) throws NamingException {
+ getOriginal().setRequestControls(requestControls);
+ }
+
+ public Control[] getRequestControls() throws NamingException {
+ return getOriginal().getRequestControls();
+ }
+
+ public Control[] getResponseControls() throws NamingException {
+ return getOriginal().getResponseControls();
+ }
+
+}
diff --git a/modules/enterprise/server/itests/pom.xml b/modules/enterprise/server/itests/pom.xml
index 8753e6f..6898621 100644
--- a/modules/enterprise/server/itests/pom.xml
+++ b/modules/enterprise/server/itests/pom.xml
@@ -56,6 +56,12 @@
<dependency>
<groupId>org.rhq</groupId>
+ <artifactId>rhq-container-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.rhq</groupId>
<artifactId>rhq-enterprise-server</artifactId>
<version>${project.version}</version>
<scope>test</scope>
12 years, 5 months
[rhq] Branch 'feature/gwt-upgrade' - modules/enterprise
by John Sanda
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/RadioGroupWithComponentsItem.java | 52 ++++------
1 file changed, 22 insertions(+), 30 deletions(-)
New commits:
commit 740e052f948e1fb9d013b5a17f3e6f8c67d8001e
Author: John Sanda <jsanda(a)redhat.com>
Date: Tue Jan 3 22:12:02 2012 -0500
[BZ 771417] Refactor logic for enabling/disabling form fields
Form fields were not getting enabled because the top level CanvasItem in
which they were contained is initially set to be disabled. Even though
child components are correctly enabled/disabled as necessary, that
top-level CanvasItem was not getting enabled; consequently, its disabled
state was propagated down. It was pointed out to me that in the version
of SmartGWT that was in use when this class was implemented, it may have
been the case that there was a bug where the enabled/disabled property
change was not propagated down.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/RadioGroupWithComponentsItem.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/RadioGroupWithComponentsItem.java
index 7a3d1e6..c087e19 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/RadioGroupWithComponentsItem.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/RadioGroupWithComponentsItem.java
@@ -23,22 +23,20 @@
package org.rhq.enterprise.gui.coregui.client.components.form;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.form.DynamicForm;
-import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.CanvasItem;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
-
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
/**
* TODO
*
@@ -48,6 +46,7 @@ import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
public class RadioGroupWithComponentsItem extends CanvasItem {
private final LinkedHashMap<NameAndTitle, Canvas> valueMap;
+ private LinkedHashMap<NameAndTitle, CanvasItem> canvasItems;
private final RGWCCanvas canvas;
private final DynamicForm form;
private String selected;
@@ -155,7 +154,7 @@ public class RadioGroupWithComponentsItem extends CanvasItem {
@Override
protected void onInit() {
super.onInit();
-
+ canvasItems = new LinkedHashMap<NameAndTitle, CanvasItem>();
ArrayList<FormItem> items = new ArrayList<FormItem>();
for (final NameAndTitle label : valueMap.keySet()) {
@@ -172,8 +171,8 @@ public class RadioGroupWithComponentsItem extends CanvasItem {
ci.setCanvas(value);
}
ci.setDisabled(true);
+ canvasItems.put(label, ci);
items.add(ci);
-
button.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent changedEvent) {
selected = (String) changedEvent.getValue();
@@ -186,40 +185,33 @@ public class RadioGroupWithComponentsItem extends CanvasItem {
}
public void updateEnablement() {
-
- for (NameAndTitle key : valueMap.keySet()) {
- Canvas value = valueMap.get(key);
- Boolean disabled = !selected.equals(key.getTitle());
+ for (NameAndTitle key : canvasItems.keySet()) {
+ CanvasItem canvasItem = canvasItems.get(key);
+ Canvas nestedCanvas = canvasItem.getCanvas();
+ boolean disabled = !selected.equals(key.getTitle());
if (disabled) {
+ canvasItem.disable();
+ clearValues(nestedCanvas);
canvas.getItem(key.getName()).clearValue();
- canvas.getItem(key.getName()).redraw();
+ if (nestedCanvas != null) {
+ nestedCanvas.markForRedraw();
+ }
+ } else {
+ canvasItem.enable();
}
- disableAllFormFields(value, disabled);
}
+
}
- private void disableAllFormFields(Canvas value, Boolean disabled) {
+ private void clearValues(Canvas value) {
if (value != null && value instanceof DynamicForm) {
for (FormItem item : ((DynamicForm) value).getFields()) {
if (item instanceof CanvasItem) {
- // recursively drill down in case this is a dynamic form inside a dynamic form
- disableAllFormFields(((CanvasItem) item).getCanvas(), disabled);
- }
-
- if (disabled) {
- item.clearValue();
- item.redraw();
- if (item instanceof ButtonItem) {
- item.disable();
- }
+ clearValues(((CanvasItem) item).getCanvas());
} else {
- if (item instanceof ButtonItem) {
- item.enable();
- }
+ item.clearValue();
}
}
- value.setDisabled(disabled);
- value.markForRedraw();
}
}
}
12 years, 5 months