com.google.security.fences.config.NamedLeafFence Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fences-maven-enforcer-rule Show documentation
Show all versions of fences-maven-enforcer-rule Show documentation
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.
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 extends Fence> 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