Search in sources :

Example 11 with ActionConfiguration

use of password.pwm.config.value.data.ActionConfiguration in project pwm by pwm-project.

the class ActionValue method toDebugString.

public String toDebugString(final Locale locale) {
    final StringBuilder sb = new StringBuilder();
    int counter = 0;
    for (final ActionConfiguration actionConfiguration : values) {
        sb.append("Action");
        if (values.size() > 1) {
            sb.append(counter);
        }
        sb.append("-");
        sb.append(actionConfiguration.getType() == null ? ActionConfiguration.Type.ldap.toString() : actionConfiguration.getType().toString());
        sb.append(": [");
        switch(actionConfiguration.getType()) {
            case webservice:
                {
                    sb.append("WebService: ");
                    sb.append("method=").append(actionConfiguration.getMethod());
                    sb.append(" url=").append(actionConfiguration.getUrl());
                    sb.append(" headers=").append(JsonUtil.serializeMap(actionConfiguration.getHeaders()));
                    sb.append(" username=").append(actionConfiguration.getUsername());
                    sb.append(" password=").append(StringUtil.isEmpty(actionConfiguration.getPassword()) ? "" : PwmConstants.LOG_REMOVED_VALUE_REPLACEMENT);
                    sb.append(" body=").append(actionConfiguration.getBody());
                }
                break;
            case ldap:
                {
                    sb.append("LDAP: ");
                    sb.append("method=").append(actionConfiguration.getLdapMethod());
                    sb.append(" attribute=").append(actionConfiguration.getAttributeName());
                    sb.append(" value=").append(actionConfiguration.getAttributeValue());
                }
                break;
            default:
                JavaHelper.unhandledSwitchStatement(actionConfiguration.getType());
        }
        sb.append("]");
        counter++;
        if (counter != values.size()) {
            sb.append("\n");
        }
    }
    return sb.toString();
}
Also used : ActionConfiguration(password.pwm.config.value.data.ActionConfiguration)

Example 12 with ActionConfiguration

use of password.pwm.config.value.data.ActionConfiguration in project pwm by pwm-project.

the class CertificateChecker method doActionHealthCheck.

private static List<HealthRecord> doActionHealthCheck(final Configuration configuration) throws PwmUnrecoverableException {
    final StoredConfigurationImpl storedConfiguration = configuration.getStoredConfiguration();
    final List<HealthRecord> returnList = new ArrayList<>();
    final List<StoredConfigReference> modifiedReferences = StoredConfigurationUtil.modifiedSettings(storedConfiguration);
    for (final StoredConfigReference storedConfigReference : modifiedReferences) {
        if (storedConfigReference.getRecordType() == StoredConfigReference.RecordType.SETTING) {
            final PwmSetting pwmSetting = PwmSetting.forKey(storedConfigReference.getRecordID());
            if (pwmSetting != null && pwmSetting.getSyntax() == PwmSettingSyntax.ACTION) {
                final ActionValue value = (ActionValue) storedConfiguration.readSetting(pwmSetting, storedConfigReference.getProfileID());
                for (final ActionConfiguration actionConfiguration : value.toNativeObject()) {
                    final List<X509Certificate> certificates = actionConfiguration.getCertificates();
                    returnList.addAll(doHealthCheck(configuration, pwmSetting, storedConfigReference.getProfileID(), certificates));
                }
            }
        }
    }
    return Collections.unmodifiableList(returnList);
}
Also used : StoredConfigReference(password.pwm.config.stored.StoredConfigReference) PwmSetting(password.pwm.config.PwmSetting) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) ActionValue(password.pwm.config.value.ActionValue) ArrayList(java.util.ArrayList) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) X509Certificate(java.security.cert.X509Certificate)

Example 13 with ActionConfiguration

use of password.pwm.config.value.data.ActionConfiguration in project pwm by pwm-project.

the class ActionCertImportFunction method store.

