예제 #1
0
 /*
  * (non-Javadoc)
  * @see
  * org.fcrepo.server.security.xacml.pdp.data.PolicyDataManager#getPolicy
  * (java.lang.String)
  */
 @Override
 public AbstractPolicy getPolicy(String name, PolicyFinder policyFinder)
     throws PolicyIndexException {
   log.debug("Getting document: " + name);
   XmlDocument doc = null;
   DbXmlManager.readLock.lock();
   try {
     doc = m_dbXmlManager.container.getDocument(name);
     return handleDocument(m_policyReader.readPolicy(doc.getContent()), policyFinder);
   } catch (XmlException xe) {
     throw new PolicyIndexException(
         "Error getting Policy: "
             + name
             + xe.getMessage()
             + " - "
             + xe.getDatabaseException().getMessage(),
         xe);
   } catch (ParsingException pe) {
     throw new PolicyIndexException("Error getting Policy: " + name + pe.getMessage(), pe);
   } finally {
     DbXmlManager.readLock.unlock();
   }
 }
예제 #2
0
  /*
   * (non-Javadoc)
   * @see
   * org.fcrepo.server.security.xacml.pdp.data.PolicyDataManager#addPolicy
   * (java.lang.String, java.lang.String)
   */
  @Override
  public String addPolicy(String name, String document) throws PolicyIndexException {

    String docName = null;
    DbXmlManager.writeLock.lock();
    try {

      XmlDocument doc = makeDocument(name, document);
      docName = doc.getName();
      log.debug("Adding document: " + docName);
      m_dbXmlManager.container.putDocument(doc, m_dbXmlManager.updateContext);
      setLastUpdate(System.currentTimeMillis());
    } catch (XmlException xe) {
      if (xe.getErrorCode() == XmlException.UNIQUE_ERROR) {
        throw new PolicyIndexException("Document already exists: " + docName);
      } else {
        throw new PolicyIndexException("Error adding policy: " + xe.getMessage(), xe);
      }
    } finally {
      DbXmlManager.writeLock.unlock();
    }

    return docName;
  }
예제 #3
0
  /**
   * Creates an instance of an XmlDocument for storage in the database.
   *
   * @param name the name of the document (policy)
   * @param document the document data as a String
   * @return the XmlDocument instance
   * @throws XmlException
   * @throws PolicyStoreException
   */
  private XmlDocument makeDocument(String name, String document)
      throws XmlException, PolicyIndexException {
    Map<String, String> metadata = m_utils.getDocumentMetadata(document.getBytes());
    XmlDocument doc = m_dbXmlManager.manager.createDocument();
    String docName = name;

    if (docName == null || docName.isEmpty()) {
      docName = metadata.get("PolicyId");
    }

    if (docName == null || docName.isEmpty()) {
      throw new PolicyIndexException("Could not extract PolicyID from document.");
    }

    doc.setMetaData("metadata", "PolicyId", new XmlValue(XmlValue.STRING, docName));
    doc.setContent(document);
    doc.setName(docName);

    // FIXME:
    // this is probably redundant as the xpath queries now directly query the policy
    // for the "any" scenarios
    String item = null;
    item = metadata.get("anySubject");
    if (item != null) {
      doc.setMetaData("metadata", "anySubject", new XmlValue(XmlValue.STRING, item));
    }

    item = metadata.get("anyResource");
    if (item != null) {
      doc.setMetaData("metadata", "anyResource", new XmlValue(XmlValue.STRING, item));
    }

    item = metadata.get("anyAction");
    if (item != null) {
      doc.setMetaData("metadata", "anyAction", new XmlValue(XmlValue.STRING, item));
    }

    item = metadata.get("anyEnvironment");
    if (item != null) {
      doc.setMetaData("metadata", "anyEnvironment", new XmlValue(XmlValue.STRING, item));
    }

    return doc;
  }