Search in sources :

Example 31 with GluuCustomPerson

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

the class ConfigureCacheRefreshAction method validateInterceptorScript.

public void validateInterceptorScript() {
    String result = update();
    if (!OxTrustConstants.RESULT_SUCCESS.equals(result)) {
        return;
    }
    // Reinit dialog
    init();
    this.showInterceptorValidationDialog = true;
    boolean loadedScripts = externalCacheRefreshService.getCustomScriptConfigurations().size() > 0;
    if (!loadedScripts) {
        String message = "Can't load Cache Refresh scripts. Using default script";
        log.error(message);
        this.interceptorValidationMessage = message;
        return;
    }
    // Prepare data for dummy entry
    String targetInum = inumService.generateInums(OxTrustConstants.INUM_TYPE_PEOPLE_SLUG, false);
    String targetPersonDn = personService.getDnForPerson(targetInum);
    String[] targetCustomObjectClasses = appConfiguration.getPersonObjectClassTypes();
    // Collect all attributes
    String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
    String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
    // Merge all attributes into one set
    Set<String> allAttributes = new HashSet<String>();
    for (String attribute : keyAttributesWithoutValues) {
        allAttributes.add(attribute);
    }
    for (String attribute : sourceAttributes) {
        allAttributes.add(attribute);
    }
    // Prepare source person entry with default attributes values
    GluuSimplePerson sourcePerson = new GluuSimplePerson();
    List<GluuCustomAttribute> customAttributes = sourcePerson.getCustomAttributes();
    for (String attribute : allAttributes) {
        customAttributes.add(new GluuCustomAttribute(attribute, "Test value"));
    }
    // Prepare target person
    GluuCustomPerson targetPerson = new GluuCustomPerson();
    targetPerson.setDn(targetPersonDn);
    targetPerson.setInum(targetInum);
    targetPerson.setStatus(GluuStatus.ACTIVE);
    targetPerson.setCustomObjectClasses(targetCustomObjectClasses);
    // Execute mapping according to configuration
    Map<String, String> targetServerAttributesMapping = getTargetServerAttributesMapping(cacheRefreshConfiguration);
    cacheRefreshService.setTargetEntryAttributes(sourcePerson, targetServerAttributesMapping, targetPerson);
    // Execute interceptor script
    boolean executionResult = externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
    if (!executionResult) {
        String message = "Can't execute Cache Refresh scripts.";
        log.error(message);
        this.interceptorValidationMessage = message;
        return;
    }
    log.info("Script has been executed successfully.\n\nSample source entry is:\n'{}'.\n\nSample result entry is:\n'{}'", getGluuSimplePersonAttributesWithValues(sourcePerson), getGluuCustomPersonAttributesWithValues(targetPerson));
    this.interceptorValidationMessage = String.format("Script has been executed successfully.\n\nSample source entry is:\n%s.\n\nSample result entry is:\n%s", getGluuSimplePersonAttributesWithValues(sourcePerson), getGluuCustomPersonAttributesWithValues(targetPerson));
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) HashSet(java.util.HashSet)

Example 32 with GluuCustomPerson

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

the class RegisterPersonAction method register.

public String register() throws CloneNotSupportedException {
    boolean registrationFormValid = StringHelper.equals(password, repeatPassword);
    if (!captchaDisabled) {
        boolean reCaptchaResponse = recaptchaService.verifyRecaptchaResponse();
        registrationFormValid &= reCaptchaResponse;
    }
    if (registrationFormValid) {
        GluuCustomPerson archivedPerson = (GluuCustomPerson) person.clone();
        String customObjectClass = attributeService.getCustomOrigin();
        this.person.setCustomObjectClasses(new String[] { customObjectClass });
        // Save person
        if (person.getInum() == null) {
            String inum = personService.generateInumForNewPerson();
            this.person.setInum(inum);
        }
        if (person.getIname() == null) {
            String iname = personService.generateInameForNewPerson(this.person.getUid());
            this.person.setIname(iname);
        }
        if (person.getDn() == null) {
            String dn = personService.getDnForPerson(this.person.getInum());
            this.person.setDn(dn);
        }
        List<GluuCustomAttribute> personAttributes = this.person.getCustomAttributes();
        if (!personAttributes.contains(new GluuCustomAttribute("cn", ""))) {
            List<GluuCustomAttribute> changedAttributes = new ArrayList<GluuCustomAttribute>();
            changedAttributes.addAll(personAttributes);
            changedAttributes.add(new GluuCustomAttribute("cn", this.person.getGivenName() + " " + this.person.getSurname()));
            this.person.setCustomAttributes(changedAttributes);
        } else {
            this.person.setCommonName(this.person.getCommonName());
        }
        // save password
        this.person.setUserPassword(password);
        this.person.setCreationDate(new Date());
        this.person.setMail(email);
        try {
            // Set default message
            this.postRegistrationInformation = "You have successfully registered with oxTrust. Login to begin your session.";
            boolean result = externalUserRegistrationService.executeExternalPreRegistrationMethods(this.person, requestParameters);
            if (!result) {
                this.person = archivedPerson;
                return OxTrustConstants.RESULT_FAILURE;
            }
            if (this.inum != null) {
                personService.updatePerson(this.person);
            } else {
                personService.addPerson(this.person);
            }
            result = externalUserRegistrationService.executeExternalPostRegistrationMethods(this.person, requestParameters);
            if (!result) {
                this.person = archivedPerson;
                return OxTrustConstants.RESULT_FAILURE;
            }
        } catch (Exception ex) {
            log.error("Failed to add new person {}", ex, this.person.getInum());
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to add new person");
            this.person = archivedPerson;
            return OxTrustConstants.RESULT_FAILURE;
        }
        return OxTrustConstants.RESULT_SUCCESS;
    }
    return OxTrustConstants.RESULT_CAPTCHA_VALIDATION_FAILED;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList) Date(java.util.Date) ValidatorException(javax.faces.validator.ValidatorException)

