Search in sources :

Example 11 with GluuCustomPerson

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

the class OxChooserWebService method addUser.

@Path("/AddUser")
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response addUser(@HeaderParam("Authorization") String authorization, ScimPerson person) throws Exception {
    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    // Return HTTP response with status code 201 Created
    log.debug(" copying gluuperson ");
    GluuCustomPerson gluuPerson = copyUtils.copy(person, null, false);
    if (gluuPerson == null) {
        return getErrorResponse("Failed to create user", Response.Status.BAD_REQUEST.getStatusCode());
    }
    try {
        log.debug(" generating inum ");
        String inum = personService.generateInumForNewPerson();
        log.debug(" getting DN ");
        String dn = personService.getDnForPerson(inum);
        log.debug(" getting iname ");
        String iname = personService.generateInameForNewPerson(person.getUserName());
        log.debug(" setting dn ");
        gluuPerson.setDn(dn);
        log.debug(" setting inum ");
        gluuPerson.setInum(inum);
        log.debug(" setting iname ");
        gluuPerson.setIname(iname);
        log.debug(" setting commonName ");
        gluuPerson.setCommonName(gluuPerson.getGivenName() + " " + gluuPerson.getSurname());
        log.info("gluuPerson.getMemberOf().size() : " + gluuPerson.getMemberOf().size());
        if (person.getGroups().size() > 0) {
            log.info(" jumping to groupMembersAdder ");
            log.info("gluuPerson.getDn() : " + gluuPerson.getDn());
            serviceUtil.groupMembersAdder(gluuPerson, gluuPerson.getDn());
        }
        log.debug("adding new GluuPerson");
        personService.addPerson(gluuPerson);
        final ScimPerson newPerson = copyUtils.copy(gluuPerson, null);
        String uri = "/oxChooser/AddUser/" + newPerson.getId();
        return Response.created(URI.create(uri)).entity(newPerson).build();
    } catch (Exception ex) {
        log.error("Failed to add user", 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) 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) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 12 with GluuCustomPerson

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

the class OxChooserWebService method editUser.

@Path("/EditUser/{email}")
@GET
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response editUser(@HeaderParam("Authorization") String authorization, @PathParam("email") String email, ScimPerson person_update) throws Exception {
    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        GluuCustomPerson gluuPerson = personService.getPersonByEmail(email);
        if (gluuPerson == null) {
            return getErrorResponse("Resource " + email + " not found", Response.Status.NOT_FOUND.getStatusCode());
        }
        GluuCustomPerson newGluuPesron = copyUtils.copy(person_update, gluuPerson, true);
        if (person_update.getGroups().size() > 0) {
            serviceUtil.groupMembersAdder(newGluuPesron, personService.getDnForPerson(gluuPerson.getUid()));
        }
        personService.updatePerson(newGluuPesron);
        log.debug(" person updated ");
        ScimPerson newPerson = copyUtils.copy(newGluuPesron, null);
        URI location = new URI("/oxChooser/AddUser/" + gluuPerson.getUid());
        return Response.ok(newPerson).location(location).build();
    } catch (EntryPersistenceException ex) {
        return getErrorResponse("Resource " + email + " not found", Response.Status.NOT_FOUND.getStatusCode());
    } catch (Exception ex) {
        log.error("Exception: ", ex);
        ex.printStackTrace();
        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) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with GluuCustomPerson

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

the class OxChooserWebService method clientIdentification.

@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response clientIdentification(InitialID id) throws DiscoveryException, Exception {
    try {
        if (personService.authenticate(id.getUserID(), id.getPassWord())) {
            GluuCustomPerson user = personService.getPersonByUid(id.getUserID());
            postLogin(user);
            return Response.ok().build();
        } else {
            return Response.status(401).entity("Not Authorized").build();
        }
    } catch (Exception ex) {
        log.error("an error occured", ex);
        return Response.status(401).entity("Not Authorized").build();
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) 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) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 14 with GluuCustomPerson

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

the class UserWebService method deleteUser.

@Path("{id}")
@DELETE
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteUser(@HeaderParam("Authorization") String authorization, @PathParam("id") String id) throws Exception {
    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
        if (gluuPerson == null) {
            return getErrorResponse("Resource " + id + " not found", Response.Status.NOT_FOUND.getStatusCode());
        } else {
            // For custom script: delete user
            if (externalScimService.isEnabled()) {
                externalScimService.executeScimDeleteUserMethods(gluuPerson);
            }
            log.info("person.getMemberOf().size() : " + gluuPerson.getMemberOf().size());
            if (gluuPerson.getMemberOf() != null) {
                if (gluuPerson.getMemberOf().size() > 0) {
                    String dn = personService.getDnForPerson(id);
                    log.info("DN : " + dn);
                    serviceUtil.deleteUserFromGroup(gluuPerson, dn);
                }
            }
            memberService.removePerson(gluuPerson);
        }
        return Response.ok().build();
    } catch (EntryPersistenceException ex) {
        ex.printStackTrace();
        return getErrorResponse("Resource " + id + " not found", Response.Status.NOT_FOUND.getStatusCode());
    } catch (Exception ex) {
        ex.printStackTrace();
        return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) Response(javax.ws.rs.core.Response) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 15 with GluuCustomPerson

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

the class ServiceUtil method personMembersAdder.

/**
	 * Adds a group to a person's memberOf
	 * 
	 * @return void
	 * @throws Exception
	 */
public void personMembersAdder(GluuGroup gluuGroup, String dn) throws Exception {
    List<String> members = gluuGroup.getMembers();
    for (String member : members) {
        GluuCustomPerson gluuPerson = personService.getPersonByDn(member);
        List<String> groups = gluuPerson.getMemberOf();
        if (!isMemberOfExist(groups, dn)) {
            List<String> cleanGroups = new ArrayList<String>();
            cleanGroups.add(dn);
            for (String aGroup : groups) {
                cleanGroups.add(aGroup);
            }
            gluuPerson.setMemberOf(cleanGroups);
            personService.updatePerson(gluuPerson);
        }
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList)

Aggregations

GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)98 ArrayList (java.util.ArrayList)34 ScimPerson (org.gluu.oxtrust.model.scim.ScimPerson)27 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)25 Test (org.testng.annotations.Test)22 ConfigurableTest (org.gluu.oxtrust.action.test.ConfigurableTest)18 Produces (javax.ws.rs.Produces)15 Response (javax.ws.rs.core.Response)14 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 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)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 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)12