3 # ============LICENSE_START====================================================
5 # ===========================================================================
6 # Copyright (c) 2017 AT&T Intellectual Property. 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
12 # http://www.apache.org/licenses/LICENSE-2.0
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 # ============LICENSE_END====================================================
21 # This script is run when starting client Container.
22 # It needs to cover the cases where the initial data doesn't exist, and when it has already been configured (don't overwrite)
25 AAF_INTERFACE_VERSION=2.1
27 # Extract Name, Domain and NS from FQI
28 FQIA=($(echo ${APP_FQI} | tr '@' '\n'))
31 # Reverse DOMAIN for NS
32 FQIA_E=($(echo ${FQI_DOMAIN} | tr '.' '\n'))
33 for (( i=( ${#FQIA_E[@]} -1 ); i>0; i-- )); do
34 NS=${NS}${FQIA_E[i]}'.'
37 CONFIG="/opt/app/aaf_config"
38 OSAAF="/opt/app/osaaf"
41 SSO="$DOT_AAF/sso.props"
43 if [ -e "$CONFIG" ]; then
44 CONFIG_BIN="$CONFIG/bin"
49 CLPATH="$CONFIG_BIN/aaf-auth-cmd-*-full.jar"
51 JAVA_CADI="$JAVA -cp $CLPATH org.onap.aaf.cadi.CmdLine"
52 JAVA_AGENT="$JAVA -cp $CLPATH -Dcadi_prop_files=$SSO org.onap.aaf.cadi.configure.Agent"
53 JAVA_AGENT_SELF="$JAVA -cp $CLPATH -Dcadi_prop_files=$LOCAL/${NS}.props org.onap.aaf.cadi.configure.Agent"
54 JAVA_AAFCLI="$JAVA -cp $CLPATH -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props org.onap.aaf.auth.cmd.AAFcli"
57 if [ ! -d $LOCAL ]; then
61 cp $CONFIG/$D/* $OSAAF/$D
65 # Setup Bash, first time only
66 if [ ! -e "$HOME/.bashrc" ] || [ -z "$(grep cadi $HOME/.bashrc)" ]; then
67 echo "alias cadi='$JAVA_CADI \$*'" >>$HOME/.bashrc
68 echo "alias agent='$CONFIG_BIN/agent.sh agent \$*'" >>$HOME/.bashrc
69 echo "alias aafcli='$JAVA_AAFCLI \$*'" >>$HOME/.bashrc
70 chmod a+x $CONFIG_BIN/agent.sh
74 # Setup SSO info for Deploy ID
75 function sso_encrypt() {
76 $JAVA_CADI digest ${1} $DOT_AAF/keyfile
79 if [ ! -e "$DOT_AAF/truststoreONAPall.jks" ]; then
81 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks
84 # Create Deployer Info, located at /root/.aaf
85 if [ ! -e "$DOT_AAF/keyfile" ]; then
86 $JAVA_CADI keygen $DOT_AAF/keyfile
87 chmod 400 $DOT_AAF/keyfile
89 # Add Deployer Creds to Root's SSO
90 DEPLOY_FQI="${DEPLOY_FQI:=$app_id}"
91 echo "aaf_id=${DEPLOY_FQI}" > ${SSO}
92 if [ ! "${DEPLOY_PASSWORD}" = "" ]; then
93 echo aaf_password=enc:$(sso_encrypt ${DEPLOY_PASSWORD}) >> ${SSO}
96 # Cover case where using app.props
97 aaf_locater_container_ns=${aaf_locator_container_ns:=$CONTAINER_NS}
100 if [ "${E:0:4}" = "aaf_" ] || [ "${E:0:5}" = "cadi_" ]; then
101 # Use Deployer ID in ${SSO}
102 if [ "app_id" != "${E%=*}" ]; then
110 echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO}
111 echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO}
112 echo "Caller Properties Initialized"
119 # Only initialize once, automatically...
120 if [ ! -e $LOCAL/${NS}.props ]; then
121 if [ -e '/opt/app/aaf_config/bin' ]; then
122 cp /opt/app/aaf_config/bin/*.jar $LOCAL
123 echo "#!/bin/bash" > agent
124 echo 'case "$1" in' >> agent
125 echo ' ""|-?|--help)CMD="";FQI="";FQDN="";;' >> agent
126 echo ' validate)CMD="$1";FQI="";FQDN="${2:-'"$NS.props"'}";;' >> agent
127 echo ' *)CMD="$1";FQI="${2:-'"$APP_FQI"'}";FQDN="${3:-'"$APP_FQDN"'}";;' >> agent
129 echo 'java -cp '$(ls aaf-auth-cmd-*-full.jar)' -Dcadi_prop_files='"$NS"'.props org.onap.aaf.cadi.configure.Agent $CMD $FQI $FQDN' >> agent
131 echo "#!/bin/bash" > cadi
132 echo "java -cp $(ls aaf-auth-cmd-*-full.jar) -Dcadi_prop_files=$NS.props org.onap.aaf.cadi.CmdLine " '$*' >> cadi
133 # echo "#!/bin/bash" > aafcli
134 # echo "java -cp $(ls aaf-auth-cmd-*-full.jar) -Dcadi_prop_files=$NS.props org.onap.aaf.auth.cmd.AAFcli " '$*' >> aafcli
136 echo "#!/bin/bash" > testConnectivity
137 echo "java -cp $(ls aaf-auth-cmd-*-full.jar) org.onap.aaf.cadi.aaf.TestConnectivity $NS.props" >> testConnectivity
138 chmod ug+x agent cadi testConnectivity
141 echo "#### Create Configuration files "
142 $JAVA_AGENT config $APP_FQI \
143 cadi_etc_dir=$LOCAL \
145 #aaf_url=https://AAF_LOCATE_URL/AAF_NS.locate:${AAF_INTERFACE_VERSION}
149 echo "#### Certificate Authorization Artifact"
152 $JAVA_AGENT read ${APP_FQI} ${APP_FQDN} \
153 cadi_prop_files=${SSO} \
154 cadi_etc_dir=$LOCAL | tee $TMP
156 if [ -n "$(grep 'Namespace:' $TMP)" ]; then
157 echo "#### Place Certificates (by deployer)"
158 $JAVA_AGENT place ${APP_FQI} ${APP_FQDN} \
159 cadi_prop_files=${SSO} \
162 echo "#### Validate Configuration and Certificate with live call"
163 echo "Obtained Certificates"
166 echo "#### Certificate Authorization Artifact must be valid to continue"
173 if [ -z "$CMD" ]; then
174 if [ -n "$INITIALIZED" ]; then
175 echo "Initialization complete"
185 find /opt/app/osaaf -depth
188 if [ "$1" = "" ]; then
189 echo "usage: cat <file... ONLY files ending in .props>"
191 if [[ $1 == *.props ]]; then
193 echo "## CONTENTS OF $3"
197 echo "### ERROR ####"
198 echo " \"cat\" may only be used with files ending with \".props\""
203 echo "## Show Passwords"
204 $JAVA_AGENT showpass ${APP_FQI} ${APP_FQDN}
207 echo "## Check Certificate"
208 $JAVA_AGENT check ${APP_FQI} ${APP_FQDN}
211 echo "## validate requested"
212 $JAVA_AGENT_SELF validate
215 echo "## Renew Certificate"
216 $JAVA_AGENT place ${APP_FQI} ${APP_FQDN}
225 FILES=$(grep -l "$1" ./*.props)
226 if [ -z "$FILES" ]; then
235 if [ "$ADD" = "Y" ]; then
236 echo "Changing $1 to $F"
239 echo "Changing $1 in $F"
240 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
248 FILES=$(grep -l "$1" ./*.props)
249 if [ "$FILES" = "" ]; then
250 FILES=$LOCAL/${NS}.cred.props
254 echo "Changing $1 in $F"
255 if [ "$2" = "" ]; then
256 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
258 if [ "$ORIG_PW" = "" ]; then
265 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/${NS}.keyfile)
266 if [ "$ADD" = "Y" ]; then
267 echo "$1=enc:$PWD" >> $F
269 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
275 sh /opt/app/osaaf/logs/taillog
277 testConnectivity|testconnectivity)
278 echo "--- Test Connectivity ---"
279 $JAVA -cp $CONFIG_BIN/aaf-auth-cmd-*-full.jar org.onap.aaf.cadi.aaf.TestConnectivity $LOCAL/org.osaaf.aaf.props
284 echo "--- Agent Container Comands ---"
285 echo " ls - Lists all files in Configuration"
286 echo " cat <file.props>> - Shows the contents (Prop files only)"
287 echo " validate - Runs a test using Configuration"
288 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
289 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
290 echo " bash - run bash in Container"
291 echo " Note: the following aliases are preset"
292 echo " cadi - CADI CmdLine tool"
293 echo " agent - Agent Java tool (see above help)"
295 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
298 echo "--- cadi Tool Comands ---"
302 echo "--- agent Tool Comands ---"
306 echo "--- aafcli Tool Comands ---"
314 # echo "--- run Sample Servlet App ---"
315 # $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -cp $CONFIG_BIN/aaf-auth-cmd-*-full.jar:$CONFIG_BIN/aaf-cadi-servlet-sample-*-sample.jar org.onap.aaf.sample.cadi.jetty.JettyStandalone ${NS}.props
318 $JAVA_AGENT "$CMD" "$@"