Search in sources :

Example 61 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class MainClass method createEnv.

private static CliEnvironment createEnv(final CliParameters parameters, final List<String> args) throws Exception {
    final Map<String, Object> options = parseCommandOptions(parameters, args);
    final File applicationPath = figureApplicationPath(mainOptions);
    out("applicationPath=" + applicationPath.getAbsolutePath());
    PwmEnvironment.verifyApplicationPath(applicationPath);
    final File configurationFile = locateConfigurationFile(applicationPath);
    final ConfigurationReader configReader = loadConfiguration(configurationFile);
    final Configuration config = configReader.getConfiguration();
    final PwmApplication pwmApplication;
    final LocalDB localDB;
    if (parameters.needsPwmApplication) {
        pwmApplication = loadPwmApplication(applicationPath, mainOptions.getApplicationFlags(), config, configurationFile, parameters.readOnly);
        localDB = pwmApplication.getLocalDB();
    } else if (parameters.needsLocalDB) {
        pwmApplication = null;
        localDB = loadPwmDB(config, parameters.readOnly, applicationPath);
    } else {
        pwmApplication = null;
        localDB = null;
    }
    out("environment initialized");
    out("");
    final Writer outputStream = new OutputStreamWriter(System.out, PwmConstants.DEFAULT_CHARSET);
    return CliEnvironment.builder().configurationReader(configReader).configurationFile(configurationFile).config(config).applicationPath(applicationPath).pwmApplication(pwmApplication).localDB(localDB).debugWriter(outputStream).options(options).mainOptions(mainOptions).build();
}
Also used : PwmApplication(password.pwm.PwmApplication) Configuration(password.pwm.config.Configuration) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) LocalDB(password.pwm.util.localdb.LocalDB) ConfigurationReader(password.pwm.config.stored.ConfigurationReader) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 62 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class TelemetryService method generatePublishableBean.

public TelemetryPublishBean generatePublishableBean() throws URISyntaxException, IOException, PwmUnrecoverableException {
    final StatisticsBundle bundle = pwmApplication.getStatisticsManager().getStatBundleForKey(StatisticsManager.KEY_CUMULATIVE);
    final Configuration config = pwmApplication.getConfig();
    final Map<PwmAboutProperty, String> aboutPropertyStringMap = PwmAboutProperty.makeInfoBean(pwmApplication);
    final Map<String, String> statData = new TreeMap<>();
    for (final Statistic loopStat : Statistic.values()) {
        statData.put(loopStat.getKey(), bundle.getStatistic(loopStat));
    }
    final List<String> configuredSettings = new ArrayList<>();
    for (final PwmSetting pwmSetting : config.nonDefaultSettings()) {
        if (!pwmSetting.getCategory().hasProfiles() && !config.isDefaultValue(pwmSetting)) {
            configuredSettings.add(pwmSetting.getKey());
        }
    }
    String ldapVendorName = null;
    for (final LdapProfile ldapProfile : config.getLdapProfiles().values()) {
        if (ldapVendorName == null) {
            try {
                final DirectoryVendor directoryVendor = ldapProfile.getProxyChaiProvider(pwmApplication).getDirectoryVendor();
                final PwmLdapVendor pwmLdapVendor = PwmLdapVendor.fromChaiVendor(directoryVendor);
                if (pwmLdapVendor != null) {
                    ldapVendorName = pwmLdapVendor.name();
                }
            } catch (Exception e) {
                LOGGER.trace(SessionLabel.TELEMETRY_SESSION_LABEL, "unable to read ldap vendor type for stats publication: " + e.getMessage());
            }
        }
    }
    final Map<String, String> aboutStrings = new TreeMap<>();
    {
        for (final Map.Entry<PwmAboutProperty, String> entry : aboutPropertyStringMap.entrySet()) {
            final PwmAboutProperty pwmAboutProperty = entry.getKey();
            aboutStrings.put(pwmAboutProperty.name(), entry.getValue());
        }
        aboutStrings.remove(PwmAboutProperty.app_instanceID.name());
        aboutStrings.remove(PwmAboutProperty.app_siteUrl.name());
    }
    final TelemetryPublishBean.TelemetryPublishBeanBuilder builder = TelemetryPublishBean.builder();
    builder.timestamp(Instant.now());
    builder.id(makeId(pwmApplication));
    builder.instanceHash(pwmApplication.getSecureService().hash(pwmApplication.getInstanceID()));
    builder.installTime(pwmApplication.getInstallTime());
    builder.siteDescription(config.readSettingAsString(PwmSetting.PUBLISH_STATS_SITE_DESCRIPTION));
    builder.versionBuild(PwmConstants.BUILD_NUMBER);
    builder.versionVersion(PwmConstants.BUILD_VERSION);
    builder.ldapVendorName(ldapVendorName);
    builder.statistics(Collections.unmodifiableMap(statData));
    builder.configuredSettings(Collections.unmodifiableList(configuredSettings));
    builder.about(aboutStrings);
    return builder.build();
}
Also used : Configuration(password.pwm.config.Configuration) ArrayList(java.util.ArrayList) PwmLdapVendor(password.pwm.ldap.PwmLdapVendor) TreeMap(java.util.TreeMap) LdapProfile(password.pwm.config.profile.LdapProfile) URISyntaxException(java.net.URISyntaxException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) PwmSetting(password.pwm.config.PwmSetting) PwmAboutProperty(password.pwm.PwmAboutProperty) StatisticsBundle(password.pwm.svc.stats.StatisticsBundle) Statistic(password.pwm.svc.stats.Statistic) DirectoryVendor(com.novell.ldapchai.provider.DirectoryVendor) TelemetryPublishBean(password.pwm.bean.TelemetryPublishBean)

