Search in sources :

Example 1 with FessUserBean

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)));
}
Also used : ClassNotFoundRuntimeException(org.codelibs.core.exception.ClassNotFoundRuntimeException) Constants(org.codelibs.fess.Constants) SortBuilders(org.elasticsearch.search.sort.SortBuilders) Enumeration(java.util.Enumeration) Date(java.util.Date) JobConcurrentExec(org.lastaflute.job.subsidiary.JobConcurrentExec) OptionalThing(org.dbflute.optional.OptionalThing) Pair(org.codelibs.core.misc.Pair) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) IntegerTypeValidator(org.lastaflute.web.validation.theme.typed.IntegerTypeValidator) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) LongTypeValidator(org.lastaflute.web.validation.theme.typed.LongTypeValidator) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BasicAttribute(javax.naming.directory.BasicAttribute) FessUserBean(org.codelibs.fess.mylasta.action.FessUserBean) Attribute(javax.naming.directory.Attribute) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) Locale(java.util.Locale) Map(java.util.Map) PrunedTag(org.codelibs.fess.util.PrunedTag) HtmlNext(org.lastaflute.web.response.next.HtmlNext) SortBuilder(org.elasticsearch.search.sort.SortBuilder) HttpSession(javax.servlet.http.HttpSession) LaJob(org.lastaflute.job.LaJob) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) FloatTypeValidator(org.lastaflute.web.validation.theme.typed.FloatTypeValidator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StringUtil(org.codelibs.core.lang.StringUtil) Set(java.util.Set) RequiredValidator(org.lastaflute.web.validation.RequiredValidator) Tuple3(org.codelibs.core.misc.Tuple3) Collectors(java.util.stream.Collectors) List(java.util.List) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SortOrder(org.elasticsearch.search.sort.SortOrder) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) DoubleTypeValidator(org.lastaflute.web.validation.theme.typed.DoubleTypeValidator) FessFunctions(org.codelibs.fess.taglib.FessFunctions) HttpSession(javax.servlet.http.HttpSession)

Example 2 with FessUserBean

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());
}
Also used : Locale(java.util.Locale) Constants(org.codelibs.fess.Constants) UserInfoHelper(org.codelibs.fess.helper.UserInfoHelper) OptionalThing(org.dbflute.optional.OptionalThing) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) FessUserBean(org.codelibs.fess.mylasta.action.FessUserBean) HttpServletRequest(javax.servlet.http.HttpServletRequest) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) ThumbnailManager(org.codelibs.fess.thumbnail.ThumbnailManager) Locale(java.util.Locale) PopularWordHelper(org.codelibs.fess.helper.PopularWordHelper) Map(java.util.Map) QueryHelper(org.codelibs.fess.helper.QueryHelper) HtmlNext(org.lastaflute.web.response.next.HtmlNext) HtmlResponse(org.lastaflute.web.response.HtmlResponse) SearchHelper(org.codelibs.fess.helper.SearchHelper) HttpSession(javax.servlet.http.HttpSession) OpenSearchHelper(org.codelibs.fess.helper.OpenSearchHelper) SsoAction(org.codelibs.fess.app.web.sso.SsoAction) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Set(java.util.Set) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) URLUtil(org.codelibs.core.net.URLUtil) ActionResponse(org.lastaflute.web.response.ActionResponse) List(java.util.List) ComponentUtil(org.codelibs.fess.util.ComponentUtil) LoginManager(org.lastaflute.web.login.LoginManager) LabelTypeHelper(org.codelibs.fess.helper.LabelTypeHelper) RoleQueryHelper(org.codelibs.fess.helper.RoleQueryHelper) FessUserBean(org.codelibs.fess.mylasta.action.FessUserBean) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with FessUserBean

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());
}
Also used : FessSearchAction(org.codelibs.fess.app.web.base.FessSearchAction) FessUserBean(org.codelibs.fess.mylasta.action.FessUserBean) Logger(org.apache.logging.log4j.Logger) Resource(javax.annotation.Resource) Execute(org.lastaflute.web.Execute) VaErrorHook(org.lastaflute.web.validation.VaErrorHook) UserService(org.codelibs.fess.app.service.UserService) HtmlResponse(org.lastaflute.web.response.HtmlResponse) LogManager(org.apache.logging.log4j.LogManager) LoginAction(org.codelibs.fess.app.web.login.LoginAction) LocalUserCredential(org.codelibs.fess.app.web.base.login.LocalUserCredential) VaErrorHook(org.lastaflute.web.validation.VaErrorHook) Execute(org.lastaflute.web.Execute)

Example 4 with FessUserBean

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);
}
Also used : HttpSession(javax.servlet.http.HttpSession) OptionalEntity(org.dbflute.optional.OptionalEntity) OptionalThing(org.dbflute.optional.OptionalThing) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) VaErrorHook(org.lastaflute.web.validation.VaErrorHook) UserService(org.codelibs.fess.app.service.UserService) LoginFailureException(org.lastaflute.web.login.exception.LoginFailureException) LocalUserCredential(org.codelibs.fess.app.web.base.login.LocalUserCredential) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) FessUserBean(org.codelibs.fess.mylasta.action.FessUserBean) FessLoginAction(org.codelibs.fess.app.web.base.FessLoginAction) ProfileAction(org.codelibs.fess.app.web.profile.ProfileAction) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Execute(org.lastaflute.web.Execute) HtmlResponse(org.lastaflute.web.response.HtmlResponse) LogManager(org.apache.logging.log4j.LogManager) VaErrorHook(org.lastaflute.web.validation.VaErrorHook) LoginFailureException(org.lastaflute.web.login.exception.LoginFailureException) Execute(org.lastaflute.web.Execute)

