use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class SAMLResourceDefinition method createAttributeWriterHandler.
@Override
protected OperationStepHandler createAttributeWriterHandler() {
List<SimpleAttributeDefinition> attributes = getAttributes();
return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {
@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
updateConfiguration(context, pathAddress, false);
return false;
}
@Override
protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
updateConfiguration(context, pathAddress, true);
}
private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
ServiceController<SAMLService> serviceController = (ServiceController<SAMLService>) serviceRegistry.getService(SAMLService.createServiceName(federationAlias));
if (serviceController != null) {
SAMLService service = serviceController.getValue();
ModelNode samlNode;
if (!rollback) {
samlNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
} else {
Resource rc = context.getOriginalRootResource().navigate(pathAddress);
samlNode = rc.getModel();
}
service.setStsType(SAMLAddHandler.toSAMLConfig(context, samlNode));
}
}
};
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class ElementMaxOccurrenceValidationStepHandler method validateOccurrence.
protected void validateOccurrence(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
PathAddress parentAddress = Util.getParentAddressByKey(address, this.parentElement.getName());
Resource parentResource = context.readResourceFromRoot(parentAddress);
Set<String> elements = parentResource.getChildrenNames(this.element.getName());
if (elements.size() > this.maxOccurs) {
throw ROOT_LOGGER.invalidChildTypeOccurrence(parentAddress.getLastElement().toString(), this.maxOccurs, this.element.getName());
}
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class RequiredChildValidationStepHandler method validateRequiredChild.
protected void validateRequiredChild(OperationContext context, ModelNode operation) throws OperationFailedException {
Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
PathAddress pathAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
Set<ResourceEntry> children = resource.getChildren(this.childElement.getName());
if (children.isEmpty()) {
throw ROOT_LOGGER.requiredChild(pathAddress.getLastElement().toString(), this.childElement.getName());
}
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class UniqueTypeValidationStepHandler method validateType.
protected void validateType(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress pathAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
String elementName = pathAddress.getLastElement().getValue();
ModelNode typeNode = context.readResource(EMPTY_ADDRESS, false).getModel();
String type = getType(context, typeNode);
PathAddress parentAddress = pathAddress.subAddress(0, pathAddress.size() - 1);
Resource parentResource = context.readResourceFromRoot(parentAddress);
Set<Resource.ResourceEntry> children = parentResource.getChildren(this.element.getName());
for (Resource.ResourceEntry child : children) {
String existingResourceName = child.getName();
String existingType = getType(context, child.getModel());
if (!elementName.equals(existingResourceName) && (type.equals(existingType))) {
throw ROOT_LOGGER.typeAlreadyDefined(type);
}
}
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class KeyStoreProviderResourceDefinition method createAttributeWriterHandler.
@Override
protected OperationStepHandler createAttributeWriterHandler() {
List<SimpleAttributeDefinition> attributes = getAttributes();
return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {
@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
updateConfiguration(context, pathAddress, false);
return false;
}
@Override
protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
updateConfiguration(context, pathAddress, true);
}
private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
ServiceController<KeyStoreProviderService> serviceController = (ServiceController<KeyStoreProviderService>) serviceRegistry.getService(KeyStoreProviderService.createServiceName(federationAlias));
if (serviceController != null) {
KeyStoreProviderService service = serviceController.getValue();
ModelNode keyStoreProviderNode;
if (!rollback) {
keyStoreProviderNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
} else {
Resource rc = context.getOriginalRootResource().navigate(pathAddress);
keyStoreProviderNode = rc.getModel();
}
ModelNode relativeToNode = KeyStoreProviderResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, keyStoreProviderNode);
String relativeTo = null;
if (relativeToNode.isDefined()) {
relativeTo = relativeToNode.asString();
}
String file = KeyStoreProviderResourceDefinition.FILE.resolveModelAttribute(context, keyStoreProviderNode).asString();
service.setKeyProviderType(KeyStoreProviderAddHandler.toKeyProviderType(context, keyStoreProviderNode), file, relativeTo);
}
}
};
}
Aggregations