Search in sources :

Example 56 with GluuCustomPerson

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<>();
        for (String aMemberOf : memberOflist) {
            tempMemberOf.add(aMemberOf);
        }
        for (String oneMemberOf : tempMemberOf) {
            if (oneMemberOf.equalsIgnoreCase(dn)) {
                tempMemberOf.remove(oneMemberOf);
                break;
            }
        }
        List<String> cleanMemberOf = new ArrayList<>();
        for (String aMemberOf : tempMemberOf) {
            cleanMemberOf.add(aMemberOf);
        }
        gluuPerson.setMemberOf(cleanMemberOf);
        personService.updatePerson(gluuPerson);
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList)

Example 57 with GluuCustomPerson

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

the class GroupService method removeGroup.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.gluu.oxtrust.ldap.service.IGroupService#removeGroup(org.gluu.oxtrust.
	 * model.GluuGroup)
	 */
@Override
public void removeGroup(GluuGroup group) {
    if (group.getMembers() != null) {
        List<String> memberDNs = group.getMembers();
        for (String memberDN : memberDNs) {
            if (personService.contains(memberDN)) {
                GluuCustomPerson person = personService.getPersonByDn(memberDN);
                List<String> groupDNs = person.getMemberOf();
                List<String> updatedGroupDNs = new ArrayList<String>();
                updatedGroupDNs.addAll(groupDNs);
                updatedGroupDNs.remove(group.getDn());
                person.setMemberOf(updatedGroupDNs);
                try {
                    personService.updatePerson(person);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    persistenceEntryManager.remove(group);
// clear references in gluuPerson entries
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException)

Example 58 with GluuCustomPerson

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

the class PersonServiceTest method testGetPersonByUid.

@Test
@Parameters({ "person.uid" })
public void testGetPersonByUid(final String personUid) throws Exception {
    GluuCustomPerson person = personService.getPersonByUid(personUid);
    assertNotNull(person, "Failed to find person");
    assertEquals(person.getUid(), personUid);
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.gluu.oxtrust.action.BaseTest)

Example 59 with GluuCustomPerson

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

the class PeopleWebResource method getPersonByInum.

@GET
@Path(ApiConstants.INUM_PARAM_PATH)
@Operation(summary = "Get person by inum", description = "Get a person by inum")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = GluuPersonApi.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { READ_ACCESS })
public Response getPersonByInum(@PathParam(ApiConstants.INUM) @NotNull String inum) {
    log(logger, "Get person " + inum);
    try {
        Objects.requireNonNull(inum, "inum should not be null");
        GluuCustomPerson person = personService.getPersonByInum(inum);
        if (person != null) {
            return Response.ok(convert(Arrays.asList(person)).get(0)).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 60 with GluuCustomPerson

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

the class PeopleWebResource method copyAttributes.

private GluuCustomPerson copyAttributes(GluuPersonApi person) {
    GluuCustomPerson gluuCustomPerson = new GluuCustomPerson();
    gluuCustomPerson.setUid(person.getUserName());
    gluuCustomPerson.setInum(person.getInum());
    gluuCustomPerson.setGivenName(person.getGivenName());
    gluuCustomPerson.setMail(person.getEmail());
    gluuCustomPerson.setDisplayName(person.getDisplayName());
    gluuCustomPerson.setSurname(person.getSurName());
    gluuCustomPerson.setCreationDate(person.getCreationDate());
    gluuCustomPerson.setStatus(person.getStatus().getValue());
    gluuCustomPerson.setUserPassword(person.getPassword());
    gluuCustomPerson.setAttribute("oxTrustActive", "true");
    return gluuCustomPerson;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson)

Aggregations

GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)133 ArrayList (java.util.ArrayList)42 ScimPerson (org.gluu.oxtrust.model.scim.ScimPerson)27 Test (org.testng.annotations.Test)22 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)21 ConfigurableTest (org.gluu.oxtrust.action.test.ConfigurableTest)18 Produces (javax.ws.rs.Produces)17 Response (javax.ws.rs.core.Response)17 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 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 ScimCustomAttributes (org.gluu.oxtrust.model.scim.ScimCustomAttributes)12 Scimx509Certificates (org.gluu.oxtrust.model.scim.Scimx509Certificates)12