Search in sources :

Example 1 with IPAException

use of com.tremolosecurity.unison.freeipa.util.IPAException in project OpenUnison by TremoloSecurity.

the class UserPrincipal method deleteUser.

public void deleteUser(User user, Map<String, Object> request) throws ProvisioningException {
    UserPrincipal principal = new UserPrincipal(user.getUserID(), multiDomain, primaryDomain);
    int approvalID = 0;
    if (request.containsKey("APPROVAL_ID")) {
        approvalID = (Integer) request.get("APPROVAL_ID");
    }
    Workflow workflow = (Workflow) request.get("WORKFLOW");
    try {
        HttpCon con = this.createClient();
        try {
            if (principal.isPrimaryDomain()) {
                IPACall deleteUser = new IPACall();
                deleteUser.setId(0);
                deleteUser.setMethod("user_del");
                ArrayList<String> userArray = new ArrayList<String>();
                userArray.add(principal.getUid());
                deleteUser.getParams().add(userArray);
                HashMap<String, String> additionalParams = new HashMap<String, String>();
                deleteUser.getParams().add(additionalParams);
                IPAResponse resp = this.executeIPACall(deleteUser, con);
                this.cfgMgr.getProvisioningEngine().logAction(name, true, ActionType.Delete, approvalID, workflow, "uid", user.getUserID());
            } else {
                IPACall idOveride = new IPACall();
                idOveride.setId(0);
                idOveride.setMethod("idoverrideuser_del");
                List<String> params = new ArrayList<String>();
                params.add(this.trustViewName);
                params.add(principal.getUPN());
                idOveride.getParams().add(params);
                Map<String, Object> param2 = new HashMap<String, Object>();
                idOveride.getParams().add(param2);
                try {
                    IPAResponse resp = this.executeIPACall(idOveride, con);
                } catch (IPAException e) {
                    if (!e.getMessage().equalsIgnoreCase("no modifications to be performed")) {
                        throw e;
                    }
                }
            }
        } finally {
            if (con != null) {
                con.getBcm().shutdown();
            }
        }
    } catch (Exception e) {
        throw new ProvisioningException("Could not run search", e);
    }
}
Also used : IPAResponse(com.tremolosecurity.unison.freeipa.json.IPAResponse) HashMap(java.util.HashMap) IPACall(com.tremolosecurity.unison.freeipa.json.IPACall) ArrayList(java.util.ArrayList) Workflow(com.tremolosecurity.provisioning.core.Workflow) ClientProtocolException(org.apache.http.client.ClientProtocolException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) IPAException(com.tremolosecurity.unison.freeipa.util.IPAException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IPAException(com.tremolosecurity.unison.freeipa.util.IPAException) HttpCon(com.tremolosecurity.provisioning.util.HttpCon) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException)

Example 2 with IPAException

use of com.tremolosecurity.unison.freeipa.util.IPAException in project OpenUnison by TremoloSecurity.

the class UserPrincipal method setAttribute.

