use of password.pwm.i18n.Display in project pwm by pwm-project.
the class ClientApiServlet method makeDisplayData.
private Map<String, String> makeDisplayData(final PwmApplication pwmApplication, final PwmSession pwmSession, final String bundleName) {
Class displayClass = LocaleHelper.classForShortName(bundleName);
displayClass = displayClass == null ? Display.class : displayClass;
final Locale userLocale = pwmSession.getSessionStateBean().getLocale();
final Configuration config = pwmApplication.getConfig();
final TreeMap<String, String> displayStrings = new TreeMap<>();
final ResourceBundle bundle = ResourceBundle.getBundle(displayClass.getName());
try {
final MacroMachine macroMachine = pwmSession.getSessionManager().getMacroMachine(pwmApplication);
for (final String key : new TreeSet<>(Collections.list(bundle.getKeys()))) {
String displayValue = LocaleHelper.getLocalizedMessage(userLocale, key, config, displayClass);
displayValue = macroMachine.expandMacros(displayValue);
displayStrings.put(key, displayValue);
}
} catch (Exception e) {
LOGGER.error(pwmSession, "error expanding macro display value: " + e.getMessage());
}
return displayStrings;
}
use of password.pwm.i18n.Display in project pwm by pwm-project.
the class PasswordRequirementsTag method getPasswordRequirementsStrings.
@SuppressWarnings("checkstyle:MethodLength")
public static List<String> getPasswordRequirementsStrings(final PwmPasswordPolicy pwordPolicy, final Configuration config, final Locale locale, final MacroMachine macroMachine) {
final List<String> returnValues = new ArrayList<>();
final ADPolicyComplexity adPolicyLevel = pwordPolicy.getRuleHelper().getADComplexityLevel();
final PwmPasswordPolicy.RuleHelper ruleHelper = pwordPolicy.getRuleHelper();
if (ruleHelper.readBooleanValue(PwmPasswordRule.CaseSensitive)) {
returnValues.add(getLocalString(Message.Requirement_CaseSensitive, null, locale, config));
} else {
returnValues.add(getLocalString(Message.Requirement_NotCaseSensitive, null, locale, config));
}
{
int value = ruleHelper.readIntValue(PwmPasswordRule.MinimumLength);
if (adPolicyLevel == ADPolicyComplexity.AD2003 || adPolicyLevel == ADPolicyComplexity.AD2008) {
if (value < 6) {
value = 6;
}
}
if (value > 0) {
returnValues.add(getLocalString(Message.Requirement_MinLength, value, locale, config));
}
}
{
final int value = ruleHelper.readIntValue(PwmPasswordRule.MaximumLength);
if (value > 0 && value < 64) {
returnValues.add(getLocalString(Message.Requirement_MaxLength, value, locale, config));
}
}
{
final int value = ruleHelper.readIntValue(PwmPasswordRule.MinimumAlpha);
if (value > 0) {
returnValues.add(getLocalString(Message.Requirement_MinAlpha, value, locale, config));
}
}
{
final int value = ruleHelper.readIntValue(PwmPasswordRule.MaximumAlpha);
if (value > 0) {
returnValues.add(getLocalString(Message.Requirement_MaxAlpha, value, locale, config));
}
}
{
if (!ruleHelper.readBooleanValue(PwmPasswordRule.AllowNumeric)) {
returnValues.add(getLocalString(Message.Requirement_AllowNumeric, null, locale, config));
} else {
final int minValue = ruleHelper.readIntValue(PwmPasswordRule.MinimumNumeric);
if (minValue > 0) {
returnValues.add(getLocalString(Message.Requirement_MinNumeric, minValue, locale, config));
}
final int maxValue = ruleHelper.readIntValue(PwmPasswordRule.MaximumNumeric);
if (maxValue > 0) {
returnValues.add(getLocalString(Message.Requirement_MaxNumeric, maxValue, locale, config));
}
if (!ruleHelper.readBooleanValue(PwmPasswordRule.AllowFirstCharNumeric)) {
returnValues.add(getLocalString(Message.Requirement_FirstNumeric, maxValue, locale, config));
}
if (!ruleHelper.readBooleanValue(PwmPasswordRule.AllowLastCharNumeric)) {
returnValues.add(getLocalString(Message.Requirement_LastNumeric, maxValue, locale, config));
}
}
}
{
if (!ruleHelper.readBooleanValue(PwmPasswordRule.AllowSpecial)) {
returnValues.add(getLocalString(Message.Requirement_AllowSpecial, null, locale, config));
} else {
final int minValue = ruleHelper.readIntValue(PwmPasswordRule.MinimumSpecial);
if (minValue > 0) {
returnValues.add(getLocalString(Message.Requirement_MinSpecial, minValue, locale, config));
}
final int maxValue = ruleHelper.readIntValue(PwmPasswordRule.MaximumSpecial);
if (maxValue > 0) {
returnValues.add(getLocalString(Message.Requirement_MaxSpecial, maxValue, locale, config));
}
if (!ruleHelper.readBooleanValue(PwmPasswordRule.AllowFirstCharSpecial)) {
returnValues.add(getLocalString(Message.Requirement_FirstSpecial, maxValue, locale, config));
}
if (!ruleHelper.readBooleanValue(PwmPasswordRule.AllowLastCharSpecial)) {
returnValues.add(getLocalString(Message.Requirement_LastSpecial, maxValue, locale, config));
}
}
}
{
final int value = pwordPolicy.getRuleHelper().readIntValue(PwmPasswordRule.MaximumRepeat);
if (value > 0) {
returnValues.add(getLocalString(Message.Requirement_MaxRepeat, value, locale, config));
}
}
{
final int value = pwordPolicy.getRuleHelper().readIntValue(PwmPasswordRule.MaximumSequentialRepeat);
if (value > 0) {
returnValues.add(getLocalString(Message.Requirement_MaxSeqRepeat, value, locale, config));
}
}
{
final int value = ruleHelper.readIntValue(PwmPasswordRule.MinimumLowerCase);
if (value > 0) {
returnValues.add(getLocalString(Message.Requirement_MinLower, value, locale, config));
}
}
{
final int value = ruleHelper.readIntValue(PwmPasswordRule.MaximumLowerCase);
if (value > 0) {
returnValues.add(getLocalString(Message.Requirement_MaxLower, value, locale, config));
}
}
{
final int value = ruleHelper.readIntValue(PwmPasswordRule.MinimumUpperCase);
if (value > 0) {
returnValues.add(getLocalString(Message.Requirement_MinUpper, value, locale, config));
}
}
{
final int value = ruleHelper.readIntValue(PwmPasswordRule.MaximumUpperCase);
if (value > 0) {
returnValues.add(getLocalString(Message.Requirement_MaxUpper, value, locale, config));
}
}
{
final int value = ruleHelper.readIntValue(PwmPasswordRule.MinimumUnique);
if (value > 0) {
returnValues.add(getLocalString(Message.Requirement_MinUnique, value, locale, config));
}
}
{
final List<String> setValue = ruleHelper.getDisallowedValues();
if (!setValue.isEmpty()) {
final StringBuilder fieldValue = new StringBuilder();
for (final String loopValue : setValue) {
fieldValue.append(" ");
final String expandedValue = macroMachine.expandMacros(loopValue);
fieldValue.append(StringUtil.escapeHtml(expandedValue));
}
returnValues.add(getLocalString(Message.Requirement_DisAllowedValues, fieldValue.toString(), locale, config));
}
}
{
final List<String> setValue = ruleHelper.getDisallowedAttributes();
if (!setValue.isEmpty() || adPolicyLevel == ADPolicyComplexity.AD2003) {
returnValues.add(getLocalString(Message.Requirement_DisAllowedAttributes, "", locale, config));
}
}
if (ruleHelper.readBooleanValue(PwmPasswordRule.EnableWordlist)) {
returnValues.add(getLocalString(Message.Requirement_WordList, "", locale, config));
}
{
final int value = ruleHelper.readIntValue(PwmPasswordRule.MaximumOldChars);
if (value > 0) {
returnValues.add(getLocalString(Message.Requirement_OldChar, value, locale, config));
}
}
{
final int value = ruleHelper.readIntValue(PwmPasswordRule.MinimumLifetime);
if (value > 0) {
final int secondsPerDay = 60 * 60 * 24;
final String durationStr;
if (value % secondsPerDay == 0) {
final int valueAsDays = value / (60 * 60 * 24);
final Display key = valueAsDays <= 1 ? Display.Display_Day : Display.Display_Days;
durationStr = valueAsDays + " " + LocaleHelper.getLocalizedMessage(locale, key, config);
} else {
final int valueAsHours = value / (60 * 60);
final Display key = valueAsHours <= 1 ? Display.Display_Hour : Display.Display_Hours;
durationStr = valueAsHours + " " + LocaleHelper.getLocalizedMessage(locale, key, config);
}
final String userMsg = Message.getLocalizedMessage(locale, Message.Requirement_MinimumFrequency, config, durationStr);
returnValues.add(userMsg);
}
}
if (adPolicyLevel == ADPolicyComplexity.AD2003) {
returnValues.add(getLocalString(Message.Requirement_ADComplexity, "", locale, config));
} else if (adPolicyLevel == ADPolicyComplexity.AD2008) {
final int maxViolations = ruleHelper.readIntValue(PwmPasswordRule.ADComplexityMaxViolations);
final int minGroups = 5 - maxViolations;
returnValues.add(getLocalString(Message.Requirement_ADComplexity2008, String.valueOf(minGroups), locale, config));
}
if (ruleHelper.readBooleanValue(PwmPasswordRule.UniqueRequired)) {
returnValues.add(getLocalString(Message.Requirement_UniqueRequired, "", locale, config));
}
return returnValues;
}
Aggregations