Package net.jini.security.policy

Examples of net.jini.security.policy.DynamicPolicyProvider$WeakGroup$Node


    return getLiteral(n, false);
  }

  public static Literal getLiteral(final Node node, final boolean allowLazyLiteral) {
    Literal literal = null;
    Node n = node;

    if (n instanceof ASTNIL) {
      try {
        literal = (allowLazyLiteral) ? LiteralFactory
            .createURILiteral("<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>")
            : LiteralFactory
                .createURILiteralWithoutLazyLiteral("<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>");
      } catch (final URISyntaxException e1) {
        e1.printStackTrace();
      }
    } else if (n instanceof ASTBlankNode) {
      final ASTBlankNode blankNode = (ASTBlankNode) n;
      final String name = blankNode.getIdentifier();
      literal = (allowLazyLiteral) ? LiteralFactory
          .createAnonymousLiteral(name) : LiteralFactory
          .createAnonymousLiteralWithoutLazyLiteral(name);
    } else if (n instanceof ASTQuotedURIRef) {
      final ASTQuotedURIRef uri = (ASTQuotedURIRef) n;
      final String name = uri.getQRef();

      if (URILiteral.isURI("<" + name + ">")) {
        try {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createURILiteral("<" + name + ">")
              : LiteralFactory
                  .createURILiteralWithoutLazyLiteral("<"
                      + name + ">");
        } catch (final Exception e) {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createLiteral("<" + name + ">") : LiteralFactory
              .createLiteralWithoutLazyLiteral("<" + name + ">");
        }
      } else {
        literal = (allowLazyLiteral) ? LiteralFactory.createLiteral("<"
            + name + ">") : LiteralFactory
            .createLiteralWithoutLazyLiteral("<" + name + ">");
      }
    } else if (n instanceof ASTRDFLiteral) {
      n = n.jjtGetChild(0);
    }

    if (literal != null) {
      return literal;
    }

    if (n instanceof ASTStringLiteral) {
      final ASTStringLiteral lit = (ASTStringLiteral) n;
      final String quotedContent = lit.getStringLiteral();

      literal = (allowLazyLiteral) ?
          LiteralFactory.createLiteral(quotedContent)
          : LiteralFactory.createLiteralWithoutLazyLiteral(quotedContent);
    } else if (n instanceof ASTInteger) {
      final ASTInteger lit = (ASTInteger) n;
      final String content = String.valueOf(lit.getValue());

      try {
        literal = (allowLazyLiteral) ? LiteralFactory
            .createTypedLiteral("\"" + content + "\"",
                "<http://www.w3.org/2001/XMLSchema#integer>")
            : TypedLiteralOriginalContent.createTypedLiteral("\""
                + content + "\"",
                "<http://www.w3.org/2001/XMLSchema#integer>");
      } catch (final URISyntaxException e) {
        literal = (allowLazyLiteral) ? LiteralFactory
            .createLiteral(content) : LiteralFactory
            .createLiteralWithoutLazyLiteral(content);
      }
    } else if (n instanceof ASTFloatingPoint) {
      final ASTFloatingPoint lit = (ASTFloatingPoint) n;
      final String content = lit.getValue();

      try {
        if (content.contains("e") || content.contains("E")) {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createTypedLiteral("\"" + content + "\"",
                  "<http://www.w3.org/2001/XMLSchema#double>")
              : TypedLiteralOriginalContent
                  .createTypedLiteral("\"" + content + "\"",
                      "<http://www.w3.org/2001/XMLSchema#double>");
        } else {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createTypedLiteral("\"" + content + "\"",
                  "<http://www.w3.org/2001/XMLSchema#decimal>")
              : TypedLiteralOriginalContent
                  .createTypedLiteral("\"" + content + "\"",
                      "<http://www.w3.org/2001/XMLSchema#decimal>");
        }
      } catch (final URISyntaxException e) {
        literal = (allowLazyLiteral) ? LiteralFactory
            .createLiteral(content) : LiteralFactory
            .createLiteralWithoutLazyLiteral(content);
      }
    } else if (n instanceof ASTBooleanLiteral) {
      final String content = ((ASTBooleanLiteral) n).getState() + "";

      try {
        literal = (allowLazyLiteral) ? LiteralFactory
            .createTypedLiteral("\"" + content + "\"",
                "<http://www.w3.org/2001/XMLSchema#boolean>")
            : TypedLiteralOriginalContent.createTypedLiteral("\""
                + content + "\"",
                "<http://www.w3.org/2001/XMLSchema#boolean>");
      } catch (final URISyntaxException e) {
        literal = (allowLazyLiteral) ? LiteralFactory
            .createLiteral(content) : LiteralFactory
            .createLiteralWithoutLazyLiteral(content);
      }
    } else if (n instanceof ASTDoubleCircumflex) {
      if (n.jjtGetNumChildren() != 2) {
        System.err.println(n + " is expected to have 2 children!");
      } else {
        final String content = getLiteral(n.jjtGetChild(0), false).toString();
        final String type = getLiteral(n.jjtGetChild(1), false).toString();

        try {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createTypedLiteral(content, type)
              : TypedLiteralOriginalContent.createTypedLiteral(
                  content, type);
        } catch (final Exception e) {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createLiteral(content + "^^" + type)
              : LiteralFactory
                  .createLiteralWithoutLazyLiteral(content
                      + "^^" + type);
        }
      }
    } else if (n instanceof ASTLangTag) {
      final String content = getLiteral(n.jjtGetChild(0), false).toString();
      final String lang = ((ASTLangTag) n).getLangTag();
      literal = (allowLazyLiteral) ? LiteralFactory
          .createLanguageTaggedLiteral(content, lang)
          : LanguageTaggedLiteralOriginalLanguage
              .createLanguageTaggedLiteral(content, lang);
    } else if (n instanceof ASTQName) {
      final ASTQName uri = (ASTQName) n;
      final String namespace = uri.getNameSpace();
      final String localName = uri.getLocalName();

      final String name = namespace + localName;

      if (URILiteral.isURI("<" + name + ">")) {
        try {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createURILiteral("<" + name + ">")
              : LiteralFactory
                  .createURILiteralWithoutLazyLiteral("<"
                      + name + ">");
        } catch (final Exception e) {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createLiteral("<" + name + ">") : LiteralFactory
              .createLiteralWithoutLazyLiteral("<" + name + ">");
        }
      } else {
        literal = (allowLazyLiteral) ? LiteralFactory.createLiteral("<"
            + name + ">") : LiteralFactory
            .createLiteralWithoutLazyLiteral("<" + name + ">");
      }
    } else if(n instanceof ASTObjectList){
      literal = getLiteral(n.jjtGetChild(0), allowLazyLiteral);
    } else {
      System.err.println("Unexpected type! "
          + n.getClass().getSimpleName());
    }

    return literal;
  }
