Tuesday, 24 April 2018

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.
 
 */
    }
}

1 comment:

  1. Nice blog! I really loved reading through this Blog... Thanks for sharing such a very interesting post with us and keep blogging.
    Visit our website-
    Xamarin App Developers
    blazor app developer
    Angularjs app developer



    ReplyDelete