summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared
diff options
context:
space:
mode:
authorMuni Mohan Kunchi <munmohan@att.com>2020-02-06 15:06:17 -0500
committerMuni Mohan Kunchi <munmohan@att.com>2020-02-07 20:21:57 +0000
commitd23e700cde07aaab62c69db9d9cdec2af3ba0b79 (patch)
treef079acdd532718d8577c0516b74bc513104ff70b /ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared
parente3636b96e9938cb89bb90672cf70fff3ae790186 (diff)
Adding missed sdk files
Adding missed sdk files Issue-ID: PORTAL-830 Signed-off-by: Muni Mohan Kunchi <munmohan@att.com> Change-Id: I784f49cb3cf724c4bacd3d4aaf5ae444fca5ba35
Diffstat (limited to 'ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared')
-rw-r--r--ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/interceptors/header-interceptor.ts70
-rw-r--r--ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/utils/utils.js43
2 files changed, 113 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/interceptors/header-interceptor.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/interceptors/header-interceptor.ts
new file mode 100644
index 00000000..5a5a41a8
--- /dev/null
+++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/interceptors/header-interceptor.ts
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal-SDK
+ * ===================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+
+import {
+ HttpEvent,
+ HttpInterceptor,
+ HttpHandler,
+ HttpRequest,
+ HttpHeaders,
+} from '@angular/common/http';
+import { Observable } from 'rxjs';
+import { v4 as uuid } from 'uuid';
+declare const getWebJunctionXSRFToken: any;
+export class HeaderInterceptor implements HttpInterceptor {
+ intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
+ // Clone the request to add the new header
+ // HttpHeader object immutable - copy values
+ var XSRFToken = getWebJunctionXSRFToken();
+ console.log('XSRFToken:', XSRFToken);
+ const headerSettings: { [name: string]: string | string[]; } = {};
+ headerSettings['X-ECOMP-RequestID'] = uuid();
+ const requestType = req.params.get('requestType');
+ if (XSRFToken.name && XSRFToken.value)
+ headerSettings['X-XSRF-TOKEN'] = XSRFToken.value;
+ if(requestType!=null && requestType==='fileUpload'){
+ //headerSettings['Content-Type'] = 'multipart/form-data';
+ }else{
+ headerSettings['Content-Type'] = 'application/json';
+ }
+ const newHeader = new HttpHeaders(headerSettings);
+ const clonedRequest = req.clone({ headers: newHeader, withCredentials: true });
+ // Pass the cloned request instead of the original request to the next handle
+ return next.handle(clonedRequest);
+ }
+} \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/utils/utils.js b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/utils/utils.js
new file mode 100644
index 00000000..3fe1c1ce
--- /dev/null
+++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/utils/utils.js
@@ -0,0 +1,43 @@
+
+function getWebJunctionXSRFToken() {
+ var cookies = getCookies();
+ var XSRFToken = {
+ name:'',
+ value:''
+ };
+ var contextRoot = getContextRoot();
+ var hasXSRFToken = false;
+ for(var name in cookies) {
+ if(name.includes('XSRF-TOKEN')){
+ if(name.includes('AMWEBJCT') && name.includes(contextRoot)){
+ XSRFToken.name = name;
+ XSRFToken.value = cookies[name];
+ }else if(name=='XSRF-TOKEN'){
+ hasXSRFToken = true;
+ }
+ }
+ }
+ return (hasXSRFToken==true)?null:XSRFToken;
+}
+
+function getCookies() {
+ var cookies = { };
+ if (document.cookie && document.cookie != '') {
+ var split = document.cookie.split(';');
+ for (var i = 0; i < split.length; i++) {
+ var name_value = split[i].split("=");
+ name_value[0] = name_value[0].replace(/^ /, '');
+ cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);
+ }
+ }
+ return cookies;
+}
+
+function getContextRoot(){
+ var pathName = window.location.pathname;
+ var pathArray = pathName.split( '/' );
+ var contextRoot='';
+ if(pathArray.length!=0 && pathArray.length>=1)
+ contextRoot = pathArray[1];
+ return contextRoot;
+} \ No newline at end of file