Search in sources :

Example 76 with GluuCustomPerson

use of org.gluu.oxtrust.model.GluuCustomPerson 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 77 with GluuCustomPerson

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

the class ClientAssociationWebService method getAssociatedClients.

@Path("/User/{uid}")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getAssociatedClients(@HeaderParam("Authorization") String authorization, @PathParam("uid") String uid) throws Exception {
    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        GluuCustomPerson gluuPerson = personService.getPersonByInum(uid);
        if (gluuPerson == null) {
            // sets HTTP status code 404 Not Found
            return getErrorResponse("Resource " + uid + " not found", Response.Status.NOT_FOUND.getStatusCode());
        }
        PersonAssociation personAssociation = MapperUtil.map(gluuPerson, null);
        URI location = new URI("/ClientAssociation/User/" + uid);
        return Response.ok(personAssociation).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Exception: ", ex);
        return getErrorResponse("Resource " + uid + " not found", Response.Status.NOT_FOUND.getStatusCode());
    } catch (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) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) PersonAssociation(org.gluu.oxtrust.model.association.PersonAssociation) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 78 with GluuCustomPerson

use of org.gluu.oxtrust.model.GluuCustomPerson 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)

Example 79 with GluuCustomPerson

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

the class CopyUtils method copy.

/**
	 * Copy data from ScimPerson object to GluuCustomPerson object "Reda"
	 * 
	 * @param source
	 * @param destination
	 * @return
	 * @throws Exception
	 */
