Search in sources :

Example 16 with Secured

use of org.codelibs.fess.annotation.Secured in project fess by codelibs.

the class AdminBadwordAction method upload.

@Execute
@Secured({ ROLE })
public HtmlResponse upload(final UploadForm form) {
    validate(form, messages -> {
    }, this::asUploadHtml);
    verifyToken(this::asUploadHtml);
    CommonPoolUtil.execute(() -> {
        try (Reader reader = new BufferedReader(new InputStreamReader(form.badWordFile.getInputStream(), getCsvEncoding()))) {
            badWordService.importCsv(reader);
            suggestHelper.storeAllBadWords(false);
        } catch (final Exception e) {
            throw new FessSystemException("Failed to import data.", e);
        }
    });
    saveInfo(messages -> messages.addSuccessUploadBadWord(GLOBAL));
    return redirect(getClass());
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FessSystemException(org.codelibs.fess.exception.FessSystemException) FessSystemException(org.codelibs.fess.exception.FessSystemException) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 17 with Secured

use of org.codelibs.fess.annotation.Secured in project fess by codelibs.

the class AdminWebconfigAction method createnew.

// ===================================================================================
// Edit Execute
// ============
// -----------------------------------------------------
// Entry Page
// ----------
@Execute
@Secured({ ROLE })
public HtmlResponse createnew() {
    saveToken();
    return asEditHtml().useForm(CreateForm.class, op -> {
        op.setup(form -> {
            form.initialize();
            ComponentUtil.getCrawlingConfigHelper().getDefaultConfig(ConfigType.WEB).ifPresent(entity -> {
                copyBeanToBean(entity, form, copyOp -> {
                    copyOp.excludeNull();
                    copyOp.exclude(Stream.concat(Stream.of(Constants.COMMON_CONVERSION_RULE), Stream.of(Constants.PERMISSIONS, Constants.VIRTUAL_HOSTS)).toArray(n -> new String[n]));
                });
                final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
                form.permissions = stream(entity.getPermissions()).get(stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
                form.virtualHosts = stream(entity.getVirtualHosts()).get(stream -> stream.filter(StringUtil::isNotBlank).map(String::trim).collect(Collectors.joining("\n")));
                form.name = null;
            });
            form.crudMode = CrudMode.CREATE;
        });
    });
}
Also used : Constants(org.codelibs.fess.Constants) WebConfigService(org.codelibs.fess.app.service.WebConfigService) OptionalThing(org.dbflute.optional.OptionalThing) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) CrudMode(org.codelibs.fess.app.web.CrudMode) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) RenderData(org.lastaflute.web.response.render.RenderData) RoleTypeService(org.codelibs.fess.app.service.RoleTypeService) WebConfig(org.codelibs.fess.es.config.exentity.WebConfig) HtmlResponse(org.lastaflute.web.response.HtmlResponse) ConfigType(org.codelibs.fess.es.config.exentity.CrawlingConfig.ConfigType) Secured(org.codelibs.fess.annotation.Secured) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) OptionalEntity(org.dbflute.optional.OptionalEntity) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Collectors(java.util.stream.Collectors) LabelTypeService(org.codelibs.fess.app.service.LabelTypeService) Stream(java.util.stream.Stream) ComponentUtil(org.codelibs.fess.util.ComponentUtil) ScheduledJobService(org.codelibs.fess.app.service.ScheduledJobService) SystemHelper(org.codelibs.fess.helper.SystemHelper) WebConfigPager(org.codelibs.fess.app.pager.WebConfigPager) Execute(org.lastaflute.web.Execute) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) StringUtil(org.codelibs.core.lang.StringUtil) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 18 with Secured

use of org.codelibs.fess.annotation.Secured in project fess by codelibs.

the class AdminElevatewordAction method details.