View Full Code Here


public class Test {
    public static void main(String[] args) throws Exception {
  if (System.getSecurityManager() == null) {
      System.setSecurityManager(new SecurityManager());
  }
  DynamicPolicyProvider policy = new DynamicPolicyProvider();
  policy.grant(null, null, null);
  try {
      policy.grant(null, new Principal[]{ null }, null);
      throw new Error();
  } catch (NullPointerException e) {
  }
  try {
      policy.grant(null, null, new Permission[]{ null });
      throw new Error();
  } catch (NullPointerException e) {
  }
  policy.getGrants(null, null);
  try {
      policy.getGrants(null, new Principal[]{ null });
      throw new Error();
  } catch (NullPointerException e) {
  }
  PermissionCollection pc =
      policy.getPermissions((ProtectionDomain) null);
  if (pc.elements().hasMoreElements()) {
      throw new Error("permissions returned for null protection domain");
  }
  if (policy.implies(null, new RuntimePermission("foo"))) {
      throw new Error();
  }
    }
View Full Code Here

     * @throws TestException if failed
     *
     */
    protected void createDynamicPolicyProvider() throws TestException {
        try {
            policy = new DynamicPolicyProvider();
        } catch (Exception e) {
            msg = "new DynamicPolicyProvider()";
            throw new TestException(Util.fail(msg, e, msg));
        }
    }
View Full Code Here

     *
     */
    protected void createDynamicPolicyProviderSE(String msg)
            throws TestException {
        try {
            DynamicPolicyProvider policy = new DynamicPolicyProvider();
            throw new TestException(Util.fail(msg, msg, SE));
        } catch (SecurityException se) {
            logger.log(Level.FINE, Util.pass(msg, se));
        } catch (TestException qae) {
            throw qae;
View Full Code Here

     *
     */
    protected void createDynamicPolicyProviderPIE(String msg)
            throws TestException {
        try {
            DynamicPolicyProvider policy = new DynamicPolicyProvider();
            throw new TestException(Util.fail(msg, msg, PIE));
        } catch (PolicyInitializationException pie) {
            logger.log(Level.FINE, Util.pass(msg, pie));
        } catch (TestException qae) {
            throw qae;
View Full Code Here

     *
     */
    protected void createDynamicPolicyProviderNPE(String msg)
            throws TestException {
        try {
            DynamicPolicyProvider policy = new DynamicPolicyProvider(null);
            throw new TestException(Util.fail(msg, msg, NPE));
        } catch (NullPointerException npe) {
            logger.log(Level.FINE, Util.pass(msg, npe));
        } catch (TestException qae) {
            throw qae;
View Full Code Here

      // supplant global policy 1st time through
      if (globalPolicy == null) {
    initialGlobalPolicy = Policy.getPolicy();
                if (!(initialGlobalPolicy instanceof DynamicPolicy)) {
                    initialGlobalPolicy =
                        new DynamicPolicyProvider(initialGlobalPolicy);
                }
    globalPolicy =
        new AggregatePolicyProvider(initialGlobalPolicy);
    Policy.setPolicy(globalPolicy);
    logger.log(Level.FINEST,
View Full Code Here

          // supplant global policy 1st time through
          if (globalPolicy == null) {
        initialGlobalPolicy = Policy.getPolicy();
                    if (!(initialGlobalPolicy instanceof DynamicPolicy)) {
                        initialGlobalPolicy =
                            new DynamicPolicyProvider(initialGlobalPolicy);
                    }
        globalPolicy =
            new AggregatePolicyProvider(initialGlobalPolicy);
        Policy.setPolicy(globalPolicy);
              logger.log(Level.FINEST,
View Full Code Here

    constructor.newInstance(new Object[]{service_policy});
      logger.log(Level.FINEST,
    "Obtained custom service policy implementation instance: {0}",
    servicePolicyWrapper);
  } else {
     servicePolicyWrapper = new DynamicPolicyProvider(service_policy);
     logger.log(Level.FINEST,
    "Using default service policy implementation instance: {0}",
    servicePolicyWrapper);
  }
  return servicePolicyWrapper;
View Full Code Here

         new Permission[]{ new RuntimePermission("foo")});
      throw new Error();
  } catch (UnsupportedOperationException ex) {
  }
 
  Policy.setPolicy(new DynamicPolicyProvider());
 
  Principal p = new StringPrincipal("foo");
  Set ps = new HashSet();
  ps.add(p);
  Subject s = new Subject(
View Full Code Here

TOP

Related Classes of net.jini.security.policy.DynamicPolicyProvider$WeakGroup$Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.