Search in sources :

Example 21 with Secured

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

the class AdminLabeltypeAction method details.

// -----------------------------------------------------
// Details
// -------
@Execute
@Secured({ ROLE, ROLE + VIEW })
public HtmlResponse details(final int crudMode, final String id) {
    verifyCrudMode(crudMode, CrudMode.DETAILS);
    saveToken();
    return asHtml(path_AdminLabeltype_AdminLabeltypeDetailsJsp).useForm(EditForm.class, op -> {
        op.setup(form -> {
            labelTypeService.getLabelType(id).ifPresent(entity -> {
                copyBeanToBean(entity, form, copyOp -> {
                    copyOp.excludeNull();
                    copyOp.exclude(Constants.PERMISSIONS);
                });
                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.crudMode = crudMode;
            }).orElse(() -> {
                throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), this::asListHtml);
            });
        });
    }).renderWith(data -> {
        registerRoleTypeItems(data);
    });
}
Also used : Constants(org.codelibs.fess.Constants) Secured(org.codelibs.fess.annotation.Secured) LabelTypePager(org.codelibs.fess.app.pager.LabelTypePager) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) OptionalEntity(org.dbflute.optional.OptionalEntity) OptionalThing(org.dbflute.optional.OptionalThing) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) Collectors(java.util.stream.Collectors) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) LabelType(org.codelibs.fess.es.config.exentity.LabelType) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) LabelTypeService(org.codelibs.fess.app.service.LabelTypeService) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) Stream(java.util.stream.Stream) CrudMode(org.codelibs.fess.app.web.CrudMode) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) SystemHelper(org.codelibs.fess.helper.SystemHelper) Execute(org.lastaflute.web.Execute) RenderData(org.lastaflute.web.response.render.RenderData) RoleTypeService(org.codelibs.fess.app.service.RoleTypeService) HtmlResponse(org.lastaflute.web.response.HtmlResponse) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) StringUtil(org.codelibs.core.lang.StringUtil) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 22 with Secured

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

the class AdminLogAction method download.

@Execute
@Secured({ ROLE, ROLE + VIEW })
public ActionResponse download(final String id) {
    final String filename = new String(Base64.getDecoder().decode(id), StandardCharsets.UTF_8).replace("..", "").replaceAll("\\s", "");
    final String logFilePath = systemHelper.getLogFilePath();
    if (StringUtil.isNotBlank(logFilePath) && isLogFilename(filename)) {
        final Path path = Paths.get(logFilePath, filename);
        return asStream(filename).contentTypeOctetStream().stream(out -> {
            try (InputStream in = Files.newInputStream(path)) {
                out.write(in);
            }
        });
    }
    throwValidationError(messages -> messages.addErrorsCouldNotFindLogFile(GLOBAL, filename), this::asIndexHtml);
    // no-op
    return redirect(getClass());
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 23 with Secured

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

the class AdminFileconfigAction method edit.

@Execute
@Secured({ ROLE })
public HtmlResponse edit(final EditForm form) {
    validate(form, messages -> {
    }, this::asListHtml);
    final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
    final String id = form.id;
    fileConfigService.getFileConfig(id).ifPresent(entity -> {
        copyBeanToBean(entity, form, copyOp -> {
            copyOp.excludeNull();
            copyOp.exclude(Constants.PERMISSIONS, Constants.VIRTUAL_HOSTS);
        });
        form.permissions = stream(entity.getPermissions()).get(stream -> stream.map(permissionHelper::decode).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")));
    }).orElse(() -> throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), this::asListHtml));
    saveToken();
    if (form.crudMode.intValue() == CrudMode.EDIT) {
        // back
        form.crudMode = CrudMode.DETAILS;
        return asDetailsHtml();
    }
    form.crudMode = CrudMode.EDIT;
    return asEditHtml();
}
Also used : Constants(org.codelibs.fess.Constants) 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) FileConfig(org.codelibs.fess.es.config.exentity.FileConfig) 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) FileConfigPager(org.codelibs.fess.app.pager.FileConfigPager) LabelTypeService(org.codelibs.fess.app.service.LabelTypeService) Stream(java.util.stream.Stream) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) FileConfigService(org.codelibs.fess.app.service.FileConfigService) Execute(org.lastaflute.web.Execute) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 24 with Secured

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

the class AdminPluginAction method delete.

@Execute
@Secured({ ROLE })
public HtmlResponse delete(final DeleteForm form) {
    validate(form, messages -> {
    }, () -> asHtml(path_AdminPlugin_AdminPluginJsp));
    verifyToken(() -> asHtml(path_AdminPlugin_AdminPluginJsp));
    final Artifact artifact = new Artifact(form.name, form.version, null);
    deleteArtifact(artifact);
    saveInfo(messages -> messages.addSuccessDeletePlugin(GLOBAL, artifact.getFileName()));
    return redirect(getClass());
}
Also used : Artifact(org.codelibs.fess.helper.PluginHelper.Artifact) 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