private void parseCustomNodeTypes(ModelNode model, EditableDocument configDoc) {
   if (model.hasDefined(ModelKeys.NODE_TYPES)) {
     EditableArray nodeTypesArray = configDoc.getOrCreateArray(FieldName.NODE_TYPES);
     for (ModelNode nodeType : model.get(ModelKeys.NODE_TYPES).asList()) {
       nodeTypesArray.add(nodeType.asString());
     }
   }
 }
  private void parseSecurity(OperationContext context, ModelNode model, EditableDocument configDoc)
      throws OperationFailedException {
    EditableDocument security = configDoc.getOrCreateDocument(FieldName.SECURITY);

    // Anonymous ...
    EditableDocument anon = security.getOrCreateDocument(FieldName.ANONYMOUS);
    String anonUsername = attribute(context, model, ModelAttributes.ANONYMOUS_USERNAME).asString();
    boolean useAnonIfFailed =
        attribute(context, model, ModelAttributes.USE_ANONYMOUS_IF_AUTH_FAILED).asBoolean();
    anon.set(FieldName.ANONYMOUS_USERNAME, anonUsername);
    anon.set(FieldName.USE_ANONYMOUS_ON_FAILED_LOGINS, useAnonIfFailed);
    List<ModelNode> modelNodes =
        model.hasDefined(ModelKeys.ANONYMOUS_ROLES)
            ? model.get(ModelKeys.ANONYMOUS_ROLES).asList()
            : ModelAttributes.ANONYMOUS_ROLES.getDefaultValue().asList();
    for (ModelNode roleNode : modelNodes) {
      EditableArray anonymousRolesArray = anon.getOrCreateArray(FieldName.ANONYMOUS_ROLES);
      String roleName = roleNode.asString();
      if (!StringUtil.isBlank(roleName)) {
        anonymousRolesArray.addString(roleName);
      }
    }

    EditableArray providers = security.getOrCreateArray(FieldName.PROVIDERS);

    // JBoss authenticator ...
    String securityDomain = attribute(context, model, ModelAttributes.SECURITY_DOMAIN).asString();
    EditableDocument jboss = Schematic.newDocument();
    jboss.set(FieldName.CLASSNAME, JBossDomainAuthenticationProvider.class.getName());
    jboss.set(FieldName.SECURITY_DOMAIN, securityDomain);
    providers.add(jboss);

    // Servlet authenticator ...
    EditableDocument servlet = Schematic.newDocument();
    servlet.set(FieldName.CLASSNAME, "servlet");
    providers.add(servlet);
  }
Beispiel #3
0
  /**
   * Immediately change and apply the specified sequencer field in the current repository
   * configuration to the new value.
   *
   * @param defn the attribute definition for the value; may not be null
   * @param newValue the new string value
   * @param sequencerName the name of the sequencer
   * @throws RepositoryException if there is a problem obtaining the repository configuration or
   *     applying the change
   * @throws OperationFailedException if there is a problem obtaining the raw value from the
   *     supplied model node
   */
  public void changeSequencerField(
      MappedAttributeDefinition defn, ModelNode newValue, String sequencerName)
      throws RepositoryException, OperationFailedException {
    ModeShapeEngine engine = getEngine();
    String repositoryName = repositoryName();

    // Get a snapshot of the current configuration ...
    RepositoryConfiguration config = engine.getRepositoryConfiguration(repositoryName);

    // Now start to make changes ...
    Editor editor = config.edit();

    // Find the array of sequencer documents ...
    List<String> pathToContainer = defn.getPathToContainerOfField();
    EditableDocument sequencing = editor.getOrCreateDocument(pathToContainer.get(0));
    EditableDocument sequencers = sequencing.getOrCreateArray(pathToContainer.get(1));

    // The container should be an array ...
    for (String configuredSequencerName : sequencers.keySet()) {
      // Look for the entry with a name that matches our sequencer name ...
      if (sequencerName.equals(configuredSequencerName)) {
        // All these entries should be nested documents ...
        EditableDocument sequencer = (EditableDocument) sequencers.get(configuredSequencerName);

        // Change the field ...
        String fieldName = defn.getFieldName();
        // Get the raw value from the model node ...
        Object rawValue = defn.getTypedValue(newValue);
        // And update the field ...
        sequencer.set(fieldName, rawValue);
        break;
      }
    }

    // Get and apply the changes to the current configuration. Note that the 'update' call
    // asynchronously
    // updates the configuration, and returns a Future<JcrRepository> that we could use if we wanted
    // to
    // wait for the changes to take place. But we don't want/need to wait, so we'll not use the
    // Future ...
    Changes changes = editor.getChanges();
    engine.update(repositoryName, changes);
  }
  private EditableDocument parseWorkspaces(
      OperationContext context, ModelNode model, EditableDocument configDoc)
      throws OperationFailedException {
    EditableDocument workspacesDoc = configDoc.getOrCreateDocument(FieldName.WORKSPACES);
    boolean allowWorkspaceCreation =
        attribute(context, model, ModelAttributes.ALLOW_WORKSPACE_CREATION).asBoolean();
    String defaultWorkspaceName =
        attribute(context, model, ModelAttributes.DEFAULT_WORKSPACE).asString();
    workspacesDoc.set(FieldName.ALLOW_CREATION, allowWorkspaceCreation);
    workspacesDoc.set(FieldName.DEFAULT, defaultWorkspaceName);
    if (model.hasDefined(ModelKeys.PREDEFINED_WORKSPACE_NAMES)) {
      for (ModelNode name : model.get(ModelKeys.PREDEFINED_WORKSPACE_NAMES).asList()) {
        workspacesDoc.getOrCreateArray(FieldName.PREDEFINED).add(name.asString());
      }

      if (model.hasDefined(ModelKeys.WORKSPACES_INITIAL_CONTENT)) {
        EditableDocument initialContentDocument =
            workspacesDoc.getOrCreateDocument(FieldName.INITIAL_CONTENT);
        List<ModelNode> workspacesInitialContent =
            model.get(ModelKeys.WORKSPACES_INITIAL_CONTENT).asList();
        for (ModelNode initialContent : workspacesInitialContent) {
          Property initialContentProperty = initialContent.asProperty();
          initialContentDocument.set(
              initialContentProperty.getName(), initialContentProperty.getValue().asString());
        }
      }
    }
    if (model.hasDefined(ModelKeys.DEFAULT_INITIAL_CONTENT)) {
      EditableDocument initialContentDocument =
          workspacesDoc.getOrCreateDocument(FieldName.INITIAL_CONTENT);
      initialContentDocument.set(
          FieldName.DEFAULT_INITIAL_CONTENT,
          model.get(ModelKeys.DEFAULT_INITIAL_CONTENT).asString());
    }
    return workspacesDoc;
  }