Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/redaction-ruleset-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/bin
.classpath
.project
/build
.gradle
.settings
15 changes: 15 additions & 0 deletions examples/redaction-ruleset-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This project shows an example of how MarkLogic 9 Redaction Rulesets can be loaded into a schemas
database from src/main/ml-schemas (the default path - this can be overridden via
mlSchemasPath).

Note that in order for this to work, the content-database.json file must specify the schema
database that it's associated with. And in most cases, you'll want your own schemas database - not the default Schemas one - so schemas-database.json can be used to create own with a name based on mlAppName.

Within each folder containing one or more Redaction Rulesets, you must provide a **collections.properties** and (optionally) a **permissions.properties** file.
These files contain the definitions for the applicable collections to be applied to the rulesets as well as the document permissions (if included).

***Note***: Rulesets must have a .json or .xml file extension.

See [Specifying collections and permissions](https://github.com/marklogic-community/ml-javaclient-util/wiki/Loading-files#specifying-collections-and-permissions) for information on how to apply the collections and permission when the rulesets are loaded

See [Redacting Document Content](http://docs.marklogic.com/guide/app-dev/redaction) for more information on redacting content
87 changes: 87 additions & 0 deletions examples/redaction-ruleset-project/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
buildscript {
repositories {
jcenter()
// Needed for mlcp dependency: XCC
maven { url "http://developer.marklogic.com/maven2/" }
}
dependencies {
classpath "com.marklogic:marklogic-contentpump:9.0.3"
classpath "com.marklogic:ml-gradle:3.0.0"
}
}

apply plugin: "com.marklogic.ml-gradle"

repositories {
jcenter()
// Needed for mlcp dependency
maven { url "http://developer.marklogic.com/maven2/" }
maven { url "http://repository.cloudera.com/artifactory/cloudera-repos/" }
}

configurations {
mlcp {
resolutionStrategy {
force "xml-apis:xml-apis:1.4.01"
}
}
}


dependencies {
mlcp "com.marklogic:mlcp:9.0.3"
mlcp files("lib")
}

/***************************************************************
Optional tasks to test redaction of data
***************************************************************/

/*
* The import task below is an example of using the built-in MLCP Task in ml-gradle and will import sample JSON
* documents to the specified content database while applying the applicable collections to the content so that
* the redaction rules can be applied
* */
task importSampleRedactionData(type: com.marklogic.gradle.task.MlcpTask) {
description = "Example of using mlcp and MlcpTask to import documents to test redaction rules"
classpath = configurations.mlcp
command = "IMPORT"
database = mlAppConfig.contentDatabaseName
input_file_path = "data/import"
output_collections = "security-rules,pii-rules,email-rules"
output_permissions = "rest-reader,read,rest-writer,update"
output_uri_replace = ".*import,'/import'"
logOutputUri = "/redaction.txt"
}


/*
* The export task below shows an example of using JavaExec inside Gradle to invoke MLCP to export the documents.
* This task, while a useful example, must be invoked this way because the built-in MLCP task does not yet recognize
* the "redaction" option being passed. This will be addressed in a future release.
* Exported documents will be within this project folder under /data/export
* */
task exportSampleRedactionData(type: JavaExec) {
classpath = configurations.mlcp
main = 'com.marklogic.contentpump.ContentPump'

args = [
"EXPORT",
"-host", "${mlHost}",
"-port", "8130",
"-username", "${mlUsername}",
"-password", "${mlPassword}",
"-database", mlAppConfig.contentDatabaseName,
"-output_file_path", "data/export",
"-collection_filter", "security-rules",
"-redaction", "security-rules"]
/*
* Applying "security-rules" as the redaction collection will redact both email and SSN fields in the documents
* You may also redact just the email or ths SSN fields individually by applying only those specific collections
* i.e. "pii-rules" OR "email-rules"

*/

}


Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions examples/redaction-ruleset-project/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mlHost=localhost
mlAppName=redaction-project
mlRestPort=8130
mlUsername=admin
mlPassword=admin
8 changes: 8 additions & 0 deletions examples/redaction-ruleset-project/lib/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Root logger option
log4j.rootLogger=INFO, stdout

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"database-name": "%%DATABASE%%",
"schema-database": "%%SCHEMAS_DATABASE%%"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"database-name": "%%SCHEMAS_DATABASE%%"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Add one or more collections to add the ruleset to (comma separated)
# Example: file.json=collection1,collection2

ssn.json=security-rules,pii-rules
email.json=security-rules,email-rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rule": {
"description": "hide email addresses",
"path": "//email",
"method": {
"function": "redact-email"
},
"options": {
"pattern": "partial"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rule": {
"description": "hide SSNs",
"path": "//ssn",
"method": {
"function": "redact-us-ssn"
},
"options": {
"pattern": "partial"
}
}
}