org.biscuitsec.biscuit.token.Policy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biscuit Show documentation
Show all versions of biscuit Show documentation
Java support for the biscuit auth token and policy language
package org.biscuitsec.biscuit.token;
import org.biscuitsec.biscuit.token.builder.Rule;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Policy {
public enum Kind {
Allow,
Deny,
}
public final List queries;
public Kind kind;
public Policy(List queries, Kind kind) {
this.queries = queries;
this.kind = kind;
}
public Policy(Rule query, Kind kind) {
ArrayList r = new ArrayList<>();
r.add(query);
this.queries = r;
this.kind = kind;
}
@Override
public String toString() {
final List qs = queries.stream().map((q) -> q.bodyToString()).collect(Collectors.toList());
switch(this.kind) {
case Allow:
return "allow if "+String.join(" or ", qs);
case Deny:
return "deny if "+String.join(" or ", qs);
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy