use of org.wso2.carbon.identity.webfinger.WebFingerEndpointException in project identity-inbound-auth-oauth by wso2-extensions.
the class DefaultWebFingerRequestBuilderTest method testBuildRequest.
@Test
public void testBuildRequest() throws WebFingerEndpointException, UserStoreException {
returnParams();
returnRelAndResource(resource, rel);
when(tenantManager.getTenantId(any(String.class))).thenReturn(MultitenantConstants.SUPER_TENANT_ID);
WebFingerRequest webFingerRequest = defaultWebFingerRequestBuilder.buildRequest(request);
assertNotNull(webFingerRequest, "WebFinger request is not null");
assertEquals(webFingerRequest.getRel(), rel, "Rel is assigned properly");
assertEquals(webFingerRequest.getResource(), resource, "Resource is assigned properly");
assertEquals(webFingerRequest.getHost(), host, "Host is assigned properly");
assertEquals(webFingerRequest.getTenant(), tenant, "Tenant is assigned properly");
assertEquals(webFingerRequest.getPath(), path, "Path is assigned properly");
assertEquals(webFingerRequest.getScheme(), scheme, "Scheme is assigned properly");
assertEquals(webFingerRequest.getPort(), port, "Port is assigned properly");
}
use of org.wso2.carbon.identity.webfinger.WebFingerEndpointException 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);
}
use of org.wso2.carbon.identity.webfinger.WebFingerEndpointException 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;
}
use of org.wso2.carbon.identity.webfinger.WebFingerEndpointException in project identity-inbound-auth-oauth by wso2-extensions.
the class DefaultWebFingerRequestBuilder method buildRequest.
@Override
public WebFingerRequest buildRequest(HttpServletRequest request) throws WebFingerEndpointException {
WebFingerRequest webFingerRequest = new WebFingerRequest();
List<String> parameters = Collections.list(request.getParameterNames());
if (parameters.size() != 2 || !parameters.contains(WebFingerConstants.REL) || !parameters.contains(WebFingerConstants.RESOURCE)) {
throw new WebFingerEndpointException(WebFingerConstants.ERROR_CODE_INVALID_REQUEST, "Bad Web " + "Finger request.");
}
webFingerRequest.setServletRequest(request);
String resource = request.getParameter(WebFingerConstants.RESOURCE);
webFingerRequest.setRel(request.getParameter(WebFingerConstants.REL));
webFingerRequest.setResource(resource);
if (StringUtils.isBlank(resource)) {
log.warn("Can't normalize null or empty URI: " + resource);
throw new WebFingerEndpointException(WebFingerConstants.ERROR_CODE_INVALID_RESOURCE, "Null or empty URI.");
} else {
URI resourceURI = URI.create(resource);
if (StringUtils.isBlank(resourceURI.getScheme())) {
throw new WebFingerEndpointException("Scheme of the resource cannot be empty");
}
String userInfo;
if (WebFingerConstants.ACCT_SCHEME.equals(resourceURI.getScheme())) {
// acct scheme
userInfo = resourceURI.getSchemeSpecificPart();
if (!userInfo.contains("@")) {
throw new WebFingerEndpointException(WebFingerConstants.ERROR_CODE_INVALID_REQUEST, "Invalid host value.");
}
userInfo = userInfo.substring(0, userInfo.lastIndexOf('@'));
} else {
// https scheme
userInfo = resourceURI.getUserInfo();
webFingerRequest.setScheme(resourceURI.getScheme());
webFingerRequest.setHost(resourceURI.getHost());
webFingerRequest.setPort(resourceURI.getPort());
webFingerRequest.setPath(resourceURI.getPath());
webFingerRequest.setQuery(resourceURI.getQuery());
}
String tenant;
if (StringUtils.isNotBlank(userInfo)) {
try {
userInfo = URLDecoder.decode(userInfo, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new WebFingerEndpointException("Cannot decode the userinfo");
}
tenant = MultitenantUtils.getTenantDomain(userInfo);
webFingerRequest.setUserInfo(resourceURI.getUserInfo());
} else {
tenant = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
validateTenant(tenant);
webFingerRequest.setTenant(tenant);
}
return webFingerRequest;
}
use of org.wso2.carbon.identity.webfinger.WebFingerEndpointException 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);
}
Aggregations