Search in sources :

Example 31 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException 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)

Example 32 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.

the class UserWebService method updateUser.

@Path("{id}")
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateUser(@HeaderParam("Authorization") String authorization, @PathParam("id") String id, ScimPerson person) 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 {
            // Validate if attempting to update userName of a different id
            if (person.getUserName() != null) {
                GluuCustomPerson personToFind = new GluuCustomPerson();
                personToFind.setUid(person.getUserName());
                List<GluuCustomPerson> foundPersons = personService.findPersons(personToFind, 2);
                if (foundPersons != null && foundPersons.size() > 0) {
                    for (GluuCustomPerson foundPerson : foundPersons) {
                        if (foundPerson != null && !foundPerson.getInum().equalsIgnoreCase(gluuPerson.getInum())) {
                            throw new DuplicateEntryException("Cannot update userName of a different id: " + person.getUserName());
                        }
                    }
                }
            }
        }
        GluuCustomPerson newGluuPerson = copyUtils.copy(person, gluuPerson, true);
        if (person.getGroups().size() > 0) {
            serviceUtil.groupMembersAdder(newGluuPerson, personService.getDnForPerson(id));
        }
        // Sync email, forward ("oxTrustEmail" -> "mail")
        newGluuPerson = ServiceUtil.syncEmailForward(newGluuPerson, false);
        // For custom script: update user
        if (externalScimService.isEnabled()) {
            externalScimService.executeScimUpdateUserMethods(newGluuPerson);
        }
        personService.updatePerson(newGluuPerson);
        log.debug(" person updated ");
        ScimPerson newPerson = copyUtils.copy(newGluuPerson, null);
        // person_update = copyUtils.copy(gluuPerson, null, attributes);
        URI location = new URI("/Users/" + id);
        return Response.ok(newPerson).location(location).build();
    } catch (EntryPersistenceException ex) {
        ex.printStackTrace();
        return getErrorResponse("Resource " + id + " not found", Response.Status.NOT_FOUND.getStatusCode());
    } catch (DuplicateEntryException ex) {
        log.error("Failed to update user", ex);
        ex.printStackTrace();
        return getErrorResponse(ex.getMessage(), Response.Status.BAD_REQUEST.getStatusCode());
    } catch (Exception ex) {
        log.error("Failed to update user", 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) ScimPerson(org.gluu.oxtrust.model.scim.ScimPerson) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) URI(java.net.URI) 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) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 33 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.

the class UserWebService method getUserByUid.

@Path("{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("/Users/" + uid);
        return Response.ok(person).location(location).build();
    } catch (EntryPersistenceException ex) {
        ex.printStackTrace();
        return getErrorResponse("Resource " + uid + " 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) ScimPerson(org.gluu.oxtrust.model.scim.ScimPerson) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) URI(java.net.URI) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 34 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxAuth by GluuFederation.

the class UmaValidationService method validateResourceSet.

public void validateResourceSet(UmaPermission resourceSetPermissionRequest) {
    String resourceSetId = resourceSetPermissionRequest.getResourceSetId();
    if (StringHelper.isEmpty(resourceSetId)) {
        log.error("Resource set id is empty");
        throw new WebApplicationException(Response.status(BAD_REQUEST).entity(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.INVALID_RESOURCE_SET_ID)).build());
    }
    ResourceSet resourceSet;
    try {
        ResourceSet exampleResourceSet = new ResourceSet();
        exampleResourceSet.setDn(resourceSetService.getBaseDnForResourceSet());
        exampleResourceSet.setId(resourceSetId);
        List<ResourceSet> resourceSets = resourceSetService.findResourceSets(exampleResourceSet);
        if (resourceSets.size() != 1) {
            log.error("Resource set isn't registered or there are two resource set with same Id");
            throw new WebApplicationException(Response.status(BAD_REQUEST).entity(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.INVALID_RESOURCE_SET_ID)).build());
        }
        resourceSet = resourceSets.get(0);
    } catch (EntryPersistenceException ex) {
        log.error("Resource set isn't registered");
        throw new WebApplicationException(Response.status(BAD_REQUEST).entity(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.INVALID_RESOURCE_SET_ID)).build());
    }
    final List<String> scopeUrls = umaScopeService.getScopeUrlsByDns(resourceSet.getScopes());
    if (!scopeUrls.containsAll(resourceSetPermissionRequest.getScopes())) {
        log.error("At least one of the scope isn't registered");
        throw new WebApplicationException(Response.status(BAD_REQUEST).entity(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.INVALID_RESOURCE_SET_SCOPE)).build());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) ResourceSet(org.xdi.oxauth.model.uma.persistence.ResourceSet)

Example 35 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxAuth by GluuFederation.

the class CleanUpClientTest method cleanUpClient.

@Test
@Parameters(value = "usedClients")
public void cleanUpClient(String usedClients) {
    Assert.assertNotNull(usedClients);
    List<String> usedClientsList = Arrays.asList(StringHelper.split(usedClients, ",", true, false));
    output("Used clients: " + usedClientsList);
    int clientsResultSetSize = 50;
    int countResults = 0;
    int countRemoved = 0;
    boolean existsMoreClients = true;
    while (existsMoreClients && countResults < 10000) {
        List<Client> clients = clientService.getAllClients(new String[] { "inum" }, clientsResultSetSize);
        existsMoreClients = clients.size() == clientsResultSetSize;
        countResults += clients.size();
        Assert.assertNotNull(clients);
        output("Found clients: " + clients.size());
        output("Total clients: " + countResults);
        for (Client client : clients) {
            String clientId = client.getClientId();
            if (!usedClientsList.contains(clientId)) {
                try {
                    clientService.remove(client);
                } catch (EntryPersistenceException ex) {
                    output("Failed to remove client: " + ex.getMessage());
                }
                countRemoved++;
            }
        }
    }
    output("Removed clients: " + countRemoved);
}
Also used : EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) Client(org.xdi.oxauth.model.registration.Client) Parameters(org.testng.annotations.Parameters) BaseComponentTest(org.xdi.oxauth.BaseComponentTest) Test(org.testng.annotations.Test)

Aggregations

EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)51 Response (javax.ws.rs.core.Response)20 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)20 Path (javax.ws.rs.Path)19 Produces (javax.ws.rs.Produces)19 URI (java.net.URI)17 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)15 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)12 EmptyEntryPersistenceException (org.gluu.site.ldap.persistence.exception.EmptyEntryPersistenceException)11 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)9 DefaultValue (javax.ws.rs.DefaultValue)9 HeaderParam (javax.ws.rs.HeaderParam)9 GluuGroup (org.gluu.oxtrust.model.GluuGroup)9 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)9 MappingException (org.gluu.site.ldap.persistence.exception.MappingException)9 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)8 ParseException (java.text.ParseException)8 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)8 ConnectionException (org.gluu.site.ldap.exception.ConnectionException)8 AuthenticationException (org.gluu.site.ldap.persistence.exception.AuthenticationException)8