All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.security.fences.config.NamedLeafFence Maven / Gradle / Ivy

Go to download

Augments Java's access control by checking that a Maven Project and all its dependencies conform to a policy that specifies which classes/packages can link to which others.

There is a newer version: 1.9-beta
Show newest version
package com.google.security.fences.config;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.security.fences.inheritance.InheritanceGraph;
import com.google.security.fences.policy.ApiElement;

abstract class NamedLeafFence extends NamedFence {
  @Override
  public Iterable getChildFences() {
    return ImmutableList.of();
  }

  @Override
  void replaceChildFences(Iterable newChildren) {
    Preconditions.checkArgument(!newChildren.iterator().hasNext());
  }

  protected abstract void addToClass(ClassFence container);

  @Override
  public Fence splitDottedNames(ApiElement parentEl, InheritanceGraph g) {
    String name = getName();
    String[] parts = name.split("[.]");
    if (parts.length == 1) {
      return this;
    }

    int i = parts.length - 1;
    this.setName(parts[i]);
    String className = parts[--i];
    ClassFence c = new ClassFence();
    c.setName(className);
    addToClass(c);

    Fence f = c;
    while (--i >= 0) {
      String part = parts[i];
      PackageFence pkg = new PackageFence();
      pkg.setName(part);
      if (f instanceof ClassFence) {
        pkg.setClass((ClassFence) f);
      } else {
        pkg.setPackage((PackageFence) f);
      }
      f = pkg;
    }
    return f;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy