add login required

This commit is contained in:
Shinsuke Sugaya 2015-12-25 23:07:46 +09:00
parent 3d7c6bc49f
commit 905cce49e1
18 changed files with 84 additions and 87 deletions

View file

@ -109,7 +109,7 @@ public class Constants extends CoreLibConstants {
public static final String DEFAULT_LABEL_VALUE_PROPERTY = "label.value";
public static final String SUPPORTED_SEARCH_FEATURE_PROPERTY = "search.feature";
public static final String LOGIN_REQUIRED_PROPERTY = "login.required";
public static final String IGNORE_FAILURE_TYPE_PROPERTY = "failure.ignoretype";
@ -154,10 +154,6 @@ public class Constants extends CoreLibConstants {
public static final int DONE_STATUS = 9999;
public static final String SUPPORTED_SEARCH_WEB = "W";
public static final String SUPPORTED_SEARCH_NONE = "n";
public static final String DEFAULT_IGNORE_FAILURE_TYPE = StringUtil.EMPTY;
public static final Integer DEFAULT_FAILURE_COUNT = -1;

View file

@ -35,7 +35,9 @@ public class RootAction extends FessSearchAction {
// ==============
@Execute
public HtmlResponse index() {
searchAvailable();
if (isLoginRequired()) {
return redirectToLogin();
}
return asHtml(path_IndexJsp).useForm(SearchForm.class, op -> {
op.setup(form -> {

View file

@ -38,7 +38,6 @@ import org.lastaflute.core.mail.Postbox;
import org.lastaflute.web.Execute;
import org.lastaflute.web.response.HtmlResponse;
import org.lastaflute.web.ruts.process.ActionRuntime;
import org.lastaflute.web.util.LaRequestUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -65,7 +64,6 @@ public class AdminGeneralAction extends FessAdminAction {
protected void setupHtmlData(final ActionRuntime runtime) {
super.setupHtmlData(runtime);
runtime.registerData("helpLink", systemHelper.getHelpLink(fessConfig.getOnlineHelpNameGeneral()));
runtime.registerData("supportedSearchItems", getSupportedSearchItems());
runtime.registerData("dayItems", getDayItems());
}
@ -127,38 +125,27 @@ public class AdminGeneralAction extends FessAdminAction {
return asHtml(path_AdminGeneral_AdminGeneralJsp);
});
updateProperty(Constants.INCREMENTAL_CRAWLING_PROPERTY,
form.incrementalCrawling != null && Constants.ON.equalsIgnoreCase(form.incrementalCrawling) ? Constants.TRUE
: Constants.FALSE);
fessConfig.setLoginRequired(Constants.ON.equalsIgnoreCase(form.loginRequired));
updateProperty(Constants.INCREMENTAL_CRAWLING_PROPERTY, getCheckboxValue(form.incrementalCrawling));
updateProperty(Constants.DAY_FOR_CLEANUP_PROPERTY, form.dayForCleanup.toString());
updateProperty(Constants.CRAWLING_THREAD_COUNT_PROPERTY, form.crawlingThreadCount.toString());
updateProperty(Constants.SEARCH_LOG_PROPERTY,
form.searchLog != null && Constants.ON.equalsIgnoreCase(form.searchLog) ? Constants.TRUE : Constants.FALSE);
updateProperty(Constants.USER_INFO_PROPERTY, form.userInfo != null && Constants.ON.equalsIgnoreCase(form.userInfo) ? Constants.TRUE
: Constants.FALSE);
updateProperty(Constants.USER_FAVORITE_PROPERTY,
form.userFavorite != null && Constants.ON.equalsIgnoreCase(form.userFavorite) ? Constants.TRUE : Constants.FALSE);
updateProperty(Constants.WEB_API_JSON_PROPERTY,
form.webApiJson != null && Constants.ON.equalsIgnoreCase(form.webApiJson) ? Constants.TRUE : Constants.FALSE);
updateProperty(Constants.SEARCH_LOG_PROPERTY, getCheckboxValue(form.searchLog));
updateProperty(Constants.USER_INFO_PROPERTY, getCheckboxValue(form.userInfo));
updateProperty(Constants.USER_FAVORITE_PROPERTY, getCheckboxValue(form.userFavorite));
updateProperty(Constants.WEB_API_JSON_PROPERTY, getCheckboxValue(form.webApiJson));
updateProperty(Constants.DEFAULT_LABEL_VALUE_PROPERTY, form.defaultLabelValue);
updateProperty(Constants.APPEND_QUERY_PARAMETER_PROPERTY,
form.appendQueryParameter != null && Constants.ON.equalsIgnoreCase(form.appendQueryParameter) ? Constants.TRUE
: Constants.FALSE);
updateProperty(Constants.SUPPORTED_SEARCH_FEATURE_PROPERTY, form.supportedSearch);
updateProperty(Constants.APPEND_QUERY_PARAMETER_PROPERTY, getCheckboxValue(form.appendQueryParameter));
updateProperty(Constants.IGNORE_FAILURE_TYPE_PROPERTY, form.ignoreFailureType);
updateProperty(Constants.FAILURE_COUNT_THRESHOLD_PROPERTY, form.failureCountThreshold.toString());
updateProperty(Constants.WEB_API_POPULAR_WORD_PROPERTY,
form.popularWord != null && Constants.ON.equalsIgnoreCase(form.popularWord) ? Constants.TRUE : Constants.FALSE);
updateProperty(Constants.WEB_API_POPULAR_WORD_PROPERTY, getCheckboxValue(form.popularWord));
updateProperty(Constants.CSV_FILE_ENCODING_PROPERTY, form.csvFileEncoding);
updateProperty(Constants.PURGE_SEARCH_LOG_DAY_PROPERTY, form.purgeSearchLogDay.toString());
updateProperty(Constants.PURGE_JOB_LOG_DAY_PROPERTY, form.purgeJobLogDay.toString());
updateProperty(Constants.PURGE_USER_INFO_DAY_PROPERTY, form.purgeUserInfoDay.toString());
updateProperty(Constants.PURGE_BY_BOTS_PROPERTY, form.purgeByBots);
updateProperty(Constants.NOTIFICATION_TO_PROPERTY, form.notificationTo);
updateProperty(Constants.SUGGEST_SEARCH_LOG_PROPERTY,
form.suggestSearchLog != null && Constants.ON.equalsIgnoreCase(form.suggestSearchLog) ? Constants.TRUE : Constants.FALSE);
updateProperty(Constants.SUGGEST_DOCUMENTS_PROPERTY,
form.suggestDocuments != null && Constants.ON.equalsIgnoreCase(form.suggestDocuments) ? Constants.TRUE : Constants.FALSE);
updateProperty(Constants.SUGGEST_SEARCH_LOG_PROPERTY, getCheckboxValue(form.suggestSearchLog));
updateProperty(Constants.SUGGEST_DOCUMENTS_PROPERTY, getCheckboxValue(form.suggestDocuments));
updateProperty(Constants.PURGE_SUGGEST_SEARCH_LOG_DAY_PROPERTY, form.purgeSuggestSearchLogDay.toString());
updateProperty(Constants.LDAP_PROVIDER_URL, form.ldapProviderUrl);
updateProperty(Constants.LDAP_SECURITY_PRINCIPAL, form.ldapSecurityPrincipal);
@ -170,7 +157,12 @@ public class AdminGeneralAction extends FessAdminAction {
return redirect(getClass());
}
private String getCheckboxValue(String value) {
return Constants.ON.equalsIgnoreCase(value) ? Constants.TRUE : Constants.FALSE;
}
protected void updateForm(final EditForm form) {
form.loginRequired = fessConfig.isLoginRequired() ? Constants.TRUE : Constants.FALSE;
form.incrementalCrawling = crawlerProperties.getProperty(Constants.INCREMENTAL_CRAWLING_PROPERTY, Constants.TRUE);
form.dayForCleanup = getPropertyAsInteger(Constants.DAY_FOR_CLEANUP_PROPERTY, Constants.DEFAULT_DAY_FOR_CLEANUP);
form.crawlingThreadCount = Integer.parseInt(crawlerProperties.getProperty(Constants.CRAWLING_THREAD_COUNT_PROPERTY, "5"));
@ -180,7 +172,6 @@ public class AdminGeneralAction extends FessAdminAction {
form.webApiJson = crawlerProperties.getProperty(Constants.WEB_API_JSON_PROPERTY, Constants.TRUE);
form.defaultLabelValue = crawlerProperties.getProperty(Constants.DEFAULT_LABEL_VALUE_PROPERTY, StringUtil.EMPTY);
form.appendQueryParameter = crawlerProperties.getProperty(Constants.APPEND_QUERY_PARAMETER_PROPERTY, Constants.FALSE);
form.supportedSearch = crawlerProperties.getProperty(Constants.SUPPORTED_SEARCH_FEATURE_PROPERTY, Constants.SUPPORTED_SEARCH_WEB);
form.ignoreFailureType =
crawlerProperties.getProperty(Constants.IGNORE_FAILURE_TYPE_PROPERTY, Constants.DEFAULT_IGNORE_FAILURE_TYPE);
form.failureCountThreshold = getPropertyAsInteger(Constants.FAILURE_COUNT_THRESHOLD_PROPERTY, Constants.DEFAULT_FAILURE_COUNT);
@ -233,23 +224,4 @@ public class AdminGeneralAction extends FessAdminAction {
return items;
}
private List<Map<String, String>> getSupportedSearchItems() {
final List<Map<String, String>> list = new ArrayList<Map<String, String>>();
list.add(createItem(
ComponentUtil.getMessageManager().getMessage(LaRequestUtil.getRequest().getLocale(), "labels.supported_search_web"),
Constants.SUPPORTED_SEARCH_WEB));
list.add(createItem(
ComponentUtil.getMessageManager().getMessage(LaRequestUtil.getRequest().getLocale(), "labels.supported_search_none"),
Constants.SUPPORTED_SEARCH_NONE));
return list;
}
private Map<String, String> createItem(final String label, final String value) {
final Map<String, String> map = new HashMap<String, String>();
map.put(Constants.ITEM_LABEL, label);
map.put(Constants.ITEM_VALUE, value);
return map;
}
}

View file

@ -66,7 +66,7 @@ public class EditForm implements Serializable {
public String appendQueryParameter;
@Size(max = 10)
public String supportedSearch;
public String loginRequired;
@Size(max = 1000)
public String ignoreFailureType;

View file

@ -46,7 +46,7 @@ public class MailForm implements Serializable {
public String appendQueryParameter;
public String supportedSearch;
public String loginRequired;
public String ignoreFailureType;

View file

@ -29,8 +29,8 @@ import org.codelibs.core.lang.StringUtil;
import org.codelibs.core.misc.DynamicProperties;
import org.codelibs.core.net.URLUtil;
import org.codelibs.fess.Constants;
import org.codelibs.fess.app.web.login.LoginAction;
import org.codelibs.fess.es.client.FessEsClient;
import org.codelibs.fess.exception.UnsupportedSearchException;
import org.codelibs.fess.helper.LabelTypeHelper;
import org.codelibs.fess.helper.OpenSearchHelper;
import org.codelibs.fess.helper.PopularWordHelper;
@ -45,7 +45,6 @@ import org.lastaflute.web.login.LoginManager;
import org.lastaflute.web.response.ActionResponse;
import org.lastaflute.web.response.HtmlResponse;
import org.lastaflute.web.ruts.process.ActionRuntime;
import org.lastaflute.web.util.LaRequestUtil;
public abstract class FessSearchAction extends FessBaseAction {
@ -126,12 +125,11 @@ public abstract class FessSearchAction extends FessBaseAction {
// ===================================================================================
// Helpers
// =========
protected void searchAvailable() {
final String supportedSearch =
crawlerProperties.getProperty(Constants.SUPPORTED_SEARCH_FEATURE_PROPERTY, Constants.SUPPORTED_SEARCH_WEB);
if (Constants.SUPPORTED_SEARCH_NONE.equals(supportedSearch)) {
throw new UnsupportedSearchException("A search is not supported: " + LaRequestUtil.getRequest().getRequestURL());
protected boolean isLoginRequired() {
if (fessConfig.isLoginRequired() && !fessLoginAssist.getSessionUserBean().isPresent()) {
return true;
}
return false;
}
protected void buildLabelParams(final Map<String, String[]> fields) {
@ -190,6 +188,10 @@ public abstract class FessSearchAction extends FessBaseAction {
}
}
protected HtmlResponse redirectToLogin() {
return redirect(LoginAction.class);
}
protected HtmlResponse redirectToRoot() {
final String contextPath = request.getServletContext().getContextPath();
return newHtmlResponseAsRediect(StringUtil.isBlank(contextPath) ? "/" : contextPath);

View file

@ -23,7 +23,7 @@ import org.codelibs.fess.util.DocumentUtil;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.lastaflute.web.Execute;
import org.lastaflute.web.response.StreamResponse;
import org.lastaflute.web.response.ActionResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -46,8 +46,10 @@ public class CacheAction extends FessSearchAction {
// Search Execute
// ==============
@Execute
public StreamResponse index(final CacheForm form) {
searchAvailable();
public ActionResponse index(final CacheForm form) {
if (isLoginRequired()) {
return redirectToLogin();
}
Map<String, Object> doc = null;
try {

View file

@ -63,7 +63,9 @@ public class GoAction extends FessSearchAction {
// ==============
@Execute
public ActionResponse index(final GoForm form) throws IOException {
searchAvailable();
if (isLoginRequired()) {
return redirectToLogin();
}
validate(form, messages -> {}, () -> asHtml(path_ErrorJsp));
Map<String, Object> doc = null;

View file

@ -40,6 +40,10 @@ public class HelpAction extends FessSearchAction {
@Execute
public HtmlResponse index() {
if (isLoginRequired()) {
return redirectToLogin();
}
return asHtml(path_HelpJsp).useForm(SearchForm.class, op -> {
op.setup(form -> {
buildLabelParams(form.fields);

View file

@ -17,7 +17,7 @@ package org.codelibs.fess.app.web.osdd;
import org.codelibs.fess.app.web.base.FessSearchAction;
import org.lastaflute.web.Execute;
import org.lastaflute.web.response.StreamResponse;
import org.lastaflute.web.response.ActionResponse;
public class OsddAction extends FessSearchAction {
@ -38,8 +38,10 @@ public class OsddAction extends FessSearchAction {
// ==============
@Execute
public StreamResponse index() {
searchAvailable();
public ActionResponse index() {
if (isLoginRequired()) {
return redirectToLogin();
}
return openSearchHelper.asStream();
}

View file

@ -59,7 +59,9 @@ public class ScreenshotAction extends FessSearchAction {
// ==============
@Execute
public HtmlResponse index(final ScreenshotForm form) {
searchAvailable();
if (isLoginRequired()) {
return redirectToLogin();
}
OutputStream out = null;
BufferedInputStream in = null;

View file

@ -94,7 +94,9 @@ public class SearchAction extends FessSearchAction {
}
protected HtmlResponse doSearch(final SearchForm form) {
searchAvailable();
if (isLoginRequired()) {
return redirectToLogin();
}
validate(form, messages -> {}, () -> asHtml(path_SearchJsp));
if (viewHelper.isUseSession()) {

View file

@ -257,9 +257,6 @@ public class FessLabels extends ActionMessages {
/** The key of the message: Start Pos */
public static final String LABELS_START = "{labels.start}";
/** The key of the message: Supported Search */
public static final String LABELS_SUPPORTED_SEARCH = "{labels.supportedSearch}";
/** The key of the message: Thread Name */
public static final String LABELS_THREAD_NAME = "{labels.threadName}";
@ -437,6 +434,9 @@ public class FessLabels extends ActionMessages {
/** The key of the message: Account Filter */
public static final String LABELS_LDAP_ACCOUNT_FILTER = "{labels.ldapAccountFilter}";
/** The key of the message: Login Required */
public static final String LABELS_LOGIN_REQUIRED = "{labels.loginRequired}";
/** The key of the message: System */
public static final String LABELS_menu_system = "{labels.menu_system}";
@ -929,8 +929,8 @@ public class FessLabels extends ActionMessages {
/** The key of the message: Append Params to URL */
public static final String LABELS_append_query_param_enabled = "{labels.append_query_param_enabled}";
/** The key of the message: Supported Search */
public static final String LABELS_supported_search_feature = "{labels.supported_search_feature}";
/** The key of the message: Login Required */
public static final String LABELS_login_required = "{labels.login_required}";
/** The key of the message: Excluded Failure Type */
public static final String LABELS_ignore_failure_type = "{labels.ignore_failure_type}";

View file

@ -28,6 +28,15 @@ public interface FessProp {
return ComponentUtil.getCrawlerProperties().getProperty(key, defaultValue);
}
public default void setLoginRequired(boolean value) {
ComponentUtil.getCrawlerProperties().setProperty(Constants.LOGIN_REQUIRED_PROPERTY, value ? Constants.TRUE : Constants.FALSE);
}
public default boolean isLoginRequired() {
return Constants.TRUE.equalsIgnoreCase(ComponentUtil.getCrawlerProperties().getProperty(Constants.LOGIN_REQUIRED_PROPERTY,
Constants.FALSE));
}
public default String getLdapInitialContextFactory() {
return getProperty(Constants.LDAP_INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
}
@ -69,4 +78,5 @@ public interface FessProp {
public default String[] getJvmSuggestOptionsAsArray() {
return getJvmSuggestOptions().split("\n");
}
}

View file

@ -75,7 +75,7 @@ labels.rt=rt
labels.searchLog=Search Log
labels.sort=Sort
labels.start=Start Pos
labels.supportedSearch=Supported Search
labels.loginRequired=Login Required
labels.threadName=Thread Name
labels.url=URL
labels.userFavorite=Favorite Log
@ -137,6 +137,7 @@ labels.ldapProviderUrl=LDAP URL
labels.ldapSecurityPrincipal=Bind DN
labels.ldapBaseDn=Base DN
labels.ldapAccountFilter=Account Filter
labels.loginRequired=Login Required
labels.menu_system=System
labels.menu_wizard=Wizard
@ -305,7 +306,7 @@ labels.user_favorite_enabled=Favorite Logging
labels.web_api_json_enabled=JSON Response
labels.default_label_value=Default Label Value
labels.append_query_param_enabled=Append Params to URL
labels.supported_search_feature=Supported Search
labels.login_required=Login Required
labels.ignore_failure_type=Excluded Failure Type
labels.failure_count_threshold=Failure Count Threshold
labels.popular_word_word_enabled=Popular Word Response

View file

@ -75,7 +75,7 @@ labels.rt=rt
labels.searchLog=Search Log
labels.sort=Sort
labels.start=Start Pos
labels.supportedSearch=Supported Search
labels.loginRequired=Login Required
labels.threadName=Thread Name
labels.url=URL
labels.userFavorite=Favorite Log
@ -137,6 +137,7 @@ labels.ldapProviderUrl=LDAP URL
labels.ldapSecurityPrincipal=Bind DN
labels.ldapBaseDn=Base DN
labels.ldapAccountFilter=Account Filter
labels.loginRequired=Login Required
labels.menu_system=System
labels.menu_wizard=Wizard
@ -305,7 +306,7 @@ labels.user_favorite_enabled=Favorite Logging
labels.web_api_json_enabled=JSON Response
labels.default_label_value=Default Label Value
labels.append_query_param_enabled=Append Params to URL
labels.supported_search_feature=Supported Search
labels.login_required=Login Required
labels.ignore_failure_type=Excluded Failure Type
labels.failure_count_threshold=Failure Count Threshold
labels.popular_word_word_enabled=Popular Word Response

View file

@ -75,7 +75,7 @@ labels.rt = rt
labels.searchLog = \u691c\u7d22\u30ed\u30b0
labels.sort = \u30bd\u30fc\u30c8
labels.start = \u30b9\u30bf\u30fc\u30c8\u4f4d\u7f6e
labels.supportedSearch = \u30b5\u30dd\u30fc\u30c8\u3059\u308b\u691c\u7d22
labels.loginRequired = \u30ed\u30b0\u30a4\u30f3\u304c\u5fc5\u8981
labels.threadName = \u30b9\u30ec\u30c3\u30c9\u540d
labels.url = URL
labels.userFavorite = \u304a\u6c17\u306b\u5165\u308a\u30ed\u30b0
@ -298,7 +298,7 @@ labels.user_favorite_enabled = \u304a\u6c17\u306b\u5165\u308a\u30ed\u30b0
labels.web_api_json_enabled = JSON\u30ec\u30b9\u30dd\u30f3\u30b9
labels.default_label_value = \u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30e9\u30d9\u30eb\u5024
labels.append_query_param_enabled = \u691c\u7d22\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u8ffd\u52a0
labels.supported_search_feature = \u30b5\u30dd\u30fc\u30c8\u3059\u308b\u691c\u7d22
labels.login_required = \u30ed\u30b0\u30a4\u30f3\u304c\u5fc5\u8981
labels.ignore_failure_type = \u9664\u5916\u3059\u308b\u30a8\u30e9\u30fc\u306e\u7a2e\u985e
labels.failure_count_threshold = \u969c\u5bb3\u6570\u306e\u3057\u304d\u3044\u5024
labels.popular_word_word_enabled = \u4eba\u6c17\u30ef\u30fc\u30c9\u306e\u30ec\u30b9\u30dd\u30f3\u30b9

View file

@ -46,16 +46,15 @@
</div>
</div>
<div class="form-group">
<label for="supportedSearch" class="col-sm-3 control-label"><la:message
key="labels.supported_search_feature" /></label>
<label for="loginRequired" class="col-sm-3 control-label"><la:message
key="labels.login_required" /></label>
<div class="col-sm-9">
<la:errors property="supportedSearch" />
<la:select property="supportedSearch"
styleClass="form-control">
<c:forEach var="item" items="${supportedSearchItems}">
<la:option value="${f:u(item.value)}">${f:h(item.label)}</la:option>
</c:forEach>
</la:select>
<la:errors property="loginRequired" />
<div class="checkbox">
<label> <la:checkbox property="loginRequired" /> <la:message
key="labels.enabled" />
</label>
</div>
</div>
</div>
<div class="form-group">