# How to Use the SAS Java Metadata Authorization Interface

standard usage

- Example 1: Obtaining the MdAuthorizationUtil Interface
- Example 2: Getting the Identity List for permissions set on an object
- Example 3: Getting the MdPermissionInfo List for a single identity
- Example 4: Getting the MdAuthorizationInfo List for multiple identities
- Example 5: Setting the MdPermissionInfo List for a single identity
- Example 6: Setting the MdAuthorizationInfo List for multiple identities

## Example 6: Setting the MdAuthorizationInfo List for multiple identities

This is an example of invoking MdAuthorizationUtil.setAuthorizations with a List of MdAuthorizationInfo instances that represent permissions set for multiple Identity objects.

         try
         {
            CMetadata object;   // any SAS CMetadata object type will work here (your code must fill this in)
            MdAuthorizationUtil authUtil = object.getAuthorizationUtil();

            // Instance a List to contain MdAuthorizationInfo instances created below
            List <MdAuthorizationInfo>authInfoList = new ArrayList<MdAuthorizationInfo>(2);

            Identity identity1;  // The first Identity for which permissions are being set (your code must set this Identity object value)
            List <MdPermissionInfo>permInfoList1 = new ArrayList<MdPermissionInfo>(2);
            permInfoList1.add(new MdPermissionInfoImpl(
                        PermissionType.GRANT, MdPermissionInfo.PERMISSION_READMETADATA ));
            permInfoList1.add(new MdPermissionInfoImpl(
                        PermissionType.DENY, MdPermissionInfo.PERMISSION_WRITEMETADATA ));
            authInfoList1.add(new MdAuthorizationInfoImpl(identity1, permInfoList1);

            Identity identity2;  // The second Identity for which permissions are being set (your code must set this Identity object value)
            List <MdPermissionInfo>permInfoList2 = new ArrayList<MdPermissionInfo>(3);
            permInfoList2.add(new MdPermissionInfoImpl(
                        PermissionType.DENY, MdPermissionInfo.PERMISSION_READ ));
            permInfoList2.add(new MdPermissionInfoImpl(
                        PermissionType.DENY, MdPermissionInfo.PERMISSION_WRITE ));
            permInfoList2.add(new MdPermissionInfoImpl(
                        PermissionType.DENY, MdPermissionInfo.PERMISSION_DELETE ));
            authInfoList.add(new MdAuthorizationInfoImpl(identity2, permInfoList2);

            Identity identity3;  // The third Identity for which permissions are being set (your code must set this Identity object value)
            List <MdPermissionInfo>permInfoList3 = new ArrayList<MdPermissionInfo>(4);
            permInfoList3.add(new MdPermissionInfoImpl(
                        PermissionType.GRANT, MdPermissionInfo.PERMISSION_CHECKINMETADATA ));
            permInfoList3.add(new MdPermissionInfoImpl(
                        PermissionType.GRANT, MdPermissionInfo.PERMISSION_CREATE ));
            permInfoList3.add(new MdPermissionInfoImpl(
                        PermissionType.GRANT, MdPermissionInfo.PERMISSION_ADMINISTER ));
            permInfoList3.add(new MdPermissionInfoImpl(
                        PermissionType.DENY, MdPermissionInfo.PERMISSION_DELETE ));
            authInfoList.add(new MdAuthorizationInfoImpl(identity3, permInfoList3);

            authUtil.setAuthorizations(authInfoList);
         }
         catch (MdException e)
         {
            e.printStackTrace();
         }
         catch (RemoteException e)
         {
            e.printStackTrace();
         }