mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V3.4-BUG-FIX to HEAD
29755: ALF-6742 Javascript error using the manager permissions action in the docLib on a folder that uses no inherit permissions Dmitry change: Modify permissions.js to store permissions that are not supported in separate array during _showDialog() method invocation. Then add them into params that are going to setPermissions() method. Error no longer takes place and dialog appears as expected. 29756: UI coding standards for r29755 29757: ALF-9908 Improvement to log output for high level audit to make it more readable to developers 29767: ALF-9351 No exception with invalid permission definitions - DTD/Schema validation added - Corrected permissionDefinitions.xml (contained extra -->) so failed validation git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29802 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,8 +18,11 @@
|
||||
*/
|
||||
package org.alfresco.repo.security.permissions.impl.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
@@ -50,11 +53,15 @@ import org.alfresco.service.namespace.DynamicNamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.dom4j.Attribute;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.DocumentType;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.dom4j.tree.DefaultDocumentType;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* The implementation of the model DAO Reads and stores the top level model information Encapsulates access to this
|
||||
@@ -93,6 +100,8 @@ public class PermissionModel implements ModelDAO
|
||||
// Instance variables
|
||||
|
||||
private String model;
|
||||
private String dtdSchema;
|
||||
private boolean validate = true;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -1142,6 +1151,26 @@ public class PermissionModel implements ModelDAO
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dtd schema that is used to validate permission model
|
||||
*
|
||||
* @param dtdSchema
|
||||
*/
|
||||
public void setDtdSchema(String dtdSchema)
|
||||
{
|
||||
this.dtdSchema = dtdSchema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether model should be validated on initialization against specified dtd
|
||||
*
|
||||
* @param validate
|
||||
*/
|
||||
public void setValidate(boolean validate)
|
||||
{
|
||||
this.validate = validate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dictionary service
|
||||
*
|
||||
@@ -1261,6 +1290,7 @@ public class PermissionModel implements ModelDAO
|
||||
private Document createDocument(String model)
|
||||
{
|
||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream(model);
|
||||
URL dtdSchemaUrl = this.getClass().getClassLoader().getResource(dtdSchema);
|
||||
if (is == null)
|
||||
{
|
||||
throw new PermissionModelException("File not found: " + model);
|
||||
@@ -1268,21 +1298,63 @@ public class PermissionModel implements ModelDAO
|
||||
SAXReader reader = new SAXReader();
|
||||
try
|
||||
{
|
||||
if (validate)
|
||||
{
|
||||
if (dtdSchemaUrl != null)
|
||||
{
|
||||
is = processModelDocType(is, dtdSchemaUrl.toString());
|
||||
reader.setValidation(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PermissionModelException("Couldn't obtain DTD schema to validate permission model.");
|
||||
}
|
||||
}
|
||||
|
||||
Document document = reader.read(is);
|
||||
is.close();
|
||||
return document;
|
||||
}
|
||||
catch (DocumentException e)
|
||||
{
|
||||
throw new PermissionModelException("Failed to create permission model document ", e);
|
||||
throw new PermissionModelException("Failed to create permission model document: " + model, e);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new PermissionModelException("Failed to close permission model document ", e);
|
||||
throw new PermissionModelException("Failed to close permission model document: " + model, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Replace or add correct DOCTYPE to the xml to allow validation against dtd
|
||||
*/
|
||||
private InputStream processModelDocType(InputStream is, String dtdSchemaUrl) throws DocumentException, IOException
|
||||
{
|
||||
SAXReader reader = new SAXReader();
|
||||
// read document without validation
|
||||
Document doc = reader.read(is);
|
||||
DocumentType docType = doc.getDocType();
|
||||
if (docType != null)
|
||||
{
|
||||
// replace DOCTYPE setting the full path to the xsd
|
||||
docType.setSystemID(dtdSchemaUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the DOCTYPE
|
||||
docType = new DefaultDocumentType(doc.getRootElement().getName(), dtdSchemaUrl);
|
||||
doc.setDocType(docType);
|
||||
}
|
||||
|
||||
File tempFile = TempFileProvider.createTempFile("permissionModel-", ".tmp");
|
||||
|
||||
// copy the modified permission model to the temp file
|
||||
FileCopyUtils.copy(doc.asXML().getBytes(), tempFile);
|
||||
|
||||
return new FileInputStream(tempFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default access status
|
||||
*
|
||||
|
Reference in New Issue
Block a user