Search in sources :

Example 6 with Secured

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);
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) Secured(org.codelibs.fess.annotation.Secured) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) DynamicProperties(org.codelibs.core.misc.DynamicProperties) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) HashMap(java.util.HashMap) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) ArrayList(java.util.ArrayList) Postbox(org.lastaflute.core.mail.Postbox) List(java.util.List) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Logger(org.apache.logging.log4j.Logger) TestmailPostcard(org.codelibs.fess.mylasta.mail.TestmailPostcard) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) SystemHelper(org.codelibs.fess.helper.SystemHelper) Map(java.util.Map) Execute(org.lastaflute.web.Execute) HtmlResponse(org.lastaflute.web.response.HtmlResponse) LogManager(org.apache.logging.log4j.LogManager) HashMap(java.util.HashMap) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 7 with Secured

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());
}
Also used : Arrays(java.util.Arrays) Constants(org.codelibs.fess.Constants) IORuntimeException(org.codelibs.core.exception.IORuntimeException) AsyncManager(org.lastaflute.core.magic.async.AsyncManager) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) FileConfigBhv(org.codelibs.fess.es.config.exbhv.FileConfigBhv) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StreamResponse(org.lastaflute.web.response.StreamResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Map(java.util.Map) LabelTypeBhv(org.codelibs.fess.es.config.exbhv.LabelTypeBhv) FavoriteLogBhv(org.codelibs.fess.es.log.exbhv.FavoriteLogBhv) GsaConfigParser(org.codelibs.fess.util.GsaConfigParser) CopyUtil(org.codelibs.core.io.CopyUtil) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) Secured(org.codelibs.fess.annotation.Secured) UserInfoBhv(org.codelibs.fess.es.log.exbhv.UserInfoBhv) Resource(javax.annotation.Resource) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ActionResponse(org.lastaflute.web.response.ActionResponse) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Writer(java.io.Writer) CurlResponse(org.codelibs.curl.CurlResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LocalDateTime(java.time.LocalDateTime) Pair(org.codelibs.core.misc.Pair) HashMap(java.util.HashMap) ResourceUtil(org.codelibs.fess.util.ResourceUtil) OutputStreamWriter(java.io.OutputStreamWriter) SearchEngineUtil(org.codelibs.fess.util.SearchEngineUtil) HtmlResponse(org.lastaflute.web.response.HtmlResponse) OutputStream(java.io.OutputStream) InputSource(org.xml.sax.InputSource) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) ClickLogBhv(org.codelibs.fess.es.log.exbhv.ClickLogBhv) StringUtil(org.codelibs.core.lang.StringUtil) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) FileInputStream(java.io.FileInputStream) InputStreamReader(java.io.InputStreamReader) File(java.io.File) Consumer(java.util.function.Consumer) SearchLogBhv(org.codelibs.fess.es.log.exbhv.SearchLogBhv) WebConfigBhv(org.codelibs.fess.es.config.exbhv.WebConfigBhv) DateTimeFormatter(java.time.format.DateTimeFormatter) Execute(org.lastaflute.web.Execute) BufferedReader(java.io.BufferedReader) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 8 with Secured

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());
}
Also used : Constants(org.codelibs.fess.Constants) Secured(org.codelibs.fess.annotation.Secured) URLDecoder(java.net.URLDecoder) FessSystemException(org.codelibs.fess.exception.FessSystemException) ResourceUtil(org.codelibs.core.io.ResourceUtil) OptionalEntity(org.dbflute.optional.OptionalEntity) StringUtil(org.codelibs.core.lang.StringUtil) Pair(org.codelibs.core.misc.Pair) FileUtils(org.apache.commons.io.FileUtils) FileInputStream(java.io.FileInputStream) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) File(java.io.File) ArrayList(java.util.ArrayList) List(java.util.List) StreamResponse(org.lastaflute.web.response.StreamResponse) Logger(org.apache.logging.log4j.Logger) FileUtil(org.codelibs.core.io.FileUtil) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Locale(java.util.Locale) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Execute(org.lastaflute.web.Execute) HtmlResponse(org.lastaflute.web.response.HtmlResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LogManager(org.apache.logging.log4j.LogManager) File(java.io.File) FessSystemException(org.codelibs.fess.exception.FessSystemException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 9 with Secured

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);
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) File(java.io.File) FessSystemException(org.codelibs.fess.exception.FessSystemException) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 10 with Secured

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);
        });
    }
}
Also used : Secured(org.codelibs.fess.annotation.Secured) UserRoleLoginException(org.codelibs.fess.exception.UserRoleLoginException) Method(java.lang.reflect.Method)

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