use of org.apereo.portal.portletpublishing.xml.Preference in project uPortal by Jasig.
the class PreferenceInputFactory method createSingleChoicePreference.
/**
* Create a single-valued choice preference input.
*
* @param name
* @param label
* @param displayType
* @param options
* @param defaultValue
* @return
*/
public static Preference createSingleChoicePreference(String name, String label, SingleChoiceDisplay displayType, List<Option> options, String defaultValue) {
SingleChoicePreferenceInput input = new SingleChoicePreferenceInput();
input.setDefault(defaultValue);
input.setDisplay(displayType);
input.getOptions().addAll(options);
Preference pref = new Preference();
pref.setName(name);
pref.setLabel(label);
pref.setPreferenceInput(new JAXBElement<SingleChoicePreferenceInput>(new QName("single-choice-parameter-input"), SingleChoicePreferenceInput.class, input));
return pref;
}
use of org.apereo.portal.portletpublishing.xml.Preference in project uPortal by Jasig.
the class PreferenceInputFactory method createSingleTextPreference.
/**
* Craete a single-valued text input preference.
*
* @param name
* @param label
* @param displayType
* @param defaultValue
* @return
*/
public static Preference createSingleTextPreference(String name, String label, TextDisplay displayType, String defaultValue) {
SingleTextPreferenceInput input = new SingleTextPreferenceInput();
input.setDefault(defaultValue);
input.setDisplay(displayType);
Preference pref = new Preference();
pref.setName(name);
pref.setLabel(label);
pref.setPreferenceInput(new JAXBElement<SingleTextPreferenceInput>(new QName("single-text-parameter-input"), SingleTextPreferenceInput.class, input));
return pref;
}
use of org.apereo.portal.portletpublishing.xml.Preference in project uPortal by Jasig.
the class PreferenceInputFactory method createMultiChoicePreference.
/**
* Create a multi-valued choice input preference.
*
* @param name
* @param label
* @param displayType
* @param options
* @param defaultValues
* @return
*/
public static Preference createMultiChoicePreference(String name, String label, MultiChoiceDisplay displayType, List<Option> options, List<String> defaultValues) {
MultiChoicePreferenceInput input = new MultiChoicePreferenceInput();
input.getDefaults().addAll(defaultValues);
input.setDisplay(displayType);
input.getOptions().addAll(options);
Preference pref = new Preference();
pref.setName(name);
pref.setLabel(label);
pref.setPreferenceInput(new JAXBElement<MultiChoicePreferenceInput>(new QName("multi-choice-parameter-input"), MultiChoicePreferenceInput.class, input));
return pref;
}
use of org.apereo.portal.portletpublishing.xml.Preference in project uPortal by Jasig.
the class UserAccountHelper method updateAccount.
public void updateAccount(IPerson currentUser, PersonForm form) {
ILocalAccountPerson account;
// username
if (form.getId() < 0) {
account = accountDao.getPerson(form.getUsername());
if (account == null) {
/*
* Should there be a permissions check to verify
* the user is allowed to create new users?
*/
account = accountDao.createPerson(form.getUsername());
}
} else // otherwise, get the existing account from the database
{
account = accountDao.getPerson(form.getId());
}
/*
* SANITY CHECK #1: Is the user permitted to modify this account?
* (Presumably this check was already made when the page was rendered,
* but re-checking alleviates danger from cleverly-crafted HTTP
* requests.)
*/
if (!canEditUser(currentUser, account.getName())) {
throw new RuntimeException("Current user " + currentUser.getName() + " does not have permissions to update person " + account.getName());
}
// Used w/ check #2
EntityIdentifier ei = currentUser.getEntityIdentifier();
IAuthorizationPrincipal ap = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
// update the account attributes to match those specified in the form
List<Preference> editableAttributes = getEditableUserAttributes(currentUser);
for (Preference editableAttribute : editableAttributes) {
String attributeName = editableAttribute.getName();
/*
* SANITY CHECK #2: Should never fail since getEditableUserAttributes should return only
* editable attribute names, but do this anyway just in case.
*/
if (!ap.hasPermission("UP_USERS", "EDIT_USER_ATTRIBUTE", attributeName)) {
throw new RuntimeException("Current user " + currentUser.getName() + " does not have permissions to edit attribute " + attributeName);
}
if (form.getAttributes().get(attributeName) == null || form.getAttributes().get(attributeName).isBlank()) {
account.removeAttribute(attributeName);
} else {
account.setAttribute(attributeName, form.getAttributes().get(attributeName).getValue());
}
}
// if a new password has been specified, update the account password
if (StringUtils.isNotBlank(form.getPassword())) {
account.setPassword(passwordService.encryptPassword(form.getPassword()));
account.setLastPasswordChange(new Date());
account.removeAttribute("loginToken");
}
accountDao.updateAccount(account);
log.info("Account " + account.getName() + " successfully updated");
}
use of org.apereo.portal.portletpublishing.xml.Preference in project uPortal by Jasig.
the class UserAccountHelperTest method generateAccountEditPreferences.
/**
* @return
*/
private List<Preference> generateAccountEditPreferences() {
List<Preference> accountEditPreferences = new ArrayList<>();
Preference preference = new Preference();
preference.setName("pref_name_0");
preference.setDescription("pref_description_0");
accountEditPreferences.add(preference);
preference = new Preference();
preference.setName("pref_name_1");
preference.setDescription("pref_description_1");
accountEditPreferences.add(preference);
return accountEditPreferences;
}
Aggregations