GithubHelp home page GithubHelp logo

jpotts / alfresco-acl-templates Goto Github PK

View Code? Open in Web Editor NEW
6.0 5.0 7.0 110 KB

Facilitates the creation of multiple named Access Control Lists (ACLs) expressed as JSON which can then be applied to a given node.

License: Apache License 2.0

Batchfile 2.14% Shell 0.55% Java 97.31%

alfresco-acl-templates's Introduction

Alfresco ACL Templates

Allows you to define a set of named ACL templates described in JSON, then apply a template to a node using the ACL template service. The service will first resolve any Authority Templates that might exist in the ACL template, then will apply the resulting ACL to the node.

Why Does this Exist?

You can often generalize how an ACL should look. For example, you might say, "This is how an ACL should look when something is approved" or "This is how an ACL should look when something is archived". In addition, you might have many places where you are making changes to ACLs, such as workflows, actions, behaviors, etc.

It is nice to be able to describe an ACL as a generalized pattern or template and do so separate from code, so that administrators or others can make adjustments without needing to touch code or know where that code is in the first place.

With this add-on, you can work with your stakeholders to determine the appropriate set of ACL templates and use JSON to describe those in a central place (the Data Dictionary). Then, any time your Java or JavaScript code needs to set permissions on a node, it can use the ACL Template Service to say, "Apply the 'archived' ACL template to this node" and the permissions will be set appropriately.

If someone later decides, for example, that archived nodes should now be readable by the Legal Department, the ACL template is edited to add the Legal Department. Code that leverages the ACL Template Service does not have to be touched.

Defining ACL Templates

ACL Template definitions reside in the Data Dictionary under a folder called "ACL Templates". That folder is created when the AMP is installed.

ACL Templates are expressed as JSON. Here is a simple example:

{
  "inherit": false,
  "permissions": [
    {
      "authorityTemplate": "site-manager-group",
      "permission": "Consumer"
    }
  ]
}

In this example, the ACL Template consists of a single entry. The entry does not specify a hard-coded authority. Instead, it specifies an Authority Template called "site-manager-group". An authority template is like an alias. It gets resolved when the ACL Template gets applied to a node.

So this ACL Template says, "When this template is applied to a node, figure out what the node's Site Manager Group is and set that to Consumer."

Authority Template

An Authority Template is just a Java Bean that implements the AuthorityResolver interface. An AuthorityResolver is responsible for returning a String which is the value of the authority to use. The AuthorityResolver gets handed the node reference for the node the ACL Template is being applied to.

In the earlier example, the Authority Template called "site-manager-group" ties to a Java class that takes a node reference, determines which Share Site it belongs to and then returns the name of the group used to store people in the SiteManager role. But AuthorityTemplates could do anything, like return a value based on a property value, for example.

Applying an ACL Template to a Node

The ACL Template Service is used to apply an ACL Template to a node. The service can be called from Java or by using a root object called "aclTemplates".

For example, to apply an ACL Template called "test-template-2.json" to a folder you could do:

aclTemplateService.apply("test-template-2.json", testFolder);

Or, if you are using JavaScript, it would look like:

aclTemplates.apply("test-template-2.json", testFolder);

In addition to the apply method, you can also ask the service for the list of ACL Templates it knows about using getAclTemplates() as well as the list of Authority Resolvers it knows about using getAuthorityResolvers().

Integration Tests

If you check the source code out you can use Maven to run integration tests. To do this, first start the embedded Alfresco server with mvn clean install alfresco:run -DskipTests=true. Wait for the server to start up.

Next, copy the test ACL templates from integration-tests/src/test/resources into the "ACL Templates" folder under the Data Dictionary. Because this project has no Share AMP, you can either start up Share in some other Tomcat, use a script to copy in the test templates via CMIS, or just map a drive to http://localhost:8080/alfresco/webdav.

If the ACL Templates folder does not exist something went wrong with the server startup.with mvn test.