public GluuCustomPerson copy(ScimPerson source, GluuCustomPerson destination, boolean isUpdate) throws Exception {
    if (source == null || !isValidData(source, isUpdate)) {
        return null;
    }
    if (destination == null) {
        log.trace(" creating a new GluuCustomPerson instant ");
        destination = new GluuCustomPerson();
    }
    if (isUpdate) {
        personService.addCustomObjectClass(destination);
        if (StringUtils.isNotEmpty(source.getUserName())) {
            log.trace(" setting userName ");
            destination.setUid(source.getUserName());
        }
        if (StringUtils.isNotEmpty(source.getName().getGivenName())) {
            log.trace(" setting givenname ");
            destination.setGivenName(source.getName().getGivenName());
        }
        if (StringUtils.isNotEmpty(source.getName().getFamilyName())) {
            log.trace(" setting familyname ");
            destination.setSurname(source.getName().getFamilyName());
        }
        if (StringUtils.isNotEmpty(source.getDisplayName())) {
            log.trace(" setting displayname ");
            destination.setDisplayName(source.getDisplayName());
        }
        setOrRemoveOptionalAttribute(destination, source.getName().getMiddleName(), OX_TRUST_MIDDLE_NAME);
        setOrRemoveOptionalAttribute(destination, source.getName().getHonorificPrefix(), OX_TRUSTHONORIFIC_PREFIX);
        setOrRemoveOptionalAttribute(destination, source.getName().getHonorificSuffix(), OX_TRUSTHONORIFIC_SUFFIX);
        setOrRemoveOptionalAttribute(destination, source.getExternalId(), OX_TRUST_EXTERNAL_ID);
        setOrRemoveOptionalAttribute(destination, source.getNickName(), OX_TRUST_NICK_NAME);
        setOrRemoveOptionalAttribute(destination, source.getProfileUrl(), OX_TRUST_PROFILE_URL);
        // setOrRemoveOptionalAttributeList(destination, source.getEmails(), OX_TRUST_EMAIL);
        if (source.getEmails() != null && source.getEmails().size() > 0) {
            /*
				List<ScimPersonEmails> emails = source.getEmails();

				// StringWriter listOfEmails = new StringWriter();
				// ObjectMapper mapper = new ObjectMapper();
				// mapper.writeValue(listOfEmails, emails);

				List<String> emailList = new ArrayList<String>();
				for (ScimPersonEmails email : emails) {
					emailList.add(Utils.getObjectMapper().writeValueAsString(email));
				}

				// destination.setAttribute("oxTrustEmail", listOfEmails.toString());
				destination.setAttribute(OX_TRUST_EMAIL, emailList.toArray(new String[]{}));
				*/
            setOrRemoveAttributeListValue(destination, source.getEmails(), OX_TRUST_EMAIL);
        }
        // setOrRemoveOptionalAttributeList(destination, source.getAddresses(), OX_TRUST_ADDRESSES);
        setOrRemoveAttributeListValue(destination, source.getAddresses(), OX_TRUST_ADDRESSES);
        // setOrRemoveOptionalAttributeList(destination, source.getPhoneNumbers(), OX_TRUST_PHONE_VALUE);
        setOrRemoveAttributeListValue(destination, source.getPhoneNumbers(), OX_TRUST_PHONE_VALUE);
        // setOrRemoveOptionalAttributeList(destination, source.getIms(), OX_TRUST_IMS_VALUE);
        setOrRemoveAttributeListValue(destination, source.getIms(), OX_TRUST_IMS_VALUE);
        // setOrRemoveOptionalAttributeList(destination, source.getPhotos(), OX_TRUST_PHOTOS);
        setOrRemoveAttributeListValue(destination, source.getPhotos(), OX_TRUST_PHOTOS);
        setOrRemoveOptionalAttribute(destination, source.getUserType(), OX_TRUST_USER_TYPE);
        setOrRemoveOptionalAttribute(destination, source.getTitle(), OX_TRUST_TITLE);
        if (source.getPreferredLanguage() != null && source.getPreferredLanguage().length() > 0) {
            destination.setPreferredLanguage(source.getPreferredLanguage());
        }
        setOrRemoveOptionalAttribute(destination, source.getLocale(), OX_TRUST_LOCALE);
        if (source.getTimezone() != null && source.getTimezone().length() > 0) {
            destination.setTimezone(source.getTimezone());
        }
        setOrRemoveOptionalAttribute(destination, source.getActive(), OX_TRUST_ACTIVE);
        if (StringUtils.isNotEmpty(source.getPassword())) {
            destination.setUserPassword(source.getPassword());
        }
        setGroups(source, destination);
        // setOrRemoveOptionalAttributeList(destination, source.getRoles(), OX_TRUST_ROLE);
        setOrRemoveAttributeListValue(destination, source.getRoles(), OX_TRUST_ROLE);
        // setOrRemoveOptionalAttributeList(destination, source.getEntitlements(), OX_TRUST_ENTITLEMENTS);
        setOrRemoveAttributeListValue(destination, source.getEntitlements(), OX_TRUST_ENTITLEMENTS);
        // setOrRemoveOptionalAttributeList(destination, source.getX509Certificates(), OX_TRUSTX509_CERTIFICATE);
        setOrRemoveAttributeListValue(destination, source.getX509Certificates(), OX_TRUSTX509_CERTIFICATE);
        setMetaData(source, destination);
        // getting customAttributes
        log.trace("getting custom attributes");
        if (source.getCustomAttributes() != null) {
            log.trace("source.getCustomAttributes() != null");
            log.trace("getting a list of ScimCustomAttributes");
            List<ScimCustomAttributes> customAttr = source.getCustomAttributes();
            log.trace("checking every attribute in the request");
            for (ScimCustomAttributes oneAttr : customAttr) {
                if (oneAttr == null) {
                    continue;
                }
                int countValues = oneAttr.getValues().size();
                if (countValues == 0) {
                    log.trace("setting a empty attribute");
                    destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), oneAttr.getValues().toArray(new String[0]));
                } else if (countValues == 1) {
                    log.trace("setting a single attribute");
                    destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), oneAttr.getValues().get(0));
                } else if (countValues > 1) {
                    log.trace("setting a multivalued attribute");
                    List<String> listOfAttr = oneAttr.getValues();
                    String[] AttrArray = new String[listOfAttr.size()];
                    int i = 0;
                    for (String oneValue : listOfAttr) {
                        if (oneValue != null && oneValue.length() > 0) {
                            log.trace("setting a value");
                            AttrArray[i] = oneValue;
                            i++;
                        }
                    }
                    log.trace("setting the list of multivalued attributes");
                    destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), AttrArray);
                }
            }
        }
    } else {
        try {
            if (personService.getPersonByUid(source.getUserName()) != null) {
                return null;
            }
            personService.addCustomObjectClass(destination);
            log.trace(" setting userName ");
            if (source.getUserName() != null && source.getUserName().length() > 0) {
                destination.setUid(source.getUserName());
            }
            log.trace(" setting givenname ");
            if (source.getName().getGivenName() != null && source.getName().getGivenName().length() > 0) {
                destination.setGivenName(source.getName().getGivenName());
            }
            log.trace(" setting famillyname ");
            if (source.getName().getFamilyName() != null && source.getName().getFamilyName().length() > 0) {
                destination.setSurname(source.getName().getFamilyName());
            }
            log.trace(" setting displayname ");
            if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
                destination.setDisplayName(source.getDisplayName());
            }
            setOrRemoveOptionalAttribute(destination, source.getName().getMiddleName(), OX_TRUST_MIDDLE_NAME);
            setOrRemoveOptionalAttribute(destination, source.getName().getHonorificPrefix(), OX_TRUSTHONORIFIC_PREFIX);
            setOrRemoveOptionalAttribute(destination, source.getName().getHonorificSuffix(), OX_TRUSTHONORIFIC_SUFFIX);
            setOrRemoveOptionalAttribute(destination, source.getExternalId(), OX_TRUST_EXTERNAL_ID);
            setOrRemoveOptionalAttribute(destination, source.getNickName(), OX_TRUST_NICK_NAME);
            setOrRemoveOptionalAttribute(destination, source.getProfileUrl(), OX_TRUST_PROFILE_URL);
            // setOrRemoveOptionalAttributeList(destination, source.getEmails(), OX_TRUST_EMAIL);
            if (source.getEmails() != null && source.getEmails().size() > 0) {
                /*
					List<ScimPersonEmails> emails = source.getEmails();

					// StringWriter listOfEmails = new StringWriter();
					// ObjectMapper mapper = new ObjectMapper();
					// mapper.writeValue(listOfEmails, emails);

					List<String> emailList = new ArrayList<String>();
					for (ScimPersonEmails email : emails) {
						emailList.add(Utils.getObjectMapper().writeValueAsString(email));
					}

					// destination.setAttribute("oxTrustEmail", listOfEmails.toString());
					destination.setAttribute(OX_TRUST_EMAIL, emailList.toArray(new String[]{}));
					*/
                setOrRemoveAttributeListValue(destination, source.getEmails(), OX_TRUST_EMAIL);
            }
            // setOrRemoveOptionalAttributeList(destination, source.getAddresses(), OX_TRUST_ADDRESSES);
            setOrRemoveAttributeListValue(destination, source.getAddresses(), OX_TRUST_ADDRESSES);
            // setOrRemoveOptionalAttributeList(destination, source.getPhoneNumbers(), OX_TRUST_PHONE_VALUE);
            setOrRemoveAttributeListValue(destination, source.getPhoneNumbers(), OX_TRUST_PHONE_VALUE);
            // setOrRemoveOptionalAttributeList(destination, source.getIms(), OX_TRUST_IMS_VALUE);
            setOrRemoveAttributeListValue(destination, source.getIms(), OX_TRUST_IMS_VALUE);
            // setOrRemoveOptionalAttributeList(destination, source.getPhotos(), OX_TRUST_PHOTOS);
            setOrRemoveAttributeListValue(destination, source.getPhotos(), OX_TRUST_PHOTOS);
            setOrRemoveOptionalAttribute(destination, source.getUserType(), OX_TRUST_USER_TYPE);
            setOrRemoveOptionalAttribute(destination, source.getTitle(), OX_TRUST_TITLE);
            if (source.getPreferredLanguage() != null && source.getPreferredLanguage().length() > 0) {
                destination.setPreferredLanguage(source.getPreferredLanguage());
            }
            setOrRemoveOptionalAttribute(destination, source.getLocale(), OX_TRUST_LOCALE);
            if (source.getTimezone() != null && source.getTimezone().length() > 0) {
                destination.setTimezone(source.getTimezone());
            }
            setOrRemoveOptionalAttribute(destination, source.getActive(), OX_TRUST_ACTIVE);
            if (source.getPassword() != null && source.getPassword().length() > 0) {
                destination.setUserPassword(source.getPassword());
            }
            setGroups(source, destination);
            // setOrRemoveOptionalAttributeList(destination, source.getRoles(), OX_TRUST_ROLE);
            setOrRemoveAttributeListValue(destination, source.getRoles(), OX_TRUST_ROLE);
            // setOrRemoveOptionalAttributeList(destination, source.getEntitlements(), OX_TRUST_ENTITLEMENTS);
            setOrRemoveAttributeListValue(destination, source.getEntitlements(), OX_TRUST_ENTITLEMENTS);
            // setOrRemoveOptionalAttributeList(destination, source.getX509Certificates(), OX_TRUSTX509_CERTIFICATE);
            setOrRemoveAttributeListValue(destination, source.getX509Certificates(), OX_TRUSTX509_CERTIFICATE);
            setMetaData(source, destination);
            // getting customAttributes
            log.trace("getting custom attributes");
            if (source.getCustomAttributes() != null && source.getCustomAttributes().size() > 0) {
                log.trace("source.getCustomAttributes() != null");
                log.trace("getting a list of ScimCustomAttributes");
                List<ScimCustomAttributes> customAttr = source.getCustomAttributes();
                log.trace("checking every attribute in the request");
                for (ScimCustomAttributes oneAttr : customAttr) {
                    if (oneAttr != null && oneAttr.getValues().size() == 1) {
                        log.trace("setting a single attribute");
                        destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), oneAttr.getValues().get(0));
                    } else if (oneAttr != null && oneAttr.getValues().size() > 1) {
                        log.trace("setting a multivalued attribute");
                        List<String> listOfAttr = oneAttr.getValues();
                        String[] AttrArray = new String[listOfAttr.size()];
                        int i = 0;
                        for (String oneValue : listOfAttr) {
                            if (oneValue != null && oneValue.length() > 0) {
                                log.trace("setting a value");
                                AttrArray[i] = oneValue;
                                i++;
                            }
                        }
                        log.trace("setting the list of multivalued attributes");
                        destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), AttrArray);
                    }
                }
            }
        } catch (Exception ex) {
            return null;
        }
    }
    setGluuStatus(source, destination);
    return destination;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) List(java.util.List) ArrayList(java.util.ArrayList) ScimCustomAttributes(org.gluu.oxtrust.model.scim.ScimCustomAttributes) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException)