// -----------------------------------------------------
// Details
// -------
@Execute
@Secured({ ROLE, ROLE + VIEW })
public HtmlResponse details(final int crudMode, final String id) {
    verifyCrudMode(crudMode, CrudMode.DETAILS);
    saveToken();
    final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
    return asHtml(path_AdminElevateword_AdminElevatewordDetailsJsp).useForm(EditForm.class, op -> op.setup(form -> {
        elevateWordService.getElevateWord(id).ifPresent(entity -> {
            copyBeanToBean(entity, form, copyOp -> {
                copyOp.excludeNull();
                copyOp.exclude(Constants.PERMISSIONS);
            });
            form.permissions = stream(entity.getPermissions()).get(stream -> stream.map(permissionHelper::decode).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
            form.crudMode = crudMode;
        }).orElse(() -> throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), this::asListHtml));
    })).renderWith(this::registerLabels);
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) FessSystemException(org.codelibs.fess.exception.FessSystemException) ElevateWordPager(org.codelibs.fess.app.pager.ElevateWordPager) OptionalThing(org.dbflute.optional.OptionalThing) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) CrudMode(org.codelibs.fess.app.web.CrudMode) CommonPoolUtil(org.codelibs.core.concurrent.CommonPoolUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) RenderData(org.lastaflute.web.response.render.RenderData) OutputStreamWriter(java.io.OutputStreamWriter) HtmlResponse(org.lastaflute.web.response.HtmlResponse) Path(java.nio.file.Path) Secured(org.codelibs.fess.annotation.Secured) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) ElevateWordService(org.codelibs.fess.app.service.ElevateWordService) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) OptionalEntity(org.dbflute.optional.OptionalEntity) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) LabelTypeService(org.codelibs.fess.app.service.LabelTypeService) ActionResponse(org.lastaflute.web.response.ActionResponse) Stream(java.util.stream.Stream) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) Writer(java.io.Writer) Execute(org.lastaflute.web.Execute) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) BufferedReader(java.io.BufferedReader) SuggestHelper(org.codelibs.fess.helper.SuggestHelper) InputStream(java.io.InputStream) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 19 with Secured

use of org.codelibs.fess.annotation.Secured in project fess by codelibs.

the class AdminElevatewordAction method upload.

