use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class ServiceUtil method deleteGroupFromPerson.
/**
* Delete a Group from a Person
*
* @return void
* @throws Exception
*/
public void deleteGroupFromPerson(GluuGroup group, String dn) throws Exception {
List<String> persons = group.getMembers();
for (String onePerson : persons) {
GluuCustomPerson gluuPerson = personService.getPersonByDn(onePerson);
List<String> memberOflist = gluuPerson.getMemberOf();
List<String> tempMemberOf = new ArrayList<String>();
for (String aMemberOf : memberOflist) {
tempMemberOf.add(aMemberOf);
}
for (String oneMemberOf : tempMemberOf) {
if (oneMemberOf.equalsIgnoreCase(dn)) {
tempMemberOf.remove(oneMemberOf);
break;
}
}
List<String> cleanMemberOf = new ArrayList<String>();
for (String aMemberOf : tempMemberOf) {
cleanMemberOf.add(aMemberOf);
}
gluuPerson.setMemberOf(cleanMemberOf);
personService.updatePerson(gluuPerson);
}
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class UserWebService method deleteUser.
@Path("{id}")
@DELETE
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@ApiOperation(value = "Delete User", notes = "Delete User (https://tools.ietf.org/html/rfc7644#section-3.6)")
public Response deleteUser(@PathParam("id") String id) {
Response response;
try {
log.debug("Executing web service method. deleteUser");
// person cannot be null (check associated decorator method)
GluuCustomPerson person = personService.getPersonByInum(id);
scim2UserService.deleteUser(person);
response = Response.noContent().build();
} catch (Exception e) {
log.error("Failure at deleteUser method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class Scim2GroupService method transferAttributesToGroupResource.
public void transferAttributesToGroupResource(GluuGroup gluuGroup, GroupResource res, String groupsUrl, String usersUrl) {
res.setId(gluuGroup.getInum());
Meta meta = new Meta();
meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
meta.setCreated(gluuGroup.getAttribute("oxTrustMetaCreated"));
meta.setLastModified(gluuGroup.getAttribute("oxTrustMetaLastModified"));
meta.setLocation(gluuGroup.getAttribute("oxTrustMetaLocation"));
if (meta.getLocation() == null)
meta.setLocation(groupsUrl + "/" + gluuGroup.getInum());
res.setMeta(meta);
res.setDisplayName(gluuGroup.getDisplayName());
// Transfer members from GluuGroup to GroupResource
List<String> memberDNs = gluuGroup.getMembers();
if (memberDNs != null) {
Set<Member> members = new HashSet<Member>();
for (String dn : memberDNs) {
GluuCustomPerson person = null;
try {
person = personService.getPersonByDn(dn);
} catch (Exception e) {
log.warn("Wrong member entry {} found in group {}", dn, gluuGroup.getDisplayName());
}
if (person != null) {
Member aMember = new Member();
aMember.setValue(person.getInum());
aMember.setRef(usersUrl + "/" + person.getInum());
aMember.setType(ScimResourceUtil.getType(UserResource.class));
aMember.setDisplay(person.getDisplayName());
members.add(aMember);
}
}
res.setMembers(members);
}
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class Scim2GroupService method syncMemberAttributeInPerson.
private void syncMemberAttributeInPerson(String groupDn, List<String> beforeMemberDns, List<String> afterMemberDns) {
log.debug("syncMemberAttributeInPerson. Updating memberOf attribute in user LDAP entries");
log.trace("Before member dns {}; After member dns {}", beforeMemberDns, afterMemberDns);
// Build 2 sets of DNs
Set<String> before = new HashSet<String>();
if (beforeMemberDns != null)
before.addAll(beforeMemberDns);
Set<String> after = new HashSet<String>();
if (afterMemberDns != null)
after.addAll(afterMemberDns);
// Do removals
for (String dn : before) {
if (!after.contains(dn)) {
try {
GluuCustomPerson gluuPerson = personService.getPersonByDn(dn);
List<String> memberOf = new ArrayList<String>();
memberOf.addAll(gluuPerson.getMemberOf());
memberOf.remove(groupDn);
gluuPerson.setMemberOf(memberOf);
personService.updatePerson(gluuPerson);
} catch (Exception e) {
log.error("An error occurred while removing user {} from group {}", dn, groupDn);
log.error(e.getMessage(), e);
}
}
}
// Do insertions
for (String dn : after) {
if (!before.contains(dn)) {
try {
GluuCustomPerson gluuPerson = personService.getPersonByDn(dn);
List<String> memberOf = new ArrayList<String>();
memberOf.add(groupDn);
if (gluuPerson.getMemberOf() != null)
memberOf.addAll(gluuPerson.getMemberOf());
gluuPerson.setMemberOf(memberOf);
personService.updatePerson(gluuPerson);
} catch (Exception e) {
log.error("An error occurred while adding user {} to group {}", dn, groupDn);
log.error(e.getMessage(), e);
}
}
}
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class Scim2UserService method updateUser.
public UserResource updateUser(String id, UserResource user, String url) throws InvalidAttributeValueException {
// This is never null (see decorator involved)
GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
UserResource tmpUser = new UserResource();
transferAttributesToUserResource(gluuPerson, tmpUser, url);
long now = System.currentTimeMillis();
tmpUser.getMeta().setLastModified(ISODateTimeFormat.dateTime().withZoneUTC().print(now));
tmpUser = (UserResource) ScimResourceUtil.transferToResourceReplace(user, tmpUser, extService.getResourceExtensions(user.getClass()));
replacePersonInfo(gluuPerson, tmpUser, url);
return tmpUser;
}
Aggregations