Skip to content

Commit 43bd764

Browse files
committed
Fix #4 - HttpOAuth2Connector is unable to identify the endpointId for root-path requests
- Improvements to logic inside getEndpointId() - Added javadoc to explain the purpose of this private method
1 parent 98b35bf commit 43bd764

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

share-oauth/src/main/java/org/sharextras/webscripts/connector/HttpOAuth2Connector.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,13 +581,26 @@ public String getEndpointId()
581581
return descriptor.getStringProperty(PARAM_TOKEN_ENDPOINT);
582582
}
583583

584+
/**
585+
* Get the endpoint ID identified in the given request object. This is necessary because the connector is
586+
* not aware of the ID of the endpoint which is utilising it, only the URI.
587+
*
588+
* @param uri URI path relative to the base endpoint URI, passed to the connector, e.g. /path/to/blah
589+
* @param request HTTP request object representing the proxied request object
590+
* @return The endpoint ID as specified in the web-tier config
591+
*/
584592
private String getEndpointId(String uri, HttpServletRequest request)
585593
{
586594
// Work out URI path (i.e. uri without the querystring portion)
587595
String uriPath = uri.indexOf('?') > -1 ? uri.substring(0, uri.indexOf('?')) : uri;
588-
return getEndpointId() != null ? getEndpointId() :
589-
request.getPathInfo().replaceAll(uriPath, "").replaceAll("/proxy/", "");
590-
596+
String endpointId = getEndpointId();
597+
if (endpointId == null)
598+
{
599+
String basePath = request.getPathInfo() // will be something like /proxy/endpoint-id/path/to/blah
600+
.substring(0, request.getPathInfo().length() - uriPath.length());
601+
endpointId = basePath.substring(basePath.lastIndexOf('/') + 1); // take the last path segment only
602+
}
603+
return endpointId;
591604
}
592605

593606
private ConnectorService getConnectorService()

0 commit comments

Comments
 (0)