Example 5 with FessUserBean

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);
    }
}
Also used : Constants(org.codelibs.fess.Constants) BufferedInputStream(java.io.BufferedInputStream) URLDecoder(java.net.URLDecoder) Date(java.util.Date) OptionalThing(org.dbflute.optional.OptionalThing) StringUtils(org.apache.commons.lang3.StringUtils) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) LaResponseUtil(org.lastaflute.web.util.LaResponseUtil) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StreamResponse(org.lastaflute.web.response.StreamResponse) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) Matcher(java.util.regex.Matcher) StreamUtil(org.codelibs.core.stream.StreamUtil) Locale(java.util.Locale) Map(java.util.Map) LaFunctions(org.lastaflute.taglib.function.LaFunctions) SearchRenderData(org.codelibs.fess.entity.SearchRenderData) HttpSession(javax.servlet.http.HttpSession) Context(com.github.jknack.handlebars.Context) FacetQueryView(org.codelibs.fess.entity.FacetQueryView) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) CoreLibConstants(org.codelibs.core.CoreLibConstants) Collectors(java.util.stream.Collectors) ActionResponse(org.lastaflute.web.response.ActionResponse) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) PostConstruct(javax.annotation.PostConstruct) LaServletContextUtil(org.lastaflute.web.util.LaServletContextUtil) FileTemplateLoader(com.github.jknack.handlebars.io.FileTemplateLoader) Pattern(java.util.regex.Pattern) CacheBuilder(com.google.common.cache.CacheBuilder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ResponseData(org.codelibs.fess.crawler.entity.ResponseData) DocumentUtil(org.codelibs.fess.util.DocumentUtil) FessSystemException(org.codelibs.fess.exception.FessSystemException) HighlightField(org.opensearch.search.fetch.subphase.highlight.HighlightField) HashMap(java.util.HashMap) ClientAbortException(org.apache.catalina.connector.ClientAbortException) Function(java.util.function.Function) CrawlingConfig(org.codelibs.fess.es.config.exentity.CrawlingConfig) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) ArrayList(java.util.ArrayList) CrawlerClient(org.codelibs.fess.crawler.client.CrawlerClient) UserAgentType(org.codelibs.fess.helper.UserAgentHelper.UserAgentType) HashSet(java.util.HashSet) FessUserBean(org.codelibs.fess.mylasta.action.FessUserBean) ResourceUtil(org.codelibs.fess.util.ResourceUtil) HttpServletRequest(javax.servlet.http.HttpServletRequest) Handlebars(com.github.jknack.handlebars.Handlebars) CharUtil(org.codelibs.fess.crawler.util.CharUtil) DynamicProperties(org.codelibs.core.misc.DynamicProperties) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) FacetResponse(org.codelibs.fess.util.FacetResponse) SessionTrackingMode(javax.servlet.SessionTrackingMode) File(java.io.File) CloseableUtil(org.codelibs.core.io.CloseableUtil) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) SearchForm(org.codelibs.fess.app.web.base.SearchForm) URLEncoder(java.net.URLEncoder) FessLoginAssist(org.codelibs.fess.app.web.base.login.FessLoginAssist) ServletContext(javax.servlet.ServletContext) HighlightInfo(org.codelibs.fess.entity.HighlightInfo) SimpleDateFormat(com.ibm.icu.text.SimpleDateFormat) Cache(com.google.common.cache.Cache) LogManager(org.apache.logging.log4j.LogManager) RequestDataBuilder(org.codelibs.fess.crawler.builder.RequestDataBuilder) CrawlerClientFactory(org.codelibs.fess.crawler.client.CrawlerClientFactory) Text(org.opensearch.common.text.Text) InputStream(java.io.InputStream) Template(com.github.jknack.handlebars.Template) FessUserBean(org.codelibs.fess.mylasta.action.FessUserBean) SearchRenderData(org.codelibs.fess.entity.SearchRenderData) ExecutionException(java.util.concurrent.ExecutionException) SearchForm(org.codelibs.fess.app.web.base.SearchForm) FessLoginAssist(org.codelibs.fess.app.web.base.login.FessLoginAssist) FessSystemException(org.codelibs.fess.exception.FessSystemException)

Aggregations

FessUserBean (org.codelibs.fess.mylasta.action.FessUserBean)7 StringUtil (org.codelibs.core.lang.StringUtil)6 ComponentUtil (org.codelibs.fess.util.ComponentUtil)6 OptionalThing (org.dbflute.optional.OptionalThing)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Map (java.util.Map)4 Set (java.util.Set)4 HttpSession (javax.servlet.http.HttpSession)4 LogManager (org.apache.logging.log4j.LogManager)4 Logger (org.apache.logging.log4j.Logger)4 Locale (java.util.Locale)3 Resource (javax.annotation.Resource)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Constants (org.codelibs.fess.Constants)3 HtmlResponse (org.lastaflute.web.response.HtmlResponse)3 LaRequestUtil (org.lastaflute.web.util.LaRequestUtil)3 Date (java.util.Date)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2