Example 63 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class PasswordUtility method sendChangePasswordHelpdeskEmailNotice.

private static void sendChangePasswordHelpdeskEmailNotice(final PwmSession pwmSession, final PwmApplication pwmApplication, final UserInfo userInfo) throws PwmUnrecoverableException {
    final Configuration config = pwmApplication.getConfig();
    final Locale locale = pwmSession.getSessionStateBean().getLocale();
    final EmailItemBean configuredEmailSetting = config.readSettingAsEmail(PwmSetting.EMAIL_CHANGEPASSWORD_HELPDESK, locale);
    if (configuredEmailSetting == null) {
        LOGGER.debug(pwmSession, "skipping send change password email for '" + pwmSession.getUserInfo().getUserIdentity() + "' no email configured");
        return;
    }
    final MacroMachine macroMachine = userInfo == null ? null : MacroMachine.forUser(pwmApplication, pwmSession.getLabel(), userInfo, null);
    pwmApplication.getEmailQueue().submitEmail(configuredEmailSetting, userInfo, macroMachine);
}
Also used : Locale(java.util.Locale) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) Configuration(password.pwm.config.Configuration) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration) EmailItemBean(password.pwm.bean.EmailItemBean) MacroMachine(password.pwm.util.macro.MacroMachine)

Example 64 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class LocalDbOtpOperator method readOtpUserConfiguration.

@Override
public OTPUserRecord readOtpUserConfiguration(final UserIdentity theUser, final String userGUID) throws PwmUnrecoverableException {
    LOGGER.trace(String.format("Enter: readOtpUserConfiguration(%s, %s)", theUser, userGUID));
    if (userGUID == null || userGUID.length() < 1) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_MISSING_GUID, "cannot save otp to localDB, user does not have a GUID"));
    }
    if (localDB == null || localDB.status() != LocalDB.Status.OPEN) {
        final String errorMsg = "LocalDB is not available, unable to write user otp";
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_LOCALDB_UNAVAILABLE, errorMsg);
        throw new PwmUnrecoverableException(errorInformation);
    }
    OTPUserRecord otpConfig = null;
    try {
        final Configuration config = this.getPwmApplication().getConfig();
        String value = localDB.get(LocalDB.DB.OTP_SECRET, userGUID);
        if (value != null && value.length() > 0) {
            if (config.readSettingAsBoolean(PwmSetting.OTP_SECRET_ENCRYPT)) {
                value = decryptAttributeValue(value);
            }
            if (value != null) {
                otpConfig = decomposeOtpAttribute(value);
            }
            if (otpConfig != null) {
                LOGGER.debug("found user OTP secret in LocalDB: " + otpConfig.toString());
            }
        }
    } catch (LocalDBException e) {
        final String errorMsg = "unexpected LocalDB error reading otp: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        throw new PwmUnrecoverableException(errorInformation);
    } catch (PwmOperationalException e) {
        final String errorMsg = "unexpected error reading otp: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        throw new PwmUnrecoverableException(errorInformation);
    }
    return otpConfig;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) Configuration(password.pwm.config.Configuration) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) LocalDBException(password.pwm.util.localdb.LocalDBException) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 65 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class CrService method readUserChallengeProfile.

