fixed gw, km, iot, apim urls

kernel-4.6.x
Amalka Subasinghe 3 years ago
parent 5272293a31
commit a031579b80

@ -92,7 +92,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
apiRevisionDeployment.setDeployment(API_PUBLISH_ENVIRONMENT);
apiRevisionDeployment.setVhost("localhost");
apiRevisionDeployment.setVhost(System.getProperty("iot.gateway.host"));
apiRevisionDeployment.setDisplayOnDevportal(true);
List<APIRevisionDeployment> apiRevisionDeploymentList = new ArrayList<>();

@ -69,14 +69,10 @@ public class DefaultTokenHandler extends HttpServlet {
String clientId = authData.getClientId();
String clientSecret = authData.getClientSecret();
String iotsCorePort = System.getProperty("iot.core.https.port");
if (HandlerConstants.HTTP_PROTOCOL.equals(req.getScheme())) {
iotsCorePort = System.getProperty("iot.core.http.port");
}
String tokenUrl =
req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty("iot.core.host")
+ HandlerConstants.COLON + iotsCorePort + "/api/device-mgt/v1.0/devices/" + clientId
String iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR
+ System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme());
String tokenUrl = iotsCoreUrl + "/api/device-mgt/v1.0/devices/" + clientId
+ "/" + clientSecret + "/default-token";
HttpGet defaultTokenRequest = new HttpGet(tokenUrl);
@ -131,8 +127,8 @@ public class DefaultTokenHandler extends HttpServlet {
URIBuilder ub = new URIBuilder();
ub.setScheme(HandlerConstants.WSS_PROTOCOL);
ub.setHost(System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR));
ub.setPort(Integer.parseInt(System.getProperty(HandlerConstants.IOT_CORE_HTTPS_PORT_ENV_VAR)));
ub.setHost(System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR));
ub.setPort(Integer.parseInt(System.getProperty(HandlerConstants.IOT_GW_HTTPS_PORT_ENV_VAR)));
ub.setPath(HandlerConstants.REMOTE_SESSION_CONTEXT);
JsonObject responseJsonObj = new JsonObject();

