#!/bin/sh

pwd=`pwd`
eloc=`which abac_prover | sed 's/\/abac_prover//'`
if [ "$eloc" = "" ]; then
  echo "ERROR: abac_prover is not in the search path!!!"
  exit 1
fi

keyloc=$pwd

acme=`creddy --keyid --cert $keyloc/Acme_ID.pem`
coyote=`creddy --keyid --cert $keyloc/Coyote_ID.pem`

preferred_customer="$acme.preferred_customer"
buy_rockets="$acme.buy_rockets"
coyote_prin="$coyote"
friend="$acme.friend"
acme_prin="$acme"

#[keyid:Acme].role:preferred_customer <-?- [keyid:Coyote]
#isMember(pCoyote, role(pAcme,preferred_customer), C).
echo "  "
echo "===good============ Acme.preferred_customer <- Coyote"
$eloc/abac_prover  --keystore $keyloc \
      --role "$preferred_customer" --principal "$coyote_prin"

#[keyid:Acme].role:buy_rockets <-?- [keyid:Coyote]
#isMember(pCoyote, role(pAcme,buy_rockets), C).
echo "  "
echo "===good=============== Acme.buy_rockets <- Coyote"
$eloc/abac_prover  --keystore $keyloc \
        --role "$buy_rockets" --principal "$coyote_prin"

## this is not suppose to work
#[keyid:Acme].role:buy_rockets <-?- [keyid:Acme].role:preferred_customer
echo "  "
echo "===bad=============== Acme.buy_rockets <- Acme.preferred_customer"
$eloc/abac_prover  --keystore $keyloc \
        --role "$buy_rockets" --principal "$preferred_customer"

#[keyid:Coyote].role:friend <-?- [keyid:Acme]
#isMember(pAcme, role(pCoyote,friend), C).
echo "  "
echo "===bad=============== Coyote.friend <- Acme"
$eloc/abac_prover  --keystore $keyloc \
        --role "$friend" --principal "$acme_prin"

