Search in sources :

Example 1 with DisplayElement

use of password.pwm.http.bean.DisplayElement in project pwm by pwm-project.

the class HelpdeskDetailInfoBean method makeHelpdeskDetailInfo.

static HelpdeskDetailInfoBean makeHelpdeskDetailInfo(final PwmRequest pwmRequest, final HelpdeskProfile helpdeskProfile, final UserIdentity userIdentity) throws PwmUnrecoverableException, ChaiUnavailableException {
    final HelpdeskDetailInfoBeanBuilder builder = HelpdeskDetailInfoBean.builder();
    final Instant startTime = Instant.now();
    LOGGER.trace(pwmRequest, "beginning to assemble detail data report for user " + userIdentity);
    final Locale actorLocale = pwmRequest.getLocale();
    final ChaiUser theUser = HelpdeskServlet.getChaiUser(pwmRequest, helpdeskProfile, userIdentity);
    if (!theUser.exists()) {
        return null;
    }
    final UserInfo userInfo = UserInfoFactory.newUserInfo(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), actorLocale, userIdentity, theUser.getChaiProvider());
    final MacroMachine macroMachine = MacroMachine.forUser(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), userInfo, null);
    try {
        final List<AccountInformationBean.ActivityRecord> userHistory = AccountInformationBean.makeAuditInfo(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), userInfo, pwmRequest.getLocale());
        builder.userHistory(userHistory);
    } catch (Exception e) {
        LOGGER.error(pwmRequest, "unexpected error reading userHistory for user '" + userIdentity + "', " + e.getMessage());
    }
    builder.userKey(userIdentity.toObfuscatedKey(pwmRequest.getPwmApplication()));
    builder.profileData(getProfileData(helpdeskProfile, userInfo, pwmRequest.getSessionLabel(), pwmRequest.getLocale()));
    builder.passwordPolicyRules(makePasswordPolicyRules(userInfo, pwmRequest.getLocale(), pwmRequest.getConfig()));
    {
        final List<String> requirementLines = PasswordRequirementsTag.getPasswordRequirementsStrings(userInfo.getPasswordPolicy(), pwmRequest.getConfig(), pwmRequest.getLocale(), macroMachine);
        builder.passwordRequirements(Collections.unmodifiableList(requirementLines));
    }
    if ((userInfo.getPasswordPolicy() != null) && (userInfo.getPasswordPolicy().getChaiPasswordPolicy() != null) && (userInfo.getPasswordPolicy().getChaiPasswordPolicy().getPolicyEntry() != null) && (userInfo.getPasswordPolicy().getChaiPasswordPolicy().getPolicyEntry().getEntryDN() != null)) {
        builder.passwordPolicyDN(userInfo.getPasswordPolicy().getChaiPasswordPolicy().getPolicyEntry().getEntryDN());
    } else {
        builder.passwordPolicyDN(LocaleHelper.getLocalizedMessage(Display.Value_NotApplicable, pwmRequest));
    }
    if ((userInfo.getPasswordPolicy() != null) && userInfo.getPasswordPolicy().getIdentifier() != null) {
        builder.passwordPolicyID(userInfo.getPasswordPolicy().getIdentifier());
    } else {
        builder.passwordPolicyID(LocaleHelper.getLocalizedMessage(Display.Value_NotApplicable, pwmRequest));
    }
    {
        final ResponseInfoBean responseInfoBean = userInfo.getResponseInfoBean();
        if (responseInfoBean != null && responseInfoBean.getHelpdeskCrMap() != null) {
            final List<DisplayElement> responseDisplay = new ArrayList<>();
            int counter = 0;
            for (final Map.Entry<Challenge, String> entry : responseInfoBean.getHelpdeskCrMap().entrySet()) {
                counter++;
                responseDisplay.add(new DisplayElement("item_" + counter, DisplayElement.Type.string, entry.getKey().getChallengeText(), entry.getValue()));
            }
            builder.helpdeskResponses = responseDisplay;
        }
    }
    builder.userDisplayName(HelpdeskCardInfoBean.figureDisplayName(helpdeskProfile, macroMachine));
    final TimeDuration timeDuration = TimeDuration.fromCurrent(startTime);
    {
        final Set<ViewStatusFields> viewStatusFields = helpdeskProfile.readSettingAsOptionList(PwmSetting.HELPDESK_VIEW_STATUS_VALUES, ViewStatusFields.class);
        builder.statusData(ViewableUserInfoDisplayReader.makeDisplayData(viewStatusFields, pwmRequest.getConfig(), userInfo, null, pwmRequest.getLocale()));
    }
    {
        final Set<HelpdeskDetailInfoBean.StandardButton> visibleButtons = determineVisibleButtons(helpdeskProfile);
        builder.visibleButtons(visibleButtons);
        builder.enabledButtons(determineEnabledButtons(visibleButtons, userInfo));
        builder.customButtons(determineCustomButtons(helpdeskProfile));
    }
    final HelpdeskDetailInfoBean helpdeskDetailInfoBean = builder.build();
    if (pwmRequest.getConfig().isDevDebugMode()) {
        LOGGER.trace(pwmRequest, "completed assembly of detail data report for user " + userIdentity + " in " + timeDuration.asCompactString() + ", contents: " + JsonUtil.serialize(helpdeskDetailInfoBean));
    }
    return builder.build();
}
Also used : Locale(java.util.Locale) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Instant(java.time.Instant) ViewStatusFields(password.pwm.config.option.ViewStatusFields) UserInfo(password.pwm.ldap.UserInfo) ResponseInfoBean(password.pwm.bean.ResponseInfoBean) DisplayElement(password.pwm.http.bean.DisplayElement) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiUser(com.novell.ldapchai.ChaiUser) MacroMachine(password.pwm.util.macro.MacroMachine) ArrayList(java.util.ArrayList) List(java.util.List) TimeDuration(password.pwm.util.java.TimeDuration)