void store(final List<X509Certificate> certs, final StoredConfigurationImpl storedConfiguration, final PwmSetting pwmSetting, final String profile, final String extraData, final UserIdentity userIdentity) throws PwmOperationalException, PwmUnrecoverableException {
    final ActionValue actionValue = (ActionValue) storedConfiguration.readSetting(pwmSetting, profile);
    final String actionName = actionNameFromExtraData(extraData);
    final List<ActionConfiguration> newList = new ArrayList<>();
    for (final ActionConfiguration loopConfiguration : actionValue.toNativeObject()) {
        if (actionName.equals(loopConfiguration.getName())) {
            final ActionConfiguration newConfig = loopConfiguration.copyWithNewCertificate(certs);
            newList.add(newConfig);
        } else {
            newList.add(JsonUtil.cloneUsingJson(loopConfiguration, ActionConfiguration.class));
        }
    }
    final ActionValue newActionValue = new ActionValue(newList);
    storedConfiguration.writeSetting(pwmSetting, profile, newActionValue, userIdentity);
}
Also used : ActionValue(password.pwm.config.value.ActionValue) ArrayList(java.util.ArrayList) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration)

Example 14 with ActionConfiguration

use of password.pwm.config.value.data.ActionConfiguration in project pwm by pwm-project.

the class ActivateUserUtils method activateUser.

