DBService implements RolesProvider { List<GroupMember> getGroupMembersWithUpdatedDueDates(List<GroupMember> groupMembers, final String userAuthorityExpiry) { List<GroupMember> groupMembersWithUpdatedDueDates = new ArrayList<>(); for (GroupMember groupMember : groupMembers) { boolean dueDateUpdated = false; if (ZMSUtils.isUserDomainPrincipal(groupMember.getMemberName(), zmsConfig.getUserDomainPrefix(), zmsConfig.getAddlUserCheckDomainPrefixList())) { if (groupMember.getExpiration() != null && userAuthorityExpiry == null) { groupMember.setExpiration(null); dueDateUpdated = true; } else if (userAuthorityExpiry != null && updateUserAuthorityExpiry(groupMember, userAuthorityExpiry)) { dueDateUpdated = true; } } if (dueDateUpdated) { groupMembersWithUpdatedDueDates.add(groupMember); } } return groupMembersWithUpdatedDueDates; } 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 testGetGroupMembersWithUpdatedDueDates() { Authority savedAuthority = zms.dbService.zmsConfig.getUserAuthority(); Authority authority = Mockito.mock(Authority.class); Date currentDate = new Date(); Timestamp authorityDate = Timestamp.fromDate(currentDate); Mockito.when(authority.getDateAttribute("user.john", "elevated-clearance")) .thenReturn(currentDate); zms.dbService.zmsConfig.setUserAuthority(authority); List<GroupMember> groupMembers = new ArrayList<>(); groupMembers.add(new GroupMember().setMemberName("sports.api")); List<GroupMember> members = zms.dbService.getGroupMembersWithUpdatedDueDates(groupMembers, "elevated-clearance"); assertTrue(members.isEmpty()); groupMembers.clear(); groupMembers.add(new GroupMember().setMemberName("user.john")); members = zms.dbService.getGroupMembersWithUpdatedDueDates(groupMembers, null); assertTrue(members.isEmpty()); groupMembers.clear(); groupMembers.add(new GroupMember().setMemberName("user.john").setExpiration(Timestamp.fromCurrentTime())); members = zms.dbService.getGroupMembersWithUpdatedDueDates(groupMembers, null); assertFalse(members.isEmpty()); assertNull(members.get(0).getExpiration()); groupMembers.clear(); groupMembers.add(new GroupMember().setMemberName("user.john")); members = zms.dbService.getGroupMembersWithUpdatedDueDates(groupMembers, "elevated-clearance"); assertFalse(members.isEmpty()); assertEquals(members.get(0).getExpiration(), authorityDate); zms.dbService.zmsConfig.setUserAuthority(savedAuthority); }