org.jboss.as.controller.AttributeDefinition Java Examples

The following examples show how to use org.jboss.as.controller.AttributeDefinition. 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: CustomMarshaller.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void marshallAsElement(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException {
  assert attribute instanceof ObjectListAttributeDefinition;
  ObjectListAttributeDefinition list = ((ObjectListAttributeDefinition) attribute);

  ObjectTypeAttributeDefinition objectType = (ObjectTypeAttributeDefinition) CustomMarshaller.getValueType(list, ObjectListAttributeDefinition.class);
  AttributeDefinition[] valueTypes = CustomMarshaller.getValueTypes(list, ObjectTypeAttributeDefinition.class);

  if (resourceModel.hasDefined(attribute.getName())) {
    writer.writeStartElement(attribute.getXmlName());
    for (ModelNode element: resourceModel.get(attribute.getName()).asList()) {
      writer.writeStartElement(objectType.getXmlName());
      for (AttributeDefinition valueType : valueTypes) {
        valueType.getAttributeMarshaller().marshallAsElement(valueType, element, false, writer);
      }
      writer.writeEndElement();
    }
    writer.writeEndElement();
  }
}
 
Example #2
Source File: InterfaceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Deprecated
static ParameterValidator createNestedParamValidator() {
    return new ModelTypeValidator(ModelType.OBJECT, true, false, true) {
        @Override
        public void validateParameter(final String parameterName, final ModelNode value) throws OperationFailedException {
            super.validateParameter(parameterName, value);

            for (final AttributeDefinition def : NESTED_ATTRIBUTES) {
                final String name = def.getName();
                if (value.hasDefined(name)) {
                    final ModelNode v = value.get(name);
                    if (NESTED_LIST_ATTRIBUTES.contains(def)) {
                        if (ModelType.LIST != v.getType()) {
                            throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.invalidType(v.getType()));
                        }
                    } else {
                        def.getValidator().validateParameter(name, v);
                    }
                }
            }
        }
    };
}
 
Example #3
Source File: AttributeAccess.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
AttributeAccess(final AccessType access, final Storage storage, final OperationStepHandler readHandler,
                final OperationStepHandler writeHandler, AttributeDefinition definition) {
    Assert.assertNotNull(access);
    Assert.assertNotNull(storage);
    this.access = access;
    this.readHandler = readHandler;
    this.writeHandler = writeHandler;
    this.storage = storage;
    this.definition = definition;
    if (definition.getImmutableFlags().contains(Flag.ALIAS)) {
        Assert.checkNotNullParam("readHandler", readHandler);
    }
    if (access == AccessType.READ_WRITE) {
        Assert.checkNotNullParam("writeHandler", writeHandler);
    }
}
 
Example #4
Source File: ModelControllerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void init() {
    complexValueType = new ModelNode();
    complexValueType.get("int-value", DESCRIPTION).set("An int value");
    complexValueType.get("int-value", EXPRESSIONS_ALLOWED).set(allowExpressions);
    complexValueType.get("int-value", TYPE).set(ModelType.INT);
    complexValueType.get("bigdecimal-value", DESCRIPTION).set("A bigdecimal value");
    complexValueType.get("bigdecimal-value", TYPE).set(ModelType.BIG_DECIMAL);
    complexValueType.get("bigdecimal-value", EXPRESSIONS_ALLOWED).set(allowExpressions);

    SimpleAttributeDefinition intValue = createAttribute("int-value", ModelType.INT, allowExpressions);
    SimpleAttributeDefinition bigDecimal = createAttribute("bigdecimal-value", ModelType.BIG_DECIMAL, allowExpressions);

    complex = new ObjectTypeAttributeDefinition.Builder("complex", intValue, bigDecimal).build();
    AttributeDefinition param1 = new ObjectTypeAttributeDefinition.Builder("param1", intValue, bigDecimal).build();
    COMPLEX_OP_DEF = new SimpleOperationDefinitionBuilder("complex", new NonResolvingResourceDescriptionResolver())
            .addParameter(param1)
            .setReplyType(ModelType.OBJECT)
            .setReplyParameters(complex)
            .build();

}
 
Example #5
Source File: HostProcessReloadHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public SimpleOperationDefinition internalBuild(final ResourceDescriptionResolver resolver, final ResourceDescriptionResolver attributeResolver) {
    return new SimpleOperationDefinition(name, resolver, attributeResolver, entryType, flags, replyType, replyValueType, false, deprecationData, replyParameters, parameters) {
        @Override
        public DescriptionProvider getDescriptionProvider() {
            return new DescriptionProvider() {
                @Override
                public ModelNode getModelDescription(Locale locale) {
                    AttributeDefinition[] params = hostControllerInfo.isMasterDomainController() ? MASTER_ATTRIBUTES : SLAVE_ATTRIBUTES;
                    return new DefaultOperationDescriptionProvider(getName(), resolver, attributeResolver, replyType, replyValueType, replyAllowNull, deprecationData, replyParameters, params, accessConstraints).getModelDescription(locale);
                }
            };
        }
    };
}
 