Example 2 with DisplayElement

use of password.pwm.http.bean.DisplayElement in project pwm by pwm-project.

the class HelpdeskDetailInfoBean method getProfileData.

private static List<DisplayElement> getProfileData(final HelpdeskProfile helpdeskProfile, final UserInfo userInfo, final SessionLabel sessionLabel, final Locale actorLocale) throws PwmUnrecoverableException {
    final List<FormConfiguration> detailFormConfig = helpdeskProfile.readSettingAsForm(PwmSetting.HELPDESK_DETAIL_FORM);
    final Map<FormConfiguration, List<String>> formData = FormUtility.populateFormMapFromLdap(detailFormConfig, sessionLabel, userInfo);
    final List<DisplayElement> profileData = new ArrayList<>();
    for (final Map.Entry<FormConfiguration, List<String>> entry : formData.entrySet()) {
        final FormConfiguration formConfiguration = entry.getKey();
        if (formConfiguration.isMultivalue()) {
            profileData.add(new DisplayElement(formConfiguration.getName(), DisplayElement.Type.multiString, formConfiguration.getLabel(actorLocale), entry.getValue()));
        } else {
            final String value = JavaHelper.isEmpty(entry.getValue()) ? "" : entry.getValue().iterator().next();
            profileData.add(new DisplayElement(formConfiguration.getName(), DisplayElement.Type.string, formConfiguration.getLabel(actorLocale), value));
        }
    }
    return profileData;
}
Also used : ArrayList(java.util.ArrayList) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) DisplayElement(password.pwm.http.bean.DisplayElement) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with DisplayElement

use of password.pwm.http.bean.DisplayElement in project pwm by pwm-project.

the class AccountInformationBean method makeFormInfo.

