Ejemplo n.º 1
0
  /**
   * Get a map of the sites custom properties
   *
   * @return map of names and values
   */
  public ScriptableQNameMap<String, CustomProperty> getCustomProperties() {
    if (this.customProperties == null) {
      // create the custom properties map
      ScriptNode siteNode = new ScriptNode(this.siteInfo.getNodeRef(), this.serviceRegistry);
      // set the scope, for use when converting props to javascript objects
      siteNode.setScope(scope);
      this.customProperties =
          new ContentAwareScriptableQNameMap<String, CustomProperty>(
              siteNode, this.serviceRegistry);

      Map<QName, Serializable> props = siteInfo.getCustomProperties();
      for (QName qname : props.keySet()) {
        // get the property value
        Serializable propValue = props.get(qname);

        // convert the value
        NodeValueConverter valueConverter = siteNode.new NodeValueConverter();
        Serializable value = valueConverter.convertValueForScript(qname, propValue);

        // get the type and label information from the dictionary
        String title = null;
        String type = null;
        PropertyDefinition propDef = this.serviceRegistry.getDictionaryService().getProperty(qname);
        if (propDef != null) {
          type = propDef.getDataType().getName().toString();
          title = propDef.getTitle(this.serviceRegistry.getDictionaryService());
        }

        // create the custom property and add to the map
        CustomProperty customProp = new CustomProperty(qname.toString(), value, type, title);
        this.customProperties.put(qname.toString(), customProp);
      }
    }
    return this.customProperties;
  }
Ejemplo n.º 2
0
 /**
  * Method to add a script-based rule on a space to apply on children space
  *
  * @param script the javascript script file containing the code of the rule to apply on the
  *     targeted space
  * @param targetSpace the targeted space
  * @param ruleType the rule type: either "inbound", "outbound" or "update"
  * @param contentType
  * @param uri
  */
 public void addScriptRuleWithTypeCondition(
     ScriptNode script, ScriptNode targetSpace, String ruleType, String contentType, String uri) {
   rulesService.addRuleWithTypeCondition(
       script.getNodeRef(),
       targetSpace.getNodeRef(),
       ruleType,
       QName.createQName(uri, contentType));
 }
  /**
   * Convert Alfresco authority to actor id
   *
   * @param authority
   * @return actor id
   */
  private String mapAuthorityToName(ScriptNode authority, boolean allowGroup) {
    String name = null;
    QName type = authority.getQNameType();

    if (dictionaryService.isSubClass(type, ContentModel.TYPE_PERSON)) {
      name = (String) authority.getProperties().get(ContentModel.PROP_USERNAME);
    } else if (allowGroup
        && dictionaryService.isSubClass(type, ContentModel.TYPE_AUTHORITY_CONTAINER)) {
      name = authorityDAO.getAuthorityName(authority.getNodeRef());
    } else if (type.equals(ContentModel.TYPE_AUTHORITY)) {
      name = authorityDAO.getAuthorityName(authority.getNodeRef());
    }
    return name;
  }
Ejemplo n.º 4
0
  /**
   * Reset any permissions that have been set on the node.
   *
   * <p>All permissions will be deleted and the node set to inherit permissions.
   *
   * @param node node
   */
  public void resetAllPermissions(ScriptNode node) {
    final NodeRef nodeRef = node.getNodeRef();

    // ensure the user has permission to Change Permissions
    final PermissionService permissionService = serviceRegistry.getPermissionService();
    if (permissionService
        .hasPermission(nodeRef, PermissionService.CHANGE_PERMISSIONS)
        .equals(AccessStatus.ALLOWED)) {
      AuthenticationUtil.runAs(
          new RunAsWork<Void>() {
            public Void doWork() throws Exception {
              // Ensure node isn't inheriting permissions from an ancestor before deleting
              if (!permissionService.getInheritParentPermissions(nodeRef)) {
                permissionService.deletePermissions(nodeRef);
                permissionService.setInheritParentPermissions(nodeRef, true);
              }
              return null;
            }
          },
          AuthenticationUtil.SYSTEM_USER_NAME);
    } else {
      throw new AlfrescoRuntimeException(
          "You do not have the authority to update permissions on this node.");
    }
  }
Ejemplo n.º 5
0
  /**
   * Apply a set of permissions to the node.
   *
   * @param node node
   * @param permissions permissions
   */
  public void setPermissions(final ScriptNode node, final Object permissions) {
    final NodeRef nodeRef = node.getNodeRef();

    if (permissions != null && permissions instanceof ScriptableObject) {
      final PermissionService permissionService = this.serviceRegistry.getPermissionService();
      // ensure the user has permission to Change Permissions
      if (permissionService
          .hasPermission(nodeRef, PermissionService.CHANGE_PERMISSIONS)
          .equals(AccessStatus.ALLOWED)) {
        AuthenticationUtil.runAs(
            new RunAsWork<Void>() {
              public Void doWork() throws Exception {
                if (!permissionService.getInheritParentPermissions(nodeRef)) {
                  // remove existing permissions
                  permissionService.deletePermissions(nodeRef);
                }

                // Assign the correct permissions
                ScriptableObject scriptable = (ScriptableObject) permissions;
                Object[] propIds = scriptable.getIds();
                for (int i = 0; i < propIds.length; i++) {
                  // Work on each key in turn
                  Object propId = propIds[i];

                  // Only interested in keys that are formed of Strings
                  if (propId instanceof String) {
                    // Get the value out for the specified key - it must be String
                    final String key = (String) propId;
                    final Object value = scriptable.get(key, scriptable);
                    if (value instanceof String) {
                      // Set the permission on the node
                      permissionService.setPermission(nodeRef, key, (String) value, true);
                    }
                  }
                }

                // always add the site managers group with SiteManager permission
                String managers =
                    siteService.getSiteRoleGroup(getShortName(), SiteModel.SITE_MANAGER);
                permissionService.setPermission(nodeRef, managers, SiteModel.SITE_MANAGER, true);

                // now turn off inherit to finalize our permission changes
                permissionService.setInheritParentPermissions(nodeRef, false);
                return null;
              }
            },
            AuthenticationUtil.SYSTEM_USER_NAME);
      }
    } else {
      // No permissions passed-in
      this.resetAllPermissions(node);
    }
  }
