Showing posts with label CE API. Show all posts
Showing posts with label CE API. Show all posts

Tuesday, 24 April 2018

Java Code to get Security and DIS (Default Instance Security ) on all Classes and sub Classes (FileNet API)

//Java Code to get Security and DIS (Default Instance Security ) on all Classes and sub Classes (FileNet API)

import java.io.IOException;
import java.util.Iterator;
import javax.security.auth.Subject;
import com.filenet.api.admin.ClassDefinition;
import com.filenet.api.collection.AccessPermissionList;
import com.filenet.api.collection.ClassDefinitionSet;
import com.filenet.api.core.Connection;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.security.AccessPermission;
import com.filenet.api.util.UserContext;

public class GetClassSecurity {
    private static Connection conn = null;
    static String className=null;
   
    static String disGranteeName =null;
    static String disGranteeType =null;
    static String disPermissionSource =null;
    static String disaccessType =null;
    static String disInheritableDepth =null;
    static String disAccessMask=null;
   
    static String GranteeName =null;
    static String GranteeType =null;
    static String PermissionSource =null;
    static String accessType =null;
    static String InheritableDepth =null;
    static String AccessMask=null;
    public static Connection getCEConn()
    {
        try {
            String ceURI =    "http://localHost:9080/wsi/FNCEWS40MTOM/";
            String userName ="userName";
            String password ="Password";
            if(conn==null){
            conn = Factory.Connection.getConnection(ceURI);
            Subject subject = UserContext.createSubject(conn, userName, password, null);
            UserContext uc = UserContext.get();
            uc.pushSubject(subject);
            }

        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        System.out.println("CE Connection"+conn);
        return conn;
    }

   
    public static void getClassPermissions(String osName) throws IOException{
       
        try{
           
           
            Connection conn = getCEConn();
            Domain domain = Factory.Domain.fetchInstance(conn,null, null);
            ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain, osName,null);
           
            System.out.println("ObjectStoreDisplayName :: "+objStore.get_DisplayName());
            System.out.println("Class Name");
            System.out.println("Grantee Name");
            System.out.println("Grantee Type");
            System.out.println("Permission Source");
            System.out.println("Access Type");
            System.out.println("Inheritabled Depth");
            System.out.println("Access Mask(Object Access Rights)");
          
           
            ClassDefinitionSet cds= objStore.get_RootClassDefinitions();
            ClassDefinition cd;
            Iterator it = cds.iterator();
            while (it.hasNext())
            {
                      System.out.println("-----------------------------");
                cd = (ClassDefinition)it.next();
                className=cd.get_DisplayName();
                System.out.println("Class name = " + className);
                System.out.println("ClassDisplayName :: "+cd.get_DisplayName());
                System.out.println("ClassName :: "+cd.get_Name());
                System.out.println("ClassSymbolicName :: "+cd.get_SymbolicName());
                System.out.println("ClassCreator :: "+cd.get_Creator());
                System.out.println("ClassDefaultInstanceOwner :: "+cd.get_DefaultInstanceOwner());
                System.out.println("ClassLastModifier :: "+cd.get_LastModifier());
                System.out.println("ClassOwner :: "+cd.get_Owner());
                System.out.println("ClassDateCreated :: "+cd.get_DateCreated());
                System.out.println("ClassID :: "+cd.get_Id());
                System.out.println("ClassDateLastModified :: "+cd.get_DateLastModified());
                System.out.println("ClassIsHidden :: "+cd.get_IsHidden());
                System.out.println("ClassIsCurrent :: "+cd.isCurrent());
                System.out.println("ClassIsPersistent :: "+cd.get_IsPersistent());
                System.out.println("ClassIsSystemOwned :: "+cd.get_IsSystemOwned());
                System.out.println("ClassIsCBREnabled :: "+cd.get_IsCBREnabled());

               
               
                System.out.println("------Default Instance Security------");

                AccessPermissionList dis = cd.get_DefaultInstancePermissions();
           
                Iterator itdis = dis.iterator();
                while (itdis.hasNext())
                {
                AccessPermission permission = (AccessPermission)itdis.next();
               
                disGranteeName=permission.get_GranteeName();
                disGranteeType=permission.get_GranteeType().toString();
                disPermissionSource=permission.get_PermissionSource().toString();
                disaccessType=permission.get_AccessType().toString();
                disInheritableDepth=permission.get_InheritableDepth().toString();       
                disAccessMask=permission.get_AccessMask().toString();
               
                System.out.println("GranteeName="+ disGranteeName);
                System.out.println("GranteeType=" + disGranteeType);
                System.out.println("PermissionSource=" +disPermissionSource);
               
                System.out.println("Accesstype =" +disaccessType);
                System.out.println("Inheritabledepth=" +disInheritableDepth);
                System.out.println(className);
                 System.out.println(disGranteeName);
                 System.out.println(disGranteeType);
                 System.out.println(disPermissionSource);
                 System.out.println(disaccessType);
                 System.out.println(disInheritableDepth);
                 System.out.println(disAccessMask);
               
               
                }
               
               
                System.out.println("------Direct Security------");
               
                 AccessPermissionList s = cd.get_Permissions();
               
                Iterator itdis1 = s.iterator();
                while (itdis1.hasNext())
                {
                AccessPermission permission1 = (AccessPermission)itdis1.next();
               
                GranteeName=permission1.get_GranteeName();
                GranteeType=permission1.get_GranteeType().toString();
                PermissionSource=permission1.get_PermissionSource().toString();
                accessType=permission1.get_AccessType().toString();
                InheritableDepth=permission1.get_InheritableDepth().toString();       
                AccessMask=permission1.get_AccessMask().toString();
                System.out.println("GranteeName="+ GranteeName);
                System.out.println("GranteeType=" + GranteeType);
                System.out.println("PermissionSource=" +PermissionSource);
               
                System.out.println("Accesstype =" +accessType);
                System.out.println("Inheritabledepth=" +InheritableDepth);
                System.out.println(className);
                 System.out.println(GranteeName);
                 System.out.println(GranteeType);
                 System.out.println(PermissionSource);
                 System.out.println(accessType);
                 System.out.println(InheritableDepth);
                 System.out.println(AccessMask);
               
               
                }
               
                ClassDefinitionSet cds1= cd.get_ImmediateSubclassDefinitions();
                  if(!cds1.isEmpty())
                  {
                      System.out.println("--------Children Class of "+className +"----------");
                       
                      childClass(cds1);
                      System.out.println("Not Empty");
                  }
            }
           
            System.out.println("-------------End Object Store--------------------------");
           
            System.out.println("Done");
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
    private static void childClass(ClassDefinitionSet cds1) throws IOException {
        // TODO Auto-generated method stub
        ClassDefinition cd;
        Iterator it = cds1.iterator();
        while (it.hasNext())
        {
                  System.out.println("-----------------------------");
               
               
            cd = (ClassDefinition)it.next();
           
            System.out.println("Class name = " + cd.get_DisplayName());
            System.out.println("ClassDisplayName :: "+cd.get_DisplayName());       
            System.out.println("ClassName :: "+cd.get_Name());
            System.out.println("ClassSymbolicName :: "+cd.get_SymbolicName());
            System.out.println("ClassCreator :: "+cd.get_Creator());
            System.out.println("ClassDefaultInstanceOwner :: "+cd.get_DefaultInstanceOwner());
            System.out.println("ClassLastModifier :: "+cd.get_LastModifier());
            System.out.println("ClassOwner :: "+cd.get_Owner());
            System.out.println("ClassDateCreated :: "+cd.get_DateCreated());
            System.out.println("ClassID :: "+cd.get_Id());
            System.out.println("ClassDateLastModified :: "+cd.get_DateLastModified());
            System.out.println("ClassIsHidden :: "+cd.get_IsHidden());
            System.out.println("ClassIsCurrent :: "+cd.isCurrent());
            System.out.println("ClassIsPersistent :: "+cd.get_IsPersistent());
            System.out.println("ClassIsSystemOwned :: "+cd.get_IsSystemOwned());
            System.out.println("ClassIsCBREnabled :: "+cd.get_IsCBREnabled());
           
            System.out.println("------Default Instance Security------");
           
            AccessPermissionList dis = cd.get_DefaultInstancePermissions();
            Iterator itdis = dis.iterator();
            while (itdis.hasNext())
            {
            AccessPermission permission = (AccessPermission)itdis.next();
           
            disGranteeName=permission.get_GranteeName();
            disGranteeType=permission.get_GranteeType().toString();
            disPermissionSource=permission.get_PermissionSource().toString();
            disaccessType=permission.get_AccessType().toString();
            disInheritableDepth=permission.get_InheritableDepth().toString();       
            disAccessMask=permission.get_AccessMask().toString();
            System.out.println("GranteeName="+ disGranteeName);
            System.out.println("GranteeType=" + disGranteeType);
            System.out.println("PermissionSource=" +disPermissionSource);

            System.out.println("Accesstype =" +disaccessType);
            System.out.println("Inheritabledepth=" +disInheritableDepth);
           
           
           
            }
           
           
            System.out.println("------Direct Security------");
           
             AccessPermissionList s = cd.get_Permissions();
            System.out.println("------------");
             System.out.println("------------");
             System.out.println("------------");
             System.out.println("------------");
             System.out.println("------------");
             System.out.println("------------");
           
            Iterator itdis1 = s.iterator();
            while (itdis1.hasNext())
            {
            AccessPermission permission1 = (AccessPermission)itdis1.next();
           
            GranteeName=permission1.get_GranteeName();
            GranteeType=permission1.get_GranteeType().toString();
            PermissionSource=permission1.get_PermissionSource().toString();
            accessType=permission1.get_AccessType().toString();
            InheritableDepth=permission1.get_InheritableDepth().toString();       
            AccessMask=permission1.get_AccessMask().toString();
           
            System.out.println(className);
             System.out.println(GranteeName);
             System.out.println(GranteeType);
             System.out.println(PermissionSource);
             System.out.println(accessType);
             System.out.println(InheritableDepth);
             System.out.println(AccessMask);
           
           
            }
           
            ClassDefinitionSet cds2= cd.get_ImmediateSubclassDefinitions();
              if(!cds2.isEmpty())
              {
                  System.out.println("--------Children Class of "+className +"----------");
                 
                  childClass(cds2);
                  System.out.println("Not Empty");
              }
        }

    }
    public static void main(String[] args) throws IOException {
   
            getClassPermissions("ObjectStore");
        }
       
       
        //    FetchOSList();
/*
         InheritableDepth
         0 - No inheritance (this object only).
        1 - This object and immediate children only.
        -1 - This object and all children (infinite levels deep).
        -2 - All children (infinite levels deep) but not this object.
        -3 - Immediate children only; not this object.
 
 */
   
}

Java Code to get security on Object Stores

//Java Code to get security on Object Stores

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.security.auth.Subject;
import com.filenet.api.collection.AccessPermissionList;
import com.filenet.api.collection.ObjectStoreSet;
import com.filenet.api.core.Connection;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.security.AccessPermission;
import com.filenet.api.util.UserContext;

public class GetObjectStoreSecurity {
    private static Connection conn = null;
   
    static String GranteeName =null;
    static String GranteeType =null;
    static String PermissionSource =null;
    static String accessType =null;
    static String InheritableDepth =null;
    static String AccessMask=null;
    public static Connection getCEConn()
    {
        try {
            String ceURI =    "http://localhost:9080/wsi/FNCEWS40MTOM/";
            String userName ="user Name";
            String password ="password";
            if(conn==null){
            conn = Factory.Connection.getConnection(ceURI);
            Subject subject = UserContext.createSubject(conn, userName, password, null);
            UserContext uc = UserContext.get();
            uc.pushSubject(subject);
            }

        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        System.out.println("CE Connection"+conn);
        return conn;
    }
    public static ArrayList FetchOSList() {
        ArrayList<String> list = new ArrayList();
        try {
           
            //String[] oslist= new String[100];
            Connection conn= getCEConn();
            Domain domain = Factory.Domain.fetchInstance(conn, null, null);
            ObjectStoreSet osSet= domain.get_ObjectStores();
            ObjectStore store;
            Iterator iterator = osSet.iterator();
            Iterator<ObjectStore> osIter = iterator;
            while (osIter.hasNext()) {
            store = (ObjectStore)osIter.next();
            list.add(store.get_Name());
            System.out.println(store.get_Name());
            }
           
        } catch (Exception e) {
            e.printStackTrace();
        }
       
        return list;
    }
    public static void getObjectStorePermissions(String osName) throws IOException{
       
        try{
                   
            Connection conn = getCEConn();
            Domain domain = Factory.Domain.fetchInstance(conn,null, null);
            ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain, osName,null);
           
            System.out.println("ObjectStoreDisplayName :: "+objStore.get_DisplayName());
            System.out.println("ObjectStoreSymbolicName :: "+objStore.get_SymbolicName());
            System.out.println("ObjectStoreName :: "+objStore.get_Name());           
            System.out.println("ObjectStoreID :: "+objStore.get_Id());           
            System.out.println("ObjectStoreCreator :: "+objStore.get_Creator());
            System.out.println("ObjectStoreLastModifier :: "+objStore.get_LocaleName());           
            System.out.println("ObjectStoreDatabaseSchemaName :: "+objStore.get_DatabaseSchemaName());           
            System.out.println("ObjectStoreJNDIDataSource :: "+objStore.get_JNDIDataSource());           
            System.out.println("ObjectStore.get_JNDIXADataSource() :: "+objStore.get_JNDIXADataSource());           
            System.out.println("ObjectStoreDescriptiveText :: "+objStore.get_DescriptiveText());           
            System.out.println("ObjectStoreSchemaVersion :: "+objStore.get_SchemaVersion());           
            System.out.println("ObjectStoreTextSearchIndexingLanguage :: "+objStore.get_TextSearchIndexingLanguage());           
            System.out.println("ObjectStoreVerityPartitionProperty :: "+objStore.get_VerityPartitionProperty());           
            System.out.println("ObjectStoreClassName :: "+objStore.getClassName());
                       
             AccessPermissionList apos = objStore.get_Permissions();
             Iterator it = apos.iterator();
             while (it.hasNext())
             {
                 AccessPermission permission = (AccessPermission)it.next();
                   
                    GranteeName=permission.get_GranteeName();
                    GranteeType=permission.get_GranteeType().toString();
                    PermissionSource=permission.get_PermissionSource().toString();
                    accessType=permission.get_AccessType().toString();
                    InheritableDepth=permission.get_InheritableDepth().toString();       
                    AccessMask=permission.get_AccessMask().toString();
                    System.out.println(objStore.get_DisplayName());
                    System.out.println("GranteeName="+ GranteeName);
                    System.out.println("GranteeType=" + GranteeType);
                    System.out.println("PermissionSource=" +PermissionSource);       
                    System.out.println("Accesstype =" +accessType);
                    System.out.println("Inheritabledepth=" +InheritableDepth);
             }
           
            System.out.println("-------------End Object Store--------------------------");
            System.out.println("Done");
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
   
    public static void main(String[] args) throws IOException {
        //getObjectStorePermissions("DMS");
   
        List objectStoreList = FetchOSList();
       
        String objectStore;
       
        Iterator it = objectStoreList.iterator();
       
        while(it.hasNext())
        {
            objectStore=(String) it.next();
            System.out.println("Object Store :: "+objectStore);
            getObjectStorePermissions(objectStore);
        }
       
        //    FetchOSList();
/*
         InheritableDepth
         0 - No inheritance (this object only).
        1 - This object and immediate children only.
        -1 - This object and all children (infinite levels deep).
        -2 - All children (infinite levels deep) but not this object.
        -3 - Immediate children only; not this object.
 
 */
    }
}

Java Code to get security on FileNet Domain

//Java Code to get security on FileNet Domain


import java.io.IOException;
import java.util.Iterator;
import javax.security.auth.Subject;
import com.filenet.api.collection.AccessPermissionList;
import com.filenet.api.core.Connection;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.security.AccessPermission;
import com.filenet.api.util.UserContext;

public class GetDomainSecurity {
private static Connection conn = null;

static String GranteeName =null;
static String GranteeType =null;
static String PermissionSource =null;
static String accessType =null;
static String InheritableDepth =null;
static String AccessMask=null;

public static Connection getCEConn()
{
try {
String ceURI="localhost:9080/wsi/FNCEWS40MTOM/";
String userName ="userName";
String password ="password";
if(conn==null){
conn = Factory.Connection.getConnection(ceURI);
Subject subject = UserContext.createSubject(conn, userName, password, null);
UserContext uc = UserContext.get();
uc.pushSubject(subject);
}

} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("CE Connection"+conn);
return conn;
}

public static void getObjectStorePermissions() throws IOException{

try{
  conn=null;
      conn = getCEConn();
Domain domain = Factory.Domain.fetchInstance(conn,null, null);
AccessPermissionList apld = domain.get_Permissions();
Iterator itd = apld.iterator();

while (itd.hasNext())
{
AccessPermission permission = (AccessPermission)itd.next();

GranteeName=permission.get_GranteeName();
GranteeType=permission.get_GranteeType().toString();
PermissionSource=permission.get_PermissionSource().toString();
accessType=permission.get_AccessType().toString();
InheritableDepth=permission.get_InheritableDepth().toString();
AccessMask=permission.get_AccessMask().toString();
System.out.println(domain.get_Name());
System.out.println("GranteeName="+ GranteeName);
System.out.println("GranteeType=" + GranteeType);
System.out.println("PermissionSource=" +PermissionSource);
System.out.println("Accesstype =" +accessType);
System.out.println("Inheritabledepth=" +InheritableDepth);

}
       
}
catch(Exception e){
e.printStackTrace();
}
}

public static void main(String[] args) throws IOException {


getObjectStorePermissions();
        
       
        }
}

Monday, 23 April 2018

Java Code to get choice value from Choice-lists in Object Stores

//Java Code to get choice value from Choice-lists in Object Stores

import java.io.IOException;
import java.util.Iterator;
import javax.security.auth.Subject;
import com.filenet.api.collection.ChoiceListSet;
import com.filenet.api.core.Connection;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.util.UserContext;

public class GetChoiceListValues {
private static Connection conn = null;
public static Connection getCEConn(String ceURI)
{
try {

String userName ="userName";
String password ="password";
if(conn==null){
conn = Factory.Connection.getConnection(ceURI);
Subject subject = UserContext.createSubject(conn, userName, password, null);
UserContext uc = UserContext.get();
uc.pushSubject(subject);
}

} catch (Exception e1) {
e1.printStackTrace();
}
System.out.println("CE Connection"+conn);
return conn;
}

public static void getChoiceListValues() throws IOException{
String ceURI = null;
try{

    ceURI="http://localhost:9080/wsi/FNCEWS40MTOM/";
      conn = getCEConn(ceURI);
Domain domain = Factory.Domain.fetchInstance(conn,null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain,"ObjectStore",null);
ChoiceListSet cls = objStore.get_ChoiceLists();
Iterator it = cls.iterator();
while(it.hasNext()){
com.filenet.api.admin.ChoiceList cl = (com.filenet.api.admin.ChoiceList) it.next();
com.filenet.api.collection.ChoiceList choicelis = cl.get_ChoiceValues();
Iterator choice_it = choicelis.iterator();
System.out.println(cl.get_DisplayName());
while(choice_it.hasNext()){
com.filenet.api.admin.Choice c = (com.filenet.api.admin.Choice) choice_it.next();
System.out.println(c.get_Name());
   
}

}
        System.out.println("Done");
}
    
  catch(Exception e){
e.printStackTrace();
}
}

public static void main(String[] args) throws IOException {
getChoiceListValues();
        }
}