Search in sources :

Example 1 with OxAuthCustomClient

use of org.gluu.oxtrust.model.OxAuthCustomClient in project oxTrust by GluuFederation.

the class ClientService method getClientByAttributeCustom.

/**
 * Get custom client by Attribute
 *
 * @param name
 * @param value
 * @return Custom client
 */
public OxAuthCustomClient getClientByAttributeCustom(String name, String value) {
    try {
        if (name.equalsIgnoreCase("dn")) {
            return getClientByDnCustom(value);
        }
        if (name.equalsIgnoreCase("inum")) {
            return getClientByInumCustom(value);
        }
        log.info("creating a new instance of OxAuthCustomClient ");
        OxAuthCustomClient client = new OxAuthCustomClient();
        log.info("getting dn for client ");
        client.setBaseDn(getDnForClient(null));
        log.info("name ", name);
        log.info("value ", value);
        log.info("setting attribute value ");
        client.setAttribute(name, value);
        log.info("finding entries ");
        List<OxAuthCustomClient> clients = ldapEntryManager.findEntries(client);
        if ((clients != null) && (clients.size() > 0)) {
            log.info("entry found ");
            return clients.get(0);
        }
        log.info("no entry ");
        return null;
    } catch (Exception ex) {
        log.error("an error occured ", ex);
        return null;
    }
}
Also used : OxAuthCustomClient(org.gluu.oxtrust.model.OxAuthCustomClient)

Example 2 with OxAuthCustomClient

use of org.gluu.oxtrust.model.OxAuthCustomClient in project oxTrust by GluuFederation.

the class ClientAssociationWebService method deleteAssociation.

@PUT
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteAssociation(@HeaderParam("Authorization") String authorization, PersonAssociation personAssociation) throws Exception {
    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        log.info("Creating an instance of GluuCustomPerson");
        GluuCustomPerson person = personService.getPersonByInum(personAssociation.getUserAssociation().replaceAll(" ", ""));
        log.info("getting a list of clientDNs");
        List<String> listClientDNs = new ArrayList<String>();
        boolean isACDNsEmpty = person.getAssociatedClient() == null;
        if (!isACDNsEmpty) {
            for (String dn : person.getAssociatedClient()) {
                log.info("isACDNsEmpty = false");
                if (dn != null && !dn.equalsIgnoreCase("")) {
                    listClientDNs.add(dn.replaceAll(" ", ""));
                }
            }
        }
        log.info("getting a list of clean clients");
        List<String> cleanPACDNs = new ArrayList<String>();
        for (String dn : personAssociation.getEntryAssociations()) {
            if (dn != null && !dn.equalsIgnoreCase("")) {
                cleanPACDNs.add(dn);
            }
        }
        log.info("removing clientdns");
        for (String clientdn : cleanPACDNs) {
            if (listClientDNs.contains(clientdn)) {
                listClientDNs.remove(clientdn);
            }
        }
        log.info("geting a cleanlist");
        List<String> cleanList = new ArrayList<String>();
        for (String cDn : listClientDNs) {
            if (cDn != null && !cDn.equalsIgnoreCase("")) {
                cleanList.add(cDn);
            }
        }
        log.info("setting AssociatedClientDNs");
        if (cleanList.size() < 1) {
            person.setAssociatedClient(null);
        } else {
            person.setAssociatedClient(cleanList);
        }
        log.info("Updating person");
        personService.updatePerson(person);
        log.info("deleting user dn from clients");
        List<String> EntryAssociations = new ArrayList<String>();
        for (String dn : personAssociation.getEntryAssociations()) {
            if (dn != null && !dn.equalsIgnoreCase("")) {
                EntryAssociations.add(dn.replaceAll(" ", ""));
            }
        }
        for (String clientDn : EntryAssociations) {
            log.info("getting a client");
            OxAuthCustomClient client = clientService.getClientByAttributeCustom(appConfiguration.getClientAssociationAttribute(), clientDn.replaceAll(" ", ""));
            // String[] personDNS =
            // client.getAttributes("associatedPersonDN");
            log.info("checking if the associatedPerson is empty");
            log.info("client dn : ", client.getDn());
            boolean isAPDNsEmpty = client.getAttributes("associatedPerson") == null;
            log.info("new ArrayList");
            List<String> list = new ArrayList<String>();
            if (!isAPDNsEmpty) {
                log.info("!isAPDNsEmpty");
                // Arrays.asList(client.getAttributes("associatedPersonDN"));
                for (int i = 0; i < client.getAttributes("associatedPerson").length; i++) {
                    if (client.getAttributes("associatedPerson")[i] != null && !client.getAttributes("associatedPerson")[i].equalsIgnoreCase("")) {
                        list.add(client.getAttributes("associatedPerson")[i]);
                    }
                }
            /*
					 * for(String dn : client.getAssociatedPersonDNs()){ if(dn
					 * != null && !dn.equalsIgnoreCase("")){list.add(dn);} }
					 */
            }
            log.info("getting personDN");
            String personInum = personAssociation.getUserAssociation().replaceAll(" ", "");
            if (list.contains(personInum)) {
                log.info("removing person's dn");
                list.remove(personInum);
            }
            log.info("Creating a clean list");
            List<String> cleanPersonList = new ArrayList<String>();
            for (String cDn : list) {
                if (cDn != null && cDn.equalsIgnoreCase("")) {
                    cleanPersonList.add(cDn);
                }
            }
            log.info("Setting AssociatedPersonDNs");
            if (cleanPersonList.size() < 1) {
                String[] nullArray = null;
                client.setAttribute("associatedPerson", nullArray);
            } else {
                String[] arrayPersonDns = new String[cleanPersonList.size()];
                for (int i = 0; i < cleanPersonList.size(); i++) {
                    arrayPersonDns[i] = cleanPersonList.get(i);
                }
                client.setAttribute("associatedPerson", arrayPersonDns);
            }
            clientService.updateCustomClient(client);
        }
        log.info("returning result;");
        return Response.ok().build();
    } catch (Exception ex) {
        log.info("Exception: ", ex);
        log.error("Exception: ", ex);
        return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
}
Also used : Response(javax.ws.rs.core.Response) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList) OxAuthCustomClient(org.gluu.oxtrust.model.OxAuthCustomClient) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 3 with OxAuthCustomClient

