001package com.identityworksllc.iiq.common.access;
002
003import com.identityworksllc.iiq.common.CommonSecurityConfig;
004import com.identityworksllc.iiq.common.auth.DummyAuthContext;
005import com.identityworksllc.iiq.common.auth.DummyPluginResource;
006import sailpoint.api.SailPointContext;
007import sailpoint.object.Identity;
008import sailpoint.tools.GeneralException;
009import sailpoint.web.UserContext;
010
011import java.util.Map;
012
013public class FluentAccessCheck {
014    private final AccessCheckInput input;
015
016    public FluentAccessCheck() {
017        this.input = new AccessCheckInput();
018    }
019
020    public AccessCheckResponse accessCheck() {
021        return AccessCheck.accessCheck(this.input);
022    }
023
024    public FluentAccessCheck config(Map<String, Object> config) throws GeneralException {
025        input.setConfiguration(config);
026        return this;
027    }
028
029    public FluentAccessCheck config(CommonSecurityConfig config) {
030        input.setConfiguration(config);
031        return this;
032    }
033
034    public boolean isAllowed() {
035        return accessCheck().isAllowed();
036    }
037
038    public FluentAccessCheck name(String name) {
039        input.setThingName(name);
040        return this;
041    }
042
043    public FluentAccessCheck state(Map<String, Object> state) {
044        input.setState(state);
045        return this;
046    }
047
048    public FluentAccessCheck state(String name, Object value) {
049        input.putState(name, value);
050        return this;
051    }
052
053    public FluentAccessCheck subject(SailPointContext ctx, Identity subject, String pluginName) {
054        input.setUserContext(new DummyPluginResource(ctx, subject, pluginName));
055        return this;
056    }
057
058    public FluentAccessCheck subject(SailPointContext ctx, Identity subject) {
059        input.setUserContext(new DummyAuthContext(ctx, subject.getName()));
060        return this;
061    }
062
063    public FluentAccessCheck subject(UserContext userContext) throws GeneralException {
064        input.setUserContext(userContext);
065        return this;
066    }
067
068    public FluentAccessCheck target(Identity target) {
069        input.setTarget(target);
070        return this;
071    }
072}