Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from Axway-API-Management-Plus/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
rathnapandi authored Feb 7, 2019
2 parents bcbf188 + e1aa4fb commit 0692bae
Show file tree
Hide file tree
Showing 19 changed files with 315 additions and 330 deletions.
2 changes: 1 addition & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ applications:
- name: axway-apim-service-broker
memory: 1G
random-route: true
path: target/axway-apim-service-broker-1.1.4.jar
path: target/axway-apim-service-broker-1.1.5.jar

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.axway.apim</groupId>
<artifactId>apim-service-broker</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
<packaging>jar</packaging>
<name>axway-apim-service-broker</name>
<description>Axway APIM Service Broker</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.springframework.cloud.servicebroker.model.BrokerApiVersion;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.client.RestTemplate;

import com.axway.apim.servicebroker.exception.AxwayAPIGatewayErrorHandler;
Expand Down Expand Up @@ -58,6 +57,7 @@ public boolean verify(String hostname, SSLSession session) {
RestTemplate restClient = restTemplateBuilder
.setConnectTimeout(connectTimeout)
.setReadTimeout(readTimeout)
.basicAuthorization(username, new String(password))
.detectRequestFactory(false)
.build();

Expand Down Expand Up @@ -101,17 +101,13 @@ public AxwayAPIClient axwayAPIClient() {
}

@Bean
public HttpHeaders authHeader() {
HttpHeaders authHeader = Util.createAuthHeaders(username, new String(password));
return authHeader;
public Util util() {
return new Util();
}

@Bean
public String url() {
return url;
}




}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.axway.apim.servicebroker.config;

import java.util.Base64;
import java.util.Iterator;
import java.util.List;

Expand All @@ -17,8 +18,6 @@
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import com.axway.apim.servicebroker.util.Util;

public class CFResourceOwnerPasswordAccessTokenProvider extends OAuth2AccessTokenSupport implements AccessTokenProvider {

private static String USERNAME="cf";
Expand All @@ -37,15 +36,15 @@ public OAuth2AccessToken refreshAccessToken(OAuth2ProtectedResourceDetails resou
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
form.add("grant_type", "refresh_token");
form.add("refresh_token", refreshToken.getValue());
HttpHeaders headers = Util.createAuthHeaders(USERNAME, "");
HttpHeaders headers = createAuthHeaders(USERNAME, "");
return retrieveToken(request, resource, form, headers);
}

public OAuth2AccessToken obtainAccessToken(OAuth2ProtectedResourceDetails details, AccessTokenRequest request)
throws UserRedirectRequiredException, AccessDeniedException, OAuth2AccessDeniedException {

ResourceOwnerPasswordResourceDetails resource = (ResourceOwnerPasswordResourceDetails) details;
HttpHeaders headers = Util.createAuthHeaders(USERNAME, "");
HttpHeaders headers = createAuthHeaders(USERNAME, "");
return retrieveToken(request, resource, getParametersForTokenRequest(resource, request), headers);

}
Expand Down Expand Up @@ -80,5 +79,20 @@ private MultiValueMap<String, String> getParametersForTokenRequest(ResourceOwner
return form;

}

private HttpHeaders createAuthHeaders(String username, String password) {

return new HttpHeaders() {

private static final long serialVersionUID = 1L;

{
String auth = username + ":" + password;
byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes());
String authHeader = "Basic " + new String(encodedAuth);
set("Authorization", authHeader);
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,104 +2,46 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.servicebroker.model.Catalog;
import org.springframework.cloud.servicebroker.model.DashboardClient;
import org.springframework.cloud.servicebroker.model.Plan;
import org.springframework.cloud.servicebroker.model.ServiceDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

@Configuration
public class CatalogConfig {

public class CatalogConfig {

private static final Logger logger = LoggerFactory.getLogger(CatalogConfig.class);

@Autowired
private ResourceLoader resourceLoader;

@Autowired
private ObjectMapper mapper;

//private static String BROKER_ID="ED01F448-40C7-4A9D-93D0-51E7D4E93CA1";

@Bean
public Catalog catalog() {
return new Catalog(
Collections.singletonList(new ServiceDefinition(getEnvOrDefault("SERVICE_ID", "ED01F448-40C7-4A9D-93D0-51E7D4E93CA1"), // env
getEnvOrDefault("SERVICE_NAME", "Axway-APIM"), // env
"Axway service broker implementation", true, false, getPlans(), getTags(),
getServiceDefinitionMetadata(), Arrays.asList("route_forwarding"), getDashboardClient())));
}

/* Used by Pivotal CF console */

private Map<String, Object> getServiceDefinitionMetadata() {
Map<String, Object> sdMetadata = new HashMap<>();
sdMetadata.put("displayName", "Axway Amplify APIM");
sdMetadata.put("imageUrl", "https://cdn.axway.com/globalnav/axway-logo-top.svg");
sdMetadata.put("longDescription", "Axway Amplify APIM Service Broker");
sdMetadata.put("providerDisplayName", "Axway");
sdMetadata.put("documentationUrl", "https://github.com/Axway-API-Management-Plus");
sdMetadata.put("supportUrl", "https://github.com/Axway-API-Management-Plus");
return sdMetadata;
}

// private Map<String, Object> getPlanMetadata() {
// Map<String, Object> planMetadata = new HashMap<>();
// planMetadata.put("displayName", "Axway APIM Route Service");
// return planMetadata;
// }

private List<String> getTags() {
return Arrays.asList("Axway", "api", "api management", "api platform", "api gateway", "Axway Amplify"); // tags
}

private List<Plan> getPlans() {
// List<Plan> plans = new ArrayList<>();
// Plan plan = new Plan(getEnvOrDefault("PLAN_ID", "1A6C15A6-1DE1-4870-A4F2-EA0A905F4A0F"), // env
// "APIM", "This is a default Axway plan. All services are created equally.", getPlanMetadata(),
// true);
// plans.add(plan);
InputStream inputStream = null;
Catalog catalog = null;
try {
inputStream = resourceLoader.getResource("classpath:plan.json").getInputStream();
TypeReference<List<Plan>> type = new TypeReference<List<Plan>>() {};
List<Plan> plans = mapper.readValue(inputStream, type);
return plans;
inputStream = resourceLoader.getResource("classpath:catalog.json").getInputStream();
catalog = mapper.readValue(inputStream, Catalog.class);

} catch (IOException e) {
e.printStackTrace();
}finally {
if(inputStream != null)
logger.error("Unable to create catalog", e);
} finally {
if (inputStream != null)
try {
inputStream.close();
} catch (IOException e) {

}
}
return null;
}

private DashboardClient getDashboardClient() {
DashboardClient dashboardClient = new DashboardClient("id", "secret", "https://axway.com");
return dashboardClient;
}

private String getEnvOrDefault(final String variable, final String defaultValue) {
String value = System.getenv(variable);
if (value != null) {
return value;
} else {
return defaultValue;
}
}
return catalog;
}

}
Loading

0 comments on commit 0692bae

Please sign in to comment.