@SuppressFBWarnings("SE_BAD_FIELD")
static void activateUser(final PwmRequest pwmRequest, final UserIdentity userIdentity) throws ChaiUnavailableException, PwmUnrecoverableException, PwmOperationalException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    final Configuration config = pwmApplication.getConfig();
    final ChaiUser theUser = pwmApplication.getProxiedChaiUser(userIdentity);
    if (config.readSettingAsBoolean(PwmSetting.ACTIVATE_USER_UNLOCK)) {
        try {
            theUser.unlockPassword();
        } catch (ChaiOperationException e) {
            final String errorMsg = "error unlocking user " + userIdentity + ": " + e.getMessage();
            final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_ACTIVATION_FAILURE, errorMsg);
            throw new PwmOperationalException(errorInformation);
        }
    }
    try {
        {
            // execute configured actions
            LOGGER.debug(pwmSession.getLabel(), "executing configured pre-actions to user " + theUser.getEntryDN());
            final List<ActionConfiguration> configValues = config.readSettingAsAction(PwmSetting.ACTIVATE_USER_PRE_WRITE_ATTRIBUTES);
            if (configValues != null && !configValues.isEmpty()) {
                final MacroMachine macroMachine = MacroMachine.forUser(pwmRequest, userIdentity);
                final ActionExecutor actionExecutor = new ActionExecutor.ActionExecutorSettings(pwmApplication, userIdentity).setExpandPwmMacros(true).setMacroMachine(macroMachine).createActionExecutor();
                actionExecutor.executeActions(configValues, pwmRequest.getSessionLabel());
            }
        }
        // authenticate the pwm session
        final SessionAuthenticator sessionAuthenticator = new SessionAuthenticator(pwmApplication, pwmSession, PwmAuthenticationSource.USER_ACTIVATION);
        sessionAuthenticator.authUserWithUnknownPassword(userIdentity, AuthenticationType.AUTH_FROM_PUBLIC_MODULE);
        // ensure a change password is triggered
        pwmSession.getLoginInfoBean().setType(AuthenticationType.AUTH_FROM_PUBLIC_MODULE);
        pwmSession.getLoginInfoBean().getAuthFlags().add(AuthenticationType.AUTH_FROM_PUBLIC_MODULE);
        pwmSession.getLoginInfoBean().getLoginFlags().add(LoginInfoBean.LoginFlag.forcePwChange);
        // mark the event log
        pwmApplication.getAuditManager().submit(AuditEvent.ACTIVATE_USER, pwmSession.getUserInfo(), pwmSession);
        // update the stats bean
        pwmApplication.getStatisticsManager().incrementValue(Statistic.ACTIVATED_USERS);
        // send email or sms
        sendPostActivationNotice(pwmRequest);
        // setup post-change attributes
        final PostChangePasswordAction postAction = new PostChangePasswordAction() {

            public String getLabel() {
                return "ActivateUser write attributes";
            }

            public boolean doAction(final PwmSession pwmSession, final String newPassword) throws PwmUnrecoverableException {
                try {
                    {
                        // execute configured actions
                        LOGGER.debug(pwmSession.getLabel(), "executing post-activate configured actions to user " + userIdentity.toDisplayString());
                        final MacroMachine macroMachine = pwmSession.getSessionManager().getMacroMachine(pwmApplication);
                        final List<ActionConfiguration> configValues = pwmApplication.getConfig().readSettingAsAction(PwmSetting.ACTIVATE_USER_POST_WRITE_ATTRIBUTES);
                        final ActionExecutor actionExecutor = new ActionExecutor.ActionExecutorSettings(pwmApplication, userIdentity).setExpandPwmMacros(true).setMacroMachine(macroMachine).createActionExecutor();
                        actionExecutor.executeActions(configValues, pwmRequest.getSessionLabel());
                    }
                } catch (PwmOperationalException e) {
                    final ErrorInformation info = new ErrorInformation(PwmError.ERROR_ACTIVATION_FAILURE, e.getErrorInformation().getDetailedErrorMsg(), e.getErrorInformation().getFieldValues());
                    final PwmUnrecoverableException newException = new PwmUnrecoverableException(info);
                    newException.initCause(e);
                    throw newException;
                } catch (ChaiUnavailableException e) {
                    final String errorMsg = "unable to reach ldap server while writing post-activate attributes: " + e.getMessage();
                    final ErrorInformation info = new ErrorInformation(PwmError.ERROR_ACTIVATION_FAILURE, errorMsg);
                    final PwmUnrecoverableException newException = new PwmUnrecoverableException(info);
                    newException.initCause(e);
                    throw newException;
                }
                return true;
            }
        };
        pwmSession.getUserSessionDataCacheBean().addPostChangePasswordActions("activateUserWriteAttributes", postAction);
    } catch (ImpossiblePasswordPolicyException e) {
        final ErrorInformation info = new ErrorInformation(PwmError.ERROR_UNKNOWN, "unexpected ImpossiblePasswordPolicyException error while activating user");
        LOGGER.warn(pwmSession, info, e);
        throw new PwmOperationalException(info);
    }
}
Also used : ActionExecutor(password.pwm.util.operations.ActionExecutor) PwmApplication(password.pwm.PwmApplication) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) Configuration(password.pwm.config.Configuration) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) SessionAuthenticator(password.pwm.ldap.auth.SessionAuthenticator) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PostChangePasswordAction(password.pwm.util.PostChangePasswordAction) PwmOperationalException(password.pwm.error.PwmOperationalException) ErrorInformation(password.pwm.error.ErrorInformation) ChaiUser(com.novell.ldapchai.ChaiUser) MacroMachine(password.pwm.util.macro.MacroMachine) List(java.util.List) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) PwmSession(password.pwm.http.PwmSession) ImpossiblePasswordPolicyException(com.novell.ldapchai.exception.ImpossiblePasswordPolicyException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)14 ArrayList (java.util.ArrayList)9 List (java.util.List)6 ErrorInformation (password.pwm.error.ErrorInformation)5 PwmOperationalException (password.pwm.error.PwmOperationalException)5 ChaiUser (com.novell.ldapchai.ChaiUser)3 X509Certificate (java.security.cert.X509Certificate)3 ActionValue (password.pwm.config.value.ActionValue)3 FormConfiguration (password.pwm.config.value.data.FormConfiguration)3 PwmSession (password.pwm.http.PwmSession)3 MacroMachine (password.pwm.util.macro.MacroMachine)3 ActionExecutor (password.pwm.util.operations.ActionExecutor)3 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)2 Map (java.util.Map)2 Element (org.jdom2.Element)2 PwmApplication (password.pwm.PwmApplication)2 UserIdentity (password.pwm.bean.UserIdentity)2 Configuration (password.pwm.config.Configuration)2 PwmSetting (password.pwm.config.PwmSetting)2 StoredConfigReference (password.pwm.config.stored.StoredConfigReference)2