Search in sources :

Example 1 with ActionConfiguration

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

the class HelpdeskDetailInfoBean method determineCustomButtons.

static List<ButtonInfo> determineCustomButtons(final HelpdeskProfile helpdeskProfile) {
    final List<ActionConfiguration> actions = helpdeskProfile.readSettingAsAction(PwmSetting.HELPDESK_ACTIONS);
    final List<ButtonInfo> buttons = new ArrayList<>();
    if (actions != null) {
        int count = 0;
        for (final ActionConfiguration action : actions) {
            buttons.add(new ButtonInfo("custom_" + count++, action.getName(), action.getDescription()));
        }
    }
    return Collections.unmodifiableList(buttons);
}
Also used : ArrayList(java.util.ArrayList) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration)

Example 2 with ActionConfiguration

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

the class HelpdeskServlet method processExecuteActionRequest.

@ActionHandler(action = "executeAction")
private ProcessStatus processExecuteActionRequest(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException, ServletException {
    final HelpdeskProfile helpdeskProfile = getHelpdeskProfile(pwmRequest);
    final String userKey = pwmRequest.readBodyAsJsonStringMap(PwmHttpRequestWrapper.Flag.BypassValidation).get(PwmConstants.PARAM_USERKEY);
    if (userKey == null || userKey.length() < 1) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_MISSING_PARAMETER, PwmConstants.PARAM_USERKEY + " parameter is missing");
        setLastError(pwmRequest, errorInformation);
        pwmRequest.respondWithError(errorInformation, false);
        return ProcessStatus.Halt;
    }
    final UserIdentity userIdentity = UserIdentity.fromKey(userKey, pwmRequest.getPwmApplication());
    LOGGER.debug(pwmRequest, "received executeAction request for user " + userIdentity.toString());
    final List<ActionConfiguration> actionConfigurations = helpdeskProfile.readSettingAsAction(PwmSetting.HELPDESK_ACTIONS);
    final String requestedName = pwmRequest.readParameterAsString("name");
    ActionConfiguration action = null;
    for (final ActionConfiguration loopAction : actionConfigurations) {
        if (requestedName != null && requestedName.equals(loopAction.getName())) {
            action = loopAction;
            break;
        }
    }
    if (action == null) {
        final String errorMsg = "request to execute unknown action: " + requestedName;
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        LOGGER.debug(pwmRequest, errorInformation.toDebugStr());
        final RestResultBean restResultBean = RestResultBean.fromError(errorInformation, pwmRequest);
        pwmRequest.outputJsonResult(restResultBean);
        return ProcessStatus.Halt;
    }
    // check if user should be seen by actor
    HelpdeskServletUtil.checkIfUserIdentityViewable(pwmRequest, helpdeskProfile, userIdentity);
    final boolean useProxy = helpdeskProfile.readSettingAsBoolean(PwmSetting.HELPDESK_USE_PROXY);
    try {
        final PwmSession pwmSession = pwmRequest.getPwmSession();
        final ChaiUser chaiUser = useProxy ? pwmRequest.getPwmApplication().getProxiedChaiUser(userIdentity) : pwmRequest.getPwmSession().getSessionManager().getActor(pwmRequest.getPwmApplication(), userIdentity);
        final MacroMachine macroMachine = MacroMachine.forUser(pwmRequest, userIdentity);
        final ActionExecutor actionExecutor = new ActionExecutor.ActionExecutorSettings(pwmRequest.getPwmApplication(), chaiUser).setExpandPwmMacros(true).setMacroMachine(macroMachine).createActionExecutor();
        actionExecutor.executeAction(action, pwmRequest.getSessionLabel());
        // mark the event log
        {
            final HelpdeskAuditRecord auditRecord = new AuditRecordFactory(pwmRequest).createHelpdeskAuditRecord(AuditEvent.HELPDESK_ACTION, pwmSession.getUserInfo().getUserIdentity(), action.getName(), userIdentity, pwmSession.getSessionStateBean().getSrcAddress(), pwmSession.getSessionStateBean().getSrcHostname());
            pwmRequest.getPwmApplication().getAuditManager().submit(auditRecord);
        }
        final RestResultBean restResultBean = RestResultBean.forSuccessMessage(pwmRequest.getLocale(), pwmRequest.getConfig(), Message.Success_Action, action.getName());
        pwmRequest.outputJsonResult(restResultBean);
        return ProcessStatus.Halt;
    } catch (PwmOperationalException e) {
        LOGGER.error(pwmRequest, e.getErrorInformation().toDebugStr());
        final RestResultBean restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmRequest);
        pwmRequest.outputJsonResult(restResultBean);
        return ProcessStatus.Halt;
    }
}
Also used : ActionExecutor(password.pwm.util.operations.ActionExecutor) UserIdentity(password.pwm.bean.UserIdentity) HelpdeskProfile(password.pwm.config.profile.HelpdeskProfile) HelpdeskAuditRecord(password.pwm.svc.event.HelpdeskAuditRecord) PwmOperationalException(password.pwm.error.PwmOperationalException) ErrorInformation(password.pwm.error.ErrorInformation) AuditRecordFactory(password.pwm.svc.event.AuditRecordFactory) ChaiUser(com.novell.ldapchai.ChaiUser) MacroMachine(password.pwm.util.macro.MacroMachine) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) PwmSession(password.pwm.http.PwmSession) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 3 with ActionConfiguration

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