Example 80 with GluuCustomPerson

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

the class OxChooserWebService method getUserByUid.

@Path("/AddUser/{uid}")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getUserByUid(@HeaderParam("Authorization") String authorization, @PathParam("uid") String uid) throws Exception {
    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        GluuCustomPerson gluuPerson = personService.getPersonByInum(uid);
        if (gluuPerson == null) {
            // sets HTTP status code 404 Not Found
            return getErrorResponse("Resource " + uid + " not found", Response.Status.NOT_FOUND.getStatusCode());
        }
        ScimPerson person = copyUtils.copy(gluuPerson, null);
        URI location = new URI("/oxChooser/AddUser/" + uid);
        return Response.ok(person).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Exception: ", ex);
        return getErrorResponse("Resource " + uid + " not found", Response.Status.NOT_FOUND.getStatusCode());
    } catch (Exception ex) {
        log.error("Exception: ", ex);
        return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
}
Also used : FetchResponse(org.openid4java.message.ax.FetchResponse) Response(javax.ws.rs.core.Response) IdentityResponse(org.gluu.oxtrust.model.oxchooser.IdentityResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ScimPerson(org.gluu.oxtrust.model.scim.ScimPerson) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) URI(java.net.URI) MessageException(org.openid4java.message.MessageException) ConsumerException(org.openid4java.consumer.ConsumerException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DiscoveryException(org.openid4java.discovery.DiscoveryException) AssociationException(org.openid4java.association.AssociationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)133 ArrayList (java.util.ArrayList)42 ScimPerson (org.gluu.oxtrust.model.scim.ScimPerson)27 Test (org.testng.annotations.Test)22 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)21 ConfigurableTest (org.gluu.oxtrust.action.test.ConfigurableTest)18 Produces (javax.ws.rs.Produces)17 Response (javax.ws.rs.core.Response)17 ScimPersonGroups (org.gluu.oxtrust.model.scim.ScimPersonGroups)14 ScimPersonIms (org.gluu.oxtrust.model.scim.ScimPersonIms)14 ScimPersonPhones (org.gluu.oxtrust.model.scim.ScimPersonPhones)14 ScimPersonPhotos (org.gluu.oxtrust.model.scim.ScimPersonPhotos)14 ScimRoles (org.gluu.oxtrust.model.scim.ScimRoles)14 PersonMeta (org.gluu.oxtrust.model.scim.PersonMeta)13 ScimEntitlements (org.gluu.oxtrust.model.scim.ScimEntitlements)13 ScimName (org.gluu.oxtrust.model.scim.ScimName)13 ScimPersonAddresses (org.gluu.oxtrust.model.scim.ScimPersonAddresses)13 ScimPersonEmails (org.gluu.oxtrust.model.scim.ScimPersonEmails)13 ScimCustomAttributes (org.gluu.oxtrust.model.scim.ScimCustomAttributes)12 Scimx509Certificates (org.gluu.oxtrust.model.scim.Scimx509Certificates)12