Friday 19 April 2019

CMIS: Check whether repository supports ACLS or not


By querying repository capabilities, you can check whether repository supports ACLS or not.

Below snippet is used to check whether repository supports ACLS or not.

                  CapabilityAcl aclCapabilities = session.getRepositoryInfo().getCapabilities().getAclCapability();

                  if (aclCapabilities == null) {
                           System.out.println("Reposiotry do not support acls");
                           return;
                  }

                  System.out.println("Repository supports acls");

Find the below working application

Test.java
import java.util.HashMap;
import java.util.Map;

import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.commons.enums.CapabilityAcl;

public class Test {

 private static String serverURL = "http://localhost:8080/chemistry-opencmis-server-inmemory-1.1.0/browser";
 private static String repositoryId = "A1";

 public static Session getSession() {
  Map<String, String> parameters = new HashMap<>();
  parameters.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());

  parameters.put(SessionParameter.USER, "");
  parameters.put(SessionParameter.PASSWORD, "");

  parameters.put(SessionParameter.REPOSITORY_ID, repositoryId);
  parameters.put(SessionParameter.BROWSER_URL, serverURL);

  SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
  return sessionFactory.createSession(parameters);
 }

 public static void main(String args[]) {
  Session session = getSession();
  CapabilityAcl aclCapabilities = session.getRepositoryInfo().getCapabilities().getAclCapability();

  if (aclCapabilities == null) {
   System.out.println("Reposiotry do not support acls");
   return;
  }

  System.out.println("Repository supports acls");
 }
}

Output
Repository supports acls

CapabilityAcl can have one of three values: none, discover, manage.

Below table summarizes the values of CapabilityAcl.
Value
Description
none
No ACL are supported
discover
Repository support discovery of ACLs
manage
Repository support discovery of ACLs and applying ACLs.

                  Session session = getSession();
                  CapabilityAcl aclCapabilities = session.getRepositoryInfo().getCapabilities().getAclCapability();

                  if (aclCapabilities == null) {
                           System.out.println("Reposiotry do not support acls");
                  } else if (aclCapabilities == CapabilityAcl.NONE) {
                           System.out.println("Reposiotry do not support acls");
                  } else if (aclCapabilities == CapabilityAcl.DISCOVER) {
                           System.out.println("Repository support discovery of ACLs");
                  } else {
                           System.out.println("Repository support discovery of ACLs and applying ACLs.");
                  }

Find the complete working application.


Test.java
import java.util.HashMap;
import java.util.Map;

import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.commons.enums.CapabilityAcl;

public class Test {

 private static String serverURL = "http://localhost:8080/chemistry-opencmis-server-inmemory-1.1.0/browser";
 private static String repositoryId = "A1";

 public static Session getSession() {
  Map<String, String> parameters = new HashMap<>();
  parameters.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());

  parameters.put(SessionParameter.USER, "");
  parameters.put(SessionParameter.PASSWORD, "");

  parameters.put(SessionParameter.REPOSITORY_ID, repositoryId);
  parameters.put(SessionParameter.BROWSER_URL, serverURL);

  SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
  return sessionFactory.createSession(parameters);
 }

 public static void main(String args[]) {
  Session session = getSession();
  CapabilityAcl aclCapabilities = session.getRepositoryInfo().getCapabilities().getAclCapability();

  if (aclCapabilities == null) {
   System.out.println("Reposiotry do not support acls");
  } else if (aclCapabilities == CapabilityAcl.NONE) {
   System.out.println("Reposiotry do not support acls");
  } else if (aclCapabilities == CapabilityAcl.DISCOVER) {
   System.out.println("Repository support discovery of ACLs");
  } else {
   System.out.println("Repository support discovery of ACLs and applying ACLs.");
  }

 }
}

Output
Repository support discovery of ACLs and applying ACLs.

Checking ACL capabilities using workbench
You can check repository ACl capabilities using workbench. Connect to the repository.


Click on the button, Repository Info

Go to Capabilities section, you can able to see whether repository supports capabilities or not.


Previous                                                 Next                                                 Home

No comments:

Post a Comment