private static List<DisplayElement> makeFormInfo(final PwmRequest pwmRequest, final Locale locale) throws PwmUnrecoverableException {
    final List<DisplayElement> returnData = new ArrayList<>();
    final List<FormConfiguration> formConfiguration = pwmRequest.getConfig().readSettingAsForm(PwmSetting.ACCOUNT_INFORMATION_VIEW_FORM);
    if (formConfiguration != null && !formConfiguration.isEmpty()) {
        final Map<FormConfiguration, List<String>> ldapValues = FormUtility.populateFormMapFromLdap(formConfiguration, pwmRequest.getSessionLabel(), pwmRequest.getPwmSession().getUserInfo(), FormUtility.Flag.ReturnEmptyValues);
        for (final Map.Entry<FormConfiguration, List<String>> entry : ldapValues.entrySet()) {
            final FormConfiguration formConfig = entry.getKey();
            final List<String> values = entry.getValue();
            final String display = formConfig.isMultivalue() ? StringUtil.collectionToString(values, ", ") : values.isEmpty() ? "" : values.iterator().next();
            returnData.add(new DisplayElement(formConfig.getName(), DisplayElement.Type.string, formConfig.getLabel(locale), display));
        }
    }
    return Collections.unmodifiableList(returnData);
}
Also used : ArrayList(java.util.ArrayList) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) DisplayElement(password.pwm.http.bean.DisplayElement) Map(java.util.Map)

Example 4 with DisplayElement

use of password.pwm.http.bean.DisplayElement in project pwm by pwm-project.

the class AppDashboardData method makeAboutJavaData.

private static List<DisplayElement> makeAboutJavaData(final PwmApplication pwmApplication, final Locale locale) {
    final Map<PwmAboutProperty, String> aboutMap = PwmAboutProperty.makeInfoBean(pwmApplication);
    final List<DisplayElement> javaInfo = new ArrayList<>();
    final String notApplicable = Display.getLocalizedMessage(locale, Display.Value_NotApplicable, pwmApplication.getConfig());
    {
        final List<PwmAboutProperty> interestedProperties = Arrays.asList(PwmAboutProperty.java_vmName, PwmAboutProperty.java_vmVendor, PwmAboutProperty.java_vmVersion, PwmAboutProperty.java_runtimeVersion, PwmAboutProperty.java_vmLocation, PwmAboutProperty.java_appServerInfo, PwmAboutProperty.java_osName, PwmAboutProperty.java_osVersion, PwmAboutProperty.java_osArch, PwmAboutProperty.java_memoryFree, PwmAboutProperty.java_memoryAllocated, PwmAboutProperty.java_memoryMax, PwmAboutProperty.java_threadCount);
        for (final PwmAboutProperty property : interestedProperties) {
            javaInfo.add(new DisplayElement(property.name(), DisplayElement.Type.string, property.getLabel(), aboutMap.getOrDefault(property, notApplicable)));
        }
    }
    {
        final PwmNumberFormat numberFormat = PwmNumberFormat.forLocale(locale);
        final String display = numberFormat.format(pwmApplication.getResourceServletService().itemsInCache()) + "items (" + numberFormat.format(pwmApplication.getResourceServletService().bytesInCache()) + " bytes)";
        javaInfo.add(new DisplayElement("resourceFileServletCacheSize", DisplayElement.Type.string, "ResourceFileServlet Cache", display));
    }
    javaInfo.add(new DisplayElement("resourceFileServletCacheHitRatio", DisplayElement.Type.string, "ResourceFileServlet Cache Hit Ratio", pwmApplication.getResourceServletService().cacheHitRatio().pretty(2)));
    {
        final Map<SessionTrackService.DebugKey, String> debugInfoMap = pwmApplication.getSessionTrackService().getDebugData();
        javaInfo.add(new DisplayElement("sessionTotalSize", DisplayElement.Type.string, "Estimated Session Total Size", debugInfoMap.get(SessionTrackService.DebugKey.HttpSessionTotalSize)));
        javaInfo.add(new DisplayElement("sessionAverageSize", DisplayElement.Type.string, "Estimated Session Average Size", debugInfoMap.get(SessionTrackService.DebugKey.HttpSessionAvgSize)));
    }
    return Collections.unmodifiableList(javaInfo);
}
Also used : PwmAboutProperty(password.pwm.PwmAboutProperty) PwmNumberFormat(password.pwm.util.java.PwmNumberFormat) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DisplayElement(password.pwm.http.bean.DisplayElement) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SessionTrackService(password.pwm.svc.sessiontrack.SessionTrackService)