Example #6
Source File: ThreadsWriteAttributeOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a handler that doesn't validate values.
 * @param attributes all persistent attributes of the
 * @param runtimeAttributes attributes whose updated value can immediately be applied to the runtime
 */
public ThreadsWriteAttributeOperationHandler(AttributeDefinition[] attributes, AttributeDefinition[] runtimeAttributes) {
    super(attributes);
    this.attributes = attributes;
    for(AttributeDefinition attr : runtimeAttributes) {
        this.runtimeAttributes.put(attr.getName(), attr);
    }
}
 
Example #7
Source File: IdentityProviderDefinition.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    super.registerAttributes(resourceRegistration);

    final OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(ALL_ATTRIBUTES);
    for (AttributeDefinition attribute : ALL_ATTRIBUTES) {
        resourceRegistration.registerReadWriteAttribute(attribute, null, writeHandler);
    }
}
 
Example #8
Source File: SSLDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static ResourceDefinition createSSLContextDefinition(String pathKey, boolean server, AbstractAddStepHandler addHandler, AttributeDefinition[] attributes, boolean serverOrHostController) {
    Builder builder = TrivialResourceDefinition.builder()
            .setPathKey(pathKey)
            .setAddHandler(addHandler)
            .setAttributes(attributes)
            .setRuntimeCapabilities(SSL_CONTEXT_RUNTIME_CAPABILITY);

    if (serverOrHostController) {
        builder.addReadOnlyAttribute(ACTIVE_SESSION_COUNT, new SSLContextRuntimeHandler() {
            @Override
            protected void performRuntime(ModelNode result, ModelNode operation, SSLContext sslContext) throws OperationFailedException {
                SSLSessionContext sessionContext = server ? sslContext.getServerSessionContext() : sslContext.getClientSessionContext();
                int sum = 0;
                for (byte[] b : Collections.list(sessionContext.getIds())) {
                    int i = 1;
                    sum += i;
                }
                result.set(sum);
            }

            @Override
            protected ServiceUtil<SSLContext> getSSLContextServiceUtil() {
                return server ? SERVER_SERVICE_UTIL : CLIENT_SERVICE_UTIL;
            }
        }).addChild(new SSLSessionDefinition(server));
    }

    return builder.build();
}
 
Example #9
Source File: DeploymentAttributes.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void validateParameter(String parameterName, ModelNode contentItemNode) throws OperationFailedException {
    for (String key : contentItemNode.keys()) {
        if (ignoredParameters.contains(key)) {
            continue;
        }
        AttributeDefinition def = MANAGED_CONTENT_ATTRIBUTES.get(key);
        if (def == null) {
            throw ServerLogger.ROOT_LOGGER.unknownContentItemKey(key);
        }
        def.validateOperation(contentItemNode);
        if (contentItemNode.hasDefined(key)) {
            String[] alts = def.getAlternatives();
            if (alts != null && alts.length > 0) {
                for (String alt : alts) {
                    if (contentItemNode.hasDefined(alt)) {
                        throw ServerLogger.ROOT_LOGGER.cannotHaveMoreThanOneManagedContentItem(MANAGED_CONTENT_ATTRIBUTES.keySet());
                    }
                }
            }
            String[] reqs = def.getRequires();
            if (reqs != null && reqs.length > 0) {
                boolean hasReq = false;
                for (String req : reqs) {
                    if (contentItemNode.hasDefined(req)) {
                        hasReq = true;
                        break;
                    }
                }
                if (!hasReq) {
                    throw ServerLogger.ROOT_LOGGER.nullParameter(reqs[0]);
                }
            }
        }
    }
}
 
Example #10
Source File: ManagedServerBootCmdFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String asStringIfDefined(ModelNode model, AttributeDefinition attribute, ExpressionResolver resolver) throws OperationFailedException {
    ModelNode value = attribute.resolveModelAttribute(resolver, model);
    if (value.isDefined()) {
        return value.asString();
    }

    return null;
}
 
Example #11
Source File: DeploymentOverlayContentDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void registerAttributes(final ManagementResourceRegistration resourceRegistration) {
    super.registerAttributes(resourceRegistration);
    for (AttributeDefinition attr : ATTRIBUTES) {
        resourceRegistration.registerReadOnlyAttribute(attr, null);
    }
    resourceRegistration.registerReadOnlyAttribute(STREAM_ATTRIBUTE, new DeploymentOverlayReadContentHandler(contentRepository));
}
 