@Execute
@Secured({ ROLE })
public HtmlResponse upload(final UploadForm form) {
    validate(form, messages -> {
    }, this::asUploadHtml);
    verifyToken(this::asUploadHtml);
    CommonPoolUtil.execute(() -> {
        try (Reader reader = new BufferedReader(new InputStreamReader(form.elevateWordFile.getInputStream(), getCsvEncoding()))) {
            elevateWordService.importCsv(reader);
            suggestHelper.deleteAllElevateWord(false);
            suggestHelper.storeAllElevateWords(false);
        } catch (final Exception e) {
            throw new FessSystemException("Failed to import data.", e);
        }
    });
    saveInfo(messages -> messages.addSuccessUploadElevateWord(GLOBAL));
    return redirect(getClass());
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FessSystemException(org.codelibs.fess.exception.FessSystemException) FessSystemException(org.codelibs.fess.exception.FessSystemException) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 20 with Secured

use of org.codelibs.fess.annotation.Secured in project fess by codelibs.

the class AdminEsreqAction method upload.

@Execute
@Secured({ ROLE })
public ActionResponse upload(final UploadForm form) {
    validate(form, messages -> {
    }, () -> asListHtml(null));
    verifyTokenKeep(() -> asListHtml(this::saveToken));
    String header = null;
    final StringBuilder buf = new StringBuilder(1000);
    try (final BufferedReader reader = new BufferedReader(new InputStreamReader(form.requestFile.getInputStream(), Constants.UTF_8))) {
        header = ReaderUtil.readLine(reader);
        if (header == null) {
            throwValidationError(messages -> messages.addErrorsInvalidHeaderForRequestFile(GLOBAL, "no header"), () -> asListHtml(this::saveToken));
            // no-op
            return redirect(getClass());
        }
        String line;
        while ((line = ReaderUtil.readLine(reader)) != null) {
            buf.append(line);
        }
    } catch (final Exception e) {
        throwValidationError(messages -> messages.addErrorsFailedToReadRequestFile(GLOBAL, e.getMessage()), () -> asListHtml(this::saveToken));
    }
    final CurlRequest curlRequest = getCurlRequest(header);
    if (curlRequest == null) {
        final String msg = header;
        throwValidationError(messages -> messages.addErrorsInvalidHeaderForRequestFile(GLOBAL, msg), () -> asListHtml(this::saveToken));
    } else {
        try (final CurlResponse response = curlRequest.body(buf.toString()).execute()) {
            final File tempFile = ComponentUtil.getSystemHelper().createTempFile("esreq_", ".json");
            try (final InputStream in = response.getContentAsStream()) {
                CopyUtil.copy(in, tempFile);
            } catch (final Exception e1) {
                if (tempFile != null && tempFile.exists() && !tempFile.delete()) {
                    logger.warn("Failed to delete {}", tempFile.getAbsolutePath());
                }
                throw e1;
            }
            return asStream("es_" + System.currentTimeMillis() + ".json").contentTypeOctetStream().stream(out -> {
                try (final InputStream in = new FileInputStream(tempFile)) {
                    out.write(in);
                } finally {
                    if (tempFile.exists() && !tempFile.delete()) {
                        logger.warn("Failed to delete {}", tempFile.getAbsolutePath());
                    }
                }
            });
        } catch (final Exception e) {
            logger.warn("Failed to process request file: {}", form.requestFile.getFileName(), e);
            throwValidationError(messages -> messages.addErrorsInvalidHeaderForRequestFile(GLOBAL, e.getMessage()), () -> asListHtml(this::saveToken));
        }
    }
    // no-op
    return redirect(getClass());
}
Also used : Constants(org.codelibs.fess.Constants) Secured(org.codelibs.fess.annotation.Secured) StringUtil(org.codelibs.core.lang.StringUtil) CurlRequest(org.codelibs.curl.CurlRequest) FileInputStream(java.io.FileInputStream) InputStreamReader(java.io.InputStreamReader) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) File(java.io.File) ActionResponse(org.lastaflute.web.response.ActionResponse) Logger(org.apache.logging.log4j.Logger) CurlHelper(org.codelibs.fess.helper.CurlHelper) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Locale(java.util.Locale) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Execute(org.lastaflute.web.Execute) BufferedReader(java.io.BufferedReader) CopyUtil(org.codelibs.core.io.CopyUtil) HtmlResponse(org.lastaflute.web.response.HtmlResponse) LogManager(org.apache.logging.log4j.LogManager) ReaderUtil(org.codelibs.core.io.ReaderUtil) CurlResponse(org.codelibs.curl.CurlResponse) InputStream(java.io.InputStream) InputStreamReader(java.io.InputStreamReader) CurlResponse(org.codelibs.curl.CurlResponse) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) CurlRequest(org.codelibs.curl.CurlRequest) File(java.io.File) FileInputStream(java.io.FileInputStream) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Aggregations

Secured (org.codelibs.fess.annotation.Secured)24 Execute (org.lastaflute.web.Execute)23 FessAdminAction (org.codelibs.fess.app.web.base.FessAdminAction)14 ComponentUtil (org.codelibs.fess.util.ComponentUtil)14 HtmlResponse (org.lastaflute.web.response.HtmlResponse)14 ActionRuntime (org.lastaflute.web.ruts.process.ActionRuntime)14 StringUtil (org.codelibs.core.lang.StringUtil)13 Constants (org.codelibs.fess.Constants)12 RenderDataUtil (org.codelibs.fess.util.RenderDataUtil)10 File (java.io.File)9 List (java.util.List)9 Resource (javax.annotation.Resource)9 LogManager (org.apache.logging.log4j.LogManager)9 Logger (org.apache.logging.log4j.Logger)9 Collectors (java.util.stream.Collectors)8 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)8 OptionalEntity (org.dbflute.optional.OptionalEntity)8 InputStream (java.io.InputStream)7 FessSystemException (org.codelibs.fess.exception.FessSystemException)7 SystemHelper (org.codelibs.fess.helper.SystemHelper)7