Search in sources :

Example 71 with PwmOperationalException

use of password.pwm.error.PwmOperationalException in project pwm by pwm-project.

the class ExportLocalDBCommand method doCommand.

@Override
void doCommand() throws Exception {
    final LocalDB localDB = cliEnvironment.getLocalDB();
    final File outputFile = (File) cliEnvironment.getOptions().get(CliParameters.REQUIRED_NEW_OUTPUT_FILE.getName());
    if (outputFile.exists()) {
        out("outputFile for exportLocalDB cannot already exist");
        return;
    }
    final LocalDBUtility localDBUtility = new LocalDBUtility(localDB);
    try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile)) {
        localDBUtility.exportLocalDB(fileOutputStream, System.out, true);
    } catch (PwmOperationalException e) {
        out("error during export: " + e.getMessage());
    }
}
Also used : LocalDBUtility(password.pwm.util.localdb.LocalDBUtility) FileOutputStream(java.io.FileOutputStream) LocalDB(password.pwm.util.localdb.LocalDB) File(java.io.File) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 72 with PwmOperationalException

use of password.pwm.error.PwmOperationalException in project pwm by pwm-project.

the class CryptoCookieLoginImpl method readLoginSessionState.

@Override
public void readLoginSessionState(final PwmRequest pwmRequest) throws PwmUnrecoverableException {
    final LoginInfoBean remoteLoginCookie;
    try {
        remoteLoginCookie = pwmRequest.readEncryptedCookie(cookieName, LoginInfoBean.class);
    } catch (PwmUnrecoverableException e) {
        final String errorMsg = "unexpected error reading login cookie, will clear and ignore; error: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        LOGGER.error(pwmRequest, errorInformation);
        clearLoginSession(pwmRequest);
        return;
    }
    if (remoteLoginCookie != null) {
        try {
            try {
                checkIfRemoteLoginCookieIsValid(pwmRequest, remoteLoginCookie);
            } catch (PwmOperationalException e) {
                LOGGER.debug(pwmRequest, e.getErrorInformation().toDebugStr());
                clearLoginSession(pwmRequest);
                return;
            }
            checkIfLoginCookieIsForeign(pwmRequest, remoteLoginCookie);
            importRemoteCookie(pwmRequest, remoteLoginCookie);
        } catch (Exception e) {
            final String errorMsg = "unexpected error authenticating using crypto session cookie: " + e.getMessage();
            final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
            LOGGER.error(pwmRequest, errorInformation);
            throw new PwmUnrecoverableException(errorInformation);
        }
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) LoginInfoBean(password.pwm.bean.LoginInfoBean) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 73 with PwmOperationalException

use of password.pwm.error.PwmOperationalException in project pwm by pwm-project.

the class PeopleSearchDataReader method makeUserDetailRequest.

UserDetailBean makeUserDetailRequest(final String userKey) throws PwmUnrecoverableException, PwmOperationalException, ChaiUnavailableException {
    final Instant startTime = Instant.now();
    final UserIdentity userIdentity = UserIdentity.fromKey(userKey, pwmRequest.getPwmApplication());
    final CacheKey cacheKey = makeCacheKey(UserDetailBean.class.getSimpleName(), userIdentity.toDelimitedKey());
    {
        final String cachedOutput = pwmRequest.getPwmApplication().getCacheService().get(cacheKey);
        if (cachedOutput != null) {
            StatisticsManager.incrementStat(pwmRequest, Statistic.PEOPLESEARCH_CACHE_HITS);
            return JsonUtil.deserialize(cachedOutput, UserDetailBean.class);
        } else {
            StatisticsManager.incrementStat(pwmRequest, Statistic.PEOPLESEARCH_CACHE_MISSES);
        }
    }
    try {
        checkIfUserIdentityViewable(userIdentity);
    } catch (PwmOperationalException e) {
        LOGGER.error(pwmRequest.getPwmSession(), "error during detail results request while checking if requested userIdentity is within search scope: " + e.getMessage());
        throw e;
    }
    final UserSearchResults detailResults = doDetailLookup(userIdentity);
    final Map<String, String> searchResults = detailResults.getResults().get(userIdentity);
    final UserDetailBean userDetailBean = new UserDetailBean();
    userDetailBean.setUserKey(userKey);
    final List<FormConfiguration> detailFormConfig = pwmRequest.getConfig().readSettingAsForm(PwmSetting.PEOPLE_SEARCH_DETAIL_FORM);
    final Map<String, AttributeDetailBean> attributeBeans = convertResultMapToBeans(pwmRequest, userIdentity, detailFormConfig, searchResults);
    userDetailBean.setDetail(attributeBeans);
    final String photoURL = figurePhotoURL(pwmRequest, userIdentity);
    if (photoURL != null) {
        userDetailBean.setPhotoURL(photoURL);
    }
    final List<String> displayName = figureDisplaynames(pwmRequest, userIdentity);
    if (displayName != null) {
        userDetailBean.setDisplayNames(displayName);
    }
    userDetailBean.setLinks(makeUserDetailLinks(userIdentity));
    LOGGER.trace(pwmRequest.getPwmSession(), "finished building userDetail result in " + TimeDuration.fromCurrent(startTime).asCompactString());
    storeDataInCache(pwmRequest.getPwmApplication(), cacheKey, userDetailBean);
    return userDetailBean;
}
Also used : Instant(java.time.Instant) UserIdentity(password.pwm.bean.UserIdentity) UserSearchResults(password.pwm.ldap.search.UserSearchResults) PwmOperationalException(password.pwm.error.PwmOperationalException) FormConfiguration(password.pwm.config.value.data.FormConfiguration) CacheKey(password.pwm.svc.cache.CacheKey)

Example 74 with PwmOperationalException

use of password.pwm.error.PwmOperationalException in project pwm by pwm-project.

the class PeopleSearchDataReader method figurePhotoURL.

private String figurePhotoURL(final PwmRequest pwmRequest, final UserIdentity userIdentity) throws PwmUnrecoverableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final boolean enabled = peopleSearchConfiguration.isPhotosEnabled(pwmRequest.getUserInfoIfLoggedIn(), pwmRequest.getSessionLabel());
    if (!enabled) {
        LOGGER.debug(pwmRequest, "detailed user data lookup for " + userIdentity.toString() + ", failed photo query filter, denying photo view");
        return null;
    }
    final String overrideURL = peopleSearchConfiguration.getPhotoUrlOverride(userIdentity);
    try {
        if (overrideURL != null && !overrideURL.isEmpty()) {
            final MacroMachine macroMachine = getMacroMachine(userIdentity);
            return macroMachine.expandMacros(overrideURL);
        }
        try {
            readPhotoDataFromLdap(userIdentity);
        } catch (PwmOperationalException e) {
            LOGGER.debug(pwmRequest, "determined " + userIdentity + " does not have photo data available while generating detail data");
            return null;
        }
    } catch (ChaiUnavailableException e) {
        throw PwmUnrecoverableException.fromChaiException(e);
    }
    String returnUrl = pwmRequest.getURLwithoutQueryString();
    returnUrl = PwmURL.appendAndEncodeUrlParameters(returnUrl, PwmConstants.PARAM_ACTION_REQUEST, PeopleSearchServlet.PeopleSearchActions.photo.name());
    returnUrl = PwmURL.appendAndEncodeUrlParameters(returnUrl, PwmConstants.PARAM_USERKEY, userIdentity.toObfuscatedKey(pwmApplication));
    return returnUrl;
}
Also used : PwmApplication(password.pwm.PwmApplication) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) MacroMachine(password.pwm.util.macro.MacroMachine) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 75 with PwmOperationalException

