Code Search for Developers
 
 
  

DisclosureRequestDecisionBean.java from Citizen Privacy Service at Krugle


Show DisclosureRequestDecisionBean.java syntax highlighted

/**
 * @(#) DisclosureRequestDecisionBean.java
 * @author <a href:mailto="rick@rickmurphy.org">Rick Murphy</a>
 * @version 0.1
 * @see <a href="http://www.rickmurphy.org/cps-license.html">Citizen Privacy Service License</a>
 */

package org.rickmurphy.pdp;

import java.io.InputStreamReader;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.ByteArrayInputStream;

import java.net.URL;

import javax.ejb.MessageDrivenContext;
import javax.ejb.MessageDrivenBean;

import javax.jms.Message;
import javax.jms.TextMessage;
import javax.jms.JMSException;

import javax.naming.Context;
import javax.naming.InitialContext;

import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

import org.rickmurphy.util.DisclosureEntailmentFactory;
import org.rickmurphy.util.DisclosureRequestModel;
import org.rickmurphy.exchangepackage.disclosure.DisclosureRequest;

import org.rickmurphy.pep.TrustProviderProxy;
import org.rickmurphy.pep.TrustProviderProxyLocalHome;

import org.mindswap.pellet.KnowledgeBase;

import org.mindswap.pellet.jena.OWLReasoner;

import com.hp.hpl.jena.rdf.model.ModelFactory;

import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntModel;

import org.rickmurphy.util.FOLGoalFactory;
import org.rickmurphy.util.SOAPMessageProducer;

import jtp.ReasoningStepIterator;

import jtp.frame.vc.Goal;

/**
 * Receives messages defined as disclosure requests from the queue, excutes a query against the knowledgebase and forwards the decision to ... and logs when appropriate ...
 */
public class DisclosureRequestDecisionBean extends SOAPMessageProducer implements MessageDrivenBean{

  /**
   *
   */
  private static Context initialContext;
  
  /**
   */
  private DisclosureRequest disclosureRequest;

  /**
   */
  private ReasoningStepIterator iterator;

  /**
   *  creates the reasoner
   */
  private static OWLReasoner reasoner = new OWLReasoner();
  
  /**
   * creates and configures the ont model with dl reasoning
   */
  private static OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
  private static OntModel lookup = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
  
  /**
   * Constructs a new instance of the message driven bean
   */
  public DisclosureRequestDecisionBean( ){}//public DisclosureRequestDecisionBean
  
  /**
   * Parses the message,
   * @param message The jms message, an xml document, representing a request
   */
  public void onMessage( Message message ) throws JMSException,Exception {
    
    System.out.println("on message: " + message.toString());
    
    toObject(new BufferedInputStream(new ByteArrayInputStream(((TextMessage)message).getText().getBytes())));  
    
    //delegates creation of the ont model to the factory
    DisclosureRequestModel requestModel = new DisclosureEntailmentFactory().create(disclosureRequest,reasoner,model,lookup);

    // gets the ont model from the concrete representation of the abstract class created by the factory
    boolean eResult = reasoner.isEntailed(requestModel.get());

    // manage accountability and enforce policy
    // tell the requestor about the result

    // put the results where the service requestor is expecting, reformat as message ?
    try{

      // execute the policy enforcement
      TrustProviderProxyLocalHome trustHome = (TrustProviderProxyLocalHome)initialContext.lookup("trustHome");
      TrustProviderProxy trustProxy = trustHome.create();
      
      // create goal from factory
      Goal goal = new FOLGoalFactory().create(disclosureRequest);
      
      // checks the query against the knowledgebase
      boolean pResult = trustProxy.challenge(goal);
      
      //generates and persists the provenance, get back provenance, package up as soap 
      iterator = trustProxy.enforce(goal);
      
      // send the soap message including provenance to the reply-to address, checksub-class execution of 
      SOAPMessage response = invokeEndpoint();
      
      // check for exceptions and finish up
      
    }catch(Exception e){

      e.getMessage();
      e.printStackTrace();

    }

  }

  /**
   * Gets the context from the container
   * @param context Container info for the message driven bean
   */
  public void setMessageDrivenContext( MessageDrivenContext context ){
    
  }
  
