use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class PasswordResetAction method updateImpl.
public String updateImpl() {
boolean valid = true;
if (captchaEnable()) {
valid = recaptchaService.verifyRecaptchaResponse();
}
if (this.password != null && this.confirm != null) {
if (!this.password.equalsIgnoreCase(this.confirm)) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Password mismatch.");
return OxTrustConstants.RESULT_FAILURE;
}
} else {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Incorrect data send.");
return OxTrustConstants.RESULT_FAILURE;
}
if (valid) {
GluuOrganization organization = organizationService.getOrganization();
try {
this.request = ldapEntryManager.find(PasswordResetRequest.class, "oxGuid=" + getCode() + ",ou=resetPasswordRequests," + organization.getDn());
} catch (Exception e) {
log.error("=================", e);
return OxTrustConstants.RESULT_FAILURE;
}
checkSecurityQuetion();
Calendar requestCalendarExpiry = Calendar.getInstance();
Calendar currentCalendar = Calendar.getInstance();
if (request != null) {
requestCalendarExpiry.setTime((request.getCreationDate()));
requestCalendarExpiry.add(Calendar.HOUR, 2);
}
GluuCustomPerson person = personService.getPersonByInum(request.getPersonInum());
if (securityAnswer == null) {
securityAnswer = getResponse();
}
if (requestCalendarExpiry.after(currentCalendar)) {
PasswordResetRequest removeRequest = new PasswordResetRequest();
removeRequest.setBaseDn(request.getBaseDn());
if (this.securityQuestion != null && this.answer != null) {
Boolean securityQuestionAnswered = (this.securityAnswer != null) && this.securityAnswer.equalsIgnoreCase(answer.getValue());
if (securityQuestionAnswered) {
person.setUserPassword(password);
try {
personService.updatePerson(person);
ldapEntryManager.remove(removeRequest);
return OxTrustConstants.RESULT_SUCCESS;
} catch (DuplicateEmailException e) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, e.getMessage());
log.error("", e);
} catch (Exception e) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Error while processing the request");
log.error("", e);
}
return OxTrustConstants.RESULT_FAILURE;
} else {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "The provided security answer is not correct. Please try again from the link!");
return OxTrustConstants.RESULT_FAILURE;
}
} else {
person.setUserPassword(password);
try {
personService.updatePerson(person);
ldapEntryManager.remove(removeRequest);
return OxTrustConstants.RESULT_SUCCESS;
} catch (DuplicateEmailException e) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, e.getMessage());
} catch (Exception e) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Error while processing the request");
}
return OxTrustConstants.RESULT_FAILURE;
}
}
} else {
facesMessages.add(FacesMessage.SEVERITY_ERROR, facesMessages.evalResourceAsString("#{msgs['person.passwordreset.catch.checkInputAndCaptcha']}"));
}
return OxTrustConstants.RESULT_FAILURE;
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class PersonImportAction method convertTableToPersons.
protected List<GluuCustomPerson> convertTableToPersons(Table table, List<ImportAttribute> importAttributes) throws Exception {
Map<String, List<AttributeData>> entriesAttributes = new HashMap<String, List<AttributeData>>();
Map<String, String> uidPAsswords = new HashMap<String, String>();
int rows = table.getCountRows();
boolean validTable = true;
for (int i = 1; i <= rows; i++) {
List<AttributeData> attributeDataList = new ArrayList<AttributeData>();
String uid = null;
String password = null;
for (ImportAttribute importAttribute : importAttributes) {
if (importAttribute.getCol() == -1) {
continue;
}
GluuAttribute attribute = importAttribute.getAttribute();
String cellValue = table.getCellValue(importAttribute.getCol(), i);
boolean isMultiValue = attribute.getOxMultiValuedAttribute();
if (StringHelper.isEmpty(cellValue)) {
if (attribute.isRequred()) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Import failed. Empty '%s' not allowed", attribute.getDisplayName());
validTable = false;
}
continue;
}
String ldapValue = getTypedValue(attribute, cellValue);
if (StringHelper.isEmpty(ldapValue)) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Invalid value '%s' in column '%s' at row %s were specified", cellValue, attribute.getDisplayName(), i + 1);
validTable = false;
continue;
}
if (attribute.getName().equalsIgnoreCase(UID)) {
uid = ldapValue;
}
if (attribute.getName().equalsIgnoreCase(USER_PASSWORD)) {
password = ldapValue;
}
if (isMultiValue) {
AttributeData attributeData = new AttributeData(attribute.getName(), ldapValue.split(SEPARATOR));
attributeDataList.add(attributeData);
} else {
AttributeData attributeData = new AttributeData(attribute.getName(), ldapValue);
attributeDataList.add(attributeData);
}
}
entriesAttributes.put(Integer.toString(i), attributeDataList);
uidPAsswords.put(uid, password);
}
if (!validTable) {
return null;
}
List<GluuCustomPerson> persons = personService.createEntities(entriesAttributes);
log.trace("Found {} persons in input Excel file", persons.size());
for (GluuCustomPerson person : persons) {
if (person.getStatus() == null) {
person.setStatus(appConfiguration.getSupportedUserStatus().get(1));
}
if (uidPAsswords.containsKey(person.getUid())) {
String password = uidPAsswords.get(person.getUid());
if (password != null) {
person.setUserPassword(uidPAsswords.get(person.getUid().trim().toString()));
} else {
person.setUserPassword(person.getUid());
}
}
}
return persons;
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class PersonImportAction method validatePersons.
private boolean validatePersons(List<GluuCustomPerson> persons) throws Exception {
Set<String> uids = new HashSet<String>();
Set<String> mails = new HashSet<String>();
for (GluuCustomPerson person : persons) {
uids.add(person.getUid());
mails.add(person.getMail());
}
if (uids.size() != persons.size()) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Import failed. There are persons with simular uid(s) in input file");
return false;
}
if (mails.size() != persons.size()) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Import failed. There are persons with simular mail(s) in input file");
return false;
}
List<GluuCustomPerson> existPersons = personService.findPersonsByUids(new ArrayList<String>(uids), PERSON_IMPORT_PERSON_LOCKUP_RETURN_ATTRIBUTES);
if (existPersons.size() > 0) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Import failed. There are persons with existing uid(s): %s", personService.getPersonUids(existPersons));
return false;
}
List<GluuCustomPerson> existEmailPersons = personService.findPersonsByMailids(new ArrayList<String>(mails), PERSON_IMPORT_PERSON_LOCKUP_RETURN_ATTRIBUTES);
if (existEmailPersons.size() > 0) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Import failed. There are persons with existing mailid(s): %s", personService.getPersonMailids(existEmailPersons));
return false;
}
return true;
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class RegisterPersonAction method register.
public String register() throws CloneNotSupportedException {
try {
GluuCustomPerson gluuCustomPerson = personService.getPersonByEmail(email);
if (gluuCustomPerson != null && appConfiguration.getEnforceEmailUniqueness()) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Registration failed. Please try again, or contact the system administrator.");
return OxTrustConstants.RESULT_FAILURE;
}
} catch (Exception e) {
log.error("===========", e);
return OxTrustConstants.RESULT_FAILURE;
}
String outcome = registerImpl();
if (OxTrustConstants.RESULT_SUCCESS.equals(outcome)) {
setPostRegistrationInformation("You successfully registered. Enjoy!");
} else if (OxTrustConstants.RESULT_DISABLED.equals(outcome)) {
setPostRegistrationInformation("You successfully registered. Please contact site administration to enable your account.");
} else if (OxTrustConstants.RESULT_FAILURE.equals(outcome)) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Registration failed. Please try again, or contact the system administrator.");
} else if (OxTrustConstants.RESULT_CAPTCHA_VALIDATION_FAILED.equals(outcome)) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Captcha validation failed. Please try again.");
}
redirectIfNeeded();
return outcome;
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class RegisterPersonAction method registerImpl.
public String registerImpl() throws CloneNotSupportedException {
boolean registrationFormValid = StringHelper.equals(password, repeatPassword);
if (!captchaDisabled) {
String gRecaptchaRresponse = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("g-recaptcha-response");
boolean reCaptchaResponse = recaptchaService.verifyRecaptchaResponse(gRecaptchaRresponse);
registrationFormValid &= reCaptchaResponse;
}
if (registrationFormValid) {
GluuCustomPerson archivedPerson = (GluuCustomPerson) person.clone();
try {
String customObjectClass = attributeService.getCustomOrigin();
this.person.setCustomObjectClasses(new String[] { customObjectClass });
if (person.getInum() == null) {
String inum = personService.generateInumForNewPerson();
this.person.setInum(inum);
}
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());
}
this.person.setUserPassword(password);
this.person.setCreationDate(new Date());
this.person.setMail(email);
this.postRegistrationInformation = "You have successfully registered with oxTrust. Login to begin your session.";
boolean result = false;
result = externalUserRegistrationService.executeExternalPreRegistrationMethods(this.person, requestParameters);
postRegistrationRedirectUri = getRegistrationRedirectUri();
if (!result) {
this.person = archivedPerson;
return OxTrustConstants.RESULT_FAILURE;
}
if ((this.inum != null) && !this.inum.isEmpty()) {
personService.updatePerson(this.person);
try {
oxTrustAuditService.audit(this.person.getInum() + " **" + this.person.getDisplayName() + "** REGISTRATION UPDATED", identity.getUser(), (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
} catch (Exception e) {
}
} else {
personService.addPerson(this.person);
try {
oxTrustAuditService.audit(this.person.getInum() + " **" + this.person.getDisplayName() + "** REGISTERED", identity.getUser(), (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
} catch (Exception e) {
}
}
requestParameters.put(HOST_NAME, new String[] { configurationService.getConfiguration().getHostname() });
result = externalUserRegistrationService.executeExternalPostRegistrationMethods(this.person, requestParameters);
if (!result) {
this.person = archivedPerson;
return OxTrustConstants.RESULT_FAILURE;
}
if (GluuStatus.INACTIVE.equals(person.getStatus())) {
return OxTrustConstants.RESULT_DISABLED;
}
} catch (DuplicateEmailException ex) {
log.error("Failed to add new person {}", this.person.getInum(), ex);
facesMessages.add(FacesMessage.SEVERITY_ERROR, ex.getMessage());
this.person = archivedPerson;
return OxTrustConstants.RESULT_FAILURE;
} catch (Exception ex) {
log.error("Failed to add new person {}", this.person.getInum(), ex);
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;
}
Aggregations