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());
}
}
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());
}
}
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());
}
}
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());
}
}
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);
}
Aggregations