Esempio n. 1
0
 /**
  * Constructor defaulting the initial namespace to "everything"
  *
  * @param name local name for this repository
  */
 public BasicPolicy(String name) {
   _pxml = new PolicyXML();
   try {
     if (null != name) _pxml.setLocalName(name);
     _pxml.setVersion(POLICY_VERSION);
     _pxml.addNamespace(ContentName.fromNative("/"));
   } catch (MalformedContentNameStringException e) {
   }
 }
Esempio n. 2
0
 public static PolicyXML createPolicyXML(InputStream stream) throws ContentDecodingException {
   Log.info(Log.FAC_REPO, "Creating policy file");
   XMLDecoder decoder = XMLCodecFactory.getDecoder(TextXMLCodec.codecName());
   decoder.beginDecoding(stream);
   PolicyXML pxml = new PolicyXML();
   pxml.decode(decoder);
   Log.fine(Log.FAC_REPO, "Finished pxml decoding");
   decoder.endDecoding();
   return pxml;
 }
Esempio n. 3
0
  /**
   * Applies policy changes
   *
   * @param pxml policy data
   * @return
   * @throws XMLStreamException
   */
  public void update(PolicyXML pxml, boolean fromNet) throws RepositoryException {
    Log.info(Log.FAC_REPO, "Updating policy");
    if (pxml._version == null) throw new RepositoryException("No version in policy file");
    if (!pxml._version.equals(POLICY_VERSION)) {
      Log.warning(Log.FAC_REPO, "Bad version in policy file: {0}", pxml._version);
      throw new RepositoryException("Bad version in policy file");
    }

    if (null == pxml._localName) throw new RepositoryException("No local name in policy file");
    if (fromNet) {
      if (!pxml._localName.equals(_pxml.getLocalName())) {
        Log.warning(
            Log.FAC_REPO, "Repository local name doesn't match: request = {0}", pxml._localName);
        throw new RepositoryException("Repository local name doesn't match policy file");
      }
    } else {
      try {
        setLocalName(pxml._localName);
      } catch (MalformedContentNameStringException e) {
        throw new RepositoryException(e.getMessage());
      }
    }

    if (null == pxml._globalPrefix) throw new RepositoryException("No globalPrefix in policy file");

    if (fromNet) {
      if (!pxml.getGlobalPrefix().equals(_pxml.getGlobalPrefix())) {
        Log.warning("Repository globalPrefix doesn't match: request = {0}", pxml._globalPrefix);
        throw new RepositoryException("Repository global prefix doesn't match policy file");
      }
    } else {
      _pxml.setGlobalPrefixOnly(pxml._globalPrefix);
    }

    _pxml.setNamespace(pxml.getNamespace());
    if (null != pxml.getNamespace()) {
      String message = "";
      for (ContentName name : pxml.getNamespace()) {
        message += name.toString() + ':';
      }
      Log.info(Log.FAC_REPO, "Policy has been updated. New namespace is: " + message);
    }
  }
Esempio n. 4
0
 /**
  * Constructor allowing an initial namespace to be set
  *
  * @param name local name for this repository
  * @param namespace the initial namespace
  */
 public BasicPolicy(String name, ArrayList<ContentName> namespace) {
   this(name);
   if (null != namespace) {
     _pxml.setNamespace(namespace);
   }
 }
Esempio n. 5
0
 public void setLocalName(String localName) throws MalformedContentNameStringException {
   if (null == _pxml.getLocalName()) {
     _pxml.setLocalName(localName);
   }
 }
Esempio n. 6
0
 /**
  * Gets the local name currently used by this repository
  *
  * @return the local name as a slash separated String
  */
 public String getLocalName() {
   return _pxml.getLocalName();
 }
Esempio n. 7
0
 /**
  * Gets the global prefix currently in use for this repository
  *
  * @return the global prefix as a ContentName
  */
 public ContentName getGlobalPrefix() {
   return _pxml.getGlobalPrefix();
 }
Esempio n. 8
0
 /**
  * Sets the global prefix for this policy interpreter. After this call any policy file containing
  * a different global prefix will be rejected
  *
  * @param globalPrefix the global prefix as a slash separated String
  */
 public void setGlobalPrefix(String globalPrefix) throws MalformedContentNameStringException {
   _pxml.setGlobalPrefix(globalPrefix);
 }
Esempio n. 9
0
 /**
  * Gets the policy path for this repository
  *
  * @return the policy path as a ContentName
  */
 public ContentName getPolicyName() {
   return getPolicyName(_pxml.getGlobalPrefix());
 }
Esempio n. 10
0
 public void setNamespace(ArrayList<ContentName> namespace) {
   _pxml.setNamespace(namespace);
 }
Esempio n. 11
0
 public ArrayList<ContentName> getNamespace() {
   return _pxml.getNamespace();
 }