Example 33 with GluuCustomPerson

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

the class CacheRefreshTimer method validateTargetServerSchema.

private boolean validateTargetServerSchema(CacheRefreshConfiguration cacheRefreshConfiguration, Map<String, String> targetServerAttributesMapping, String[] customObjectClasses) {
    // Get list of return attributes
    String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
    String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
    String[] returnAttributes = ArrayHelper.arrayMerge(keyAttributesWithoutValues, sourceAttributes);
    GluuSimplePerson sourcePerson = new GluuSimplePerson();
    for (String returnAttribute : returnAttributes) {
        sourcePerson.setAttribute(returnAttribute, "Test");
    }
    String targetInum = inumService.generateInums(OxTrustConstants.INUM_TYPE_PEOPLE_SLUG, false);
    String targetPersonDn = personService.getDnForPerson(targetInum);
    GluuCustomPerson targetPerson = new GluuCustomPerson();
    targetPerson.setDn(targetPersonDn);
    targetPerson.setInum(targetInum);
    targetPerson.setStatus(GluuStatus.ACTIVE);
    targetPerson.setCustomObjectClasses(customObjectClasses);
    // Update list of return attributes according mapping
    cacheRefreshService.setTargetEntryAttributes(sourcePerson, targetServerAttributesMapping, targetPerson);
    // Execute interceptor script
    externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
    boolean executionResult = externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
    if (!executionResult) {
        log.error("Failed to execute Cache Refresh scripts for person '{}'", targetInum);
        return false;
    }
    // Validate target server attributes
    List<GluuCustomAttribute> customAttributes = targetPerson.getCustomAttributes();
    List<String> targetAttributes = new ArrayList<String>(customAttributes.size());
    for (GluuCustomAttribute customAttribute : customAttributes) {
        targetAttributes.add(customAttribute.getName());
    }
    List<String> targetObjectClasses = Arrays.asList(ldapEntryManager.getObjectClasses(targetPerson, GluuCustomPerson.class));
    return validateTargetServerSchema(targetObjectClasses, targetAttributes);
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList)

Example 34 with GluuCustomPerson

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

the class Scim2UserService method removeUserPatch.

private void removeUserPatch(Operation operation, String id) throws Exception {
    User user = operation.getValue();
    GluuCustomPerson updatedGluuPerson = patchUtil.removePatch(user, validUsernameByInum(user, id));
    log.info(" Setting meta: removeUserPatch update user ");
    setMeta(updatedGluuPerson);
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser)

Example 35 with GluuCustomPerson

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

the class Scim2UserService method validUsernameByInum.

private GluuCustomPerson validUsernameByInum(User user, String id) throws DuplicateEntryException {
    GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
    if (gluuPerson == null) {
        throw new EntryPersistenceException("Scim2UserService.updateUser(): " + "Resource " + id + " not found");
    } else {
        // Validate if attempting to update userName of a different id
        if (user.getUserName() != null) {
            GluuCustomPerson personToFind = new GluuCustomPerson();
            personToFind.setUid(user.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: " + user.getUserName());
                    }
                }
            }
        }
    }
    return gluuPerson;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException)

Aggregations

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