use of com.forgerock.spring.security.multiauth.model.authentication.PSD2Authentication in project openbanking-aspsp by OpenBankingToolkit.
the class ApiClientIdentityFactoryTest method returnsApiClientQWac_getApiClientIdentity.
@Test
public void returnsApiClientQWac_getApiClientIdentity() throws CertificateException, IOException, InvalidPsd2EidasCertificate, ApiClientException, OAuth2InvalidClientException {
// given
X509Certificate[] certificatesChain = TestHelperFunctions.getCertChainFromFile("src/test/resources/certificates/QWac.pem");
Psd2CertInfo certInfo = new Psd2CertInfo(certificatesChain);
String tppName = "TestTppName";
Collection<OBRIRole> authorities = new ArrayList<>();
authorities.add(OBRIRole.UNREGISTERED_TPP);
PSD2Authentication authentication = new PSD2Authentication(tppName, authorities, certificatesChain, certInfo);
ApiClientIdentityFactory identityFactory = new ApiClientIdentityFactory();
// when
ApiClientIdentity identity = identityFactory.getApiClientIdentity(authentication);
// then
assertThat(identity).isInstanceOf(ApiClientIdentityQWac.class);
}
use of com.forgerock.spring.security.multiauth.model.authentication.PSD2Authentication in project openbanking-aspsp by OpenBankingToolkit.
the class ApiClientIdentityFactory method getApiClientIdentity.
public ApiClientIdentity getApiClientIdentity(Principal principal) throws ApiClientException, OAuth2InvalidClientException {
ApiClientIdentity apiClientIdentity = null;
if (principal instanceof PSD2Authentication) {
PSD2Authentication authentication = (PSD2Authentication) principal;
Psd2CertInfo certInfo = authentication.getPsd2CertInfo();
if (certInfo.isPsd2Cert()) {
ApiClientCertificateType certType = getApiClientCertificateTypeFromPSD2(authentication);
switch(certType) {
case FR_TRANSPORT:
apiClientIdentity = new ApiClientIdentityFRTransport(authentication);
break;
case OBWAC:
apiClientIdentity = new ApiClientIdentityOBWac(authentication);
break;
case QWAC:
apiClientIdentity = new ApiClientIdentityQWac(authentication);
break;
default:
String errorString = "Client presented an invalid Certificate " + "Type for use as a Transport certificate. Type presented ': " + certType + "'";
log.info("getApiClientIdentity() {}", errorString);
throw new ApiClientException(errorString);
}
} else {
log.info("ApiClient presented a deprecated OBTransport certificate.");
throw new OAuth2InvalidClientException("Onboarding must be done with a PSD2 eIDAS certificate. " + "OBTransport certificates have been depricated");
}
} else if (principal instanceof X509Authentication) {
X509Authentication authentication = (X509Authentication) principal;
apiClientIdentity = createOBTransportIdentity(authentication);
} else {
log.info("getApiClientIdentity() Principal is not of recognised type. Class name is '{}'", apiClientIdentity.getClass().getName());
throw new ApiClientException("Unrecognised Principal type. Was expecting a PSDAuthentication or a " + "X509Authentication");
}
return apiClientIdentity;
}
use of com.forgerock.spring.security.multiauth.model.authentication.PSD2Authentication in project openbanking-aspsp by OpenBankingToolkit.
the class ApiClientIdentityFactoryTest method returnsApiClientFRTransport_getApiClientIdentity.
@Test
public void returnsApiClientFRTransport_getApiClientIdentity() throws CertificateException, IOException, ApiClientException, InvalidPsd2EidasCertificate, OAuth2InvalidClientException {
// given
X509Certificate[] certificatesChain = TestHelperFunctions.getCertChainFromFile("src/test/resources/certificates/fr-transport.pem");
Psd2CertInfo certInfo = new Psd2CertInfo(certificatesChain);
String tppName = "TestTppName";
Collection<OBRIRole> authorities = new ArrayList<>();
authorities.add(OBRIRole.UNREGISTERED_TPP);
PSD2Authentication authentication = new PSD2Authentication(tppName, authorities, certificatesChain, certInfo);
ApiClientIdentityFactory identityFactory = new ApiClientIdentityFactory();
// when
ApiClientIdentity identity = identityFactory.getApiClientIdentity(authentication);
// then
assertThat(identity).isInstanceOf(ApiClientIdentityFRTransport.class);
}
use of com.forgerock.spring.security.multiauth.model.authentication.PSD2Authentication in project openbanking-aspsp by OpenBankingToolkit.
the class ApiClientIdentityFactoryTest method returnsApiClientOBWac_getApiClientIdentity.
@Test
public void returnsApiClientOBWac_getApiClientIdentity() throws CertificateException, IOException, ApiClientException, InvalidPsd2EidasCertificate, OAuth2InvalidClientException {
// given
X509Certificate[] certificatesChain = TestHelperFunctions.getCertChainFromFile("src/test/resources/certificates/OBWac.pem");
Psd2CertInfo certInfo = new Psd2CertInfo(certificatesChain);
String tppName = "TestTppName";
Collection<OBRIRole> authorities = new ArrayList<>();
authorities.add(OBRIRole.UNREGISTERED_TPP);
PSD2Authentication authentication = new PSD2Authentication(tppName, authorities, certificatesChain, certInfo);
ApiClientIdentityFactory identityFactory = new ApiClientIdentityFactory();
// when
ApiClientIdentity identity = identityFactory.getApiClientIdentity(authentication);
// then
assertThat(identity).isInstanceOf(ApiClientIdentityOBWac.class);
}
Aggregations