Example #12
Source File: TrivialAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
TrivialAddHandler(Class<T> serviceType, Mode initialMode, Mode adminOnlyInitialMode, AttributeDefinition[] attributes, RuntimeCapability<?> runtimeCapability) {
    super(new HashSet<>(Collections.singletonList(checkNotNullParam("runtimeCapabilities", runtimeCapability))), attributes);
    this.runtimeCapability = runtimeCapability;
    checkNotNullParam("serviceType", serviceType);
    this.initialMode = checkNotNullParam("initialMode", initialMode);
    this.adminOnlyInitialMode = checkNotNullParam("adminOnlyInitialMode", adminOnlyInitialMode);
}
 
Example #13
Source File: ObjectTypeValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void validateParameter(final String parameterName, final ModelNode value) throws OperationFailedException {
    super.validateParameter(parameterName, value);
    if (value.isDefined()) {
        for (AttributeDefinition ad : allowedValues.values()) {
            String key = ad.getName();
            // Don't modify the value by calls to get(), because that's best in general.
            // Plus modifying it results in an irrelevant test failure in full where the test
            // isn't expecting the modification and complains.
            // Changing the test is too much trouble.
            ModelNode toTest = value.has(key) ? value.get(key) : new ModelNode();
            ad.getValidator().validateParameter(key, toTest);
        }
    }
}
 
Example #14
Source File: ResolvePathHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ResolvePathHandler(final OperationDefinition operationDefinition, final AttributeDefinition parentAttribute,
                           final AttributeDefinition relativeToAttribute, final AttributeDefinition pathAttribute,
                           final PathManager pathManager, final boolean checkAbsolutePath) {
    this.parentAttribute = parentAttribute;
    this.relativeToAttribute = relativeToAttribute;
    this.pathAttribute = pathAttribute;
    this.operationDefinition = operationDefinition;
    this.pathManager = pathManager;
    this.checkAbsolutePath = checkAbsolutePath;
}
 
Example #15
Source File: BaseHttpInterfaceResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected static AttributeDefinition[] combine(AttributeDefinition[] commonAttributes, AttributeDefinition... additionalAttributes) {
    AttributeDefinition[] combined = new AttributeDefinition[commonAttributes.length + additionalAttributes.length];
    System.arraycopy(commonAttributes, 0, combined, 0, commonAttributes.length);
    System.arraycopy(additionalAttributes, 0, combined, commonAttributes.length, additionalAttributes.length);

    return combined;
}
 
Example #16
Source File: SaslServerDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
SaslServerResourceDefinition(String pathKey, AbstractAddStepHandler add, AttributeDefinition ... attributes) {
    super(new Parameters(PathElement.pathElement(pathKey),
            ElytronExtension.getResourceDescriptionResolver(pathKey))
        .setAddHandler(add)
        .setRemoveHandler(new TrivialCapabilityServiceRemoveHandler(add, SASL_SERVER_FACTORY_RUNTIME_CAPABILITY))
        .setAddRestartLevel(OperationEntry.Flag.RESTART_RESOURCE_SERVICES)
        .setRemoveRestartLevel(OperationEntry.Flag.RESTART_RESOURCE_SERVICES)
        .setCapabilities(SASL_SERVER_FACTORY_RUNTIME_CAPABILITY));
    this.pathKey = pathKey;
    this.attributes = attributes;
}
 
Example #17
Source File: AbstractHandlerDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected AbstractHandlerDefinition(final PathElement path,
                                    final boolean registerLegacyOps,
                                    final Class<? extends Handler> type,
                                    final PropertySorter propertySorter,
                                    final AttributeDefinition[] attributes) {
    this(createParameters(path, type, propertySorter, attributes), registerLegacyOps, propertySorter, null, attributes);
}
 
Example #18
Source File: RejectExpressionValuesTransformer.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Set<String> namesFromDefinitions(AttributeDefinition... attributes) {
    final Set<String> names = new HashSet<String>();
    for (final AttributeDefinition def : attributes) {
        names.add(def.getName());
    }
    return names;
}
 
Example #19
Source File: RealmAddHandler.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException {
    for (AttributeDefinition attrib : RealmDefinition.ALL_ATTRIBUTES) {
        attrib.validateAndSet(operation, model);
    }

    if (!SharedAttributeDefinitons.validateTruststoreSetIfRequired(model.clone())) {
        //TODO: externalize message
        throw new OperationFailedException("truststore and truststore-password must be set if ssl-required is not none and disable-trust-manager is false.");
    }
}
 
Example #20
Source File: DiscardUndefinedAttributesTransformer.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Set<String> namesFromDefinitions(AttributeDefinition... attributes) {
    final Set<String> names = new HashSet<String>();
    for (final AttributeDefinition def : attributes) {
        names.add(def.getName());
    }
    return names;
}
 