Example 5 with DisplayElement

use of password.pwm.http.bean.DisplayElement in project pwm by pwm-project.

the class AppDashboardData method makeAboutData.

private static List<DisplayElement> makeAboutData(final PwmApplication pwmApplication, final ContextManager contextManager, final Locale locale) {
    final LocaleHelper.DisplayMaker l = new LocaleHelper.DisplayMaker(locale, Admin.class, pwmApplication);
    final String notApplicableValue = Display.getLocalizedMessage(locale, Display.Value_NotApplicable, pwmApplication.getConfig());
    final PwmNumberFormat numberFormat = PwmNumberFormat.forLocale(locale);
    final List<DisplayElement> aboutData = new ArrayList<>();
    aboutData.add(new DisplayElement("appVersion", DisplayElement.Type.string, l.forKey("Field_AppVersion", PwmConstants.PWM_APP_NAME), PwmConstants.SERVLET_VERSION));
    aboutData.add(new DisplayElement("currentTime", DisplayElement.Type.timestamp, l.forKey("Field_CurrentTime"), JavaHelper.toIsoDate(Instant.now())));
    aboutData.add(new DisplayElement("startupTime", DisplayElement.Type.timestamp, l.forKey("Field_StartTime"), JavaHelper.toIsoDate(pwmApplication.getStartupTime())));
    aboutData.add(new DisplayElement("runningDuration", DisplayElement.Type.string, l.forKey("Field_UpTime"), TimeDuration.fromCurrent(pwmApplication.getStartupTime()).asLongString(locale)));
    aboutData.add(new DisplayElement("installTime", DisplayElement.Type.timestamp, l.forKey("Field_InstallTime"), JavaHelper.toIsoDate(pwmApplication.getInstallTime())));
    aboutData.add(new DisplayElement("siteURL", DisplayElement.Type.string, l.forKey("Field_SiteURL"), pwmApplication.getConfig().readSettingAsString(PwmSetting.PWM_SITE_URL)));
    aboutData.add(new DisplayElement("instanceID", DisplayElement.Type.string, l.forKey("Field_InstanceID"), pwmApplication.getInstanceID()));
    aboutData.add(new DisplayElement("configRestartCounter", DisplayElement.Type.number, "Configuration Restart Counter", contextManager == null ? notApplicableValue : numberFormat.format(contextManager.getRestartCount())));
    aboutData.add(new DisplayElement("chaiApiVersion", DisplayElement.Type.string, l.forKey("Field_ChaiAPIVersion"), com.novell.ldapchai.ChaiConstant.CHAI_API_VERSION));
    return Collections.unmodifiableList(aboutData);
}
Also used : PwmNumberFormat(password.pwm.util.java.PwmNumberFormat) LocaleHelper(password.pwm.util.LocaleHelper) ArrayList(java.util.ArrayList) DisplayElement(password.pwm.http.bean.DisplayElement)

Aggregations

ArrayList (java.util.ArrayList)7 DisplayElement (password.pwm.http.bean.DisplayElement)7 List (java.util.List)4 Map (java.util.Map)3 PwmNumberFormat (password.pwm.util.java.PwmNumberFormat)3 Instant (java.time.Instant)2 LinkedHashMap (java.util.LinkedHashMap)2 Locale (java.util.Locale)2 FormConfiguration (password.pwm.config.value.data.FormConfiguration)2 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)2 ChaiUser (com.novell.ldapchai.ChaiUser)1 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 PwmAboutProperty (password.pwm.PwmAboutProperty)1 ResponseInfoBean (password.pwm.bean.ResponseInfoBean)1 Configuration (password.pwm.config.Configuration)1 ViewStatusFields (password.pwm.config.option.ViewStatusFields)1 ErrorInformation (password.pwm.error.ErrorInformation)1