DataCache { void processRoleMembers(String roleName, List<RoleMember> members) { if (members == null) { return; } long currentTime = System.currentTimeMillis(); for (RoleMember member : members) { if (AuthzHelper.isMemberDisabled(member.getSystemDisabled())) { continue; } long expiration = member.getExpiration() == null ? 0 : member.getExpiration().millis(); if (expiration != 0 && expiration < currentTime) { continue; } final String memberName = member.getMemberName(); if (memberName.equals("*")) { memberAllRoleCache.add(new MemberRole(roleName, expiration)); } else if (memberName.endsWith("*")) { final String keyName = memberName.substring(0, memberName.length() - 1); if (!memberPrefixRoleCache.containsKey(keyName)) { memberPrefixRoleCache.put(keyName, new HashSet<>()); } final Set<MemberRole> rolesForMember = memberPrefixRoleCache.get(keyName); rolesForMember.add(new MemberRole(roleName, expiration)); } else { if (!memberRoleCache.containsKey(memberName)) { memberRoleCache.put(memberName, new HashSet<>()); } final Set<MemberRole> rolesForMember = memberRoleCache.get(memberName); rolesForMember.add(new MemberRole(roleName, expiration)); } } } DataCache(); void setDomainData(DomainData domainData); DomainData getDomainData(); void processRole(Role role); void processPolicy(String domainName, Policy policy, Map<String, Role> roles); void processServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity service); Set<MemberRole> getMemberRoleSet(final String member); List<String> getProviderDnsSuffixList(final String provider); List<String> getProviderHostnameAllowedSuffixList(final String provider); List<String> getProviderHostnameDeniedSuffixList(final String provider); Set<MemberRole> getAllMemberRoleSet(); Map<String, Set<MemberRole>> getPrefixMemberRoleSetMap(); int getMemberCount(); Set<String> getAWSResourceRoleSet(String role); RoleMeta getRoleMeta(String role); Map<String, Set<String>> getTrustMap(); Map<String, Set<String>> getHostMap(); Map<String, String> getPublicKeyMap(); Map<String, List<String>> getProviderDnsSuffixCache(); Map<String, List<String>> getProviderHostnameAllowedSuffixCache(); Map<String, List<String>> getProviderHostnameDeniedSuffixCache(); static final String ACTION_ASSUME_ROLE; static final String ACTION_ASSUME_AWS_ROLE; static final String ACTION_LAUNCH; static final String RESOURCE_DNS_PREFIX; static final String RESOURCE_HOSTNAME_PREFIX; }
@Test public void testProcessRoleMembers() { List<RoleMember> members1 = new ArrayList<>(); members1.add(new RoleMember().setMemberName("user_domain.user1")); members1.add(new RoleMember().setMemberName("user_domain.user2")); members1.add(new RoleMember().setMemberName("user_domain.user3").setSystemDisabled(1)); DataCache cache = new DataCache(); cache.processRoleMembers("dom.role1", members1); Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1"); assertNotNull(set1); assertTrue(set1.contains(new MemberRole("dom.role1", 0))); assertEquals(set1.size(), 1); Set<MemberRole> set2 = cache.getMemberRoleSet("user_domain.user2"); assertNotNull(set2); assertTrue(set2.contains(new MemberRole("dom.role1", 0))); assertEquals(set2.size(), 1); Set<MemberRole> set3 = cache.getMemberRoleSet("user_domain.user3"); assertNull(set3); }