Search in sources :

Example 1 with Secured

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

the class AdminWizardAction method startCrawling.

@Execute
@Secured({ ROLE })
public HtmlResponse startCrawling(final StartCrawlingForm form) {
    verifyToken(this::asIndexHtml);
    if (!processHelper.isProcessRunning()) {
        final List<ScheduledJob> scheduledJobList = scheduledJobService.getCrawlerJobList();
        final JobManager jobManager = ComponentUtil.getJobManager();
        for (final ScheduledJob scheduledJob : scheduledJobList) {
            jobManager.findJobByUniqueOf(LaJobUnique.of(scheduledJob.getId())).ifPresent(job -> {
                job.launchNow();
            });
        }
        saveInfo(messages -> messages.addSuccessStartCrawlProcess(GLOBAL));
    } else {
        saveError(messages -> messages.addErrorsFailedToStartCrawlProcess(GLOBAL));
    }
    return redirect(AdminWizardAction.class);
}
Also used : ScheduledJob(org.codelibs.fess.es.config.exentity.ScheduledJob) JobManager(org.lastaflute.job.JobManager) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 2 with Secured

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

the class AdminStorageAction method download.

@Execute
@Secured({ ROLE, ROLE + VIEW })
public ActionResponse download(final String id) {
    final String[] values = decodeId(id);
    if (StringUtil.isEmpty(values[1])) {
        throwValidationError(messages -> messages.addErrorsStorageFileNotFound(GLOBAL), () -> asListHtml(encodeId(values[0])));
    }
    final StreamResponse response = new StreamResponse(StringUtil.EMPTY);
    final String name = values[1];
    final String encodedName = URLEncoder.encode(name, Constants.UTF_8_CHARSET).replace("+", "%20");
    response.header("Content-Disposition", "attachment; filename=\"" + name + "\"; filename*=utf-8''" + encodedName);
    response.header("Pragma", "no-cache");
    response.header("Cache-Control", "no-cache");
    response.header("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
    response.contentTypeOctetStream();
    return response.stream(out -> {
        try {
            downloadObject(getObjectName(values[0], values[1]), out);
        } catch (final StorageException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to download {}", values[1], e);
            }
            throwValidationError(messages -> messages.addErrorsStorageFileDownloadFailure(GLOBAL, values[1]), () -> asListHtml(encodeId(values[0])));
        }
    });
}
Also used : Result(io.minio.Result) URLDecoder(java.net.URLDecoder) MakeBucketArgs(io.minio.MakeBucketArgs) OptionalThing(org.dbflute.optional.OptionalThing) HashMap(java.util.HashMap) GetObjectArgs(io.minio.GetObjectArgs) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StreamResponse(org.lastaflute.web.response.StreamResponse) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Map(java.util.Map) MinioClient(io.minio.MinioClient) Item(io.minio.messages.Item) PutObjectArgs(io.minio.PutObjectArgs) HtmlResponse(org.lastaflute.web.response.HtmlResponse) Secured(org.codelibs.fess.annotation.Secured) StringUtil(org.codelibs.core.lang.StringUtil) ListObjectsArgs(io.minio.ListObjectsArgs) StorageException(org.codelibs.fess.exception.StorageException) Constants(org.codelibs.fess.crawler.Constants) ActionResponse(org.lastaflute.web.response.ActionResponse) URLEncoder(java.net.URLEncoder) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) RemoveObjectArgs(io.minio.RemoveObjectArgs) MultipartFormFile(org.lastaflute.web.ruts.multipart.MultipartFormFile) Execute(org.lastaflute.web.Execute) WrittenStreamOut(org.lastaflute.web.servlet.request.stream.WrittenStreamOut) ErrorResponseException(io.minio.errors.ErrorResponseException) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) StreamResponse(org.lastaflute.web.response.StreamResponse) StorageException(org.codelibs.fess.exception.StorageException) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 3 with Secured

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

the class AdminMaintenanceAction method downloadLogs.

@Execute
@Secured({ ROLE, ROLE + VIEW })
public ActionResponse downloadLogs(final ActionForm form) {
    validate(form, messages -> {
    }, this::asIndexHtml);
    verifyTokenKeep(this::asIndexHtml);
    final String diagnosticId = "log" + new SimpleDateFormat("yyyyMMddHHmm").format(ComponentUtil.getSystemHelper().getCurrentTime());
    return asStream(diagnosticId + ".zip").contentTypeOctetStream().stream(out -> {
        try (ZipOutputStream zos = new ZipOutputStream(out.stream())) {
            writeLogFiles(zos, diagnosticId);
            writeSystemProperties(zos, diagnosticId);
            writeFessBasicConfig(zos, diagnosticId);
            writeFessConfig(zos, diagnosticId);
            writeFesenCat(zos, diagnosticId);
            writeFesenJson(zos, diagnosticId);
        }
    });
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) SimpleDateFormat(java.text.SimpleDateFormat) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 4 with Secured

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

the class AdminSearchlistAction method delete.