private void setAttribute(UserPrincipal principal, Attribute attrNew, HttpCon con, int approvalID, Workflow workflow) throws Exception {
    if (principal.isPrimaryDomain()) {
        IPACall modify = new IPACall();
        modify.setId(0);
        modify.setMethod("user_mod");
        ArrayList<String> userArray = new ArrayList<String>();
        userArray.add(principal.getUid());
        modify.getParams().add(userArray);
        HashMap<String, Object> additionalParams = new HashMap<String, Object>();
        if (attrNew.getValues().size() > 1) {
            additionalParams.put(attrNew.getName(), attrNew.getValues());
        } else {
            additionalParams.put(attrNew.getName(), attrNew.getValues().get(0));
        }
        modify.getParams().add(additionalParams);
        try {
            IPAResponse resp = this.executeIPACall(modify, con);
        } catch (IPAException e) {
            if (!e.getMessage().equalsIgnoreCase("no modifications to be performed")) {
                throw e;
            }
        }
    } else {
        if (attrNew.getName().equalsIgnoreCase("uid") && attrNew.getValues().get(0).equals(principal.getUPN())) {
            return;
        }
        IPACall idOveride = new IPACall();
        idOveride.setId(0);
        idOveride.setMethod("idoverrideuser_mod");
        List<String> params = new ArrayList<String>();
        params.add(this.trustViewName);
        params.add(principal.getUPN());
        idOveride.getParams().add(params);
        Map<String, Object> param2 = new HashMap<String, Object>();
        param2.put("all", true);
        param2.put("rights", false);
        param2.put(attrNew.getName(), attrNew.getValues().get(0));
        idOveride.getParams().add(param2);
        try {
            IPAResponse resp = this.executeIPACall(idOveride, con);
        } catch (IPAException e) {
            if (!e.getMessage().equalsIgnoreCase("no modifications to be performed")) {
                throw e;
            }
        }
    }
}
Also used : IPAResponse(com.tremolosecurity.unison.freeipa.json.IPAResponse) IPAException(com.tremolosecurity.unison.freeipa.util.IPAException) HashMap(java.util.HashMap) IPACall(com.tremolosecurity.unison.freeipa.json.IPACall) ArrayList(java.util.ArrayList)

Example 3 with IPAException

use of com.tremolosecurity.unison.freeipa.util.IPAException in project OpenUnison by TremoloSecurity.

the class UserPrincipal method isGroupExists.

