Search in sources :

Example 1 with Preference

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;
}
Also used : Preference(org.apereo.portal.portletpublishing.xml.Preference) SingleChoicePreferenceInput(org.apereo.portal.portletpublishing.xml.SingleChoicePreferenceInput) QName(javax.xml.namespace.QName)

Example 2 with Preference

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;
}
Also used : Preference(org.apereo.portal.portletpublishing.xml.Preference) QName(javax.xml.namespace.QName) SingleTextPreferenceInput(org.apereo.portal.portletpublishing.xml.SingleTextPreferenceInput)

Example 3 with Preference

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;
}
Also used : MultiChoicePreferenceInput(org.apereo.portal.portletpublishing.xml.MultiChoicePreferenceInput) Preference(org.apereo.portal.portletpublishing.xml.Preference) QName(javax.xml.namespace.QName)

Example 4 with Preference

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");
}
Also used : Preference(org.apereo.portal.portletpublishing.xml.Preference) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) EntityIdentifier(org.apereo.portal.EntityIdentifier) ILocalAccountPerson(org.apereo.portal.persondir.ILocalAccountPerson) Date(java.util.Date)

Example 5 with Preference

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;
}
Also used : Preference(org.apereo.portal.portletpublishing.xml.Preference) ArrayList(java.util.ArrayList)

Aggregations

Preference (org.apereo.portal.portletpublishing.xml.Preference)10 QName (javax.xml.namespace.QName)4 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)3 Step (org.apereo.portal.portletpublishing.xml.Step)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 EntityIdentifier (org.apereo.portal.EntityIdentifier)2 MultiValuedPreferenceInputType (org.apereo.portal.portletpublishing.xml.MultiValuedPreferenceInputType)2 Parameter (org.apereo.portal.portletpublishing.xml.Parameter)2 ParameterInputType (org.apereo.portal.portletpublishing.xml.ParameterInputType)2 PortletPublishingDefinition (org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition)2 PreferenceInputType (org.apereo.portal.portletpublishing.xml.PreferenceInputType)2 SingleValuedPreferenceInputType (org.apereo.portal.portletpublishing.xml.SingleValuedPreferenceInputType)2 Attribute (org.apereo.portal.portlets.Attribute)2 BooleanAttribute (org.apereo.portal.portlets.BooleanAttribute)2 StringListAttribute (org.apereo.portal.portlets.StringListAttribute)2 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1