Skip to content

Commit 2229ab9

Browse files
committed
Tidy up methods related to fetching endpoint/connector properties
1 parent cbc4830 commit 2229ab9

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

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

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void setApplicationContext(ApplicationContext applicationContext)
7878

7979
private String getAuthenticationMethod()
8080
{
81-
String descriptorMethod = descriptor.getStringProperty(PARAM_AUTH_METHOD);
81+
String descriptorMethod = getDescriptorProperty(PARAM_AUTH_METHOD, (EndpointDescriptor) null);
8282
return descriptorMethod != null ? descriptorMethod : AUTH_METHOD_OAUTH;
8383
}
8484

@@ -445,21 +445,12 @@ protected void applyRequestAuthentication(RemoteClient remoteClient, ConnectorCo
445445
protected String doRefresh(String endpointId) throws TokenRefreshException
446446
{
447447
String refreshToken = getRefreshToken();
448-
ConnectorService connectorService = getConnectorService();
449-
EndpointDescriptor epd = connectorService.getRemoteConfig().getEndpointDescriptor(endpointId);
448+
EndpointDescriptor epd = getEndpointDescriptor(endpointId);
450449

451450
// First try to get the client-id and access-token-url from the endpoint, then from the connector
452451
// TODO Make these strings constants in a Descriptor sub-class or interface
453-
String clientId = epd.getStringProperty("client-id");
454-
String tokenUrl = epd.getStringProperty("access-token-url");
455-
if (clientId == null)
456-
{
457-
clientId = descriptor.getStringProperty("client-id");
458-
}
459-
if (tokenUrl == null)
460-
{
461-
tokenUrl = descriptor.getStringProperty("access-token-url");
462-
}
452+
String clientId = getDescriptorProperty("client-id", epd);
453+
String tokenUrl = getDescriptorProperty("access-token-url", epd);
463454
/*
464455
RemoteClient remoteClient = buildRemoteClient(tokenUrl);
465456
@@ -537,6 +528,31 @@ protected String doRefresh(String endpointId) throws TokenRefreshException
537528
return null;
538529
}
539530
}
531+
532+
protected EndpointDescriptor getEndpointDescriptor(String endpointId)
533+
{
534+
return getConnectorService().getRemoteConfig().getEndpointDescriptor(endpointId);
535+
}
536+
537+
protected String getDescriptorProperty(String propertyName, EndpointDescriptor endpointDescriptor)
538+
{
539+
String propertyValue = null;
540+
if (endpointDescriptor != null)
541+
{
542+
propertyValue = endpointDescriptor.getStringProperty(propertyName);
543+
}
544+
// Fall back to connector property if not found on endpoint
545+
if (propertyValue == null)
546+
{
547+
propertyValue = descriptor.getStringProperty(propertyName);
548+
}
549+
return propertyValue;
550+
}
551+
552+
protected String getDescriptorProperty(String propertyName, String endpointId)
553+
{
554+
return getDescriptorProperty(propertyName, getEndpointDescriptor(endpointId));
555+
}
540556

541557
public String getEndpointId()
542558
{

0 commit comments

Comments
 (0)