public ChallengeProfile readUserChallengeProfile(final SessionLabel sessionLabel, final UserIdentity userIdentity, final ChaiUser theUser, final PwmPasswordPolicy policy, final Locale locale) throws PwmUnrecoverableException {
    final Configuration config = pwmApplication.getConfig();
    final long methodStartTime = System.currentTimeMillis();
    ChallengeSet returnSet = null;
    if (config.readSettingAsBoolean(PwmSetting.EDIRECTORY_READ_CHALLENGE_SET)) {
        try {
            if (theUser.getChaiProvider().getDirectoryVendor() == DirectoryVendor.EDIRECTORY) {
                if (policy != null && policy.getChaiPasswordPolicy() != null) {
                    returnSet = NmasCrFactory.readAssignedChallengeSet(theUser.getChaiProvider(), policy.getChaiPasswordPolicy(), locale);
                }
                if (returnSet == null) {
                    returnSet = NmasCrFactory.readAssignedChallengeSet(theUser, locale);
                }
                if (returnSet == null) {
                    LOGGER.debug(sessionLabel, "no nmas c/r policy found for user " + theUser.getEntryDN());
                } else {
                    LOGGER.debug(sessionLabel, "using nmas c/r policy for user " + theUser.getEntryDN() + ": " + returnSet.toString());
                    final String challengeID = "nmasPolicy-" + userIdentity.toDelimitedKey();
                    final ChallengeProfile challengeProfile = ChallengeProfile.createChallengeProfile(challengeID, locale, applyPwmPolicyToNmasChallenges(returnSet, config), null, (int) config.readSettingAsLong(PwmSetting.EDIRECTORY_CR_MIN_RANDOM_DURING_SETUP), 0);
                    LOGGER.debug(sessionLabel, "using ldap c/r policy for user " + theUser.getEntryDN() + ": " + returnSet.toString());
                    LOGGER.trace(sessionLabel, "readUserChallengeProfile completed in " + TimeDuration.fromCurrent(methodStartTime).asCompactString() + ", result=" + JsonUtil.serialize(challengeProfile));
                    return challengeProfile;
                }
            }
        } catch (ChaiException e) {
            LOGGER.error(sessionLabel, "error reading nmas c/r policy for user " + theUser.getEntryDN() + ": " + e.getMessage());
        }
        LOGGER.debug(sessionLabel, "no detected c/r policy for user " + theUser.getEntryDN() + " in nmas");
    }
    // use PWM policies if PWM is configured and either its all that is configured OR the NMAS policy read was not successful
    final String challengeProfileID = determineChallengeProfileForUser(pwmApplication, sessionLabel, userIdentity, locale);
    final ChallengeProfile challengeProfile = config.getChallengeProfile(challengeProfileID, locale);
    LOGGER.trace(sessionLabel, "readUserChallengeProfile completed in " + TimeDuration.fromCurrent(methodStartTime).asCompactString() + " returned profile: " + (challengeProfile == null ? "null" : challengeProfile.getIdentifier()));
    return challengeProfile;
}
Also used : ChaiChallengeSet(com.novell.ldapchai.cr.ChaiChallengeSet) ChallengeSet(com.novell.ldapchai.cr.ChallengeSet) Configuration(password.pwm.config.Configuration) ChallengeProfile(password.pwm.config.profile.ChallengeProfile) ChaiException(com.novell.ldapchai.exception.ChaiException)

Aggregations

Configuration (password.pwm.config.Configuration)111 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)45 FormConfiguration (password.pwm.config.value.data.FormConfiguration)37 PwmApplication (password.pwm.PwmApplication)33 ErrorInformation (password.pwm.error.ErrorInformation)33 PwmOperationalException (password.pwm.error.PwmOperationalException)25 ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)23 Locale (java.util.Locale)22 PwmSession (password.pwm.http.PwmSession)21 PwmException (password.pwm.error.PwmException)17 EmailItemBean (password.pwm.bean.EmailItemBean)16 SearchConfiguration (password.pwm.ldap.search.SearchConfiguration)16 UserInfo (password.pwm.ldap.UserInfo)15 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)14 IOException (java.io.IOException)14 ArrayList (java.util.ArrayList)13 MacroMachine (password.pwm.util.macro.MacroMachine)13 LinkedHashMap (java.util.LinkedHashMap)12 Instant (java.time.Instant)11 UserIdentity (password.pwm.bean.UserIdentity)10