@Test public void testTLSClient() { unifiedUserDetailsService.loadUserBySAML(buildLandstingslakareSamlCredential()); verify(webCertUserDetailsService, times(1)).loadUserBySAML(any(SAMLCredential.class)); }
@Override public Object loadUserBySAML(SAMLCredential samlCredential) { if (samlCredential.getAuthenticationAssertion() == null) { throw new IllegalArgumentException("Cannot determine which underlying UserDetailsService to use for SAMLCredential. " + "Must contain an authenticationAssertion"); } String authnContextClassRef = samlCredential.getAuthenticationAssertion().getAuthnStatements().get(0).getAuthnContext() .getAuthnContextClassRef().getAuthnContextClassRef(); if (authnContextClassRef == null || authnContextClassRef.trim().length() == 0) { throw new IllegalArgumentException("Cannot determine which underlying UserDetailsService to use for SAMLCredential. " + "AuthenticationContextClassRef was null or empty. Should be one of:\n" + HTTP_ID_SAMBI_SE_LOA_LOA3 + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI); } switch (authnContextClassRef) { case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT: case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI: case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI: return elegWebCertUserDetailsService.loadUserBySAML(samlCredential); case HTTP_ID_SAMBI_SE_LOA_LOA3: return webcertUserDetailsService.loadUserBySAML(samlCredential); case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_UNSPECIFIED: if (Arrays.stream(environment.getActiveProfiles()).anyMatch("wc-security-test"::equalsIgnoreCase)) { return webcertUserDetailsService.loadUserBySAML(samlCredential); } throw new IllegalArgumentException( "AuthorizationContextClassRef " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_UNSPECIFIED + " is not allowed"); default: throw new IllegalArgumentException("AuthorizationContextClassRef was " + authnContextClassRef + ", expected one of: " + HTTP_ID_SAMBI_SE_LOA_LOA3 + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI); } }
UnifiedUserDetailsService implements SAMLUserDetailsService { @Override public Object loadUserBySAML(SAMLCredential samlCredential) { if (samlCredential.getAuthenticationAssertion() == null) { throw new IllegalArgumentException("Cannot determine which underlying UserDetailsService to use for SAMLCredential. " + "Must contain an authenticationAssertion"); } String authnContextClassRef = samlCredential.getAuthenticationAssertion().getAuthnStatements().get(0).getAuthnContext() .getAuthnContextClassRef().getAuthnContextClassRef(); if (authnContextClassRef == null || authnContextClassRef.trim().length() == 0) { throw new IllegalArgumentException("Cannot determine which underlying UserDetailsService to use for SAMLCredential. " + "AuthenticationContextClassRef was null or empty. Should be one of:\n" + HTTP_ID_SAMBI_SE_LOA_LOA3 + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI); } switch (authnContextClassRef) { case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT: case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI: case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI: return elegWebCertUserDetailsService.loadUserBySAML(samlCredential); case HTTP_ID_SAMBI_SE_LOA_LOA3: return webcertUserDetailsService.loadUserBySAML(samlCredential); case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_UNSPECIFIED: if (Arrays.stream(environment.getActiveProfiles()).anyMatch("wc-security-test"::equalsIgnoreCase)) { return webcertUserDetailsService.loadUserBySAML(samlCredential); } throw new IllegalArgumentException( "AuthorizationContextClassRef " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_UNSPECIFIED + " is not allowed"); default: throw new IllegalArgumentException("AuthorizationContextClassRef was " + authnContextClassRef + ", expected one of: " + HTTP_ID_SAMBI_SE_LOA_LOA3 + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI); } } }
UnifiedUserDetailsService implements SAMLUserDetailsService { @Override public Object loadUserBySAML(SAMLCredential samlCredential) { if (samlCredential.getAuthenticationAssertion() == null) { throw new IllegalArgumentException("Cannot determine which underlying UserDetailsService to use for SAMLCredential. " + "Must contain an authenticationAssertion"); } String authnContextClassRef = samlCredential.getAuthenticationAssertion().getAuthnStatements().get(0).getAuthnContext() .getAuthnContextClassRef().getAuthnContextClassRef(); if (authnContextClassRef == null || authnContextClassRef.trim().length() == 0) { throw new IllegalArgumentException("Cannot determine which underlying UserDetailsService to use for SAMLCredential. " + "AuthenticationContextClassRef was null or empty. Should be one of:\n" + HTTP_ID_SAMBI_SE_LOA_LOA3 + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI); } switch (authnContextClassRef) { case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT: case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI: case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI: return elegWebCertUserDetailsService.loadUserBySAML(samlCredential); case HTTP_ID_SAMBI_SE_LOA_LOA3: return webcertUserDetailsService.loadUserBySAML(samlCredential); case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_UNSPECIFIED: if (Arrays.stream(environment.getActiveProfiles()).anyMatch("wc-security-test"::equalsIgnoreCase)) { return webcertUserDetailsService.loadUserBySAML(samlCredential); } throw new IllegalArgumentException( "AuthorizationContextClassRef " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_UNSPECIFIED + " is not allowed"); default: throw new IllegalArgumentException("AuthorizationContextClassRef was " + authnContextClassRef + ", expected one of: " + HTTP_ID_SAMBI_SE_LOA_LOA3 + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI); } }  }
UnifiedUserDetailsService implements SAMLUserDetailsService { @Override public Object loadUserBySAML(SAMLCredential samlCredential) { if (samlCredential.getAuthenticationAssertion() == null) { throw new IllegalArgumentException("Cannot determine which underlying UserDetailsService to use for SAMLCredential. " + "Must contain an authenticationAssertion"); } String authnContextClassRef = samlCredential.getAuthenticationAssertion().getAuthnStatements().get(0).getAuthnContext() .getAuthnContextClassRef().getAuthnContextClassRef(); if (authnContextClassRef == null || authnContextClassRef.trim().length() == 0) { throw new IllegalArgumentException("Cannot determine which underlying UserDetailsService to use for SAMLCredential. " + "AuthenticationContextClassRef was null or empty. Should be one of:\n" + HTTP_ID_SAMBI_SE_LOA_LOA3 + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI); } switch (authnContextClassRef) { case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT: case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI: case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI: return elegWebCertUserDetailsService.loadUserBySAML(samlCredential); case HTTP_ID_SAMBI_SE_LOA_LOA3: return webcertUserDetailsService.loadUserBySAML(samlCredential); case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_UNSPECIFIED: if (Arrays.stream(environment.getActiveProfiles()).anyMatch("wc-security-test"::equalsIgnoreCase)) { return webcertUserDetailsService.loadUserBySAML(samlCredential); } throw new IllegalArgumentException( "AuthorizationContextClassRef " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_UNSPECIFIED + " is not allowed"); default: throw new IllegalArgumentException("AuthorizationContextClassRef was " + authnContextClassRef + ", expected one of: " + HTTP_ID_SAMBI_SE_LOA_LOA3 + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI); } }  @Override Object loadUserBySAML(SAMLCredential samlCredential); }
UnifiedUserDetailsService implements SAMLUserDetailsService { @Override public Object loadUserBySAML(SAMLCredential samlCredential) { if (samlCredential.getAuthenticationAssertion() == null) { throw new IllegalArgumentException("Cannot determine which underlying UserDetailsService to use for SAMLCredential. " + "Must contain an authenticationAssertion"); } String authnContextClassRef = samlCredential.getAuthenticationAssertion().getAuthnStatements().get(0).getAuthnContext() .getAuthnContextClassRef().getAuthnContextClassRef(); if (authnContextClassRef == null || authnContextClassRef.trim().length() == 0) { throw new IllegalArgumentException("Cannot determine which underlying UserDetailsService to use for SAMLCredential. " + "AuthenticationContextClassRef was null or empty. Should be one of:\n" + HTTP_ID_SAMBI_SE_LOA_LOA3 + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI); } switch (authnContextClassRef) { case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT: case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI: case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI: return elegWebCertUserDetailsService.loadUserBySAML(samlCredential); case HTTP_ID_SAMBI_SE_LOA_LOA3: return webcertUserDetailsService.loadUserBySAML(samlCredential); case URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_UNSPECIFIED: if (Arrays.stream(environment.getActiveProfiles()).anyMatch("wc-security-test"::equalsIgnoreCase)) { return webcertUserDetailsService.loadUserBySAML(samlCredential); } throw new IllegalArgumentException( "AuthorizationContextClassRef " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_UNSPECIFIED + " is not allowed"); default: throw new IllegalArgumentException("AuthorizationContextClassRef was " + authnContextClassRef + ", expected one of: " + HTTP_ID_SAMBI_SE_LOA_LOA3 + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SOFTWARE_PKI + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_MOBILE_TWO_FACTOR_CONTRACT + " or " + URN_OASIS_NAMES_TC_SAML_2_0_AC_CLASSES_SMARTCARD_PKI); } }  @Override Object loadUserBySAML(SAMLCredential samlCredential);  }