Search in sources :

Example 1 with OIDCDiscoveryResponse

use of com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse in project openbanking-aspsp by OpenBankingToolkit.

the class ASDiscoveryService method discovery.

public OIDCDiscoveryResponse discovery(String oidcRootEndpoint) {
    String wellKnownEndpoint = oidcRootEndpoint + OIDCConstants.Endpoint.WELL_KNOWN;
    LOGGER.debug("Call the well-known endpoint of the AS {}", wellKnownEndpoint);
    ParameterizedTypeReference<OIDCDiscoveryResponse> ptr = new ParameterizedTypeReference<OIDCDiscoveryResponse>() {
    };
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(wellKnownEndpoint);
    URI uri = builder.build().encode().toUri();
    ResponseEntity<OIDCDiscoveryResponse> entity = restTemplate.exchange(uri, HttpMethod.GET, null, ptr);
    return entity.getBody();
}
Also used : OIDCDiscoveryResponse(com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) URI(java.net.URI)

Example 2 with OIDCDiscoveryResponse

use of com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse in project openbanking-aspsp by OpenBankingToolkit.

the class DiscoveryApiControllerTest method requireRequestUriRegistration_isNull_when_requestUriParameterNotSupported.

@Test
public void requireRequestUriRegistration_isNull_when_requestUriParameterNotSupported() throws OBErrorResponseException {
    // Given
    MockHttpServletRequest req = new MockHttpServletRequest();
    OIDCDiscoveryResponse oidcDiscoveryResponse = JMockData.mock(OIDCDiscoveryResponse.class);
    oidcDiscoveryResponse.setRequireRequestUriRegistration(true);
    oidcDiscoveryResponse.setRequestUriParameterSupported(false);
    ResponseEntity<OIDCDiscoveryResponse> response = new ResponseEntity<>(oidcDiscoveryResponse, HttpStatus.OK);
    given(amGateway.toAM(req, new HttpHeaders(), new ParameterizedTypeReference<OIDCDiscoveryResponse>() {
    })).willReturn(response);
    // When
    ResponseEntity<OIDCDiscoveryResponse> discovery = discoveryApiController.getDiscovery(req);
    // Then
    OIDCDiscoveryResponse respBody = Objects.requireNonNull(discovery.getBody());
    assertThat(respBody.getRequestUriParameterSupported()).isFalse();
    assertThat(respBody.getRequireRequestUriRegistration()).isNull();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) OIDCDiscoveryResponse(com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 3 with OIDCDiscoveryResponse

use of com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse in project openbanking-aspsp by OpenBankingToolkit.

the class DiscoveryApiControllerTest method testResponseTypesSupported_dont_match.

@Test
public void testResponseTypesSupported_dont_match() {
    // Given
    List<String> responseTypes = List.of("code", "id_token", "code id_token");
    given(config.getSupportedResponseTypes()).willReturn(responseTypes);
    discoveryApiController = new DiscoveryApiController(amGateway, config, "localhost", "", "", "");
    MockHttpServletRequest req = new MockHttpServletRequest();
    OIDCDiscoveryResponse oidcDiscoveryResponse = JMockData.mock(OIDCDiscoveryResponse.class);
    List<String> amResponseTypes = new ArrayList<>();
    amResponseTypes.addAll(responseTypes.subList(0, 1));
    amResponseTypes.add("device_code");
    amResponseTypes.add("device_code code id_token");
    oidcDiscoveryResponse.setResponseTypesSupported(amResponseTypes);
    ResponseEntity<OIDCDiscoveryResponse> response = new ResponseEntity<>(oidcDiscoveryResponse, HttpStatus.OK);
    given(amGateway.toAM(req, new HttpHeaders(), new ParameterizedTypeReference<OIDCDiscoveryResponse>() {
    })).willReturn(response);
    // When
    OBErrorResponseException e = catchThrowableOfType(() -> discoveryApiController.getDiscovery(req), OBErrorResponseException.class);
    // Then
    assertThat(e.getErrors().get(0).getMessage()).isEqualTo("The response types supported by the authorisation server '" + amResponseTypes + "' don't match with the response types supported '" + responseTypes + "' by as-api");
    assertThat(e.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) OIDCDiscoveryResponse(com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ArrayList(java.util.ArrayList) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) Test(org.junit.Test)

Example 4 with OIDCDiscoveryResponse

use of com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse in project openbanking-aspsp by OpenBankingToolkit.

the class DiscoveryApiControllerTest method testResponseTypeSupported_dont_match.

@Test
public void testResponseTypeSupported_dont_match() {
    // Given
    List<String> responseTypes = List.of("code id_token");
    given(config.getSupportedResponseTypes()).willReturn(responseTypes);
    discoveryApiController = new DiscoveryApiController(amGateway, config, "localhost", "", "", "");
    MockHttpServletRequest req = new MockHttpServletRequest();
    OIDCDiscoveryResponse oidcDiscoveryResponse = JMockData.mock(OIDCDiscoveryResponse.class);
    List<String> amResponseTypes = List.of("device_code", "device_code code id_token");
    oidcDiscoveryResponse.setResponseTypesSupported(amResponseTypes);
    ResponseEntity<OIDCDiscoveryResponse> response = new ResponseEntity<>(oidcDiscoveryResponse, HttpStatus.OK);
    given(amGateway.toAM(req, new HttpHeaders(), new ParameterizedTypeReference<OIDCDiscoveryResponse>() {
    })).willReturn(response);
    // When
    OBErrorResponseException e = catchThrowableOfType(() -> discoveryApiController.getDiscovery(req), OBErrorResponseException.class);
    // Then
    assertThat(e.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST);
    assertThat(e.getErrors().get(0).getMessage()).isEqualTo("The response types supported by the authorisation server '" + amResponseTypes + "' don't match with the response types supported '" + responseTypes + "' by as-api");
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) OIDCDiscoveryResponse(com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) Test(org.junit.Test)

Example 5 with OIDCDiscoveryResponse

use of com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse in project openbanking-aspsp by OpenBankingToolkit.

the class DiscoveryApiControllerTest method testCustomAPIVersion.

@Test
public void testCustomAPIVersion() throws OBErrorResponseException {
    // Given
    discoveryApiController = new DiscoveryApiController(amGateway, config, "localhost", "8074", "RWApiVersion", "CRApiVersion");
    MockHttpServletRequest req = new MockHttpServletRequest();
    OIDCDiscoveryResponse oidcDiscoveryResponse = JMockData.mock(OIDCDiscoveryResponse.class);
    ResponseEntity<OIDCDiscoveryResponse> response = new ResponseEntity<>(oidcDiscoveryResponse, HttpStatus.OK);
    given(amGateway.toAM(req, new HttpHeaders(), new ParameterizedTypeReference<OIDCDiscoveryResponse>() {
    })).willReturn(response);
    // When
    ResponseEntity<OIDCDiscoveryResponse> discovery = discoveryApiController.getDiscovery(req);
    // Then
    assertThat(discovery.getBody().getReadWriteApiVersion()).isEqualTo("RWApiVersion");
    assertThat(discovery.getBody().getClientRegistrationApiVersion()).isEqualTo("CRApiVersion");
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) OIDCDiscoveryResponse(com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

OIDCDiscoveryResponse (com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse)10 HttpHeaders (org.springframework.http.HttpHeaders)9 Test (org.junit.Test)8 ResponseEntity (org.springframework.http.ResponseEntity)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)3 ArrayList (java.util.ArrayList)3 ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)2 URI (java.net.URI)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1