DBService implements RolesProvider { PublicKeyEntry getServicePublicKeyEntry(String domainName, String serviceName, String keyId, boolean domainStateCheck) { try (ObjectStoreConnection con = store.getConnection(true, false)) { return con.getPublicKeyEntry(domainName, serviceName, keyId, domainStateCheck); } catch (ResourceException ex) { if (ex.getCode() != ResourceException.SERVICE_UNAVAILABLE) { throw ex; } } PublicKeyEntry keyEntry = getPublicKeyFromCache(domainName, serviceName, keyId); if (keyEntry == null) { throw new ResourceException(ResourceException.SERVICE_UNAVAILABLE, "Unable to retrieve public key from DB store"); } return keyEntry; } 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 testGetServicePublicKeyEntryServiceUnavailable() { final String domainName = "test1"; final String serviceName = "service1"; final String keyId = "0"; ObjectStore saveStore = zms.dbService.store; zms.dbService.store = mockObjStore; ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class); Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockConn); Mockito.when(mockConn.getPublicKeyEntry(domainName, serviceName, keyId, false)) .thenThrow(new ResourceException(ResourceException.SERVICE_UNAVAILABLE)); try { zms.dbService.getServicePublicKeyEntry(domainName, serviceName, keyId, false); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE); } zms.dbService.store = saveStore; }