use of com.forgerock.openbanking.common.error.exception.oauth2.OAuth2InvalidClientException in project openbanking-aspsp by OpenBankingToolkit.
the class TppRegistrationServiceTest method ensureTppOwnsOidcRegistration_ThrowsWhenNoMatch.
@Test
public void ensureTppOwnsOidcRegistration_ThrowsWhenNoMatch() throws OAuth2InvalidClientException {
// Given
String clientId = "ClientId";
String clientName = "Name";
String authorizationNumber = "PSDUK-FCA-12345";
Tpp tpp = TestHelperFunctions.getValidTpp(clientId, clientName);
tpp.setAuthorisationNumber(authorizationNumber);
// When
Exception e = catchThrowableOfType(() -> tppRegistrationService.ensureTppOwnsOidcRegistration(tpp, "PSDUK-FCA" + "-54321"), Exception.class);
// Then
assertThat(e).isNotNull();
assertThat(e).isInstanceOf(OAuth2InvalidClientException.class);
}
use of com.forgerock.openbanking.common.error.exception.oauth2.OAuth2InvalidClientException in project openbanking-aspsp by OpenBankingToolkit.
the class ApiClientIdentityOBWacTest method throwIfNotValidCertAuthority.
@Test
public void throwIfNotValidCertAuthority() throws CertificateException, IOException {
// Given
X509Certificate[] certChain = TestHelperFunctions.getCertChainFromFile(QWAC_CERT_PATH);
when(authentication.getCertificateChain()).thenReturn(certChain);
Collection<GrantedAuthority> authorities = new ArrayList<>(List.of(OBRIRole.UNKNOWN_CERTIFICATE));
when(authentication.getAuthorities()).thenReturn(authorities);
// When
OAuth2InvalidClientException exception = catchThrowableOfType(() -> new ApiClientIdentityOBWac(authentication), OAuth2InvalidClientException.class);
// Then
assertThat(exception.getRfc6750ErrorCode()).isEqualTo(OAuth2Exception.INVALID_CLIENT);
}
use of com.forgerock.openbanking.common.error.exception.oauth2.OAuth2InvalidClientException in project openbanking-aspsp by OpenBankingToolkit.
the class ApiClientIdentityQWacTest method throwIfNotValidCertAuthority.
@Test
public void throwIfNotValidCertAuthority() throws CertificateException, IOException {
// Given
X509Certificate[] certChain = TestHelperFunctions.getCertChainFromFile(OBWAC_CERT_PATH);
when(authentication.getCertificateChain()).thenReturn(certChain);
Collection<GrantedAuthority> authorities = new ArrayList<>(List.of(OBRIRole.UNKNOWN_CERTIFICATE));
when(authentication.getAuthorities()).thenReturn(authorities);
// When
OAuth2InvalidClientException exception = catchThrowableOfType(() -> new ApiClientIdentityOBWac(authentication), OAuth2InvalidClientException.class);
// Then
assertThat(exception.getRfc6750ErrorCode()).isEqualTo(OAuth2Exception.INVALID_CLIENT);
}
use of com.forgerock.openbanking.common.error.exception.oauth2.OAuth2InvalidClientException in project openbanking-aspsp by OpenBankingToolkit.
the class TppRegistrationService method getTpp.
/**
* getTpp returns the tpp associated with the principal. If not tpp can be found will throw.
* @param clientId the principal as obtained from the client MATLS certificate used to make the request
* @return a Tpp object belonging to the principal. If no tpp can be found then will throw
* OAuth2InvalidClientException
* @throws OAuth2InvalidClientException
*/
@NotNull
public Tpp getTpp(@NotNull String clientId) throws OAuth2InvalidClientException {
Optional<Tpp> optionalTpp = tppStoreService.findByClientId(clientId);
if (optionalTpp.isEmpty()) {
String errorMessage = "No registration exists for the clientId in the request path. clientId was '" + clientId + "'";
log.info("getTpp() {}", errorMessage);
throw new OAuth2InvalidClientException(errorMessage);
}
Tpp tpp = optionalTpp.get();
log.debug("getTpp(): Tpp is {}", tpp);
return tpp;
}
use of com.forgerock.openbanking.common.error.exception.oauth2.OAuth2InvalidClientException in project openbanking-aspsp by OpenBankingToolkit.
the class ApiClientIdentity method throwIfNotValidCertAuthority.
/**
* Check the transport certificate is issued by a recognised authority. Will throw with errors that can be
* directly returned from Client Registration Endpoints.
*/
public void throwIfNotValidCertAuthority() throws OAuth2InvalidClientException {
if (this.authentication.getAuthorities().contains(OBRIRole.UNKNOWN_CERTIFICATE)) {
String helpString = "The transport certificate is not signed by a recognised " + "authority";
X509Certificate certificate = this.getTransportCertificate();
if (certificate != null) {
X500Principal principal = certificate.getIssuerX500Principal();
if (principal != null) {
helpString += " '" + principal + "'";
}
}
log.info("throwIfNotValidCertAuthority() {}. X509Authentication; {}", helpString, this.authentication);
throw new OAuth2InvalidClientException(helpString);
}
}
Aggregations