Search in sources :

Example 26 with ProvisioningException

use of com.tremolosecurity.provisioning.core.ProvisioningException in project OpenUnison by TremoloSecurity.

the class LoadResultGroupsFromK8s method modifyObject.

@Override
public void modifyObject(TremoloType cfg, JSONObject item) throws ProvisioningException {
    String rawJson = item.toJSONString();
    StringBuffer b = new StringBuffer();
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, rawJson);
    try {
        JSONObject newRoot = (JSONObject) new JSONParser().parse(b.toString());
        JSONObject metadata = (JSONObject) newRoot.get("metadata");
        if (metadata == null) {
            throw new ProvisioningException("No metadata");
        }
        String name = (String) metadata.get("name");
        logger.info("modifying result group " + name);
        ResultGroupType rgt = this.createResultGroup(newRoot, name);
        ResultGroupType rgtToRemove = null;
        for (ResultGroupType rgtCheck : cfg.getResultGroups().getResultGroup()) {
            if (rgtCheck.getName().equalsIgnoreCase(name)) {
                rgtToRemove = rgtCheck;
                break;
            }
        }
        if (rgtToRemove != null) {
            cfg.getResultGroups().getResultGroup().remove(rgtToRemove);
        }
        cfg.getResultGroups().getResultGroup().add(rgt);
        GlobalEntries.getGlobalEntries().getConfigManager().addResultGroup(rgt);
    } catch (ParseException e) {
        throw new ProvisioningException("Could not parse resultgroup", e);
    }
}
Also used : JSONObject(org.json.simple.JSONObject) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ResultGroupType(com.tremolosecurity.config.xml.ResultGroupType) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Example 27 with ProvisioningException

use of com.tremolosecurity.provisioning.core.ProvisioningException in project OpenUnison by TremoloSecurity.

the class LoadResultGroupsFromK8s method deleteObject.

@Override
public void deleteObject(TremoloType cfg, JSONObject item) throws ProvisioningException {
    JSONObject metadata = (JSONObject) item.get("metadata");
    if (metadata == null) {
        throw new ProvisioningException("No metadata");
    }
    String name = (String) metadata.get("name");
    logger.info("Deleting result group " + name);
    ResultGroupType rgtToRemove = null;
    for (ResultGroupType rgtCheck : cfg.getResultGroups().getResultGroup()) {
        if (rgtCheck.getName().equalsIgnoreCase(name)) {
            rgtToRemove = rgtCheck;
            break;
        }
    }
    if (rgtToRemove != null) {
        cfg.getResultGroups().getResultGroup().remove(rgtToRemove);
        GlobalEntries.getGlobalEntries().getConfigManager().removeResultGroup(rgtToRemove);
    }
}
Also used : JSONObject(org.json.simple.JSONObject) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ResultGroupType(com.tremolosecurity.config.xml.ResultGroupType)

Example 28 with ProvisioningException

use of com.tremolosecurity.provisioning.core.ProvisioningException in project OpenUnison by TremoloSecurity.

the class K8sProjectCheck method createTremoloUser.

@Override
public String createTremoloUser(NewUserRequest newUser, List<String> errors, AuthInfo userData) throws ProvisioningException {
    if (errors.size() == 0) {
        String targetName = newUser.getAttributes().get("cluster");
        if (targetName == null) {
            targetName = this.targetName;
        }
        OpenShiftTarget target = (OpenShiftTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(targetName).getProvider();
        HttpCon con = null;
        try {
            String token = target.getAuthToken();
            con = target.createClient();
            if (target.isObjectExistsByName(token, con, "/api/v1/namespaces", newUser.getAttributes().get(this.projectAttributeName))) {
                errors.add("Namespace name already exists");
                return "";
            }
        } catch (Exception e) {
            throw new ProvisioningException("Could not check if namespace exists", e);
        } finally {
            if (con != null) {
                try {
                    con.getHttp().close();
                } catch (IOException e) {
                // doesn't matter
                }
                con.getBcm().close();
            }
        }
        if (target.getGitUrl() != null && !target.getGitUrl().isEmpty()) {
            String gitUrlForNs = newUser.getAttributes().get("gitUrl");
            String sshPrivKey = newUser.getAttributes().get("gitSshKey");
            if (gitUrlForNs == null || gitUrlForNs.isEmpty()) {
                errors.add("Git URL is required for clusters configured to use git");
            }
            if (sshPrivKey == null || sshPrivKey.isEmpty()) {
                errors.add("Git SSH Private Key is required for clusters configured to use git");
            }
            if (errors.size() > 0) {
                return "";
            }
            GitUtils gitUtil = new GitUtils(gitUrlForNs, sshPrivKey);
            try {
                gitUtil.checkOut();
            } catch (Throwable t) {
                logger.warn("Could not checkout '" + gitUrlForNs + "'", t);
                errors.add(t.getMessage());
            } finally {
                gitUtil.cleanup();
            }
        }
        return this.workflowName;
    } else {
        return "";
    }
}
Also used : HttpCon(com.tremolosecurity.provisioning.util.HttpCon) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) GitUtils(com.tremolosecurity.git.GitUtils) OpenShiftTarget(com.tremolosecurity.unison.openshiftv3.OpenShiftTarget) IOException(java.io.IOException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException)

