Java Code Examples for org.jboss.as.controller.PathElement#isWildcard()
The following examples show how to use
org.jboss.as.controller.PathElement#isWildcard() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalOperationHandlers.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override protected boolean authorize(OperationContext context, PathAddress base, ModelNode operation) { if (base.size() > 0) { PathElement element = base.getLastElement(); if (!element.isWildcard() && (element.getKey().equals(HOST)/* || element.getKey().equals(RUNNING_SERVER)*/)) { //Only do this for host resources. The rest of r-r-d does filtering itself. However, without //this: // - a slave host scoped role doing a /host=*:r-r-d will not get rid of the host=master resource // - a master host scoped role doing a /host=*/server=*/subsystem=thing:r-r-d will not get rid of the host=slave resource ModelNode toAuthorize = operation.clone(); toAuthorize.get(OP).set(READ_RESOURCE_DESCRIPTION_OPERATION); toAuthorize.get(OP_ADDR).set(base.toModelNode()); AuthorizationResult.Decision decision = context.authorize(toAuthorize, EnumSet.of(Action.ActionEffect.ADDRESS)).getDecision(); return decision == AuthorizationResult.Decision.PERMIT; } } return true; }
Example 2
Source File: ImmutableManagementResourceRegistration.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
default String getFeature() { if(PathAddress.EMPTY_ADDRESS.equals(getPathAddress())) { if(getProcessType().isServer()) { return "server-root"; } return ""; } StringJoiner joiner = new StringJoiner("."); final PathAddress pathAddress = getPathAddress(); final String initialKey = pathAddress.getElement(0).getKey(); if (getProcessType().isManagedDomain() && !HOST.equals(initialKey) && !PROFILE.equals(initialKey)) { joiner.add(DOMAIN); } for (int i = 0; i < pathAddress.size(); i++) { PathElement elt = pathAddress.getElement(i); joiner.add(elt.getKey()); if (!elt.isWildcard() && (i > 0 || !HOST.equals(elt.getKey()))) { joiner.add(elt.getValue()); } } return joiner.toString(); }
Example 3
Source File: CoreModelTestDelegate.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private void harmonizeModel(ModelVersion modelVersion, ModelNode legacyModel, ModelNode transformed, PathAddress address, ModelHarmonizer harmonizer) { if (address.size() > 0) { PathElement pathElement = address.getElement(0); if (legacyModel.hasDefined(pathElement.getKey()) && transformed.hasDefined(pathElement.getKey())) { ModelNode legacyType = legacyModel.get(pathElement.getKey()); ModelNode transformedType = transformed.get(pathElement.getKey()); PathAddress childAddress = address.size() > 1 ? address.subAddress(1) : PathAddress.EMPTY_ADDRESS; if (pathElement.isWildcard()) { for (String key : legacyType.keys()) { if (transformedType.has(key)) { harmonizeModel(modelVersion, legacyType.get(key), transformedType.get(key), childAddress, harmonizer); } } } else { harmonizeModel(modelVersion, legacyType.get(pathElement.getValue()), transformedType.get(pathElement.getValue()), address, harmonizer); } } } else { harmonizer.harmonizeModel(modelVersion, legacyModel, transformed); } }
Example 4
Source File: DMRLocationResolver.java From hawkular-agent with Apache License 2.0 | 5 votes |
@Override public String findWildcardMatch(DMRNodeLocation multiTargetLocation, DMRNodeLocation singleLocation) throws ProtocolException { if (multiTargetLocation == null) { throw new ProtocolException("multiTargetLocation is null"); } PathAddress multiTargetPaths = multiTargetLocation.getPathAddress(); for (int i = 0; i < multiTargetPaths.size(); i++) { PathElement multiTargetPathElement = multiTargetPaths.getElement(i); if (multiTargetPathElement.isWildcard()) { PathElement singleLocationPathElement; try { singleLocationPathElement = singleLocation.getPathAddress().getElement(i); } catch (Exception e) { throw new ProtocolException(String.format("[%s] doesn't have the same path size as [%s]", singleLocation, multiTargetLocation)); } // DMR wildcards are only in values ("/name=*" not "/*=value") if (singleLocationPathElement.getKey().equals(multiTargetPathElement.getKey())) { return singleLocationPathElement.getValue(); } else { throw new ProtocolException(String.format("[%s] doesn't match the multi-target key in [%s]", singleLocation, multiTargetLocation)); } } } // nothing matched - single location must not have resulted from a query using the given multi-target location throw new ProtocolException(String.format("[%s] doesn't match the wildcard from [%s]", singleLocation, multiTargetLocation)); }
Example 5
Source File: DomainTestUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Check if a path address exists. * * @param address the path address * @param client the controller client * @return whether the child exists or not * @throws IOException * @throws MgmtOperationException */ public static boolean exists(PathAddress address, ModelControllerClient client) throws IOException, MgmtOperationException { final PathElement element = address.getLastElement(); final PathAddress subAddress = address.subAddress(0, address.size() -1); final boolean checkType = element.isWildcard(); final ModelNode e; final ModelNode operation; if(checkType) { e = new ModelNode().set(element.getKey()); operation = createOperation(READ_CHILDREN_TYPES_OPERATION, subAddress); } else { e = new ModelNode().set(element.getValue()); operation = createOperation(READ_CHILDREN_NAMES_OPERATION, subAddress); operation.get(CHILD_TYPE).set(element.getKey()); } try { final ModelNode result = executeForResult(operation, client); return result.asList().contains(e); } catch (MgmtOperationException ex) { if(! checkType) { final String failureDescription = ex.getResult().get(FAILURE_DESCRIPTION).asString(); if(failureDescription.contains("WFLYCTL0202") && failureDescription.contains(element.getKey())) { return false; } } throw ex; } }
Example 6
Source File: WildcardOperationsTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
static void assertMatchingAddress(PathAddress toMatch, ModelNode node, WildcardChecker wildcardChecker) { assertTrue(node.hasDefined(OP_ADDR)); PathAddress testee = PathAddress.pathAddress(node.get(OP_ADDR)); assertEquals(testee + " length matches " + toMatch, toMatch.size(), testee.size()); for (int i = 0; i < toMatch.size(); i++) { PathElement matchElement = toMatch.getElement(i); PathElement testeeElement = testee.getElement(i); assertEquals(testee.toString(), matchElement.getKey(), testeeElement.getKey()); // the /host=* registration can be returned as part of RRD, so we skip it. if (! (node.get(RESULT).has(DESCRIPTION) && node.get(RESULT).get(DESCRIPTION).asString().contains("The root node of the host-level management model"))) { wildcardChecker.checkPathElement(testeeElement); } if (!matchElement.isWildcard()) { if (matchElement.isMultiTarget()) { boolean matched = false; for (String option : matchElement.getSegments()) { if (option.equals(testeeElement.getValue())) { matched = true; break; } } assertTrue(testeeElement + " value in " + matchElement.getValue(), matched); } else { assertEquals(matchElement.getValue(), testeeElement.getValue()); } } } }
Example 7
Source File: WildcardOperationsTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void checkPathElement(PathElement actualElement) { if (!actualElement.getKey().equals(RUNNING_SERVER)) { super.checkPathElement(actualElement); } else { if (actualElement.isWildcard()) { seenWildcardServer = true; } else { nonWildcardServers++; } } }
Example 8
Source File: AuditLogAddressUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static boolean matches(PathElement pattern, PathElement element) { if (!pattern.getKey().equals(element.getKey())) { return false; } if (pattern.isWildcard()) { return true; } return pattern.getValue().equals(element.getValue()); }
Example 9
Source File: AbstractModelResource.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public boolean hasChild(final PathElement address) { final ResourceProvider provider = getProvider(address.getKey()); if(provider == null) { return false; } if(address.isWildcard()) { return provider.hasChildren(); } return provider.has(address.getValue()); }
Example 10
Source File: SubsystemTestDelegate.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void removeIgnoredChildren(final Collection<PathAddress> ignoredChildAddresses, final Collection<PathAddress> addresses) { // Remove all known ignored children addresses.removeAll(ignoredChildAddresses); // Checked for wildcards removals for (PathAddress ignoredChildAddress : ignoredChildAddresses) { final PathElement lastIgnoredElement = ignoredChildAddress.getLastElement(); if (lastIgnoredElement.isWildcard()) { // Check each address for (final Iterator<PathAddress> iterator = addresses.iterator(); iterator.hasNext(); ) { final PathAddress childAddress = iterator.next(); if (childAddress.size() == ignoredChildAddress.size()) { // Check the last element key for a match if (lastIgnoredElement.getKey().equals(childAddress.getLastElement().getKey())) { boolean match = true; // Check for matches on previous elements for (int i = 0; i < ignoredChildAddress.size() - 1; i++) { final PathElement e1 = ignoredChildAddress.getElement(i); final PathElement e2 = childAddress.getElement(i); if (!e1.equals(e2)) { match = false; break; } } if (match) { iterator.remove(); } } } } } } }
Example 11
Source File: SubsystemTestDelegate.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public ManagementResourceRegistration getSubModel(PathAddress address) { if (address.size() == 0) { return MOCK_RESOURCE_REG; } else if (address.size() == 1) { PathElement pe = address.getElement(0); String key = pe.getKey(); if (pe.isWildcard() && (ModelDescriptionConstants.PROFILE.equals(key) || ModelDescriptionConstants.DEPLOYMENT.equals(key))) { return MOCK_RESOURCE_REG; } } return null; }
Example 12
Source File: GlobalOperationHandlers.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override protected void executeMultiTargetChildren(PathAddress base, PathElement currentElement, PathAddress newRemaining, OperationContext context, ImmutableManagementResourceRegistration registration, boolean ignoreMissing) { final String childType = currentElement.getKey().equals("*") ? null : currentElement.getKey(); if (registration.isRemote()) {// || registration.isRuntimeOnly()) { // At least for proxies it should use the proxy operation handler throw new IllegalStateException(); } final Set<PathElement> children = context.getResourceRegistration().getChildAddresses(base); if (children == null || children.isEmpty()) { throw new NoSuchResourceTypeException(base.append(currentElement)); } boolean foundValid = false; PathAddress invalid = null; for (final PathElement path : children) { if (childType != null && !childType.equals(path.getKey())) { continue; } // matches /host=xxx/server=*/... address final boolean isHostWildcardServerAddress = base.size() > 0 && base.getLastElement().getKey().equals(HOST) && path.getKey().equals(RUNNING_SERVER) && path.isWildcard(); if (isHostWildcardServerAddress && newRemaining.size() > 0) { //Trying to get e.g. /host=xxx/server=*/interface=public will fail, so make sure if there are remaining elements for //a /host=master/server=* that we don't attempt to get those continue; } final PathAddress next = base.append(path); final ImmutableManagementResourceRegistration nr = context.getResourceRegistration().getSubModel(next); try { execute(next, newRemaining, context, nr, ignoreMissing); foundValid = true; } catch (NoSuchResourceTypeException e) { if (!foundValid) { PathAddress failedAddr = e.getPathAddress(); // Store the failed address for error reporting, but only if // 1) this is the first failure, or // 2) The size of the failed address is larger than the currently // cached one, indicating there is some path that has a larger number // of valid elements than the currently cached path. So we want to // report that larger path if (invalid == null || failedAddr.size() > invalid.size()) { PathAddress newBase = base.append(currentElement); invalid = newBase.append(failedAddr.subAddress(newBase.size())); } } } } if (!foundValid) { if (invalid == null) { // No children matched currentElement invalid = base.append(currentElement); } throw new NoSuchResourceTypeException(invalid); } }