the class GuestRegistrationServlet method handleCreateRequest.

private void handleCreateRequest(final PwmRequest pwmRequest, final GuestRegistrationBean guestRegistrationBean) throws PwmUnrecoverableException, ChaiUnavailableException, IOException, ServletException {
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final LocalSessionStateBean ssBean = pwmSession.getSessionStateBean();
    final Configuration config = pwmApplication.getConfig();
    final Locale locale = ssBean.getLocale();
    final List<FormConfiguration> guestUserForm = config.readSettingAsForm(PwmSetting.GUEST_FORM);
    try {
        // read the values from the request
        final Map<FormConfiguration, String> formValues = FormUtility.readFormValuesFromRequest(pwmRequest, guestUserForm, locale);
        // read the expiration date from the request.
        final Instant expirationDate = readExpirationFromRequest(pwmRequest);
        // see if the values meet form requirements.
        FormUtility.validateFormValues(config, formValues, locale);
        // read new user DN
        final String guestUserDN = determineUserDN(formValues, config);
        // read a chai provider to make the user
        final ChaiProvider provider = pwmSession.getSessionManager().getChaiProvider();
        // set up the user creation attributes
        final Map<String, String> createAttributes = new HashMap<>();
        for (final Map.Entry<FormConfiguration, String> entry : formValues.entrySet()) {
            final FormConfiguration formItem = entry.getKey();
            final String value = entry.getValue();
            LOGGER.debug(pwmSession, "Attribute from form: " + formItem.getName() + " = " + value);
            final String n = formItem.getName();
            final String v = formValues.get(formItem);
            if (n != null && n.length() > 0 && v != null && v.length() > 0) {
                createAttributes.put(n, v);
            }
        }
        // Write creator DN
        createAttributes.put(config.readSettingAsString(PwmSetting.GUEST_ADMIN_ATTRIBUTE), pwmSession.getUserInfo().getUserIdentity().getUserDN());
        // read the creation object classes.
        final Set<String> createObjectClasses = new HashSet<>(config.readSettingAsStringArray(PwmSetting.DEFAULT_OBJECT_CLASSES));
        provider.createEntry(guestUserDN, createObjectClasses, createAttributes);
        LOGGER.info(pwmSession, "created user object: " + guestUserDN);
        final ChaiUser theUser = provider.getEntryFactory().newChaiUser(guestUserDN);
        final UserIdentity userIdentity = new UserIdentity(guestUserDN, pwmSession.getUserInfo().getUserIdentity().getLdapProfileID());
        // write the expiration date:
        if (expirationDate != null) {
            final String expirationAttr = config.readSettingAsString(PwmSetting.GUEST_EXPIRATION_ATTRIBUTE);
            theUser.writeDateAttribute(expirationAttr, expirationDate);
        }
        final PwmPasswordPolicy passwordPolicy = PasswordUtility.readPasswordPolicyForUser(pwmApplication, pwmSession.getLabel(), userIdentity, theUser, locale);
        final PasswordData newPassword = RandomPasswordGenerator.createRandomPassword(pwmSession.getLabel(), passwordPolicy, pwmApplication);
        theUser.setPassword(newPassword.getStringValue());
        {
            // execute configured actions
            LOGGER.debug(pwmSession, "executing configured actions to user " + theUser.getEntryDN());
            final List<ActionConfiguration> actions = pwmApplication.getConfig().readSettingAsAction(PwmSetting.GUEST_WRITE_ATTRIBUTES);
            if (actions != null && !actions.isEmpty()) {
                final MacroMachine macroMachine = MacroMachine.forUser(pwmRequest, userIdentity);
                final ActionExecutor actionExecutor = new ActionExecutor.ActionExecutorSettings(pwmApplication, theUser).setExpandPwmMacros(true).setMacroMachine(macroMachine).createActionExecutor();
                actionExecutor.executeActions(actions, pwmRequest.getSessionLabel());
            }
        }
        // everything good so forward to success page.
        this.sendGuestUserEmailConfirmation(pwmRequest, userIdentity);
        pwmApplication.getStatisticsManager().incrementValue(Statistic.NEW_USERS);
        pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_CreateGuest);
    } catch (ChaiOperationException e) {
        final ErrorInformation info = new ErrorInformation(PwmError.ERROR_NEW_USER_FAILURE, "error creating user: " + e.getMessage());
        setLastError(pwmRequest, info);
        LOGGER.warn(pwmSession, info);
        this.forwardToJSP(pwmRequest, guestRegistrationBean);
    } catch (PwmOperationalException e) {
        LOGGER.error(pwmSession, e.getErrorInformation().toDebugStr());
        setLastError(pwmRequest, e.getErrorInformation());
        this.forwardToJSP(pwmRequest, guestRegistrationBean);
    }
}
Also used : Locale(java.util.Locale) FormConfiguration(password.pwm.config.value.data.FormConfiguration) SearchConfiguration(password.pwm.ldap.search.SearchConfiguration) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) Configuration(password.pwm.config.Configuration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PwmOperationalException(password.pwm.error.PwmOperationalException) ErrorInformation(password.pwm.error.ErrorInformation) PasswordData(password.pwm.util.PasswordData) PwmPasswordPolicy(password.pwm.config.profile.PwmPasswordPolicy) FormConfiguration(password.pwm.config.value.data.FormConfiguration) List(java.util.List) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) HashSet(java.util.HashSet) ActionExecutor(password.pwm.util.operations.ActionExecutor) PwmApplication(password.pwm.PwmApplication) Instant(java.time.Instant) UserIdentity(password.pwm.bean.UserIdentity) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiUser(com.novell.ldapchai.ChaiUser) MacroMachine(password.pwm.util.macro.MacroMachine) LocalSessionStateBean(password.pwm.bean.LocalSessionStateBean) PwmSession(password.pwm.http.PwmSession) Map(java.util.Map) FormMap(password.pwm.util.FormMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with ActionConfiguration

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

the class ConfigManagerCertificatesServlet method makeCertificateDebugData.

List<CertificateDebugDataItem> makeCertificateDebugData(final Configuration configuration) throws PwmUnrecoverableException {
    final StoredConfigurationImpl storedConfiguration = configuration.getStoredConfiguration();
    final List<StoredConfigReference> modifiedSettings = StoredConfigurationUtil.modifiedSettings(storedConfiguration);
    final List<CertificateDebugDataItem> certificateDebugDataItems = new ArrayList<>();
    for (final StoredConfigReference ref : modifiedSettings) {
        if (ref.getRecordType() == StoredConfigReference.RecordType.SETTING) {
            final PwmSetting pwmSetting = PwmSetting.forKey(ref.getRecordID());
            if (pwmSetting.getSyntax() == PwmSettingSyntax.X509CERT) {
                final StoredValue storedValue;
                if (pwmSetting.getCategory().hasProfiles()) {
                    storedValue = storedConfiguration.readSetting(pwmSetting, ref.getProfileID());
                } else {
                    storedValue = storedConfiguration.readSetting(pwmSetting);
                }
                final X509Certificate[] arrayCerts = (X509Certificate[]) storedValue.toNativeObject();
                final List<X509Certificate> certificates = arrayCerts == null ? Collections.emptyList() : Arrays.asList(arrayCerts);
                certificateDebugDataItems.addAll(makeItems(pwmSetting, ref.getProfileID(), certificates));
            } else if (pwmSetting.getSyntax() == PwmSettingSyntax.ACTION) {
                final StoredValue storedValue;
                if (pwmSetting.getCategory().hasProfiles()) {
                    storedValue = storedConfiguration.readSetting(pwmSetting, ref.getProfileID());
                } else {
                    storedValue = storedConfiguration.readSetting(pwmSetting);
                }
                final List<ActionConfiguration> actionConfigurations = (List) storedValue.toNativeObject();
                for (final ActionConfiguration actionConfiguration : actionConfigurations) {
                    final List<X509Certificate> certificates = actionConfiguration.getCertificates();
                    certificateDebugDataItems.addAll(makeItems(pwmSetting, ref.getProfileID(), certificates));
                }
            }
        }
    }
    Collections.sort(certificateDebugDataItems);
    return Collections.unmodifiableList(certificateDebugDataItems);
}
Also used : StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) ArrayList(java.util.ArrayList) StoredValue(password.pwm.config.StoredValue) X509Certificate(java.security.cert.X509Certificate) StoredConfigReference(password.pwm.config.stored.StoredConfigReference) PwmSetting(password.pwm.config.PwmSetting) ArrayList(java.util.ArrayList) List(java.util.List) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration)

Example 5 with ActionConfiguration

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

the class ActionCertImportFunction method getUri.

@Override
String getUri(final StoredConfigurationImpl storedConfiguration, final PwmSetting pwmSetting, final String profile, final String extraData) throws PwmOperationalException {
    final ActionValue actionValue = (ActionValue) storedConfiguration.readSetting(pwmSetting, profile);
    final String actionName = actionNameFromExtraData(extraData);
    final ActionConfiguration action = actionValue.forName(actionName);
    final String uriString = action.getUrl();
    if (uriString == null || uriString.isEmpty()) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, "Setting " + pwmSetting.toMenuLocationDebug(profile, null) + " action " + actionName + " must first be configured");
        throw new PwmOperationalException(errorInformation);
    }
    try {
        URI.create(uriString);
    } catch (IllegalArgumentException e) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, "Setting " + pwmSetting.toMenuLocationDebug(profile, null) + " action " + actionName + " has an invalid URL syntax");
        throw new PwmOperationalException(errorInformation);
    }
    return uriString;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ActionValue(password.pwm.config.value.ActionValue) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) PwmOperationalException(password.pwm.error.PwmOperationalException)

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