Example #21
Source File: LoggingSubsystemWriter.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void writeContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws XMLStreamException {
    context.startSubsystemElement(Namespace.CURRENT.getUriString(), false);

    ModelNode model = context.getModelNode();

    // Marshall attributes
    for (AttributeDefinition attribute : LoggingResourceDefinition.ATTRIBUTES) {
        attribute.marshallAsElement(model, false, writer);
    }

    writeContent(writer, model);

    if (model.hasDefined(LOGGING_PROFILE)) {
        final List<Property> profiles = model.get(LOGGING_PROFILE).asPropertyList();
        if (!profiles.isEmpty()) {
            writer.writeStartElement(LOGGING_PROFILES);
            for (Property profile : profiles) {
                final String name = profile.getName();
                writer.writeStartElement(LOGGING_PROFILE);
                writer.writeAttribute(Attribute.NAME.getLocalName(), name);
                writeContent(writer, profile.getValue());
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }
    }
    writer.writeEndElement();
}
 
Example #22
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void writeRealms(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
    if (!context.getModelNode().get(RealmDefinition.TAG_NAME).isDefined()) {
        return;
    }
    for (Property realm : context.getModelNode().get(RealmDefinition.TAG_NAME).asPropertyList()) {
        writer.writeStartElement(RealmDefinition.TAG_NAME);
        writer.writeAttribute("name", realm.getName());
        ModelNode realmElements = realm.getValue();
        for (AttributeDefinition element : RealmDefinition.ALL_ATTRIBUTES) {
            element.marshallAsElement(realmElements, writer);
        }

        writer.writeEndElement();
    }
}
 
Example #23
Source File: AttributeConverter.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void convertResourceAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
    if (!attributeValue.isDefined()) {
        ImmutableManagementResourceRegistration registration = context.getResourceRegistrationFromRoot(PathAddress.EMPTY_ADDRESS);
        AttributeDefinition definition = registration.getAttributeAccess(address, attributeName).getAttributeDefinition();
        attributeValue.set(definition.getDefaultValue());
    }
}
 
Example #24
Source File: PropertyAttributeMarshaller.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void marshallAsElement(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException {
    resourceModel = resourceModel.get(attribute.getName());
    if (resourceModel.isDefined()) {
        writer.writeStartElement(attribute.getName());
        for (Property property : resourceModel.asPropertyList()) {
            writer.writeEmptyElement(Element.PROPERTY.getLocalName());
            writer.writeAttribute(Attribute.NAME.getLocalName(), property.getName());
            writer.writeAttribute(Attribute.VALUE.getLocalName(), property.getValue().asString());
        }
        writer.writeEndElement();
    }
}
 
Example #25
Source File: TrivialResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
Builder addReadOnlyAttribute(AttributeDefinition attribute, OperationStepHandler handler) {
    if (readOnlyAttributes == null) {
        readOnlyAttributes = new HashMap<>();
    }
    readOnlyAttributes.put(attribute, handler);

    return this;
}
 
Example #26
Source File: WrappedAttributeMarshaller.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void marshallAsElement(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException {
    if (isMarshallable(attribute, resourceModel)) {
        writer.writeEmptyElement(attribute.getXmlName());
        writer.writeAttribute(xmlAttribute.getLocalName(), resourceModel.get(attribute.getName()).asString());
    }
}
 
Example #27
Source File: AttributeTransformationDescriptionBuilderImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public T setValueConverter(AttributeConverter attributeConverter, AttributeDefinition...convertedAttributes) {
    for (AttributeDefinition attribute : convertedAttributes) {
        String attrName = getAttributeName(attribute);
        registry.addAttributeConverter(attrName, attributeConverter);
    }
    return thisBuilder();
}
 
Example #28
Source File: CredentialAddHandler.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException {
    if (attributes != null) {
        for (AttributeDefinition attr : attributes) {
            attr.validateAndSet(operation, model);
        }
    }
}
 
Example #29
Source File: VaultResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    VaultWriteAttributeHandler write = new VaultWriteAttributeHandler(ALL_ATTRIBUTES);
    for (AttributeDefinition def : ALL_ATTRIBUTES) {
        resourceRegistration.registerReadWriteAttribute(def, null, write);
    }
}
 
Example #30
Source File: DefaultOperationDescriptionProvider.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public DefaultOperationDescriptionProvider(final String operationName,
        final ResourceDescriptionResolver descriptionResolver,
        final ResourceDescriptionResolver attributeDescriptionResolver,
        final ModelType replyType,
        final ModelType replyValueType,
        final boolean replyAllowNull,
        final DeprecationData deprecationData,
        final AttributeDefinition[] replyParameters,
        final AttributeDefinition... parameters) {
    this(operationName, descriptionResolver, attributeDescriptionResolver, replyType, replyValueType, replyAllowNull, deprecationData, replyParameters, parameters, null);
}