DBService implements RolesProvider { public void processExpiredPendingMembers(int pendingRoleMemberLifespan, final String monitorIdentity) { final String auditRef = "Expired - auto reject"; final String caller = "processExpiredPendingMembers"; Map<String, List<DomainRoleMember>> memberList; try (ObjectStoreConnection con = store.getConnection(true, false)) { memberList = con.getExpiredPendingDomainRoleMembers(pendingRoleMemberLifespan); } for (String domainName : memberList.keySet()) { for (DomainRoleMember domainRoleMember : memberList.get(domainName)) { final String principalName = domainRoleMember.getMemberName(); for (MemberRole memberRole : domainRoleMember.getMemberRoles()) { try (ObjectStoreConnection con = store.getConnection(true, true)) { if (con.deletePendingRoleMember(domainName, memberRole.getRoleName(), principalName, monitorIdentity, auditRef)) { auditLogRequest(monitorIdentity, domainName, auditRef, caller, "REJECT", memberRole.getRoleName(), "{\"member\": \"" + principalName + "\"}"); } } } } } } DBService(ObjectStore store, AuditLogger auditLogger, ZMSConfig zmsConfig, AuditReferenceValidator auditReferenceValidator); DomainRoleMembers listOverdueReviewRoleMembers(String domainName); @Override List<Role> getRolesByDomain(String domain); ResourceAccessList getResourceAccessList(String principal, String action); AthenzDomain getAthenzDomain(final String domainName, boolean masterCopy); Quota getQuota(String domainName); void executePutRoleSystemMeta(ResourceContext ctx, final String domainName, final String roleName,
           RoleSystemMeta meta, final String attribute, final String auditRef, final String caller); void executePutGroupSystemMeta(ResourceContext ctx, final String domainName, final String groupName,
                                          GroupSystemMeta meta, final String attribute, final String auditRef); void executePutServiceIdentitySystemMeta(ResourceContext ctx, String domainName, String serviceName,
            ServiceIdentitySystemMeta meta, String attribute, String auditRef, String caller); void executePutRoleMeta(ResourceContext ctx, String domainName, String roleName, Role originalRole,
                                   RoleMeta meta, String auditRef, String caller); void executePutGroupMeta(ResourceContext ctx, final String domainName, final String groupName,
                                    GroupMeta meta, final String auditRef); Set<String> getPendingMembershipApproverRoles(int delayDays); Set<String> getPendingGroupMembershipApproverRoles(int delayDays); Map<String, DomainRoleMember> getRoleExpiryMembers(int delayDays); Map<String, DomainRoleMember> getRoleReviewMembers(int delayDays); Map<String, DomainGroupMember> getGroupExpiryMembers(int delayDays); void processExpiredPendingMembers(int pendingRoleMemberLifespan, final String monitorIdentity); void processExpiredPendingGroupMembers(int pendingGroupMemberLifespan, final String monitorIdentity); static int AUDIT_TYPE_ROLE; static int AUDIT_TYPE_POLICY; static int AUDIT_TYPE_SERVICE; static int AUDIT_TYPE_DOMAIN; static int AUDIT_TYPE_ENTITY; static int AUDIT_TYPE_TENANCY; static int AUDIT_TYPE_TEMPLATE; static int AUDIT_TYPE_GROUP; }
@Test public void testProcessExpiredPendingMembers() { Map<String, List<DomainRoleMember>> memberList = new LinkedHashMap<>(); DomainRoleMember domainRoleMember1 = new DomainRoleMember(); domainRoleMember1.setMemberName("user.user1"); List<MemberRole> memberRoles1 = new ArrayList<>(); memberRoles1.add(new MemberRole().setRoleName("role1")); domainRoleMember1.setMemberRoles(memberRoles1); DomainRoleMember domainRoleMember2 = new DomainRoleMember(); domainRoleMember2.setMemberName("user.user2"); List<MemberRole> memberRoles2 = new ArrayList<>(); memberRoles2.add(new MemberRole().setRoleName("role1")); domainRoleMember2.setMemberRoles(memberRoles2); List<DomainRoleMember> domainRoleMembers = new ArrayList<>(); domainRoleMembers.add(domainRoleMember1); domainRoleMembers.add(domainRoleMember2); memberList.put("dom1", domainRoleMembers); ObjectStore saveStore = zms.dbService.store; zms.dbService.store = mockObjStore; Mockito.when(mockObjStore.getConnection(anyBoolean(), anyBoolean())).thenReturn(mockJdbcConn); Mockito.when(mockJdbcConn.getExpiredPendingDomainRoleMembers(30)).thenReturn(memberList); Mockito.when(mockJdbcConn.deletePendingRoleMember("dom1", "role1", "user.user1", "sys.auth.monitor", "Expired - auto reject")).thenReturn(true); Mockito.when(mockJdbcConn.deletePendingRoleMember("dom1", "role1", "user.user2", "sys.auth.monitor", "Expired - auto reject")).thenReturn(false); zms.dbService.processExpiredPendingMembers(30, "sys.auth.monitor"); zms.dbService.store = saveStore; }