diff options
author | Patrick Brady <patrick.brady@att.com> | 2020-03-24 15:44:15 -0700 |
---|---|---|
committer | Patrick Brady <patrick.brady@att.com> | 2020-03-24 16:47:23 -0700 |
commit | 0141df20b1f533cd2acabdf7ea986aebab8d6868 (patch) | |
tree | 7df75e7fd455aeb0ccedeac6be801d4cab4d508d /CdtProxyService/src | |
parent | 179fea047479a44ef2fb0490c272f7f97127bbe9 (diff) |
Authentication support for cdt
-Adding a password box to cdt
-Adding a function to check login by making a request
to appc
-Moving username and authentication to session storage
from localstorage so that it is not saved in the browser
-Removing the hardcoded credentials from the cdt proxy
since these are coming from the cdt login form now
Change-Id: I8bd829a22d1b83829c1d53637dc1ad035d1030e9
Signed-off-by: Patrick Brady <patrick.brady@att.com>
Issue-ID: APPC-1854
Diffstat (limited to 'CdtProxyService/src')
-rw-r--r-- | CdtProxyService/src/main/java/org/onap/appc/cdt/service/controller/CdtController.java | 36 | ||||
-rw-r--r-- | CdtProxyService/src/main/resources/application.properties | 2 |
2 files changed, 18 insertions, 20 deletions
diff --git a/CdtProxyService/src/main/java/org/onap/appc/cdt/service/controller/CdtController.java b/CdtProxyService/src/main/java/org/onap/appc/cdt/service/controller/CdtController.java index 78a94f6..bdb12e5 100644 --- a/CdtProxyService/src/main/java/org/onap/appc/cdt/service/controller/CdtController.java +++ b/CdtProxyService/src/main/java/org/onap/appc/cdt/service/controller/CdtController.java @@ -1,7 +1,7 @@ /* ============LICENSE_START========================================== =================================================================== -Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved. =================================================================== Unless otherwise specified, all software contained herein is licensed @@ -41,6 +41,7 @@ import org.springframework.web.client.RestTemplate; import java.net.UnknownHostException; import java.util.Base64; +import java.util.List; /** * Created by Amaresh Kumar on 09/May/2018. @@ -62,11 +63,6 @@ public class CdtController { @Value("${restConf.backend.port}") private String restConfPort; - @Value("${restConf.username}") - private String restConfUsername; - - @Value("${restConf.password}") - private String restConfPassword; @ApiOperation(value = "Return All Test Data for a given user", response = CdtController.class) @ApiResponses(value = { @@ -87,8 +83,8 @@ public class CdtController { }) @RequestMapping(value = "/getDesigns", method = RequestMethod.POST) @CrossOrigin(origins = "*", allowedHeaders = "*") - public String getDesigns(@RequestBody String getDesignsRequest) throws UnknownHostException { - HttpEntity<String> entity = getStringHttpEntity(getDesignsRequest); + public String getDesigns(@RequestBody String getDesignsRequest, @RequestHeader HttpHeaders requestHeader) throws UnknownHostException { + HttpEntity<String> entity = getStringHttpEntity(getDesignsRequest, requestHeader); HttpClient httpClient = HttpClientBuilder.create().build(); ClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient); restTemplate.setRequestFactory(factory); @@ -103,8 +99,8 @@ public class CdtController { }) @RequestMapping(value = "/testVnf", method = RequestMethod.POST) @CrossOrigin(origins = "*", allowedHeaders = "*") - public String testVnf(@RequestParam String urlAction, @RequestBody String testVnf) throws UnknownHostException { - HttpEntity<String> entity = getStringHttpEntity(testVnf); + public String testVnf(@RequestParam String urlAction, @RequestBody String testVnf, @RequestHeader HttpHeaders requestHeader) throws UnknownHostException { + HttpEntity<String> entity = getStringHttpEntity(testVnf, requestHeader); String testVnfResponse = restTemplate.postForObject(getUrl("testVnf")+urlAction, entity, String.class); return testVnfResponse; } @@ -116,8 +112,8 @@ public class CdtController { }) @RequestMapping(value = "/checkTestStatus", method = RequestMethod.POST) @CrossOrigin(origins = "*", allowedHeaders = "*") - public String checkTestStatus(@RequestBody String checkTestStatusRequest) throws UnknownHostException { - HttpEntity<String> entity = getStringHttpEntity(checkTestStatusRequest); + public String checkTestStatus(@RequestBody String checkTestStatusRequest, @RequestHeader HttpHeaders requestHeader) throws UnknownHostException { + HttpEntity<String> entity = getStringHttpEntity(checkTestStatusRequest, requestHeader); String checkTestStatusResponse = restTemplate.postForObject(getUrl("checkTestStatus"), entity, String.class); return checkTestStatusResponse; } @@ -129,19 +125,23 @@ public class CdtController { }) @RequestMapping(value = "/validateTemplate", method = RequestMethod.POST) @CrossOrigin(origins = "*", allowedHeaders = "*") - public String validateTemplate(@RequestBody String validateTemplateRequest) throws UnknownHostException { - HttpEntity<String> entity = getStringHttpEntity(validateTemplateRequest); + public String validateTemplate(@RequestBody String validateTemplateRequest, @RequestHeader HttpHeaders requestHeader) throws UnknownHostException { + HttpEntity<String> entity = getStringHttpEntity(validateTemplateRequest, requestHeader); String validateTemplateResponse = restTemplate.postForObject(getUrl("validateTemplate"), entity, String.class); return validateTemplateResponse; } - private HttpEntity<String> getStringHttpEntity(@RequestBody String getDesignsRequest) { + private HttpEntity<String> getStringHttpEntity(@RequestBody String getDesignsRequest, @RequestHeader HttpHeaders requestHeader) { + HttpHeaders headers = new HttpHeaders(); + if(requestHeader.containsKey("authorization")) { + List<String> headerAuthValue = requestHeader.get("authorization"); + if(headerAuthValue != null && headerAuthValue.size() > 0) { + headers.set("authorization", headerAuthValue.get(0)); + } + } headers.setAccessControlAllowCredentials(true); headers.setContentType(MediaType.APPLICATION_JSON); - String planCredentials = restConfUsername + ":" + restConfPassword; - String base64Credentails = Base64.getEncoder().encodeToString(planCredentials.getBytes()); - headers.set("Authorization", "Basic " + base64Credentails); return new HttpEntity<String>(getDesignsRequest, headers); } diff --git a/CdtProxyService/src/main/resources/application.properties b/CdtProxyService/src/main/resources/application.properties index d33188a..3b21458 100644 --- a/CdtProxyService/src/main/resources/application.properties +++ b/CdtProxyService/src/main/resources/application.properties @@ -13,8 +13,6 @@ Djavax.net.debug=ssl; #=========RestConf Backend properties START================== restConf.backend.hostname=localhost restConf.backend.port=8181 -restConf.username=admin -restConf.password=Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U #=========RestConf Backend properties END================== #====Allowed origins====================== |