ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractControllerAuthenticationFilter { @Override public HeaderAuthentication getPreAuthenticatedPrincipal(final DmfTenantSecurityToken secruityToken) { final String commonNameValue = secruityToken.getHeader(caCommonNameHeader); final String knownSslIssuerConfigurationValue = tenantAware.runAsTenant(secruityToken.getTenant(), sslIssuerNameConfigTenantRunner); final String sslIssuerHashValue = getIssuerHashHeader(secruityToken, knownSslIssuerConfigurationValue); if (commonNameValue != null && LOGGER.isTraceEnabled()) { LOGGER.trace("Found commonNameHeader {}={}, using as credentials", caCommonNameHeader, commonNameValue); } if (sslIssuerHashValue != null && LOGGER.isTraceEnabled()) { LOGGER.trace("Found sslIssuerHash ****, using as credentials for tenant {}", secruityToken.getTenant()); } if (commonNameValue != null && sslIssuerHashValue != null) { return new HeaderAuthentication(commonNameValue, sslIssuerHashValue); } return null; } ControllerPreAuthenticatedSecurityHeaderFilter(final String caCommonNameHeader,
            final String caAuthorityNameHeader, final TenantConfigurationManagement tenantConfigurationManagement,
            final TenantAware tenantAware, final SystemSecurityContext systemSecurityContext); @Override HeaderAuthentication getPreAuthenticatedPrincipal(final DmfTenantSecurityToken secruityToken); @Override Object getPreAuthenticatedCredentials(final DmfTenantSecurityToken secruityToken);  }
@Test @Description("Tests the filter for issuer hash based authentication with a single known hash") public void testIssuerHashBasedAuthenticationWithSingleKnownHash() { final DmfTenantSecurityToken securityToken = prepareSecurityToken(SINGLE_HASH); when(tenantConfigurationManagementMock.getConfigurationValue( eq(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME), eq(String.class))) .thenReturn(CONFIG_VALUE_SINGLE_HASH); assertThat(underTest.getPreAuthenticatedPrincipal(securityToken)).isNotNull(); }
@Test @Description("Tests the filter for issuer hash based authentication with multiple known hashes") public void testIssuerHashBasedAuthenticationWithMultipleKnownHashes() { when(tenantConfigurationManagementMock.getConfigurationValue( eq(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME), eq(String.class))) .thenReturn(CONFIG_VALUE_MULTI_HASH); assertThat(underTest.getPreAuthenticatedPrincipal(prepareSecurityToken(SINGLE_HASH))).isNotNull(); assertThat(underTest.getPreAuthenticatedPrincipal(prepareSecurityToken(SECOND_HASH))).isNotNull(); assertThat(underTest.getPreAuthenticatedPrincipal(prepareSecurityToken(THIRD_HASH))).isNotNull(); }
@Test @Description("Tests the filter for issuer hash based authentication with unknown hash") public void testIssuerHashBasedAuthenticationWithUnknownHash() { final DmfTenantSecurityToken securityToken = prepareSecurityToken(UNKNOWN_HASH); when(tenantConfigurationManagementMock.getConfigurationValue( eq(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME), eq(String.class))) .thenReturn(CONFIG_VALUE_MULTI_HASH); assertThat(underTest.getPreAuthenticatedPrincipal(securityToken)).isNull(); }