@ -73,7 +73,7 @@ public class InvokerHandler extends HttpServlet {
private static final long serialVersionUID = -6508020875358160165L;
private static AuthData authData;
private static String apiEndpoint;
private static String iotsCoreUrl;
private static String kmManagerUrl;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
@ -85,7 +85,7 @@ public class InvokerHandler extends HttpServlet {
ProxyResponse proxyResponse = HandlerUtil.execute(postRequest);
if (HandlerConstants.TOKEN_IS_EXPIRED.equals(proxyResponse.getExecutorResponse())) {
proxyResponse = HandlerUtil.retryRequestWithRefreshedToken(req, resp, postRequest, apiEndpoint);
proxyResponse = HandlerUtil.retryRequestWithRefreshedToken(req, resp, postRequest, kmManagerUrl);
if (proxyResponse == null) {
return;
}
@ -113,14 +113,14 @@ public class InvokerHandler extends HttpServlet {
getRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + authData.getAccessToken());
ProxyResponse proxyResponse = HandlerUtil.execute(getRequest);
if (HandlerConstants.TOKEN_IS_EXPIRED.equals(proxyResponse.getExecutorResponse())) {
proxyResponse = HandlerUtil.retryRequestWithRefreshedToken(req, resp, getRequest, apiEndpoint);
proxyResponse = HandlerUtil.retryRequestWithRefreshedToken(req, resp, getRequest, kmManagerUrl);
if (proxyResponse == null) {
return;
}
}
if (proxyResponse.getExecutorResponse().contains(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)) {
if (proxyResponse.getCode() == HttpStatus.SC_UNAUTHORIZED) {
proxyResponse = HandlerUtil.retryRequestWithRefreshedToken(req, resp, getRequest, apiEndpoint);
proxyResponse = HandlerUtil.retryRequestWithRefreshedToken(req, resp, getRequest, kmManagerUrl);
} else {
log.error("Error occurred while invoking the GET API endpoint.");
HandlerUtil.handleError(resp, proxyResponse);
@ -143,7 +143,7 @@ public class InvokerHandler extends HttpServlet {
headRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + authData.getAccessToken());
ProxyResponse proxyResponse = HandlerUtil.execute(headRequest);
if (HandlerConstants.TOKEN_IS_EXPIRED.equals(proxyResponse.getExecutorResponse())) {
proxyResponse = HandlerUtil.retryRequestWithRefreshedToken(req, resp, headRequest, apiEndpoint);
proxyResponse = HandlerUtil.retryRequestWithRefreshedToken(req, resp, headRequest, kmManagerUrl);
if (proxyResponse == null) {
return;
}
@ -170,7 +170,7 @@ public class InvokerHandler extends HttpServlet {
ProxyResponse proxyResponse = HandlerUtil.execute(putRequest);
if (HandlerConstants.TOKEN_IS_EXPIRED.equals(proxyResponse.getExecutorResponse())) {
proxyResponse = HandlerUtil.retryRequestWithRefreshedToken(req, resp, putRequest, apiEndpoint);
proxyResponse = HandlerUtil.retryRequestWithRefreshedToken(req, resp, putRequest, kmManagerUrl);
if (proxyResponse == null) {
return;
}
@ -198,7 +198,7 @@ public class InvokerHandler extends HttpServlet {
deleteRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + authData.getAccessToken());
ProxyResponse proxyResponse = HandlerUtil.execute(deleteRequest);
if (HandlerConstants.TOKEN_IS_EXPIRED.equals(proxyResponse.getExecutorResponse())) {
proxyResponse = HandlerUtil.retryRequestWithRefreshedToken(req, resp, deleteRequest, apiEndpoint);
proxyResponse = HandlerUtil.retryRequestWithRefreshedToken(req, resp, deleteRequest, kmManagerUrl);
if (proxyResponse == null) {
return;
}
@ -302,9 +302,12 @@ public class InvokerHandler extends HttpServlet {
*/
private static boolean validateRequest(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
apiEndpoint = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty("iot.gateway.host")
apiEndpoint = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme());
kmManagerUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_KM_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getKeymanagerPort(req.getScheme());
if (HandlerConstants.REPORTS.equalsIgnoreCase(req.getHeader(HandlerConstants.APP_NAME))){
apiEndpoint = System.getProperty("iot.reporting.webapp.host");
if (StringUtils.isBlank(apiEndpoint)){
@ -373,14 +376,9 @@ public class InvokerHandler extends HttpServlet {
if (log.isDebugEnabled()) {
log.debug("refreshing the token");
}
String iotsCorePort = System.getProperty("iot.core.https.port");
if (HandlerConstants.HTTP_PROTOCOL.equals(req.getScheme())) {
iotsCorePort = System.getProperty("iot.core.http.port");
}
iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty("iot.core.host")
+ HandlerConstants.COLON + iotsCorePort;
HttpPost tokenEndpoint = new HttpPost(
iotsCoreUrl + HandlerConstants.TOKEN_ENDPOINT);
kmManagerUrl + HandlerConstants.TOKEN_ENDPOINT);
HttpSession session = req.getSession(false);
if (session == null) {
log.error("Couldn't find a session, hence it is required to login and proceed.");

@ -59,7 +59,8 @@ public class LoginHandler extends HttpServlet {
private static String password;
private static String gatewayUrl;
private static String uiConfigUrl;
private static String iotsCoreUrl;
private static String iotCoreUrl;
private static String kmManagerUrl;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
@ -201,18 +202,16 @@ public class LoginHandler extends HttpServlet {
* Define username and password static parameters.
*/
private static void validateLoginRequest(HttpServletRequest req) throws LoginException {
String iotsCorePort = System.getProperty(HandlerConstants.IOT_CORE_HTTPS_PORT_ENV_VAR);
if (HandlerConstants.HTTP_PROTOCOL.equals(req.getScheme())) {
iotsCorePort = System.getProperty(HandlerConstants.IOT_CORE_HTTP_PORT_ENV_VAR);
}
username = req.getParameter("username");
password = req.getParameter("password");
gatewayUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme());
uiConfigUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
+ HandlerConstants.COLON + iotsCorePort + HandlerConstants.UI_CONFIG_ENDPOINT;
iotsCoreUrl = HandlerConstants.HTTPS_PROTOCOL + HandlerConstants.SCHEME_SEPARATOR +
System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR) + HandlerConstants.COLON + iotsCorePort;
iotCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme());
uiConfigUrl = iotCoreUrl + HandlerConstants.UI_CONFIG_ENDPOINT;
kmManagerUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_KM_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getKeymanagerPort(req.getScheme());
if (username == null || password == null) {
String msg = "Invalid login request. Username or Password is not received for login request.";
log.error(msg);
@ -229,7 +228,7 @@ public class LoginHandler extends HttpServlet {
* @throws IOException IO exception throws if an error occurred when invoking token endpoint
*/
private ProxyResponse getTokenResult(String encodedClientApp, JsonArray scopes) throws IOException {
HttpPost tokenEndpoint = new HttpPost(iotsCoreUrl+ HandlerConstants.TOKEN_ENDPOINT);
HttpPost tokenEndpoint = new HttpPost(kmManagerUrl+ HandlerConstants.TOKEN_ENDPOINT);
tokenEndpoint.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BASIC + encodedClientApp);
tokenEndpoint.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.toString());
String scopeString = HandlerUtil.getScopeString(scopes);

@ -241,8 +241,8 @@ public class OTPInvokerHandler extends HttpServlet {
private static boolean validateRequest(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String schema = req.getScheme();
apiEndpoint = schema + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getCorePort(schema);
apiEndpoint = schema + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getGatewayPort(schema);
if (StringUtils.isBlank(req.getHeader(HandlerConstants.OTP_HEADER))) {
log.error("Unauthorized, Please provide OTP token.");

@ -49,15 +49,11 @@ public class SsoLoginCallbackHandler extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String code = req.getParameter("code");
HttpSession session = req.getSession(false);
String iotsCorePort = System.getProperty(HandlerConstants.IOT_CORE_HTTPS_PORT_ENV_VAR);
if (HandlerConstants.HTTP_PROTOCOL.equals(req.getScheme())) {
iotsCorePort = System.getProperty(HandlerConstants.IOT_CORE_HTTP_PORT_ENV_VAR);
}
String gatewayUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme());
String iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
+ HandlerConstants.COLON + iotsCorePort;
+ HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme());
String keyManagerUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_KM_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getKeymanagerPort(req.getScheme());
if (session == null) {
String baseContextPath = req.getContextPath();
@ -72,7 +68,7 @@ public class SsoLoginCallbackHandler extends HttpServlet {
String scope = session.getAttribute("scope").toString();
HttpPost tokenEndpoint = new HttpPost(iotsCoreUrl + HandlerConstants.TOKEN_ENDPOINT);
HttpPost tokenEndpoint = new HttpPost(keyManagerUrl + HandlerConstants.TOKEN_ENDPOINT);
tokenEndpoint.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BASIC + session.getAttribute("encodedClientApp"));
tokenEndpoint.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.toString());

@ -72,6 +72,8 @@ public class SsoLoginHandler extends HttpServlet {
private static String adminPassword;
private static String gatewayUrl;
private static String iotsCoreUrl;
private static String apiMgtUrl;
private static String keyManagerUrl;
private static int sessionTimeOut;
private static String encodedAdminCredentials;
private static String encodedClientApp;
@ -99,14 +101,14 @@ public class SsoLoginHandler extends HttpServlet {
baseContextPath = req.getContextPath();
applicationName = baseContextPath.substring(1, baseContextPath.indexOf("-ui-request-handler"));
String iotsCorePort = System.getProperty(HandlerConstants.IOT_CORE_HTTPS_PORT_ENV_VAR);
if (HandlerConstants.HTTP_PROTOCOL.equals(req.getScheme())) {
iotsCorePort = System.getProperty(HandlerConstants.IOT_CORE_HTTP_PORT_ENV_VAR);
}
gatewayUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme());
iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
+ HandlerConstants.COLON + iotsCorePort;
+ HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme());
apiMgtUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_APIM_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getAPIManagerPort(req.getScheme());
keyManagerUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_KM_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getKeymanagerPort(req.getScheme());
// Fetch ui config and persists in session
String uiConfigUrl = iotsCoreUrl + HandlerConstants.UI_CONFIG_ENDPOINT;
@ -127,7 +129,7 @@ public class SsoLoginHandler extends HttpServlet {
persistAuthSessionData(req, oAuthApp.getClientId(), oAuthApp.getClientSecret(),
oAuthApp.getEncodedClientApp(), scopesSsoString);
resp.sendRedirect(iotsCoreUrl + HandlerConstants.AUTHORIZATION_ENDPOINT +
resp.sendRedirect(keyManagerUrl + HandlerConstants.AUTHORIZATION_ENDPOINT +
"?response_type=code" +
"&client_id=" + clientId +
"&state=" +
@ -193,7 +195,7 @@ public class SsoLoginHandler extends HttpServlet {
}
// Get the details of the registered application
String getApplicationEndpointUrl = iotsCoreUrl + HandlerConstants.APIM_APPLICATIONS_ENDPOINT +
String getApplicationEndpointUrl = apiMgtUrl + HandlerConstants.APIM_APPLICATIONS_ENDPOINT +
"?query=" + applicationName;
HttpGet getApplicationEndpoint = new HttpGet(getApplicationEndpointUrl);
getApplicationEndpoint.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER +
@ -224,7 +226,7 @@ public class SsoLoginHandler extends HttpServlet {
}
// Update the grant types of the application
String url = iotsCoreUrl + HandlerConstants.APIM_APPLICATIONS_ENDPOINT + applicationId + "/keys/" +
String url = apiMgtUrl + HandlerConstants.APIM_APPLICATIONS_ENDPOINT + applicationId + "/keys/" +
HandlerConstants.PRODUCTION_KEY;
HttpPut updateApplicationGrantTypesEndpoint = new HttpPut(url);
updateApplicationGrantTypesEndpoint.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER +
@ -323,7 +325,7 @@ public class SsoLoginHandler extends HttpServlet {
* @throws IOException IO exception throws if an error occurred when invoking token endpoint
*/
private ProxyResponse getTokenResult(String encodedClientApp) throws IOException {
HttpPost tokenEndpoint = new HttpPost(iotsCoreUrl + HandlerConstants.TOKEN_ENDPOINT);
HttpPost tokenEndpoint = new HttpPost(keyManagerUrl + HandlerConstants.TOKEN_ENDPOINT);
tokenEndpoint.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BASIC + encodedClientApp);
tokenEndpoint.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.toString());
@ -372,7 +374,7 @@ public class SsoLoginHandler extends HttpServlet {
*/
private void updateSaasApp(String appName) throws ParserConfigurationException, IOException, SAXException {
File getAppRequestXmlFile = new File(HandlerConstants.PAYLOADS_DIR + "/get-app-request.xml");
String identityAppMgtUrl = iotsCoreUrl + HandlerConstants.IDENTITY_APP_MGT_ENDPOINT;
String identityAppMgtUrl = apiMgtUrl + HandlerConstants.IDENTITY_APP_MGT_ENDPOINT;
HttpPost getApplicationEndpoint = new HttpPost(identityAppMgtUrl);
getApplicationEndpoint.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BASIC +

@ -54,10 +54,10 @@ public class UserHandler extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
try {
String serverUrl =
String keymanagerUrl =
req.getScheme() + HandlerConstants.SCHEME_SEPARATOR +
System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme());
System.getProperty(HandlerConstants.IOT_KM_HOST_ENV_VAR)
+ HandlerConstants.COLON + HandlerUtil.getKeymanagerPort(req.getScheme());
HttpSession httpSession = req.getSession(false);
if (httpSession == null) {
HandlerUtil.sendUnAuthorizeResponse(resp);
@ -72,7 +72,7 @@ public class UserHandler extends HttpServlet {
String accessToken = authData.getAccessToken();
HttpPost tokenEndpoint = new HttpPost(serverUrl + HandlerConstants.INTROSPECT_ENDPOINT);
HttpPost tokenEndpoint = new HttpPost(keymanagerUrl + HandlerConstants.INTROSPECT_ENDPOINT);
tokenEndpoint.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.toString());
DeviceManagementConfig dmc = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
String adminUsername = dmc.getKeyManagerConfigurations().getAdminUsername();
@ -86,7 +86,7 @@ public class UserHandler extends HttpServlet {
if (tokenStatus.getExecutorResponse().contains(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)) {
if (tokenStatus.getCode() == HttpStatus.SC_UNAUTHORIZED) {
tokenStatus = HandlerUtil.retryRequestWithRefreshedToken(req, resp, tokenEndpoint, serverUrl);
tokenStatus = HandlerUtil.retryRequestWithRefreshedToken(req, resp, tokenEndpoint, keymanagerUrl);
} else {
log.error("Error occurred while invoking the API to get token status.");
HandlerUtil.handleError(resp, tokenStatus);

@ -78,6 +78,12 @@ public class HandlerConstants {
public static final String IOT_CORE_HOST_ENV_VAR = "iot.core.host";
public static final String IOT_CORE_HTTP_PORT_ENV_VAR = "iot.core.http.port";
public static final String IOT_CORE_HTTPS_PORT_ENV_VAR = "iot.core.https.port";
public static final String IOT_APIM_HOST_ENV_VAR = "iot.apim.host";
public static final String IOT_APIM_HTTP_PORT_ENV_VAR = "iot.apim.http.port";
public static final String IOT_APIM_HTTPS_PORT_ENV_VAR = "iot.apim.https.port";
public static final String IOT_KM_HOST_ENV_VAR = "iot.keymanager.host";
public static final String IOT_KM_HTTP_PORT_ENV_VAR = "iot.keymanager.http.port";
public static final String IOT_KM_HTTPS_PORT_ENV_VAR = "iot.keymanager.https.port";
public static final String IOT_GW_HOST_ENV_VAR = "iot.gateway.host";
public static final String IOT_GW_HTTP_PORT_ENV_VAR = "iot.gateway.http.port";
public static final String IOT_GW_HTTPS_PORT_ENV_VAR = "iot.gateway.https.port";

@ -244,6 +244,35 @@ public class HandlerUtil {
}
}
/**
* Get api manager port according to request received scheme
*
* @param scheme https or https
* @return {@link String} api manager port
*/
public static String getAPIManagerPort(String scheme) {
String apiManagerPort = System.getProperty(HandlerConstants.IOT_APIM_HTTPS_PORT_ENV_VAR);
if (HandlerConstants.HTTP_PROTOCOL.equals(scheme)) {
apiManagerPort = System.getProperty(HandlerConstants.IOT_APIM_HTTP_PORT_ENV_VAR);
}
return apiManagerPort;
}
/**
* Get keymanager port according to request received scheme
*
* @param scheme https or https
* @return {@link String} keymanager port
*/
public static String getKeymanagerPort(String scheme) {
String keymanagerPort = System.getProperty(HandlerConstants.IOT_KM_HTTPS_PORT_ENV_VAR);
if (HandlerConstants.HTTP_PROTOCOL.equals(scheme)) {
keymanagerPort = System.getProperty(HandlerConstants.IOT_KM_HTTP_PORT_ENV_VAR);
}
return keymanagerPort;
}
/**
* Get gateway port according to request received scheme
*
@ -502,19 +531,13 @@ public class HandlerUtil {
* @return If successfully renew tokens, returns TRUE otherwise return FALSE
* @throws IOException If an error occurs while witting error response to client side or invoke token renewal API
*/
private static boolean refreshToken(HttpServletRequest req, HttpServletResponse resp, String gatewayUrl)
private static boolean refreshToken(HttpServletRequest req, HttpServletResponse resp, String keymanagerUrl)
throws IOException {
if (log.isDebugEnabled()) {
log.debug("refreshing the token");
}
String iotsCorePort = System.getProperty("iot.core.https.port");
if (HandlerConstants.HTTP_PROTOCOL.equals(req.getScheme())) {
iotsCorePort = System.getProperty("iot.core.http.port");
}
String iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty("iot.core.host")
+ HandlerConstants.COLON + iotsCorePort;
HttpPost tokenEndpoint = new HttpPost(iotsCoreUrl + HandlerConstants.TOKEN_ENDPOINT);
HttpPost tokenEndpoint = new HttpPost(keymanagerUrl + HandlerConstants.TOKEN_ENDPOINT);
HttpSession session = req.getSession(false);
if (session == null) {
log.error("Couldn't find a session, hence it is required to login and proceed.");

@ -7,7 +7,7 @@
<Parameter Name="IsRemote">false</Parameter>
<Parameter Name="TokenValidationEndpointUrl">https://${iot.keymanager.host}:${iot.keymanager.https.port}</Parameter>
<Parameter Name="Username">${admin.username}</Parameter>
<Parameter Name="Password">${admin.username}</Parameter>
<Parameter Name="Password">${admin.password}</Parameter>
<Parameter Name="MaxTotalConnections">100</Parameter>
<Parameter Name="MaxConnectionsPerHost">100</Parameter>
</Parameters>

@ -15,7 +15,7 @@
<Parameter Name="IsRemote">false</Parameter>
<Parameter Name="TokenValidationEndpointUrl">https://${iot.keymanager.host}:${iot.keymanager.https.port}</Parameter>
<Parameter Name="Username">${admin.username}</Parameter>
<Parameter Name="Password">${admin.username}</Parameter>
<Parameter Name="Password">${admin.password}</Parameter>
<Parameter Name="MaxTotalConnections">100</Parameter>
<Parameter Name="MaxConnectionsPerHost">100</Parameter>
</Parameters>

Loading…
Cancel
Save