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

org.biscuitsec.biscuit.token.Policy Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
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