@Override
public boolean isGroupExists(String name, User user, Map<String, Object> request) throws ProvisioningException {
    IPACall groupSearch = new IPACall();
    groupSearch.setId(0);
    groupSearch.setMethod("group_show");
    ArrayList<String> groupArray = new ArrayList<String>();
    groupArray.add(name);
    groupSearch.getParams().add(groupArray);
    HashMap<String, String> additionalParams = new HashMap<String, String>();
    groupSearch.getParams().add(additionalParams);
    HttpCon con = null;
    try {
        con = this.createClient();
        IPAResponse resp = this.executeIPACall(groupSearch, con);
        return true;
    } catch (IPAException ipae) {
        if (ipae.getCode() == 4001) {
            return false;
        } else {
            throw new ProvisioningException("Could not find groups", ipae);
        }
    } catch (Exception e) {
        throw new ProvisioningException("Could not find groups", e);
    } finally {
        if (con != null) {
            con.getBcm().close();
        }
    }
}
Also used : IPAResponse(com.tremolosecurity.unison.freeipa.json.IPAResponse) IPAException(com.tremolosecurity.unison.freeipa.util.IPAException) HttpCon(com.tremolosecurity.provisioning.util.HttpCon) HashMap(java.util.HashMap) IPACall(com.tremolosecurity.unison.freeipa.json.IPACall) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ArrayList(java.util.ArrayList) ClientProtocolException(org.apache.http.client.ClientProtocolException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) IPAException(com.tremolosecurity.unison.freeipa.util.IPAException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with IPAException

use of com.tremolosecurity.unison.freeipa.util.IPAException in project OpenUnison by TremoloSecurity.

the class UserPrincipal method executeIPACall.

private IPAResponse executeIPACall(IPACall ipaCall, HttpCon con) throws IPAException, ClientProtocolException, IOException {
    Gson gson = new Gson();
    String json = gson.toJson(ipaCall);
    if (logger.isDebugEnabled()) {
        logger.debug("Outbound JSON : '" + json + "'");
    }
    HttpClient http = con.getHttp();
    StringEntity str = new StringEntity(json, ContentType.APPLICATION_JSON);
    HttpPost httppost = new HttpPost(this.url + "/ipa/session/json");
    httppost.addHeader("Referer", this.url + "/ipa/ui/");
    httppost.setEntity(str);
    HttpResponse resp = http.execute(httppost);
    BufferedReader in = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
    StringBuffer b = new StringBuffer();
    String line = null;
    while ((line = in.readLine()) != null) {
        b.append(line);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Inbound JSON : " + b.toString());
    }
    EntityUtils.consumeQuietly(resp.getEntity());
    httppost.completed();
    IPAResponse ipaResponse = gson.fromJson(b.toString(), IPAResponse.class);
    if (ipaResponse.getError() != null) {
        IPAException ipaException = new IPAException(ipaResponse.getError().getMessage());
        ipaException.setCode(ipaResponse.getError().getCode());
        ipaException.setName(ipaResponse.getError().getName());
        throw ipaException;
    } else {
        return ipaResponse;
    }
}
Also used : IPAResponse(com.tremolosecurity.unison.freeipa.json.IPAResponse) StringEntity(org.apache.http.entity.StringEntity) HttpPost(org.apache.http.client.methods.HttpPost) IPAException(com.tremolosecurity.unison.freeipa.util.IPAException) InputStreamReader(java.io.InputStreamReader) HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BufferedReader(java.io.BufferedReader) Gson(com.google.gson.Gson) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpResponse(org.apache.http.HttpResponse)

Example 5 with IPAException

use of com.tremolosecurity.unison.freeipa.util.IPAException in project OpenUnison by TremoloSecurity.

the class UserPrincipal method executeIPABatchCall.

private IPABatchResponse executeIPABatchCall(IPACall ipaCall, HttpCon con) throws IPAException, ClientProtocolException, IOException {
    Gson gson = new Gson();
    String json = gson.toJson(ipaCall);
    if (logger.isDebugEnabled()) {
        logger.debug("Outbound JSON : '" + json + "'");
    }
    HttpClient http = con.getHttp();
    StringEntity str = new StringEntity(json, ContentType.APPLICATION_JSON);
    HttpPost httppost = new HttpPost(this.url + "/ipa/session/json");
    httppost.addHeader("Referer", this.url + "/ipa/ui/");
    httppost.setEntity(str);
    HttpResponse resp = http.execute(httppost);
    BufferedReader in = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
    StringBuffer b = new StringBuffer();
    String line = null;
    while ((line = in.readLine()) != null) {
        b.append(line);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Inbound JSON : " + b.toString());
    }
    EntityUtils.consumeQuietly(resp.getEntity());
    httppost.completed();
    IPABatchResponse ipaResponse = gson.fromJson(b.toString(), IPABatchResponse.class);
    if (ipaResponse.getError() != null) {
        IPAException ipaException = new IPAException(ipaResponse.getError().getMessage());
        ipaException.setCode(ipaResponse.getError().getCode());
        ipaException.setName(ipaResponse.getError().getName());
        throw ipaException;
    } else {
        return ipaResponse;
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpPost(org.apache.http.client.methods.HttpPost) IPAException(com.tremolosecurity.unison.freeipa.util.IPAException) InputStreamReader(java.io.InputStreamReader) IPABatchResponse(com.tremolosecurity.unison.freeipa.json.IPABatchResponse) HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BufferedReader(java.io.BufferedReader) Gson(com.google.gson.Gson) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpResponse(org.apache.http.HttpResponse)

Aggregations

IPAException (com.tremolosecurity.unison.freeipa.util.IPAException)8 IPAResponse (com.tremolosecurity.unison.freeipa.json.IPAResponse)6 IPACall (com.tremolosecurity.unison.freeipa.json.IPACall)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)3 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)3 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ClientProtocolException (org.apache.http.client.ClientProtocolException)3 Gson (com.google.gson.Gson)2 User (com.tremolosecurity.provisioning.core.User)2 Workflow (com.tremolosecurity.provisioning.core.Workflow)2 Attribute (com.tremolosecurity.saml.Attribute)2 IPABatchResponse (com.tremolosecurity.unison.freeipa.json.IPABatchResponse)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 HttpResponse (org.apache.http.HttpResponse)2 HttpClient (org.apache.http.client.HttpClient)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2