Search in sources :

Example 61 with ChaiUser

use of com.novell.ldapchai.ChaiUser in project pwm by pwm-project.

the class SetupResponsesServlet method handleClearExisting.

@ActionHandler(action = "clearExisting")
private ProcessStatus handleClearExisting(final PwmRequest pwmRequest) throws PwmUnrecoverableException, ChaiUnavailableException, IOException {
    LOGGER.trace(pwmRequest, "request for response clear received");
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    try {
        final String userGUID = pwmSession.getUserInfo().getUserGuid();
        final ChaiUser theUser = pwmSession.getSessionManager().getActor(pwmApplication);
        pwmApplication.getCrService().clearResponses(pwmSession.getLabel(), pwmRequest.getUserInfoIfLoggedIn(), theUser, userGUID);
        pwmSession.reloadUserInfoBean(pwmApplication);
        pwmRequest.getPwmApplication().getSessionStateService().clearBean(pwmRequest, SetupResponsesBean.class);
        // mark the event log
        final UserAuditRecord auditRecord = new AuditRecordFactory(pwmRequest).createUserAuditRecord(AuditEvent.CLEAR_RESPONSES, pwmSession.getUserInfo(), pwmSession);
        pwmApplication.getAuditManager().submit(auditRecord);
        pwmRequest.sendRedirect(PwmServletDefinition.SetupResponses);
    } catch (PwmOperationalException e) {
        LOGGER.debug(pwmSession, e.getErrorInformation());
        setLastError(pwmRequest, e.getErrorInformation());
    }
    return ProcessStatus.Continue;
}
Also used : UserAuditRecord(password.pwm.svc.event.UserAuditRecord) AuditRecordFactory(password.pwm.svc.event.AuditRecordFactory) PwmApplication(password.pwm.PwmApplication) ChaiUser(com.novell.ldapchai.ChaiUser) PwmSession(password.pwm.http.PwmSession) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 62 with ChaiUser

use of com.novell.ldapchai.ChaiUser in project pwm by pwm-project.

the class SetupResponsesServlet method saveResponses.

private void saveResponses(final PwmRequest pwmRequest, final ResponseInfoBean responseInfoBean) throws PwmUnrecoverableException, ChaiUnavailableException, PwmOperationalException, ChaiValidationException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    final ChaiUser theUser = pwmSession.getSessionManager().getActor(pwmApplication);
    final String userGUID = pwmSession.getUserInfo().getUserGuid();
    pwmApplication.getCrService().writeResponses(pwmRequest.getUserInfoIfLoggedIn(), theUser, userGUID, responseInfoBean);
    pwmSession.reloadUserInfoBean(pwmApplication);
    pwmApplication.getStatisticsManager().incrementValue(Statistic.SETUP_RESPONSES);
    pwmApplication.getAuditManager().submit(AuditEvent.SET_RESPONSES, pwmSession.getUserInfo(), pwmSession);
}
Also used : PwmApplication(password.pwm.PwmApplication) ChaiUser(com.novell.ldapchai.ChaiUser) PwmSession(password.pwm.http.PwmSession)

Example 63 with ChaiUser

use of com.novell.ldapchai.ChaiUser 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)

Example 64 with ChaiUser

use of com.novell.ldapchai.ChaiUser in project ldapchai by ldapchai.

the class ReadUserData method main.

public static void main(final String[] args) {
    String ldapURL = "ldap://ldaphost:389";
    String ldapBindDN = "cn=admin,ou=ou,o=o";
    String ldapBindPW = "password";
    if (args.length == 3) {
        ldapURL = args[0];
        ldapBindDN = args[1];
        ldapBindPW = args[2];
    }
    try {
        // create provider factory
        final ChaiProviderFactory chaiProviderFactory = ChaiProviderFactory.newProviderFactory();
        // create a provider using the standard JNDI factory.
        ChaiProvider chaiProvider = chaiProviderFactory.newProvider(ldapURL, ldapBindDN, ldapBindPW);
        ChaiUser user = chaiProvider.getEntryFactory().newChaiUser(ldapBindDN);
        // read the value of the bindDN's cn attribute, and print it to stdout.
        Map<String, String> allUserAttributes = user.readStringAttributes(null);
        System.out.println("UserDN: " + user.getEntryDN());
        // Output each of the user's attributes, and one value for each attribute:
        for (String key : allUserAttributes.keySet()) {
            String value = allUserAttributes.get(key);
            System.out.println(key + ": " + value);
        }
        // Detect the user's password and output the debug string
        ChaiPasswordPolicy pwdPolicy = user.getPasswordPolicy();
        System.out.println("PasswordPolicy = " + pwdPolicy);
        System.out.println("PasswordModificationDate = " + user.readPasswordModificationDate());
        System.out.println("PasswordExpirationDate = " + user.readPasswordExpirationDate());
        System.out.println("PasswordExpired = " + user.isPasswordExpired());
        System.out.println("PasswordLocked = " + user.isPasswordLocked());
        // Read the user's group membership, and output each group DN.
        System.out.println(user.getEntryDN() + " groups: ");
        for (ChaiGroup group : user.getGroups()) {
            System.out.println(group.getEntryDN());
        }
        System.out.println("");
    } catch (ChaiException e) {
        System.out.println("LDAP error: " + e.getMessage());
    }
}
Also used : ChaiPasswordPolicy(com.novell.ldapchai.ChaiPasswordPolicy) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiUser(com.novell.ldapchai.ChaiUser) ChaiProviderFactory(com.novell.ldapchai.provider.ChaiProviderFactory) ChaiGroup(com.novell.ldapchai.ChaiGroup) ChaiException(com.novell.ldapchai.exception.ChaiException)

Example 65 with ChaiUser

use of com.novell.ldapchai.ChaiUser in project ldapchai by ldapchai.

the class SimpleConnection method main.

public static void main(final String[] args) throws ChaiException {
    final ChaiProviderFactory chaiProviderFactory = ChaiProviderFactory.newProviderFactory();
    final ChaiProvider chaiProvider = chaiProviderFactory.newProvider("ldap://ldaphost:389", "cn=admin,ou=ou,o=o", "password");
    // create a provider using the quick chai factory
    final ChaiUser user = chaiProvider.getEntryFactory().newChaiUser("cn=admin,ou=ou,o=o");
    // read the value of the bindDN's cn attribute, and print it to stdout.
    final String cnValue = user.readStringAttribute("cn");
    // output the CN of the user
    System.out.println("cnValue = " + cnValue);
}
Also used : ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiUser(com.novell.ldapchai.ChaiUser) ChaiProviderFactory(com.novell.ldapchai.provider.ChaiProviderFactory)

Aggregations

ChaiUser (com.novell.ldapchai.ChaiUser)69 ErrorInformation (password.pwm.error.ErrorInformation)38 UserIdentity (password.pwm.bean.UserIdentity)30 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)27 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)25 PwmOperationalException (password.pwm.error.PwmOperationalException)23 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)21 ChaiException (com.novell.ldapchai.exception.ChaiException)18 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)18 PwmApplication (password.pwm.PwmApplication)16 PwmSession (password.pwm.http.PwmSession)12 UserInfo (password.pwm.ldap.UserInfo)12 Instant (java.time.Instant)10 FormConfiguration (password.pwm.config.value.data.FormConfiguration)10 PasswordData (password.pwm.util.PasswordData)10 MacroMachine (password.pwm.util.macro.MacroMachine)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 LdapProfile (password.pwm.config.profile.LdapProfile)9 Locale (java.util.Locale)8