2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.pap.xacml.rest;
23 import java.io.FileInputStream;
24 import java.io.FileNotFoundException;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.util.Base64;
28 import java.util.Properties;
30 import javax.servlet.ServletContext;
31 import javax.servlet.ServletRegistration;
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35 import org.springframework.web.WebApplicationInitializer;
36 import org.springframework.web.context.support.XmlWebApplicationContext;
37 import org.springframework.web.servlet.DispatcherServlet;
39 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
42 public class WebConfig implements WebApplicationInitializer {
44 private static final Log logger = LogFactory.getLog(WebConfig.class);
47 public void onStartup(ServletContext container) {
49 //need to get properties for userid and password on the pap to get authorization string used in URI Mapping
50 Properties prop = new Properties();
51 String propFileName = "xacml.pap.properties";
54 InputStream is = new FileInputStream(propFileName);
56 } catch (Exception e) {
57 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "property file '" + propFileName + "' not found in the classpath");
60 String papID = prop.getProperty("xacml.rest.pap.userid");
61 String papPass = prop.getProperty("xacml.rest.pap.password");
63 String usernameAndPassword = papID+":"+papPass;
64 String authorizationString = Base64.getEncoder().encodeToString(usernameAndPassword.getBytes());
67 XmlWebApplicationContext appContext = new XmlWebApplicationContext();
68 appContext.setConfigLocation("classpath:spring.xml");
70 System.out.println("Spring XML File Location: " + appContext.getConfigLocations());
71 logger.info("Spring XML File Location: " + appContext.getConfigLocations());
73 ServletRegistration.Dynamic dispatcher =
74 container.addServlet("dispatcher", new DispatcherServlet(appContext));
75 dispatcher.setLoadOnStartup(1);
76 dispatcher.addMapping("/@Auth@"+authorizationString+"/ecomp/*");