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