Example 29 with ProvisioningException

use of com.tremolosecurity.provisioning.core.ProvisioningException in project OpenUnison by TremoloSecurity.

the class LoadConfigMap method doTask.

@Override
public boolean doTask(User user, Map<String, Object> request) throws ProvisioningException {
    try {
        logger.info("Loading " + this.target + "." + this.namespace + "." + this.configmap);
        Map<String, String> cm = K8sUtils.loadConfigMap(target, namespace, configmap);
        logger.info("map : " + cm.toString());
        for (String wfname : mapping.keySet()) {
            logger.info("wfname : " + wfname);
            String cmname = this.mapping.get(wfname);
            logger.info("cmname : " + cmname);
            String cmval = cm.get(cmname);
            logger.info("cmval : " + cmval);
            if (cmval == null) {
                StringBuilder sb = new StringBuilder();
                sb.append("Unable to find key '").append(cmname).append("' in ").append(namespace).append(".").append(configmap);
                logger.warn(sb.toString());
            } else {
                logger.info("putting " + wfname + " - " + cmval);
                request.put(wfname, cmval);
            }
        }
    } catch (Exception e) {
        throw new ProvisioningException("Could not load configmap " + this.configmap + " from " + this.namespace);
    }
    return true;
}
Also used : ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException)

Example 30 with ProvisioningException

use of com.tremolosecurity.provisioning.core.ProvisioningException in project OpenUnison by TremoloSecurity.

the class JavaScriptRegister method init.

@Override
public void init(ScaleJSRegisterConfig registerConfig) throws ProvisioningException {
    initCompleted = false;
    Context context = Context.newBuilder("js").allowAllAccess(true).build();
    globals = new HashMap<String, Object>();
    context.getBindings("js").putMember("globals", globals);
    try {
        Attribute attr = registerConfig.getCustomSubmissionConfig().get("javaScript");
        if (attr == null) {
            logger.error("javaScript not set");
            return;
        }
        this.javaScript = attr.getValues().get(0);
        globals = new HashMap<String, Object>();
        context.getBindings("js").putMember("globals", globals);
        Value val = context.eval("js", this.javaScript);
        Value init = context.getBindings("js").getMember("init");
        if (init == null || !init.canExecute()) {
            throw new ProvisioningException("init function must be defined with one paramter");
        }
        Value doFilter = context.getBindings("js").getMember("createTremoloUser");
        if (doFilter == null || !doFilter.canExecute()) {
            throw new ProvisioningException("createTremoloUser function must be defined with three paramters");
        }
        doFilter = context.getBindings("js").getMember("setWorkflowParameters");
        if (doFilter == null || !doFilter.canExecute()) {
            throw new ProvisioningException("setWorkflowParameters function must be defined with three paramters");
        }
        init.executeVoid(registerConfig);
        initCompleted = true;
    } catch (Throwable t) {
        logger.error("Could not initialize javascript filter", t);
        return;
    } finally {
        if (context != null) {
            context.close();
        }
    }
}
Also used : Context(org.graalvm.polyglot.Context) Attribute(com.tremolosecurity.saml.Attribute) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Value(org.graalvm.polyglot.Value)

Aggregations

ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)265 IOException (java.io.IOException)91 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)79 Attribute (com.tremolosecurity.saml.Attribute)75 Workflow (com.tremolosecurity.provisioning.core.Workflow)67 JSONObject (org.json.simple.JSONObject)67 UnsupportedEncodingException (java.io.UnsupportedEncodingException)57 ClientProtocolException (org.apache.http.client.ClientProtocolException)57 LDAPException (com.novell.ldap.LDAPException)56 ArrayList (java.util.ArrayList)54 ParseException (org.json.simple.parser.ParseException)51 HashMap (java.util.HashMap)50 Gson (com.google.gson.Gson)45 User (com.tremolosecurity.provisioning.core.User)44 JSONParser (org.json.simple.parser.JSONParser)42 SQLException (java.sql.SQLException)39 LDAPAttribute (com.novell.ldap.LDAPAttribute)33 LDAPEntry (com.novell.ldap.LDAPEntry)33 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)30 OpenShiftTarget (com.tremolosecurity.unison.openshiftv3.OpenShiftTarget)28