  /**
   * Lookup environment variables, create connection factories, and configure document builder
   */
  public void ejbCreate( ){

    try{

      // reads the context from the environment and gets the privacy ontology
      initialContext = (Context)new InitialContext().lookup("java:comp/env");  

      // loads and initializes the reasoner
      reasoner.load((String)initialContext.lookup("us-privacy"));  
      reasoner.getKB().realize();
      
      // reads the lookup ontology into memory
      lookup.read((String)initialContext.lookup("us-privacy"));            
      
    }catch(Exception e){
      System.out.println("exception");   
      e.printStackTrace();   
    }

  }
  
  /**
   * Closes the connection to the registry
   */
  public void ejbRemove( ){
    
  }
  
  /**
   * Creates java objects from the message queue input stream using jaxb unmarshalling based on disclosure-request.xsd
   * @param in The input stream from the jms message queue
   * @throws Exception Encapsulates exception handling 
   */
  public void toObject(InputStream in) throws Exception{
    
    JAXBContext disclosureContext = JAXBContext.newInstance((String)initialContext.lookup("disclosureContext"),this.getClass().getClassLoader());
    Unmarshaller unmarshaller = disclosureContext.createUnmarshaller();
    disclosureRequest = (DisclosureRequest)unmarshaller.unmarshal(in);
    
    System.out.println("got disclosure request: " + disclosureRequest);    
    
  }//toObject
  
  /**
   * Creates a soap element from java objects
   * @return SOAPElement The soap element produced from the objects
   */
  public SOAPElement fromObject( ) throws Exception{
    return null; 
  }//fromObject
  
  /**
   * Creates soap header elements, need to change name
   * @param en The soap envelope
   * @throws Exception Encapsulates exception handling 
   */
  protected void createSoapHeaderElements(SOAPEnvelope en)throws Exception{}//createSoapHeaderElements
  
  /**
   * Creates soap body elements
   * @param en The soap envelope
   * @throws Exception Encapsulates exception handling 
   */
  protected void createSoapBodyElements(SOAPEnvelope en) throws Exception {

    // Get the SOAP body from the envelope and populate it
    SOAPBody body = en.getBody();
    body.addNamespaceDeclaration((String)initialContext.lookup("urlPrefix"),(String)initialContext.lookup("nameSpace"));

    javax.xml.soap.Name name = en.createName("acceptDisclosureConfirmation",(String)initialContext.lookup("urlPrefix"),(String)initialContext.lookup("nameSpace"));
    SOAPBodyElement acceptDisclosureConfirmation = body.addBodyElement(name);
    
    name = en.createName("SOAPElement_1");
    SOAPBodyElement soapElement_1 = body.addBodyElement(name);

    name = en.createName("DisclosureConfirmation");
    SOAPBodyElement disclosureConfirmation = body.addBodyElement(name);

    name = en.createName("wsa:MessageID");
    SOAPBodyElement messageID = body.addBodyElement(name);
    messageID.addTextNode("need the original message id");
    
    name = en.createName("correlationID");
    SOAPBodyElement correlationID = body.addBodyElement(name);
    correlationID.addTextNode("need the uuid originally returned as a response to the calling web service");

    name = en.createName("privacy-action");
    SOAPBodyElement privacyAction = body.addBodyElement(name);
    privacyAction.addTextNode("put the reasoning step iterator in here");

    name = en.createName("provenance");
    SOAPBodyElement provenance = body.addBodyElement(name);
    provenance.addTextNode("put the reasoning step iterator in here");
    
    disclosureConfirmation.addChildElement(privacyAction);
    disclosureConfirmation.addChildElement(provenance);
    
    disclosureConfirmation.addChildElement(messageID);
    disclosureConfirmation.addChildElement(correlationID);
    
    soapElement_1.addChildElement(disclosureConfirmation);
    acceptDisclosureConfirmation.addChildElement(soapElement_1);
    
    body.addChildElement(acceptDisclosureConfirmation);
    
  }//createSoapBodyElements

}//DisclosureRequestDecisionBean




See more files for this project here

Citizen Privacy Service

The Citizen Privacy Service is an asynchronous component using artificial intelligence capabilities including DL decidability and first order logic provenance that provide policy decision and policy enforcement points based on the US Privacy Act of 1974.

Project homepage: http://sourceforge.net/projects/us-privacy
Programming language(s): Java,XML
License: bsd

  DisclosureRequestDecisionBean.java