use of password.pwm.error.PwmOperationalException in project pwm by pwm-project.

the class LdapOperationsHelper method writeMapToLdap.

/**
 * Writes a Map of values to ldap onto the supplied user object.
 * The map key must be a string of attribute names.
 * <p/>
 * Any ldap operation exceptions are not reported (but logged).
 *
 * @param theUser  User to write to
 * @param valueMap A map with String keys and String values.
 * @throws ChaiUnavailableException if the directory is unavailable
 * @throws PwmOperationalException  if their is an unexpected ldap problem
 */
public static void writeMapToLdap(final ChaiUser theUser, final Map<String, String> valueMap, final MacroMachine macroMachine, final boolean expandMacros) throws PwmOperationalException, ChaiUnavailableException {
    final Map<String, String> currentValues;
    try {
        currentValues = theUser.readStringAttributes(valueMap.keySet());
    } catch (ChaiOperationException e) {
        final String errorMsg = "error reading existing values on user " + theUser.getEntryDN() + " prior to replacing values, error: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        final PwmOperationalException newException = new PwmOperationalException(errorInformation);
        newException.initCause(e);
        throw newException;
    }
    for (final Map.Entry<String, String> entry : valueMap.entrySet()) {
        final String attrName = entry.getKey();
        final String value = entry.getValue();
        String attrValue = value != null ? value : "";
        if (expandMacros) {
            attrValue = macroMachine.expandMacros(attrValue);
        }
        if (!attrValue.equals(currentValues.get(attrName))) {
            if (attrValue.length() > 0) {
                try {
                    theUser.writeStringAttribute(attrName, attrValue);
                    LOGGER.info("set attribute on user " + theUser.getEntryDN() + " (" + attrName + "=" + attrValue + ")");
                } catch (ChaiOperationException e) {
                    final String errorMsg = "error setting '" + attrName + "' attribute on user " + theUser.getEntryDN() + ", error: " + e.getMessage();
                    final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
                    final PwmOperationalException newException = new PwmOperationalException(errorInformation);
                    newException.initCause(e);
                    throw newException;
                }
            } else {
                if (currentValues.get(attrName) != null && currentValues.get(attrName).length() > 0) {
                    try {
                        theUser.deleteAttribute(attrName, null);
                        LOGGER.info("deleted attribute value on user " + theUser.getEntryDN() + " (" + attrName + ")");
                    } catch (ChaiOperationException e) {
                        final String errorMsg = "error removing '" + attrName + "' attribute value on user " + theUser.getEntryDN() + ", error: " + e.getMessage();
                        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
                        final PwmOperationalException newException = new PwmOperationalException(errorInformation);
                        newException.initCause(e);
                        throw newException;
                    }
                }
            }
        } else {
            LOGGER.debug("skipping attribute modify for attribute '" + attrName + "', no change in value");
        }
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) Map(java.util.Map) HashMap(java.util.HashMap) PwmOperationalException(password.pwm.error.PwmOperationalException)

Aggregations

PwmOperationalException (password.pwm.error.PwmOperationalException)134 ErrorInformation (password.pwm.error.ErrorInformation)104 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)57 UserIdentity (password.pwm.bean.UserIdentity)39 PwmApplication (password.pwm.PwmApplication)27 PwmSession (password.pwm.http.PwmSession)26 ChaiUser (com.novell.ldapchai.ChaiUser)20 Configuration (password.pwm.config.Configuration)19 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)17 UserSearchEngine (password.pwm.ldap.search.UserSearchEngine)17 FormConfiguration (password.pwm.config.value.data.FormConfiguration)16 PwmException (password.pwm.error.PwmException)16 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)15 SearchConfiguration (password.pwm.ldap.search.SearchConfiguration)14 Instant (java.time.Instant)13 LinkedHashMap (java.util.LinkedHashMap)13 MacroMachine (password.pwm.util.macro.MacroMachine)13 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12 UserInfo (password.pwm.ldap.UserInfo)11