use of org.gluu.oxtrust.model.OxAuthCustomClient in project oxTrust by GluuFederation.

the class ClientAssociationWebService method createAssociation.

@Path("/Associate/")
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createAssociation(@HeaderParam("Authorization") String authorization, PersonAssociation personAssociation) throws Exception {
    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        log.info("creating an instance of gluuCustomperson");
        GluuCustomPerson person = personService.getPersonByInum(personAssociation.getUserAssociation().replaceAll(" ", ""));
        log.info("setting AssociatedClientDNs");
        List<String> cleanCDNList = new ArrayList<String>();
        for (String dn : personAssociation.getEntryAssociations()) {
            cleanCDNList.add(dn.replaceAll(" ", ""));
        }
        person.setAssociatedClient(cleanCDNList);
        log.info("updating person");
        personService.updatePerson(person);
        log.info("setting user in clients");
        for (String clientDn : personAssociation.getEntryAssociations()) {
            log.info("getting a client");
            OxAuthCustomClient client = clientService.getClientByAttributeCustom(appConfiguration.getClientAssociationAttribute(), clientDn.replaceAll(" ", ""));
            log.info("the inum of the client ", client.getInum());
            log.info("checking if the list is empty");
            boolean isAPDNsEmpty = client.getAttributes("associatedPerson") == null;
            log.info("instantiating a new arraylist");
            List<String> listOfpersons = new ArrayList<String>();
            log.info("getting AssociatedPersonDN");
            if (!isAPDNsEmpty) {
                listOfpersons = new ArrayList(Arrays.asList(client.getAttributes("associatedPerson")));
            /*
					 * for(String dn :
					 * client.getAttributes("associatedPersonDN")){ if(dn !=
					 * null && !dn.equalsIgnoreCase("")){listOfpersons.add(dn);}
					 * }
					 */
            }
            log.info("getting persons dn");
            String personInum = personAssociation.getUserAssociation().replaceAll(" ", "");
            if (isAPDNsEmpty || !listOfpersons.contains(personInum)) {
                log.info("adding person");
                listOfpersons.add(personInum);
            }
            String[] arrayOfpersons = new String[listOfpersons.size()];
            for (int i = 0; i < listOfpersons.size(); i++) {
                arrayOfpersons[i] = listOfpersons.get(i);
            }
            log.info("setting list of AssociatedPersonDns");
            client.setAttribute("associatedPerson", arrayOfpersons);
            log.info("Updating client");
            clientService.updateCustomClient(client);
        }
        String uri = "/ClientAssociation/Associate/" + person.getInum();
        log.info("returning response");
        return Response.created(URI.create(uri)).entity(personAssociation).build();
    } catch (Exception ex) {
        log.error("Failed to add Association", ex);
        // log.info("Failed to add Association" , ex);
        return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
}
Also used : Response(javax.ws.rs.core.Response) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList) OxAuthCustomClient(org.gluu.oxtrust.model.OxAuthCustomClient) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

OxAuthCustomClient (org.gluu.oxtrust.model.OxAuthCustomClient)3 ArrayList (java.util.ArrayList)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)2 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)2 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1