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