Search in sources :

Example 86 with GluuCustomPerson

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

the class PatchUtil method replacePatch.

public GluuCustomPerson replacePatch(User source, GluuCustomPerson destination) throws Exception {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        log.trace(" creating a new GluuCustomPerson instant ");
        destination = new GluuCustomPerson();
    }
    log.trace(" setting schemas ");
    destination.setSchemas(source.getSchemas());
    personService.addCustomObjectClass(destination);
    log.trace(" setting userName ");
    if (source.getUserName() != null && source.getUserName().length() > 0) {
        destination.setUid(source.getUserName());
    }
    if (source.getName() != null) {
        log.trace(" setting givenname ");
        if (source.getName().getGivenName() != null && source.getName().getGivenName().length() > 0) {
            destination.setGivenName(source.getName().getGivenName());
        }
        log.trace(" setting famillyname ");
        if (source.getName().getFamilyName() != null && source.getName().getFamilyName().length() > 0) {
            destination.setSurname(source.getName().getFamilyName());
        }
        log.trace(" setting middlename ");
        if (source.getName().getMiddleName() != null && source.getName().getMiddleName().length() > 0) {
            // destination.setAttribute("oxTrustMiddleName",
            // source.getName().getMiddleName());
            destination.setAttribute("middleName", source.getName().getMiddleName());
        }
        log.trace(" setting honor");
        if (source.getName().getHonorificPrefix() != null && source.getName().getHonorificPrefix().length() > 0) {
            destination.setAttribute("oxTrusthonorificPrefix", source.getName().getHonorificPrefix());
        }
        if (source.getName().getHonorificSuffix() != null && source.getName().getHonorificSuffix().length() > 0) {
            destination.setAttribute("oxTrusthonorificSuffix", source.getName().getHonorificSuffix());
        }
    }
    log.trace(" setting displayname ");
    if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
        destination.setDisplayName(source.getDisplayName());
    }
    log.trace(" setting externalID ");
    if (source.getExternalId() != null && source.getExternalId().length() > 0) {
        destination.setAttribute("oxTrustExternalId", source.getExternalId());
    }
    log.trace(" setting nickname ");
    if (source.getNickName() != null && source.getNickName().length() > 0) {
        // destination.setAttribute("oxTrustNickName",
        // source.getNickName());
        destination.setAttribute("nickname", source.getNickName());
    }
    log.trace(" setting profileURL ");
    if (source.getProfileUrl() != null && source.getProfileUrl().length() > 0) {
        destination.setAttribute("oxTrustProfileURL", source.getProfileUrl());
    }
    // getting emails
    log.trace(" setting emails ");
    if (source.getEmails() != null && source.getEmails().size() > 0) {
        List<Email> emails = copyUtils2.getAttributeListValue(destination, Email.class, "oxTrustEmail");
        if (emails != null) {
            List<Email> newemails = source.getEmails();
            for (Email email : emails) {
                if (email != null && email.getType() != null) {
                    for (Email newEmail : newemails) {
                        if ((newEmail.getType() != null) && newEmail.getType().getValue().equals(email.getType().getValue())) {
                            emails.remove(email);
                            emails.add(newEmail);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, emails, "oxTrustEmail");
        }
    }
    // getting addresses
    log.trace(" setting addresses ");
    if (source.getAddresses() != null && source.getAddresses().size() > 0) {
        List<Address> addresses = copyUtils2.getAttributeListValue(destination, Address.class, "oxTrustAddresses");
        if (addresses != null) {
            List<Address> newaddresses = source.getAddresses();
            for (Address address : addresses) {
                if (address != null && address.getType() != null) {
                    for (Address newAddress : newaddresses) {
                        if ((newAddress.getType() != null) && newAddress.getType().getValue().equals(address.getType().getValue())) {
                            addresses.remove(address);
                            addresses.add(newAddress);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, addresses, "oxTrustAddresses");
        }
    }
    // getting phone numbers;
    log.trace(" setting phoneNumbers ");
    if (source.getPhoneNumbers() != null && source.getPhoneNumbers().size() > 0) {
        List<PhoneNumber> phoneNumbers = copyUtils2.getAttributeListValue(destination, PhoneNumber.class, "oxTrustPhoneValue");
        if (phoneNumbers != null) {
            List<PhoneNumber> newPhoneNumbers = source.getPhoneNumbers();
            for (PhoneNumber phoneNumber : phoneNumbers) {
                if (phoneNumber != null && phoneNumber.getType() != null) {
                    for (PhoneNumber newPhoneNumber : newPhoneNumbers) {
                        if ((newPhoneNumber.getType() != null) && (phoneNumber.getType().getValue() != null) && newPhoneNumber.getType().getValue().equals(phoneNumber.getType().getValue())) {
                            phoneNumbers.remove(phoneNumber);
                            phoneNumbers.add(newPhoneNumber);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, phoneNumbers, "oxTrustPhoneValue");
        }
    }
    // getting ims
    log.trace(" setting ims ");
    if (source.getIms() != null && source.getIms().size() > 0) {
        List<Im> ims = copyUtils2.getAttributeListValue(destination, Im.class, "oxTrustImsValue");
        if (ims != null && ims.size() > 0) {
            List<Im> newims = source.getIms();
            for (Im im : ims) {
                if (im != null && im.getType() != null) {
                    for (Im newIm : newims) {
                        if (newIm.getType() != null && newIm.getType().getValue().equals(im.getType().getValue())) {
                            ims.remove(im);
                            ims.add(newIm);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, ims, "oxTrustImsValue");
        }
    }
    // getting Photos
    log.trace(" setting photos ");
    if (source.getPhotos() != null && source.getPhotos().size() > 0) {
        List<Photo> photos = copyUtils2.getAttributeListValue(destination, Photo.class, "oxTrustPhotos");
        if (photos != null && photos.size() > 0) {
            List<Photo> newPhotos = source.getPhotos();
            for (Photo photo : photos) {
                if (photo != null && photo.getType() != null) {
                    for (Photo newPhoto : newPhotos) {
                        if (newPhoto.getType() != null && newPhoto.getType().getValue().equals(photo.getType().getValue())) {
                            photos.remove(photo);
                            photos.add(newPhoto);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, photos, "oxTrustPhotos");
        }
    }
    if (source.getUserType() != null && source.getUserType().length() > 0) {
        destination.setAttribute("oxTrustUserType", source.getUserType());
    }
    if (source.getTitle() != null && source.getTitle().length() > 0) {
        destination.setAttribute("oxTrustTitle", source.getTitle());
    }
    if (source.getPreferredLanguage() != null && source.getPreferredLanguage().length() > 0) {
        destination.setPreferredLanguage(source.getPreferredLanguage());
    }
    if (source.getLocale() != null && source.getLocale().length() > 0) {
        // destination.setAttribute("oxTrustLocale", source.getLocale());
        destination.setAttribute("locale", source.getLocale());
    }
    if (source.getTimezone() != null && source.getTimezone().length() > 0) {
        destination.setTimezone(source.getTimezone());
    }
    if (source.isActive() != null) {
        destination.setAttribute("oxTrustActive", source.isActive().toString());
    }
    if (source.getPassword() != null && source.getPassword().length() > 0) {
        destination.setUserPassword(source.getPassword());
    }
    // getting user groups
    log.trace(" setting groups ");
    if (source.getGroups() != null && source.getGroups().size() > 0) {
        List<GroupRef> listGroups = source.getGroups();
        List<String> members = new ArrayList<String>();
        for (GroupRef group : listGroups) {
            members.add(groupService.getDnForGroup(group.getValue()));
        }
        destination.setMemberOf(members);
    }
    // getting roles
    log.trace(" setting roles ");
    if (source.getRoles() != null && source.getRoles().size() > 0) {
        List<Role> roles = copyUtils2.getAttributeListValue(destination, Role.class, "oxTrustRole");
        if (roles != null && roles.size() > 0) {
            List<Role> newRoles = source.getRoles();
            for (Role role : roles) {
                if (role != null && role.getType() != null) {
                    for (Role newRole : newRoles) {
                        if ((newRole.getType() != null) && newRole.getType().getValue().equals(role.getType().getValue())) {
                            roles.remove(role);
                            roles.add(newRole);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, roles, "oxTrustRole");
        }
    }
    // getting entitlements
    log.trace(" setting entitlements ");
    if (source.getEntitlements() != null && source.getEntitlements().size() > 0) {
        List<Entitlement> entitlements = copyUtils2.getAttributeListValue(destination, Entitlement.class, "oxTrustEntitlements");
        if (entitlements != null && entitlements.size() > 0) {
            List<Entitlement> newEentitlements = source.getEntitlements();
            for (Entitlement entitlement : entitlements) {
                if (entitlement != null && entitlement.getType() != null) {
                    for (Entitlement newEntitlement : newEentitlements) {
                        if ((newEntitlement.getType() != null) && newEntitlement.getType().getValue().equals(entitlement.getType().getValue())) {
                            entitlements.remove(entitlement);
                            entitlements.add(newEntitlement);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, entitlements, "oxTrustEntitlements");
        }
    }
    // getting x509Certificates
    log.trace(" setting certs ");
    if (source.getX509Certificates() != null && source.getX509Certificates().size() > 0) {
        List<X509Certificate> X509Certificates = copyUtils2.getAttributeListValue(destination, X509Certificate.class, "oxTrustx509Certificate");
        if (X509Certificates != null) {
            List<X509Certificate> newX509Certificates = source.getX509Certificates();
            for (X509Certificate X509Certificate : X509Certificates) {
                if (X509Certificate != null && X509Certificate.getType() != null) {
                    for (X509Certificate newX509Certificate : newX509Certificates) {
                        if ((newX509Certificate.getType() != null) && newX509Certificate.getType().getValue().equals(X509Certificate.getType().getValue())) {
                            X509Certificates.remove(X509Certificate);
                            X509Certificates.add(newX509Certificate);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, X509Certificates, "oxTrustx509Certificate");
        }
    }
    log.trace(" setting extensions ");
    if (source.getExtensions() != null && (source.getExtensions().size() > 0)) {
        destination.setExtensions(source.getExtensions());
    }
    if (source.isActive() != null) {
        copyUtils2.setGluuStatus(source, destination);
    }
    return destination;
}
Also used : Email(org.gluu.oxtrust.model.scim2.Email) Address(org.gluu.oxtrust.model.scim2.Address) Im(org.gluu.oxtrust.model.scim2.Im) ArrayList(java.util.ArrayList) Photo(org.gluu.oxtrust.model.scim2.Photo) X509Certificate(org.gluu.oxtrust.model.scim2.X509Certificate) Role(org.gluu.oxtrust.model.scim2.Role) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) PhoneNumber(org.gluu.oxtrust.model.scim2.PhoneNumber) GroupRef(org.gluu.oxtrust.model.scim2.GroupRef) Entitlement(org.gluu.oxtrust.model.scim2.Entitlement)

Example 87 with GluuCustomPerson

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

the class Scim2UserService method createUser.

public User createUser(User user) throws Exception {
    log.debug(" copying gluuperson ");
    GluuCustomPerson gluuPerson = copyUtils2.copy(user, null, false);
    if (gluuPerson == null) {
        throw new Exception("Scim2UserService.createUser(): Failed to create user; GluuCustomPerson is null");
    }
    log.debug(" generating inum ");
    // inumService.generateInums(Configuration.INUM_TYPE_PEOPLE_SLUG);
    String inum = personService.generateInumForNewPerson();
    // //personService.generateInumForNewPerson();
    log.debug(" getting DN ");
    String dn = personService.getDnForPerson(inum);
    log.debug(" getting iname ");
    String iname = personService.generateInameForNewPerson(user.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 (user.getGroups().size() > 0) {
        log.info(" jumping to groupMembersAdder ");
        log.info("gluuPerson.getDn() : " + gluuPerson.getDn());
        serviceUtil.groupMembersAdder(gluuPerson, gluuPerson.getDn());
    }
    // As per spec, the SP must be the one to assign the meta attributes
    log.info(" Setting meta: create user ");
    // Date should be in UTC format
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
    Date dateCreated = DateTime.now().toDate();
    String relativeLocation = "/scim/v2/Users/" + inum;
    gluuPerson.setAttribute("oxTrustMetaCreated", dateTimeFormatter.print(dateCreated.getTime()));
    gluuPerson.setAttribute("oxTrustMetaLastModified", dateTimeFormatter.print(dateCreated.getTime()));
    gluuPerson.setAttribute("oxTrustMetaLocation", relativeLocation);
    // Sync email, forward ("oxTrustEmail" -> "mail")
    gluuPerson = serviceUtil.syncEmailForward(gluuPerson, true);
    // For custom script: create user
    if (externalScimService.isEnabled()) {
        externalScimService.executeScimCreateUserMethods(gluuPerson);
    }
    log.debug("adding new GluuPerson");
    personService.addPerson(gluuPerson);
    User createdUser = copyUtils2.copy(gluuPerson, null);
    return createdUser;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) Date(java.util.Date)

Example 88 with GluuCustomPerson

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

the class Scim2UserService method addUserPatch.

private void addUserPatch(Operation operation, String id) throws Exception {
    User user = operation.getValue();
    GluuCustomPerson updatedGluuPerson = patchUtil.addPatch(user, validUsernameByInum(user, id));
    log.info(" Setting meta: addUserPatch 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 89 with GluuCustomPerson

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

the class PasswordReminderAction method requestReminder.

public String requestReminder() throws Exception {
    if (enabled()) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (facesContext == null) {
            return OxTrustConstants.RESULT_FAILURE;
        }
        ExternalContext externalContext = facesContext.getExternalContext();
        if (externalContext == null) {
            return OxTrustConstants.RESULT_FAILURE;
        }
        HttpServletRequest httpServletRequest = (HttpServletRequest) externalContext.getRequest();
        GluuCustomPerson person = new GluuCustomPerson();
        person.setMail(email);
        List<GluuCustomPerson> matchedPersons = personService.findPersons(person, 0);
        if (matchedPersons != null && matchedPersons.size() > 0) {
            GluuAppliance appliance = applianceService.getAppliance();
            OrganizationalUnit requests = new OrganizationalUnit();
            requests.setOu("resetPasswordRequests");
            requests.setDn("ou=resetPasswordRequests," + appliance.getDn());
            if (!ldapEntryManager.contains(requests)) {
                ldapEntryManager.persist(requests);
            }
            PasswordResetRequest request = new PasswordResetRequest();
            do {
                request.setCreationDate(Calendar.getInstance().getTime());
                request.setPersonInum(matchedPersons.get(0).getInum());
                request.setOxGuid(StringHelper.getRandomString(16));
                request.setBaseDn("oxGuid=" + request.getOxGuid() + ", ou=resetPasswordRequests," + appliance.getDn());
            } while (ldapEntryManager.contains(request));
            String subj = String.format("Password reset was requested at %1$s identity server", organizationService.getOrganization().getDisplayName());
            MailUtils mail = new MailUtils(appliance.getSmtpHost(), appliance.getSmtpPort(), appliance.isRequiresSsl(), appliance.isRequiresAuthentication(), appliance.getSmtpUserName(), applianceService.getDecryptedSmtpPassword(appliance));
            mail.sendMail(appliance.getSmtpFromName() + " <" + appliance.getSmtpFromEmailAddress() + ">", email, subj, String.format(MESSAGE_FOUND, matchedPersons.get(0).getGivenName(), organizationService.getOrganization().getDisplayName(), appConfiguration.getApplianceUrl() + httpServletRequest.getContextPath() + "/resetPassword/" + request.getOxGuid()));
            ldapEntryManager.persist(request);
        } else {
            GluuAppliance appliance = applianceService.getAppliance();
            String subj = String.format("Password reset was requested at %1$s identity server", organizationService.getOrganization().getDisplayName());
            MailUtils mail = new MailUtils(appliance.getSmtpHost(), appliance.getSmtpPort(), appliance.isRequiresSsl(), appliance.isRequiresAuthentication(), appliance.getSmtpUserName(), applianceService.getDecryptedSmtpPassword(appliance));
            String fromName = appliance.getSmtpFromName();
            if (fromName == null) {
                fromName = String.format("%1$s identity server", organizationService.getOrganization().getDisplayName());
            }
            mail.sendMail(fromName + " <" + appliance.getSmtpFromEmailAddress() + ">", email, subj, String.format(MESSAGE_NOT_FOUND, organizationService.getOrganization().getDisplayName()));
        }
        return OxTrustConstants.RESULT_SUCCESS;
    }
    return OxTrustConstants.RESULT_FAILURE;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PasswordResetRequest(org.gluu.oxtrust.model.PasswordResetRequest) FacesContext(javax.faces.context.FacesContext) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) OrganizationalUnit(org.gluu.oxtrust.model.OrganizationalUnit) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) ExternalContext(javax.faces.context.ExternalContext) MailUtils(org.gluu.oxtrust.util.MailUtils)

Example 90 with GluuCustomPerson

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

the class PasswordResetAction method update.

public String update() throws ParseException {
    boolean valid = true;
    if (recaptchaService.isEnabled()) {
        valid = recaptchaService.verifyRecaptchaResponse();
    }
    if (valid) {
        GluuAppliance appliance = applianceService.getAppliance();
        this.request = ldapEntryManager.find(PasswordResetRequest.class, "oxGuid=" + this.guid + ", ou=resetPasswordRequests," + appliance.getDn());
        Calendar requestCalendarExpiry = Calendar.getInstance();
        Calendar currentCalendar = Calendar.getInstance();
        if (request != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
            requestCalendarExpiry.setTime((request.getCreationDate()));
            requestCalendarExpiry.add(Calendar.HOUR, 2);
        }
        GluuCustomPerson person = personService.getPersonByInum(request.getPersonInum());
        GluuCustomAttribute question = null;
        GluuCustomAttribute answer = null;
        if (person != null) {
            question = person.getGluuCustomAttribute("secretQuestion");
            answer = person.getGluuCustomAttribute("secretAnswer");
        }
        if (request != null && requestCalendarExpiry.after(currentCalendar)) /*&& question != null && answer != null*/
        {
            if (question != null && answer != null) {
                String correctAnswer = answer.getValue();
                Boolean securityQuestionAnswered = (securityAnswer != null) && securityAnswer.equals(correctAnswer);
                if (securityQuestionAnswered) {
                    person.setUserPassword(password);
                    personService.updatePerson(person);
                    return OxTrustConstants.RESULT_SUCCESS;
                }
            } else {
                person.setUserPassword(password);
                personService.updatePerson(person);
                return OxTrustConstants.RESULT_SUCCESS;
            }
        }
    }
    return OxTrustConstants.RESULT_FAILURE;
}
Also used : PasswordResetRequest(org.gluu.oxtrust.model.PasswordResetRequest) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat)

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