FileConnection implements ObjectStoreConnection { @Override public Map<String, List<DomainRoleMember>> getExpiredPendingDomainRoleMembers(int pendingRoleMemberLifespan) { Map<String, List<DomainRoleMember>> domainRoleMembersMap = new HashMap<>();; String[] fnames = getDomainList(); for (String name : fnames) { DomainStruct domain = getDomainStruct(name); if (domain == null) { continue; } DomainRoleMembers domainRoleMembers = new DomainRoleMembers(); domainRoleMembers.setDomainName(domain.getName()); List<DomainRoleMember> domainRoleMemberList = new ArrayList<>(); domainRoleMembers.setMembers(domainRoleMemberList); long now = System.currentTimeMillis(); for (Role role : domain.getRoles().values()) { for (RoleMember roleMember : role.getRoleMembers()) { if (roleMember.getApproved() == Boolean.FALSE && now - roleMember.getRequestTime().millis() > TimeUnit.MILLISECONDS.convert(pendingRoleMemberLifespan, TimeUnit.DAYS)) { DomainRoleMember domainRoleMember = new DomainRoleMember(); domainRoleMember.setMemberName(roleMember.getMemberName()); List<MemberRole> memberRoles = new ArrayList<>(); MemberRole memberRole = new MemberRole(); memberRole.setActive(false); memberRole.setRoleName(AthenzUtils.extractRoleName(role.getName())); memberRole.setExpiration(roleMember.getExpiration()); memberRole.setRequestTime(roleMember.getRequestTime()); memberRole.setRequestPrincipal(roleMember.getRequestPrincipal()); memberRoles.add(memberRole); domainRoleMember.setMemberRoles(memberRoles); domainRoleMemberList.add(domainRoleMember); } } } if (!domainRoleMemberList.isEmpty()) { domainRoleMembersMap.put(domain.getName(), domainRoleMemberList); } } return domainRoleMembersMap; } FileConnection(File rootDir, File quotaDir); @Override void commitChanges(); @Override void rollbackChanges(); @Override void close(); @Override void setOperationTimeout(int opTimeout); @Override Domain getDomain(String domainName); @Override long getDomainModTimestamp(String domainName); @Override boolean insertDomain(Domain domain); @Override boolean updateDomain(Domain domain); @Override boolean deleteDomain(String domainName); @Override boolean updateDomainModTimestamp(String domainName); @Override List<String> listDomains(String prefix, long modifiedSince); @Override List<String> lookupDomainByRole(String roleMember, String roleName); @Override String lookupDomainById(String account, int productId); @Override AthenzDomain getAthenzDomain(String domainName); @Override DomainMetaList listModifiedDomains(long modifiedSince); @Override boolean insertDomainTemplate(String domainName, String templateName, String params); @Override boolean updateDomainTemplate(String domainName, String templateName, TemplateMetaData templateMetaData); @Override boolean deleteDomainTemplate(String domainName, String templateName, String params); @Override List<String> listDomainTemplates(String domainName); @Override Map<String, List<String>> getDomainFromTemplateName(Map<String, Integer> templateNameAndLatestVersion); @Override List<PrincipalRole> listPrincipalRoles(String domainName, String principalName); void addPrincipalRoles(DomainStruct domainStruct, List<PrincipalRole> roles,
            String domainName, String principalName); @Override List<String> listPrincipals(String domainName); @SuppressWarnings("SuspiciousListRemoveInLoop") @Override boolean deletePrincipal(String principalName, boolean subDomains); @Override Role getRole(String domainName, String roleName); @Override boolean insertRole(String domainName, Role role); @Override boolean updateRole(String domainName, Role role); @Override boolean updateRoleModTimestamp(String domainName, String roleName); @Override boolean deleteRole(String domainName, String roleName); @Override List<String> listEntities(String domainName); @Override List<String> listRoles(String domainName); @Override List<RoleMember> listRoleMembers(String domainName, String roleName, Boolean pending); @Override Membership getRoleMember(String domainName, String roleName, String principal,
            long expiration, boolean pending); @Override boolean insertRoleMember(String domainName, String roleName, RoleMember member,
            String admin, String auditRef); @Override boolean updateRoleMemberDisabledState(String domainName, String roleName, String principal,
            String admin, int disabledState, String auditRef); @Override boolean deleteRoleMember(String domainName, String roleName, String principal,
            String admin, String auditRef); @Override Policy getPolicy(String domainName, String policyName); @Override boolean insertPolicy(String domainName, Policy policy); @Override boolean updatePolicy(String domainName, Policy policy); @Override boolean deletePolicy(String domainName, String policyName); @Override List<String> listPolicies(String domainName, String assertionRoleName); @Override boolean insertAssertion(String domainName, String policyName, Assertion assertion); @Override boolean deleteAssertion(String domainName, String policyName, Long assertionId); @Override List<Assertion> listAssertions(String domainName, String policyName); @Override ServiceIdentity getServiceIdentity(String domainName, String serviceName); @Override boolean insertServiceIdentity(String domainName, ServiceIdentity service); @Override boolean updateServiceIdentity(String domainName, ServiceIdentity service); @Override boolean deleteServiceIdentity(String domainName, String serviceName); @Override List<String> listServiceIdentities(String domainName); @Override boolean updateServiceIdentityModTimestamp(String domainName, String serviceName); @Override PublicKeyEntry getPublicKeyEntry(String domainName, String serviceName,
            String keyId, boolean domainStateCheck); @Override boolean insertPublicKeyEntry(String domainName, String serviceName, PublicKeyEntry publicKey); @Override boolean updatePublicKeyEntry(String domainName, String serviceName, PublicKeyEntry publicKey); @Override boolean deletePublicKeyEntry(String domainName, String serviceName, String keyId); @Override List<PublicKeyEntry> listPublicKeys(String domainName, String serviceName); @Override List<String> listServiceHosts(String domainName, String serviceName); @Override boolean insertServiceHost(String domainName, String serviceName, String hostName); @Override boolean deleteServiceHost(String domainName, String serviceName, String hostName); @Override Entity getEntity(String domainName, String entityName); @Override boolean insertEntity(String domainName, Entity entity); @Override boolean updateEntity(String domainName, Entity entity); @Override boolean deleteEntity(String domainName, String entityName); synchronized DomainStruct getDomainStruct(String name); synchronized void putDomainStruct(String name, DomainStruct data); static void deleteDirectory(File f); synchronized boolean delete(String name); @Override List<RoleAuditLog> listRoleAuditLogs(String domainName, String roleName); @Override ResourceAccessList listResourceAccess(String principal, String action, String userDomain); @Override Assertion getAssertion(String domainName, String policyName, Long assertionId); @Override boolean updatePolicyModTimestamp(String domainName, String policyName); @Override Quota getQuota(String domainName); @Override boolean insertQuota(String domainName, Quota quota); @Override boolean updateQuota(String domainName, Quota quota); @Override boolean deleteQuota(String domainName); @Override int countRoles(String domainName); @Override int countRoleMembers(String domainName, String roleName); @Override int countPolicies(String domainName); @Override int countAssertions(String domainName, String policyName); @Override int countServiceIdentities(String domainName); @Override int countPublicKeys(String domainName, String serviceName); @Override int countEntities(String domainName); @Override DomainRoleMembers listDomainRoleMembers(String domainName); @Override DomainRoleMember getPrincipalRoles(String principal, String domainName); @Override DomainRoleMembers listOverdueReviewRoleMembers(String domainName); @Override Map<String, List<DomainGroupMember>> getPendingDomainGroupMembers(String principal); @Override Map<String, List<DomainGroupMember>> getExpiredPendingDomainGroupMembers(int pendingRoleMemberLifespan); @Override Set<String> getPendingGroupMembershipApproverRoles(String server, long timestamp); @Override boolean updatePendingGroupMembersNotificationTimestamp(String server, long timestamp, int delayDays); @Override Map<String, DomainGroupMember> getNotifyTemporaryGroupMembers(String server, long timestamp); @Override boolean updateGroupMemberExpirationNotificationTimestamp(String server, long timestamp, int delayDays); @Override boolean confirmRoleMember(String domainName, String roleName, RoleMember member,
                                    String admin, String auditRef); @Override Map<String, List<DomainRoleMember>> getPendingDomainRoleMembers(String principal); @Override Set<String> getPendingMembershipApproverRoles(String server, long timestamp); @Override Map<String, List<DomainRoleMember>> getExpiredPendingDomainRoleMembers(int pendingRoleMemberLifespan); @Override boolean updatePendingRoleMembersNotificationTimestamp(String server, long timestamp, int delayDays); @Override boolean deletePendingRoleMember(String domainName, String roleName, String principal,
             String admin, String auditRef); @Override Map<String, DomainRoleMember> getNotifyTemporaryRoleMembers(String server, long timestamp); @Override Map<String, DomainRoleMember> getNotifyReviewRoleMembers(String server, long timestamp); @Override boolean updateRoleMemberExpirationNotificationTimestamp(String server, long timestamp, int delayDays); @Override boolean updateRoleMemberReviewNotificationTimestamp(String server, long timestamp, int delayDays); @Override List<TemplateMetaData> getDomainTemplates(String domainName); @Override boolean updateRoleReviewTimestamp(String domainName, String roleName); @Override List<PrincipalRole> listRolesWithUserAuthorityRestrictions(); @Override Group getGroup(String domainName, String groupName); @Override boolean insertGroup(String domainName, Group group); @Override boolean updateGroup(String domainName, Group group); @Override boolean deleteGroup(String domainName, String groupName); @Override boolean updateGroupModTimestamp(String domainName, String groupName); @Override int countGroups(String domainName); @Override List<GroupAuditLog> listGroupAuditLogs(String domainName, String groupName); @Override boolean updateGroupReviewTimestamp(String domainName, String groupName); @Override List<GroupMember> listGroupMembers(String domainName, String groupName, Boolean pending); @Override int countGroupMembers(String domainName, String groupName); @Override GroupMembership getGroupMember(String domainName, String groupName, String member, long expiration, boolean pending); @Override boolean insertGroupMember(String domainName, String groupName, GroupMember groupMember, String principal, String auditRef); @Override boolean deleteGroupMember(String domainName, String groupName, String member, String principal, String auditRef); @Override boolean updateGroupMemberDisabledState(String domainName, String groupName, String member, String principal, int disabledState, String auditRef); @Override boolean deletePendingGroupMember(String domainName, String groupName, String member, String principal, String auditRef); @Override boolean confirmGroupMember(String domainName, String groupName, GroupMember groupMember, String principal, String auditRef); @Override DomainGroupMember getPrincipalGroups(String principal, String domainName); @Override List<PrincipalGroup> listGroupsWithUserAuthorityRestrictions();  }
@Test public void testGetExpiredPendingMembers() { File fileDir = new File("/home/athenz/zms_store"); File quotaDir = new File("/home/athenz/zms_quota"); try (FileConnection fileconnection = new FileConnection(fileDir, quotaDir)) { assertTrue(fileconnection.getExpiredPendingDomainRoleMembers(30).isEmpty()); } }