use of org.jboss.dmr.Property in project wildfly by wildfly.
the class AbstractEntityProviderAddHandler method configureHandler.
protected static void configureHandler(OperationContext context, ModelNode model, EntityProviderService service) throws OperationFailedException {
if (model.hasDefined(ModelElement.COMMON_HANDLER.getName())) {
for (Property handlerProperty : model.get(ModelElement.COMMON_HANDLER.getName()).asPropertyList()) {
ModelNode handler = handlerProperty.getValue();
Handler newHandler = toHandlerConfig(context, handler);
if (handler.hasDefined(COMMON_HANDLER_PARAMETER.getName())) {
for (Property handlerParameter : handler.get(COMMON_HANDLER_PARAMETER.getName()).asPropertyList()) {
String paramName = handlerParameter.getName();
ModelNode parameterNode = handlerParameter.getValue();
KeyValueType kv = toHandlerParameterConfig(context, paramName, parameterNode);
newHandler.add(kv);
}
}
service.addHandler(newHandler);
}
}
}
use of org.jboss.dmr.Property in project wildfly by wildfly.
the class LegacyPropertyWriteOperationTransformer method transformOperation.
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
if (operation.get(NAME).asString().equals(PROPERTIES)) {
InitialAttributeValueOperationContextAttachment attachment = context.getAttachment(InitialAttributeValueOperationContextAttachment.INITIAL_VALUES_ATTACHMENT);
assert attachment != null;
// Workaround aliases limitations!
// we need to painstakingly undo path alias translations, since we need to know the address of the real resource,
// since the readResourceFromRoot() will not work on the aliased address
Map<String, String> undoAliases = new HashMap<>();
undoAliases.put("BINARY_KEYED_JDBC_STORE", "binary-jdbc");
undoAliases.put("STORE", "custom");
undoAliases.put("FILE_STORE", "file");
undoAliases.put("MIXED_KEYED_JDBC_STORE", "mixed-jdbc");
undoAliases.put("REMOTE_STORE", "remote");
undoAliases.put("STRING_KEYED_JDBC_STORE", "string-jdbc");
if (undoAliases.containsKey(address.getLastElement().getValue())) {
address = address.subAddress(0, address.size() - 1).append("store", undoAliases.get(address.getLastElement().getValue()));
}
ModelNode initialValue = attachment.getInitialValue(address, Operations.getAttributeName(operation));
ModelNode newValue = context.readResourceFromRoot(address).getModel().get(PROPERTIES).clone();
if (initialValue.equals(newValue) || (initialValue.isDefined() && initialValue.asPropertyList().isEmpty() && !newValue.isDefined())) {
// There is nothing to do, discard this operation
return new TransformedOperation(null, DEFAULT_REJECTION_POLICY, SUCCESSFUL_RESULT);
}
final Map<String, ModelNode> oldMap = new HashMap<>();
if (initialValue.isDefined()) {
for (Property property : initialValue.asPropertyList()) {
oldMap.put(property.getName(), property.getValue());
}
}
// Transformed address for all operations
final PathAddress legacyAddress = Operations.getPathAddress(operation);
// This may result as multiple operations on the legacy node
final ModelNode composite = new ModelNode();
composite.get(OP).set(COMPOSITE);
composite.get(OP_ADDR).setEmptyList();
if (newValue.isDefined()) {
for (Property property : newValue.asPropertyList()) {
String key = property.getName();
ModelNode value = property.getValue();
if (!oldMap.containsKey(key)) {
// This is a newly added property => :add operation
ModelNode addOp = Util.createAddOperation(legacyAddress.append(PathElement.pathElement(PROPERTY, key)));
addOp.get(VALUE).set(value);
composite.get(STEPS).add(addOp);
} else {
final ModelNode oldPropValue = oldMap.get(key);
if (!oldPropValue.equals(value)) {
// Property value is different => :write-attribute operation
ModelNode writeOp = Util.getWriteAttributeOperation(legacyAddress.append(PathElement.pathElement(PROPERTY, key)), VALUE, value);
composite.get(STEPS).add(writeOp);
}
// Otherwise both property name and value are the same => no operation
// Remove this key
oldMap.remove(key);
}
}
}
// Properties that were removed = :remove operation
for (Map.Entry<String, ModelNode> prop : oldMap.entrySet()) {
ModelNode removeOperation = Util.createRemoveOperation(legacyAddress.append(PathElement.pathElement(PROPERTY, prop.getKey())));
composite.get(STEPS).add(removeOperation);
}
initialValue.set(newValue.clone());
return new TransformedOperation(composite, OperationResultTransformer.ORIGINAL_RESULT);
}
return new TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT);
}
use of org.jboss.dmr.Property in project wildfly by wildfly.
the class SecurityDomainAdd method processIdentityTrust.
private boolean processIdentityTrust(OperationContext context, String securityDomain, ModelNode node, ApplicationPolicy applicationPolicy) throws OperationFailedException {
node = peek(node, IDENTITY_TRUST, CLASSIC, TRUST_MODULE);
if (node == null) {
return false;
}
IdentityTrustInfo identityTrustInfo = new IdentityTrustInfo(securityDomain);
for (Property moduleProperty : node.asPropertyList()) {
ModelNode module = moduleProperty.getValue();
String codeName = LoginModuleResourceDefinition.CODE.resolveModelAttribute(context, module).asString();
String flag = LoginModuleResourceDefinition.FLAG.resolveModelAttribute(context, module).asString();
ControlFlag controlFlag = ControlFlag.valueOf(flag);
Map<String, Object> options = extractOptions(context, module);
IdentityTrustModuleEntry entry = new IdentityTrustModuleEntry(codeName, options);
entry.setControlFlag(controlFlag);
identityTrustInfo.add(entry);
ModelNode moduleName = LoginModuleResourceDefinition.MODULE.resolveModelAttribute(context, module);
if (moduleName.isDefined() && !moduleName.asString().isEmpty()) {
identityTrustInfo.addJBossModuleName(moduleName.asString());
} else {
identityTrustInfo.addJBossModuleName(DEFAULT_MODULE);
}
}
applicationPolicy.setIdentityTrustInfo(identityTrustInfo);
return true;
}
use of org.jboss.dmr.Property in project wildfly by wildfly.
the class SecurityDomainAdd method processJASPIAuth.
private boolean processJASPIAuth(OperationContext context, String securityDomain, ModelNode node, ApplicationPolicy applicationPolicy) throws OperationFailedException {
node = peek(node, AUTHENTICATION, JASPI);
if (node == null) {
return false;
}
JASPIAuthenticationInfo authenticationInfo = new JASPIAuthenticationInfo(securityDomain);
Map<String, LoginModuleStackHolder> holders = new HashMap<String, LoginModuleStackHolder>();
if (node.hasDefined(LOGIN_MODULE_STACK)) {
List<Property> stacks = node.get(LOGIN_MODULE_STACK).asPropertyList();
for (Property stack : stacks) {
String name = stack.getName();
ModelNode stackNode = stack.getValue();
final LoginModuleStackHolder holder = new LoginModuleStackHolder(name, null);
holders.put(name, holder);
authenticationInfo.add(holder);
if (stackNode.hasDefined(LOGIN_MODULE)) {
processLoginModules(context, stackNode.get(LOGIN_MODULE), authenticationInfo, new LoginModuleContainer() {
public void addAppConfigurationEntry(AppConfigurationEntry entry) {
holder.addAppConfigurationEntry(entry);
}
});
}
}
}
for (Property moduleProperty : node.get(AUTH_MODULE).asPropertyList()) {
ModelNode authModule = moduleProperty.getValue();
String code = extractCode(context, authModule, ModulesMap.AUTHENTICATION_MAP);
String loginStackRef = null;
if (authModule.hasDefined(LOGIN_MODULE_STACK_REF)) {
loginStackRef = JASPIMappingModuleDefinition.LOGIN_MODULE_STACK_REF.resolveModelAttribute(context, authModule).asString();
}
Map<String, Object> options = extractOptions(context, authModule);
AuthModuleEntry entry = new AuthModuleEntry(code, options, loginStackRef);
if (authModule.hasDefined(FLAG)) {
String flag = LoginModuleResourceDefinition.FLAG.resolveModelAttribute(context, authModule).asString();
entry.setControlFlag(ControlFlag.valueOf(flag));
}
if (loginStackRef != null) {
if (!holders.containsKey(loginStackRef)) {
throw SecurityLogger.ROOT_LOGGER.loginModuleStackIllegalArgument(loginStackRef);
}
entry.setLoginModuleStackHolder(holders.get(loginStackRef));
}
authenticationInfo.add(entry);
ModelNode moduleName = LoginModuleResourceDefinition.MODULE.resolveModelAttribute(context, authModule);
if (moduleName.isDefined() && !moduleName.asString().isEmpty()) {
authenticationInfo.addJBossModuleName(moduleName.asString());
} else {
authenticationInfo.addJBossModuleName(DEFAULT_MODULE);
}
}
applicationPolicy.setAuthenticationInfo(authenticationInfo);
return true;
}
use of org.jboss.dmr.Property in project wildfly by wildfly.
the class SecurityDomainAdd method processMapping.
private boolean processMapping(OperationContext context, String securityDomain, ModelNode node, ApplicationPolicy applicationPolicy) throws OperationFailedException {
node = peek(node, MAPPING, CLASSIC, MAPPING_MODULE);
if (node == null) {
return false;
}
for (Property moduleProperty : node.asPropertyList()) {
ModelNode module = moduleProperty.getValue();
MappingInfo mappingInfo = new MappingInfo(securityDomain);
String codeName = extractCode(context, module, ModulesMap.MAPPING_MAP);
String mappingType;
if (module.hasDefined(TYPE)) {
mappingType = MappingModuleDefinition.TYPE.resolveModelAttribute(context, module).asString();
} else {
mappingType = MappingType.ROLE.toString();
}
Map<String, Object> options = extractOptions(context, module);
MappingModuleEntry entry = new MappingModuleEntry(codeName, options, mappingType);
mappingInfo.add(entry);
applicationPolicy.setMappingInfo(mappingType, mappingInfo);
ModelNode moduleName = LoginModuleResourceDefinition.MODULE.resolveModelAttribute(context, module);
if (moduleName.isDefined() && !moduleName.asString().isEmpty()) {
mappingInfo.addJBossModuleName(moduleName.asString());
} else {
mappingInfo.addJBossModuleName(DEFAULT_MODULE);
}
}
return true;
}
Aggregations