Package com.getperka.flatpack.policy.pst

Examples of com.getperka.flatpack.policy.pst.TypePolicy


      return false;
    }

    @Override
    public boolean visit(TypePolicy x) {
      TypePolicy n = new TypePolicy();
      n.setAllows(clone(x.getAllows()));
      n.setGroups(clone(x.getGroups()));
      n.setName(clone(x.getName()));
      n.setPolicies(clone(x.getPolicies()));
      n.setVerbs(clone(x.getVerbs()));
      stack.push(n);
      return false;
    }
View Full Code Here


    Ident<Property> inheritFrom = x.getInheritFrom();
    if (inheritFrom == null) {
      return true;
    }
    Property p = ensureReferent(inheritFrom);
    TypePolicy policy = p == null ? null : findTypePolicy(p);
    if (policy == null || hasUnroselvedInherits(policy)) {
      // Skip for the second pass
      unresolved.add(inheritFrom);
      return false;
    }

    x.setInheritFrom(null);

    /*
     * Make copies of each AclRule to ensure that groups are resolved against the current type's
     * scope.
     */
    List<AllowRule> toInherit = listForAny();
    for (AllowBlock inherited : policy.getAllows()) {
      toInherit.addAll(inherited.getAclRules());
    }
    for (ListIterator<AllowRule> it = toInherit.listIterator(); it.hasNext();) {
      it.set(new AllowRule(it.next()));
    }
View Full Code Here

    Ident<Property> inheritFrom = x.getInheritFrom();
    if (inheritFrom == null) {
      return true;
    }
    Property p = ensureReferent(inheritFrom);
    TypePolicy policy = p == null ? null : findTypePolicy(p);
    if (policy == null || hasUnroselvedInherits(policy)) {
      // Skip for the second pass
      unresolved.add(inheritFrom);
      return false;
    }

    // Prevent loops
    x.setInheritFrom(null);

    /*
     * Set up inherited groups. This map is used to allow simple names to refer to the inherit
     * groups, unless the group name is overridden by a local declaration.
     */
    Map<Ident<SecurityGroup>, GroupDefinition> uniqueNames = mapForIteration();
    for (GroupBlock group : policy.getGroups()) {
      // Make a copy of the GroupDefinition that prepends the property being inherited from
      for (GroupDefinition def : group.getDefinitions()) {
        GroupDefinition inherited = new GroupDefinition(def, inheritFrom);
        uniqueNames.put(inherited.getName(), inherited);

View Full Code Here

    }
    x.setReferent(desc.getEntityType());
  }

  void resolveProperty(Ident<Property> x) {
    TypePolicy typePolicy = currentLocation(TypePolicy.class);
    if (typePolicy == null) {
      error("Cannot refer to property outside of a type");
      return;
    }
    Class<? extends HasUuid> clazz = ensureReferent(typePolicy);
    if (clazz == null) {
      // Error already reported
      return;
    }
    for (Property p : typeContext.describe(clazz).getProperties()) {
      if (p.getName().equals(x.getSimpleName())) {
        if (p.getEnclosingType().getTypeName().equals(typePolicy.getName().getSimpleName())) {
          x.setReferent(p);
        } else {
          error("Type " + typePolicy.getName() + " does not define property " + p.getName());
        }

        return;
      }
    }
    error("Could not find property " + x + " in type " + typePolicy.getName());
  }
View Full Code Here

  /**
   * Convert a simple or compound name into a {@link PropertyPath}, using the currently-enclosing
   * {@link TypePolicy} as the basis for resolving property names.
   */
  void resolvePropertyPath(Ident<PropertyPath> x) {
    TypePolicy typePolicy = currentLocation(TypePolicy.class);
    if (typePolicy == null) {
      error("Expecting to be in a type declaration");
      return;
    }
    // Ensure the type name has been resolved
View Full Code Here

      x.setReferent(securityGroups.getGroupReflexive());
      return;
    }

    // Determine if a group is being declared
    TypePolicy typePolicy = currentLocation(TypePolicy.class);
    GroupDefinition groupDefinition = currentLocation(GroupDefinition.class);
    if (groupDefinition != null) {
      // Ensure that all the PropertyPaths are set up
      List<PropertyPath> paths = ensureReferent(groupDefinition.getPaths());
      Class<? extends HasUuid> type = ensureReferent(typePolicy);
      if (type == null) {
        unresolved.add(typePolicy.getName());
        return;
      }
      SecurityGroup group = paths.isEmpty() ?
          securityGroups.getGroupEmpty() :
          securityGroups.getGroup(type, groupDefinition.getName().toString(),
View Full Code Here

  @SuppressWarnings({ "unchecked", "rawtypes" })
  private TypePolicy findTypePolicy(Property p) {
    String typeName = nextPropertyPathTypeName(p);
    Class ref = Class.class;
    TypePolicy toReturn = scope().get(TypePolicy.class, ref, typeName);

    /*
     * Synthesize an empty TypePolicy on the second pass to stub out any types that are implicitly
     * referenced through property chains but that do not have their own type policy.
     */
    if (toReturn == null && secondPass) {
      Ident ident = new Ident(Class.class, typeName);
      toReturn = new TypePolicy();
      toReturn.setName(ident);
      ensureReferent(ident);
      scope().put(toReturn);
    }
    return toReturn;
  }
View Full Code Here

   *   verb ...;
   * }
   * </pre>
   */
  Rule TypePolicy() {
    final Var<TypePolicy> x = new Var<TypePolicy>(new TypePolicy());
    return Sequence(
        "type",
        NodeNameRaw(Class.class, x),
        "{",
        ZeroOrMore(FirstOf(
View Full Code Here

TOP

Related Classes of com.getperka.flatpack.policy.pst.TypePolicy

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.