With the test templates in place you are ready to run the integration tests. You can do so from your IDE if you want, or open a new terminal window, change to the project root and run mvn integration-test.

Installing

Running mvn package will produce an AMP that can be installed in your Alfresco WAR. Copy the AMP to $ALFRESCO_HOME/amps, then use the MMT to install the AMP, which is typically done by running a script such as bin/apply_amps.sh.

Adding Your Own Authority Resolvers

It is unlikely that this addon will be useful without adding your own Authority Resolver beans. To do that, write one or more Java classes that implement the AuthorityResolver interface, then wire them up in a Spring context XML file.

Then, override the acl-template-service bean with your own definition that passes in your own map of authorityResolvers.

Your custom Authority Resolver Java beans and the related Spring context should go in your own repo-tier AMP, which means you'll need to add this AMP as a dependency to your own project.

alfresco-acl-templates's People

Contributors

dependabot[bot] avatar douglascrp avatar jpotts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

alfresco-acl-templates's Issues

Sugestion to replace all the LUCENE queries by FTS_ALFRESCO

It would be nice to have all the Lucene queries replaced by FTS Alfresco, as Lucene is considered deprecated now.

Lucene is being used in some places, like:
https://github.com/Conexiam/alfresco-acl-templates/blob/master/acl-templates-repo/src/main/java/com/conexiam/acl/templates/service/AclTemplateServiceImpl.java#L46
and
https://github.com/Conexiam/alfresco-acl-templates/blob/master/acl-templates-repo/src/main/java/com/conexiam/acl/templates/service/AclTemplateServiceImpl.java#L64

I am working on the addon right now, so I hope to be able to send a PR to fix this.

Improve the AclTemplateServiceImpl.resolveAuthorityTemplates method to avoid null authorities

When I was developing my custom authority resolver, I got to the point where the authority as not "resolvable" based on the current node I was working on, because the property the resolver relied on was null.
In this case, the authority got resolved to null, and when the permission was going to be applied into the node, I got the exception:

"Authority is a mandatory parameter" at https://github.com/Conexiam/alfresco-acl-templates/blob/master/acl-templates-repo/src/main/java/com/conexiam/acl/templates/service/AclTemplateServiceImpl.java#L101

My idea is to make it fail first, when actually trying to resolve the authority, and if it is not possible to do so, throw the exception and not even try to set the permission on the node.

Release version 1.0.1

Hello @jpotts

Would you mind releasing the version 1.0.1?
The version has been changed in the pom file, but the releases page does not contain the AMP files.

Thank you

Restructure and add integration tests back in

The integration tests were removed when the project was upgraded to SDK 3.0.1.

I now have a dup of this project working using the Alfresco Yeoman Generator structure which makes it easier to get the integration test working in a repo-only AMP project.

So this issue is a reminder/to-do for me to commit the restructured project to add the integration tests back in.

Refactor the ACL template finder to be a separate bean

There may be cases where customers would like to use a different mechanism to find the persisted ACL template JSON.

One simple example would be to store the JSON somewhere a non-admin would find it easier to manage.

To facilitate this, we should refactor the ACL template location to a separate bean to let customers implement their own implementations.

Add the option to DENY permission for specific authorities

Currently, this addon allows one to grant authorities permissions, but there is no way to set a DENY for them.

Being able to DENY permissions would be useful for cases when a document should be read by specific users only after it has been published.

The set permission right now is setting READ as true: https://github.com/Conexiam/alfresco-acl-templates/blob/master/acl-templates-repo/src/main/java/com/conexiam/acl/templates/service/AclTemplateServiceImpl.java#L101

I thought about having the hardcoded "true" replaced by some logic reading a new property inside the json, which reads "DENY" or "ALLOW", and having those values translated to boolean values.
And in order to make things easier and backward compatible, if there is not "DENY" or "ALLOW" present in the json, simply assume true, meaning the ALLOW is the default.

This is what I am trying to implement right now.

@jpotts I am not sure if you will remember, but we talked about this idea by email 3 months ago.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.