use of org.codelibs.fess.mylasta.action.FessUserBean in project fess by codelibs.
the class FessProp method processSearchPreference.
public default default void processSearchPreference(final SearchRequestBuilder searchRequestBuilder, final OptionalThing<FessUserBean> userBean) {
userBean.map(user -> {
if (user.hasRoles(getAuthenticationAdminRolesAsArray())) {
return Constants.SEARCH_PREFERENCE_PRIMARY;
}
return user.getUserId();
}).ifPresent(p -> searchRequestBuilder.setPreference(p)).orElse(() -> LaRequestUtil.getOptionalRequest().map(r -> {
final HttpSession session = r.getSession(false);
if (session != null) {
return session.getId();
}
final String preference = r.getParameter("preference");
if (preference != null) {
return Integer.toString(preference.hashCode());
}
return null;
}).ifPresent(p -> searchRequestBuilder.setPreference(p)));
}
use of org.codelibs.fess.mylasta.action.FessUserBean in project fess by codelibs.
the class FessSearchAction method setupHtmlData.
@Override
protected void setupHtmlData(final ActionRuntime runtime) {
super.setupHtmlData(runtime);
systemHelper.setupSearchHtmlData(this, runtime);
runtime.registerData("osddLink", openSearchHelper.hasOpenSearchFile());
final List<Map<String, String>> labelTypeItems = labelTypeHelper.getLabelTypeItemList(SearchRequestType.SEARCH, request.getLocale() == null ? Locale.ROOT : request.getLocale());
runtime.registerData("labelTypeItems", labelTypeItems);
runtime.registerData("displayLabelTypeItems", labelTypeItems != null && !labelTypeItems.isEmpty());
Locale locale = ComponentUtil.getRequestManager().getUserLocale();
if (locale == null) {
locale = Locale.ENGLISH;
}
runtime.registerData("langItems", systemHelper.getLanguageItems(locale));
final String username = systemHelper.getUsername();
runtime.registerData("username", username);
runtime.registerData("editableUser", fessLoginAssist.getSavedUserBean().map(FessUserBean::isEditable).orElse(false));
runtime.registerData("adminUser", fessConfig.isAdminUser(username) || fessLoginAssist.getSavedUserBean().map(user -> user.hasRoles(fessConfig.getAuthenticationAdminRolesAsArray())).orElse(false));
runtime.registerData("pageLoginLink", fessConfig.isLoginLinkEnabled());
}
use of org.codelibs.fess.mylasta.action.FessUserBean in project fess by codelibs.
the class ProfileAction method changePassword.
@Execute
public HtmlResponse changePassword(final ProfileForm form) {
final VaErrorHook toIndexPage = () -> {
form.clearSecurityInfo();
return asIndexHtml();
};
validatePasswordForm(form, toIndexPage);
final String username = getUserBean().map(FessUserBean::getUserId).get();
try {
userService.changePassword(username, form.newPassword);
saveInfo(messages -> messages.addSuccessChangedPassword(GLOBAL));
} catch (final Exception e) {
logger.error("Failed to change password for {}", username, e);
throwValidationError(messages -> messages.addErrorsFailedToChangePassword(GLOBAL), toIndexPage);
}
return redirect(getClass());
}
use of org.codelibs.fess.mylasta.action.FessUserBean in project fess by codelibs.
the class LoginAction method changePassword.
@Execute
public HtmlResponse changePassword(final PasswordForm form) {
final VaErrorHook toIndexPage = () -> {
form.clearSecurityInfo();
return getUserBean().map(u -> asHtml(virtualHost(path_Login_NewpasswordJsp)).useForm(PasswordForm.class)).orElseGet(() -> redirect(LoginAction.class));
};
validatePasswordForm(form, toIndexPage);
final String username = getUserBean().map(FessUserBean::getUserId).get();
try {
userService.changePassword(username, form.password);
saveInfo(messages -> messages.addSuccessChangedPassword(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to change newPassword for {}", username, e);
throwValidationError(messages -> messages.addErrorsFailedToChangePassword(GLOBAL), toIndexPage);
}
getSession().ifPresent(session -> session.removeAttribute(INVALID_OLD_PASSWORD));
return redirect(ProfileAction.class);
}
use of org.codelibs.fess.mylasta.action.FessUserBean in project fess by codelibs.
the class ViewHelper method getCachedFacetResponse.
public FacetResponse getCachedFacetResponse(final String query) {
final OptionalThing<FessUserBean> userBean = ComponentUtil.getComponent(FessLoginAssist.class).getSavedUserBean();
final String permissionKey = userBean.map(user -> StreamUtil.stream(user.getPermissions()).get(stream -> stream.sorted().distinct().collect(Collectors.joining("\n")))).orElse(StringUtil.EMPTY);
try {
return facetCache.get(query + "\n" + permissionKey, () -> {
final SearchHelper searchHelper = ComponentUtil.getSearchHelper();
final SearchForm params = new SearchForm() {
@Override
public int getPageSize() {
return 0;
}
@Override
public int getStartPosition() {
return 0;
}
};
params.q = query;
final SearchRenderData data = new SearchRenderData();
searchHelper.search(params, data, userBean);
if (logger.isDebugEnabled()) {
logger.debug("loaded facet data: {}", data);
}
return data.getFacetResponse();
});
} catch (final ExecutionException e) {
throw new FessSystemException("Cannot load facet from cache.", e);
}
}
Aggregations