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);
}
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])));
}
});
}
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);
}
});
}
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();
}
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());
}
Aggregations