Search in sources :

Example 1 with ServerConfigurationException

use of org.wso2.carbon.base.ServerConfigurationException in project identity-inbound-auth-oauth by wso2-extensions.

the class OIDCDiscoveryEndpoint method getResponse.

private Response getResponse(HttpServletRequest request, String tenant) {
    String response;
    OIDCProcessor processor = EndpointUtil.getOIDCService();
    try {
        OIDProviderResponseBuilder responseBuilder = getOidProviderResponseBuilder();
        response = responseBuilder.getOIDProviderConfigString(processor.getResponse(request, tenant));
    } catch (OIDCDiscoveryEndPointException e) {
        Response.ResponseBuilder errorResponse = Response.status(processor.handleError(e));
        return errorResponse.entity(e.getMessage()).build();
    } catch (ServerConfigurationException e) {
        log.error("Server Configuration error occurred.", e);
        Response.ResponseBuilder errorResponse = Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return errorResponse.entity("Error in reading configuration.").build();
    }
    Response.ResponseBuilder responseBuilder = Response.status(HttpServletResponse.SC_OK);
    return responseBuilder.entity(response).build();
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) ServerConfigurationException(org.wso2.carbon.base.ServerConfigurationException) OIDCProcessor(org.wso2.carbon.identity.discovery.OIDCProcessor) OIDProviderResponseBuilder(org.wso2.carbon.identity.discovery.builders.OIDProviderResponseBuilder) OIDCDiscoveryEndPointException(org.wso2.carbon.identity.discovery.OIDCDiscoveryEndPointException) OIDProviderResponseBuilder(org.wso2.carbon.identity.discovery.builders.OIDProviderResponseBuilder)

Example 2 with ServerConfigurationException

use of org.wso2.carbon.base.ServerConfigurationException in project identity-inbound-auth-oauth by wso2-extensions.

the class DefaultOIDCProcessor method getResponse.

public OIDProviderConfigResponse getResponse(HttpServletRequest request, String tenantDomain) throws OIDCDiscoveryEndPointException, ServerConfigurationException {
    OIDCProviderRequestBuilder requestBuilder = new DefaultOIDCProviderRequestBuilder();
    OIDProviderRequest requestObject = requestBuilder.buildRequest(request, tenantDomain);
    ProviderConfigBuilder responseBuilder = new ProviderConfigBuilder();
    return responseBuilder.buildOIDProviderConfig(requestObject);
}
Also used : ProviderConfigBuilder(org.wso2.carbon.identity.discovery.builders.ProviderConfigBuilder) DefaultOIDCProviderRequestBuilder(org.wso2.carbon.identity.discovery.builders.DefaultOIDCProviderRequestBuilder) DefaultOIDCProviderRequestBuilder(org.wso2.carbon.identity.discovery.builders.DefaultOIDCProviderRequestBuilder) OIDCProviderRequestBuilder(org.wso2.carbon.identity.discovery.builders.OIDCProviderRequestBuilder)

Example 3 with ServerConfigurationException

use of org.wso2.carbon.base.ServerConfigurationException in project identity-inbound-auth-oauth by wso2-extensions.

the class WebFingerOIDCResponseBuilderTest method testBuildWebFingerException.

@Test(expectedExceptions = ServerConfigurationException.class)
public void testBuildWebFingerException() throws WebFingerEndpointException, ServerConfigurationException, IdentityException {
    when(OAuth2Util.getIssuerLocation(any(String.class))).thenThrow(new IdentityOAuth2Exception("Error"));
    webFingerOIDCResponseBuilder.buildWebFingerResponse(webFingerRequest);
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with ServerConfigurationException

use of org.wso2.carbon.base.ServerConfigurationException in project identity-inbound-auth-oauth by wso2-extensions.

the class WebFingerOIDCResponseBuilder method buildWebFingerResponse.

public WebFingerResponse buildWebFingerResponse(WebFingerRequest request) throws WebFingerEndpointException, ServerConfigurationException {
    WebFingerResponse response;
    String oidcIssuerLocation;
    try {
        oidcIssuerLocation = getOidcIssuerLocation(request.getTenant());
    } catch (URISyntaxException | IdentityOAuth2Exception e) {
        throw new ServerConfigurationException("Error while building discovery endpoint", e);
    }
    response = new WebFingerResponse();
    response.setSubject(request.getResource());
    response.addLink(WebFingerConstants.OPENID_CONNETCT_ISSUER_REL, oidcIssuerLocation);
    return response;
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) ServerConfigurationException(org.wso2.carbon.base.ServerConfigurationException) WebFingerResponse(org.wso2.carbon.identity.webfinger.WebFingerResponse) URISyntaxException(java.net.URISyntaxException)

Example 5 with ServerConfigurationException

use of org.wso2.carbon.base.ServerConfigurationException in project identity-inbound-auth-oauth by wso2-extensions.

the class WebFingerServlet method getOIDProviderIssuer.

public void getOIDProviderIssuer(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
    WebFingerProcessor processor = WebFingerServiceComponentHolder.getWebFingerProcessor();
    String response = "";
    try {
        WebFingerResponseBuilder webFingerResponseBuilder = new JSONResponseBuilder();
        response = webFingerResponseBuilder.getOIDProviderIssuerString(processor.getResponse(httpServletRequest));
    } catch (WebFingerEndpointException e) {
        httpServletResponse.setStatus(processor.handleError(e));
        return;
    } catch (ServerConfigurationException e) {
        log.error("Server Configuration error occurred.", e);
        httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return;
    }
    httpServletResponse.setContentType(WebFingerConstants.RESPONSE_CONTENT_TYPE);
    PrintWriter out = httpServletResponse.getWriter();
    out.print(response);
}
Also used : ServerConfigurationException(org.wso2.carbon.base.ServerConfigurationException) WebFingerResponseBuilder(org.wso2.carbon.identity.webfinger.builders.WebFingerResponseBuilder) WebFingerProcessor(org.wso2.carbon.identity.webfinger.WebFingerProcessor) WebFingerEndpointException(org.wso2.carbon.identity.webfinger.WebFingerEndpointException) PrintWriter(java.io.PrintWriter)

Aggregations

ServerConfigurationException (org.wso2.carbon.base.ServerConfigurationException)4 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)3 URISyntaxException (java.net.URISyntaxException)2 PrintWriter (java.io.PrintWriter)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Response (javax.ws.rs.core.Response)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)1 ExternalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)1 OIDCDiscoveryEndPointException (org.wso2.carbon.identity.discovery.OIDCDiscoveryEndPointException)1 OIDCProcessor (org.wso2.carbon.identity.discovery.OIDCProcessor)1 OIDProviderConfigResponse (org.wso2.carbon.identity.discovery.OIDProviderConfigResponse)1 DefaultOIDCProviderRequestBuilder (org.wso2.carbon.identity.discovery.builders.DefaultOIDCProviderRequestBuilder)1 OIDCProviderRequestBuilder (org.wso2.carbon.identity.discovery.builders.OIDCProviderRequestBuilder)1 OIDProviderResponseBuilder (org.wso2.carbon.identity.discovery.builders.OIDProviderResponseBuilder)1 ProviderConfigBuilder (org.wso2.carbon.identity.discovery.builders.ProviderConfigBuilder)1 WebFingerEndpointException (org.wso2.carbon.identity.webfinger.WebFingerEndpointException)1 WebFingerProcessor (org.wso2.carbon.identity.webfinger.WebFingerProcessor)1 WebFingerResponse (org.wso2.carbon.identity.webfinger.WebFingerResponse)1