// -----------------------------------------------------
// Confirm
// -------
@Execute
@Secured({ ROLE })
public HtmlResponse delete(final DeleteForm form) {
    validate(form, messages -> {
    }, this::asListHtml);
    verifyToken(this::asListHtml);
    final String docId = form.docId;
    try {
        final QueryBuilder query = QueryBuilders.termQuery(fessConfig.getIndexFieldDocId(), docId);
        searchEngineClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(), query);
        saveInfo(messages -> messages.addSuccessDeleteDocFromIndex(GLOBAL));
    } catch (final Exception e) {
        throwValidationError(messages -> messages.addErrorsFailedToDeleteDocInAdmin(GLOBAL), this::asListHtml);
    }
    return asListHtml();
}
Also used : Constants(org.codelibs.fess.Constants) HashMap(java.util.HashMap) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) HttpServletRequest(javax.servlet.http.HttpServletRequest) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) CrudMode(org.codelibs.fess.app.web.CrudMode) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Map(java.util.Map) QueryHelper(org.codelibs.fess.helper.QueryHelper) RenderData(org.lastaflute.web.response.render.RenderData) HtmlResponse(org.lastaflute.web.response.HtmlResponse) SearchHelper(org.codelibs.fess.helper.SearchHelper) SearchRenderData(org.codelibs.fess.entity.SearchRenderData) QueryBuilders(org.opensearch.index.query.QueryBuilders) Secured(org.codelibs.fess.annotation.Secured) FessMessages(org.codelibs.fess.mylasta.action.FessMessages) OptionalEntity(org.dbflute.optional.OptionalEntity) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Consumer(java.util.function.Consumer) URLUtil(org.codelibs.core.net.URLUtil) List(java.util.List) Logger(org.apache.logging.log4j.Logger) QueryBuilder(org.opensearch.index.query.QueryBuilder) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) Execute(org.lastaflute.web.Execute) VaMessenger(org.lastaflute.web.validation.VaMessenger) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) LogManager(org.apache.logging.log4j.LogManager) QueryBuilder(org.opensearch.index.query.QueryBuilder) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 5 with Secured

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

the class AdminPluginAction method install.

@Execute
@Secured({ ROLE })
public HtmlResponse install(final InstallForm form) {
    validate(form, messages -> {
    }, () -> asHtml(path_AdminPlugin_AdminPluginInstallpluginJsp));
    verifyToken(() -> asHtml(path_AdminPlugin_AdminPluginInstallpluginJsp));
    try {
        if (UPLOAD.equals(form.id)) {
            if (form.jarFile == null) {
                throwValidationError(messages -> messages.addErrorsPluginFileIsNotFound(GLOBAL, form.id), this::asListHtml);
            }
            if (!form.jarFile.getFileName().endsWith(".jar")) {
                throwValidationError(messages -> messages.addErrorsFileIsNotSupported(GLOBAL, form.jarFile.getFileName()), this::asListHtml);
            }
            final String filename = form.jarFile.getFileName();
            final File tempFile = ComponentUtil.getSystemHelper().createTempFile("tmp-adminplugin-", ".jar");
            try (final InputStream is = form.jarFile.getInputStream();
                final OutputStream os = new FileOutputStream(tempFile)) {
                CopyUtil.copy(is, os);
            } catch (final Exception e) {
                if (tempFile.exists() && !tempFile.delete()) {
                    logger.warn("Failed to delete {}.", tempFile.getAbsolutePath());
                }
                logger.debug("Failed to copy {}", filename, e);
                throwValidationError(messages -> messages.addErrorsFailedToInstallPlugin(GLOBAL, filename), this::asListHtml);
            }
            new Thread(() -> {
                try {
                    final PluginHelper pluginHelper = ComponentUtil.getPluginHelper();
                    final Artifact artifact = pluginHelper.getArtifactFromFileName(ArtifactType.UNKNOWN, filename, tempFile.getAbsolutePath());
                    pluginHelper.installArtifact(artifact);
                } catch (final Exception e) {
                    logger.warn("Failed to install {}", filename, e);
                } finally {
                    if (tempFile.exists() && !tempFile.delete()) {
                        logger.warn("Failed to delete {}.", tempFile.getAbsolutePath());
                    }
                }
            }).start();
            saveInfo(messages -> messages.addSuccessInstallPlugin(GLOBAL, form.jarFile.getFileName()));
        } else {
            final Artifact artifact = getArtifactFromInstallForm(form);
            if (artifact == null) {
                throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), this::asListHtml);
            }
            installArtifact(artifact);
            saveInfo(messages -> messages.addSuccessInstallPlugin(GLOBAL, artifact.getFileName()));
        }
    } catch (final ValidationErrorException e) {
        throw e;
    } catch (final Exception e) {
        throwValidationError(messages -> messages.addErrorsFailedToInstallPlugin(GLOBAL, form.id), this::asListHtml);
    }
    return redirect(getClass());
}
Also used : OutputStream(java.io.OutputStream) Arrays(java.util.Arrays) Secured(org.codelibs.fess.annotation.Secured) Artifact(org.codelibs.fess.helper.PluginHelper.Artifact) PluginHelper(org.codelibs.fess.helper.PluginHelper) FileOutputStream(java.io.FileOutputStream) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) File(java.io.File) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ArtifactType(org.codelibs.fess.helper.PluginHelper.ArtifactType) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Map(java.util.Map) ValidationErrorException(org.lastaflute.web.validation.exception.ValidationErrorException) Execute(org.lastaflute.web.Execute) CopyUtil(org.codelibs.core.io.CopyUtil) HtmlResponse(org.lastaflute.web.response.HtmlResponse) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) PluginHelper(org.codelibs.fess.helper.PluginHelper) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ValidationErrorException(org.lastaflute.web.validation.exception.ValidationErrorException) File(java.io.File) ValidationErrorException(org.lastaflute.web.validation.exception.ValidationErrorException) 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