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());
}
}
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);
}
}
}
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;
}
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;
}
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");
}
}
}
Aggregations