Ejemplo n.º 6
0
 /**
  * Method to add a script-based rule with full setting
  *
  * @param script
  * @param targetSpace
  * @param ruleType
  * @param contentType
  * @param uri
  * @param applyToChildren
  * @param setExecuteAsynchronously
  * @param setRuleDisabled
  * @param title
  * @param description
  */
 public void addScriptRuleWithTypeCondition(
     ScriptNode script,
     ScriptNode targetSpace,
     String ruleType,
     String contentType,
     String uri,
     boolean applyToChildren,
     boolean setExecuteAsynchronously,
     boolean setRuleDisabled,
     String title,
     String description) {
   rulesService.addRuleWithTypeCondition(
       script.getNodeRef(),
       targetSpace.getNodeRef(),
       ruleType,
       QName.createQName(uri, contentType),
       applyToChildren,
       setExecuteAsynchronously,
       setRuleDisabled,
       title,
       description);
 }
Ejemplo n.º 7
0
 /**
  * Method to add a script-based rule on a space to apply on children space
  *
  * @param script the javascript script file containing the code of the rule to apply on the
  *     targeted space
  * @param targetSpace the targeted space
  * @param ruleType the rule type: either "inbound", "outbound" or "update"
  */
 public void addScriptRule(ScriptNode script, ScriptNode targetSpace, String ruleType) {
   rulesService.addRule(script.getNodeRef(), targetSpace.getNodeRef(), ruleType);
 }
Ejemplo n.º 8
0
 /**
  * @param script
  * @param title (optional return all if null)
  * @param ruleTypeName (optional return all if null)
  * @param includeInhertiedRuleType
  */
 public void enableRules(
     ScriptNode script, String title, String ruleTypeName, boolean includeInhertiedRuleType) {
   rulesService.enableRules(script.getNodeRef(), title, ruleTypeName, includeInhertiedRuleType);
 }
Ejemplo n.º 9
0
  /** Upload an encoded Base64 file to the repository and decode it back once it's uploaded. */
  @Override
  protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    HashMap<String, Object> model = new HashMap<String, Object>();
    UserTransaction trx = serviceRegistry.getTransactionService().getUserTransaction();

    try {
      trx.begin();
      System.out.println(trx.hashCode());
      Element args = Arguments.getArguments(req);
      String username =
          args.getElementsByTagName(FORM_PARAM_USERNAME).item(0).getFirstChild().getNodeValue();

      model.put(FTL_USERNAME, username);
      Impersonate.impersonate(username);

      String ref = DocumentUtils.pujarDocumentBase64(req, args, username).trim();
      NodeRef nodeRef = new NodeRef(ref);

      Map<QName, Serializable> props = serviceRegistry.getNodeService().getProperties(nodeRef);
      ContentReader reader =
          serviceRegistry.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT);
      byte[] contentDecoded =
          es.mityc.firmaJava.libreria.utilidades.Base64.decode(reader.getContentString());
      ContentWriter writer =
          serviceRegistry.getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
      writer.putContent(new ByteArrayInputStream(contentDecoded));

      serviceRegistry.getOwnableService().setOwner(nodeRef, username);

      Context cx = Context.enter();
      Scriptable scope = cx.initStandardObjects();
      ScriptNode document = new ScriptNode(nodeRef, serviceRegistry, scope);

      model.put(FTL_DOCUMENT, document);
      model.put(FTL_SUCCESS, String.valueOf(true));

      // Auditar creación de documento
      String type = document.getTypeShort();
      String site = document.getSiteShortName();
      if (type.equals("udl:documentSimple")) {
        AuditUdl.auditRecord(
            auditComponent,
            username,
            document.getNodeRef().toString(),
            AUDIT_ACTION_CREATE_DOCUMENT_SIMPLE,
            type,
            site);
        QName qNameIdDocSimple =
            QName.createQName(
                "http://www.smile.com/model/udl/1.0", "secuencial_identificador_documentSimple");
        String idDocSimple =
            (String) serviceRegistry.getNodeService().getProperty(nodeRef, qNameIdDocSimple);

        if ("".equals(idDocSimple) || idDocSimple == null) {
          // serviceRegistry.getNodeService().deleteNode(nodeRef);
          throw new Exception("Error obtenint identificador via WebService.");
        }
      }

      trx.commit();

    } catch (Exception e) {
      e.printStackTrace();
      model.put(FTL_ERROR, e.getMessage());
      model.put(FTL_SUCCESS, String.valueOf(false));

      try {
        if (trx.getStatus() == javax.transaction.Status.STATUS_ACTIVE) {
          System.out.println(trx.hashCode());
          trx.rollback();
        }
      } catch (SystemException ex) {
        e.printStackTrace();
      }
    }

    return model;
  }