Skip to content

Commit

Permalink
Merge pull request #574 from jianghaolu/configuration
Browse files Browse the repository at this point in the history
Fix handling of access tokens in Configuration
  • Loading branch information
jianghaolu committed Jan 6, 2016
2 parents 052cdd1 + 240a42f commit b66df65
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ public class Configuration {
* of the proxy to use
*/
public static final String PROPERTY_HTTP_PROXY_PORT = "http.proxyPort";

/**
* The configuration instance.
*/
private static Configuration instance;

/**
* The configuration properties.
Expand All @@ -85,21 +80,14 @@ public Configuration(Builder builder) {
}

public static Configuration getInstance() {
if (instance == null) {
try {
instance = Configuration.load();
} catch (IOException e) {
log.error(
"Unable to load META-INF/com.microsoft.windowsazure.properties",
e);
instance = new Configuration();
}
try {
return Configuration.load();
} catch (IOException e) {
log.error(
"Unable to load META-INF/com.microsoft.windowsazure.properties",
e);
return new Configuration();
}
return instance;
}

public static void setInstance(final Configuration configuration) {
Configuration.instance = configuration;
}

public static Configuration load() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,11 @@ public HttpClientBuilder applyConfig(HttpClientBuilder httpClientBuilder) {
httpClientBuilder.addInterceptorFirst(new HttpHeaderRemovalFilter());
}

if (properties.containsKey("AuthFilters"))
if (properties.containsKey("AuthFilter"))
{
@SuppressWarnings("unchecked")
ArrayList<ServiceRequestFilter> filters = (ArrayList<ServiceRequestFilter>) properties.get("AuthFilters");
for (ServiceRequestFilter filter : filters) {
httpClientBuilder.addInterceptorFirst(new FilterInterceptor(filter));
}
ServiceRequestFilter filter = (ServiceRequestFilter) properties.get("AuthFilter");
httpClientBuilder.addInterceptorFirst(new FilterInterceptor(filter));
}

return httpClientBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,7 @@ public void setToken(String token) {
@Override
@SuppressWarnings("unchecked")
public <T> void applyConfig(String profile, Map<String, Object> properties) {
ArrayList<AdalAuthFilter> filters;
if (!properties.containsKey("AuthFilters"))
{
filters = new ArrayList<AdalAuthFilter>();
properties.put("AuthFilters", filters);
} else {
filters = (ArrayList<AdalAuthFilter>)properties.get("AuthFilters");
}

filters.add(new AdalAuthFilter(this.token));
properties.put("AuthFilter", new AdalAuthFilter(this.token));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public Client alter(String profile, Client instance,
});

// applied as default configuration
Configuration.setInstance(config);
service = ServiceBusService.create();
service = ServiceBusService.create(config);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.microsoft.windowsazure.core.pipeline.filter.ServiceRequestContext;
import com.microsoft.windowsazure.core.pipeline.filter.ServiceRequestFilter;
import com.microsoft.windowsazure.credentials.CloudCredentials;
import org.apache.http.auth.AUTH;

/**
* An implementation of {@link CloudCredentials} that supports automatic bearer
Expand All @@ -38,7 +39,7 @@
*/
public abstract class KeyVaultCredentials extends CloudCredentials implements BearerCredentialsSupport {

private static final String AUTH_FILTERS_KEY = "AuthFilters";
private static final String AUTH_FILTERS_KEY = "AuthFilter";

private final HashMap<String, Map<String, String>> cachedChallenges = new HashMap<String, Map<String, String>>();

Expand All @@ -48,17 +49,7 @@ public <T> void applyConfig(String profile, Map<String, Object> properties) {

// Modifies properties to add our authenticating filter.

// First get the existing list of filters...
ArrayList<ServiceRequestFilter> filters;
if (!properties.containsKey(AUTH_FILTERS_KEY)) {
filters = new ArrayList<ServiceRequestFilter>();
properties.put(AUTH_FILTERS_KEY, filters);
} else {
filters = (ArrayList<ServiceRequestFilter>) properties.get(AUTH_FILTERS_KEY);
}

// ...then we add our filter.
filters.add(new ServiceRequestFilter() {
properties.put(AUTH_FILTERS_KEY, new ServiceRequestFilter() {

@Override
public void filter(ServiceRequestContext request) {
Expand Down

0 comments on commit b66df65

Please sign in to comment.