use of org.codelibs.fess.annotation.Secured in project fess by codelibs.
the class AdminGeneralAction method sendmail.
@Execute
@Secured({ ROLE })
public HtmlResponse sendmail(final MailForm form) {
validate(form, messages -> {
}, () -> asHtml(path_AdminGeneral_AdminGeneralJsp));
final String[] toAddresses = form.notificationTo.split(",");
final Map<String, Object> dataMap = new HashMap<>();
dataMap.put("hostname", systemHelper.getHostname());
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
try {
TestmailPostcard.droppedInto(postbox, postcard -> {
postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
postcard.addReplyTo(fessConfig.getMailReturnPath());
stream(toAddresses).of(stream -> stream.forEach(address -> {
postcard.addTo(address);
}));
BeanUtil.copyMapToBean(dataMap, postcard);
});
saveInfo(messages -> messages.addSuccessSendTestmail(GLOBAL));
updateProperty(Constants.NOTIFICATION_TO_PROPERTY, form.notificationTo);
systemProperties.store();
} catch (final Exception e) {
logger.warn("Failed to send a test mail.", e);
saveError(messages -> messages.addErrorsFailedToSendTestmail(GLOBAL));
}
return redirectByParam(AdminGeneralAction.class, "notificationTo", form.notificationTo);
}
use of org.codelibs.fess.annotation.Secured in project fess by codelibs.
the class AdminBackupAction method upload.
@Execute
@Secured({ ROLE })
public HtmlResponse upload(final UploadForm form) {
validate(form, messages -> {
}, this::asListHtml);
verifyToken(this::asListHtml);
final String fileName = form.bulkFile.getFileName();
final File tempFile = ComponentUtil.getSystemHelper().createTempFile("fess_restore_", ".tmp");
try (final InputStream in = form.bulkFile.getInputStream();
final OutputStream out = new FileOutputStream(tempFile)) {
CopyUtil.copy(in, out);
asyncImport(fileName, tempFile);
} catch (final IOException e) {
logger.warn("Failed to create a temp file.", e);
if (tempFile.exists() && !tempFile.delete()) {
logger.warn("Failed to delete {}.", tempFile.getAbsolutePath());
}
throwValidationError(messages -> messages.addErrorsFileIsNotSupported(GLOBAL, fileName), this::asListHtml);
}
saveInfo(messages -> messages.addSuccessBulkProcessStarted(GLOBAL));
// no-op
return redirect(getClass());
}
use of org.codelibs.fess.annotation.Secured in project fess by codelibs.
the class AdminDesignAction method update.
@Execute
@Secured({ ROLE })
public HtmlResponse update(final EditForm form) {
final String jspType = "view";
final File jspFile = getJspFile(form.fileName, jspType);
if (form.content == null) {
form.content = StringUtil.EMPTY;
}
validate(form, messages -> {
}, () -> asEditHtml(form));
verifyToken(() -> asEditHtml(form));
try {
write(jspFile.getAbsolutePath(), form.content.getBytes(Constants.UTF_8));
saveInfo(messages -> messages.addSuccessUpdateDesignJspFile(GLOBAL, jspFile.getAbsolutePath()));
} catch (final Exception e) {
logger.error("Failed to update {}", form.fileName, e);
throwValidationError(messages -> messages.addErrorsFailedToUpdateJspFile(GLOBAL), this::asListHtml);
}
return redirect(getClass());
}
use of org.codelibs.fess.annotation.Secured in project fess by codelibs.
the class AdminDesignAction method edit.
// -----------------------------------------------------
// Edit
// ------
@Execute
@Secured({ ROLE })
public HtmlResponse edit(final EditForm form) {
final String jspType = "view";
final File jspFile = getJspFile(form.fileName, jspType);
try {
form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
} catch (final UnsupportedEncodingException e) {
throw new FessSystemException("Invalid encoding", e);
}
saveToken();
return asEditHtml(form);
}
use of org.codelibs.fess.annotation.Secured in project fess by codelibs.
the class FessLoginAssist method checkPermission.
@Override
protected void checkPermission(final LoginHandlingResource resource) throws LoginRequiredException {
if (FessAdminAction.class.isAssignableFrom(resource.getActionClass())) {
getSavedUserBean().ifPresent(user -> {
if (user.hasRoles(fessConfig.getAuthenticationAdminRolesAsArray())) {
return;
}
final Method executeMethod = resource.getExecuteMethod();
final Secured secured = executeMethod.getAnnotation(Secured.class);
if (secured != null && user.hasRoles(secured.value())) {
return;
}
throw new UserRoleLoginException(RootAction.class);
});
}
}
Aggregations