Migrate pap startup & controllers to spring boot
[policy/pap.git] / packages / policy-pap-docker / src / main / docker / policy-pap.sh
1 #!/usr/bin/env sh
2 #
3 # ============LICENSE_START=======================================================
4 #  Copyright (C) 2019-2020 Nordix Foundation.
5 #  Modifications Copyright (C) 2019-2021 AT&T Intellectual Property.
6 #  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
7 # ================================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #      http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20 # SPDX-License-Identifier: Apache-2.0
21 # ============LICENSE_END=========================================================
22 #
23
24 JAVA_HOME=/usr/lib/jvm/java-11-openjdk/
25 KEYSTORE="${KEYSTORE:-$POLICY_HOME/etc/ssl/policy-keystore}"
26 TRUSTSTORE="${TRUSTSTORE:-$POLICY_HOME/etc/ssl/policy-truststore}"
27 KEYSTORE_PASSWD="${KEYSTORE_PASSWD:-Pol1cy_0nap}"
28 TRUSTSTORE_PASSWD="${TRUSTSTORE_PASSWD:-Pol1cy_0nap}"
29
30 if [ "$#" -ge 1 ]; then
31     CONFIG_FILE=$1
32 else
33     CONFIG_FILE=${CONFIG_FILE}
34 fi
35
36 touch /app/pap.jar
37
38 if [ -z "$CONFIG_FILE" ]; then
39     CONFIG_FILE="${POLICY_HOME}/etc/papParameters.yaml"
40 fi
41
42 echo "Policy pap config file: $CONFIG_FILE"
43
44 if [ -f "${POLICY_HOME}/etc/mounted/policy-truststore" ]; then
45     echo "overriding policy-truststore"
46     cp -f "${POLICY_HOME}"/etc/mounted/policy-truststore "${TRUSTSTORE}"
47 fi
48
49 if [ -f "${POLICY_HOME}/etc/mounted/policy-keystore" ]; then
50     echo "overriding policy-keystore"
51     cp -f "${POLICY_HOME}"/etc/mounted/policy-keystore "${KEYSTORE}"
52 fi
53
54 if [ -f "${POLICY_HOME}/etc/mounted/logback.xml" ]; then
55     echo "overriding logback.xml"
56     cp -f "${POLICY_HOME}"/etc/mounted/logback.xml "${POLICY_HOME}"/etc/
57 fi
58
59 # provide and external PDP group configuration if a groups.json
60 # file is present in the data directory. If none is present,
61 # the PAP will use the PapDb.json resource in the classpath
62 # to load a default group.
63
64 if [ -f "${POLICY_HOME}/etc/mounted/groups.json" ]; then
65     CUSTOM_GROUPS="${POLICY_HOME}/etc/mounted/groups.json"
66 fi
67
68 $JAVA_HOME/bin/java \
69     -Dlogback.configurationFile="${POLICY_HOME}/etc/logback.xml" \
70     -Dserver.ssl.key-store="${KEYSTORE}" \
71     -Dserver.ssl.key-store-password="${KEYSTORE_PASSWD}" \
72     -Djavax.net.ssl.trustStore="${TRUSTSTORE}" \
73     -Djavax.net.ssl.trustStorePassword="${TRUSTSTORE_PASSWD}" \
74     -jar /app/pap.jar \
75     --spring.config.location="${CONFIG_FILE}" \
76     --group-config-file="${CUSTOM_GROUPS}"