fix #2804 Disable OSDD processing when SSO is active to enhance usability

This commit is contained in:
Shinsuke Sugaya 2024-02-08 14:03:19 +09:00
parent 479eeab409
commit f1894f70e1
7 changed files with 224 additions and 34 deletions

View file

@ -53,6 +53,10 @@ public class Constants extends CoreLibConstants {
public static final String STOP = "stop";
public static final String AUTO = "auto";
public static final String NONE = "none";
public static final String ITEM_LABEL = "label";
public static final String ITEM_VALUE = "value";
@ -158,6 +162,8 @@ public class Constants extends CoreLibConstants {
public static final String LTR_WINDOW_SIZE_PROPERTY = "ltr.window.size";
public static final String SSO_TYPE_PROPERTY = "sso.type";
public static final String REQUEST_QUERIES = "fess.Queries";
public static final String HIGHLIGHT_QUERIES = "fess.HighlightQueries";

View file

@ -23,6 +23,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.Constants;
import org.codelibs.fess.mylasta.direction.FessConfig;
import org.codelibs.fess.util.ComponentUtil;
import org.lastaflute.web.response.StreamResponse;
import org.lastaflute.web.util.LaServletContextUtil;
@ -51,20 +52,44 @@ public class OsddHelper {
if (logger.isDebugEnabled()) {
logger.debug("Initialize {}", this.getClass().getSimpleName());
}
if (Constants.TRUE.equalsIgnoreCase(ComponentUtil.getFessConfig().getOsddLinkEnabled())) {
if (StringUtil.isNotBlank(osddPath)) {
final String path = LaServletContextUtil.getServletContext().getRealPath(osddPath);
osddFile = new File(path);
if (!osddFile.isFile()) {
osddFile = null;
logger.warn("{} was not found.", path);
}
} else {
logger.info("OSDD file is not found.");
}
} else {
osddFile = getOsddFile();
}
protected File getOsddFile() {
if (!isOsddLinkEnabled()) {
logger.debug("OSDD is disabled.");
return null;
}
if (StringUtil.isBlank(osddPath)) {
logger.info("OSDD file is not found.");
return null;
}
final String path = LaServletContextUtil.getServletContext().getRealPath(osddPath);
if (path == null) {
logger.warn("{} was not found.", path);
return null;
}
final File osddFile = new File(path);
if (!osddFile.isFile()) {
logger.warn("{} was not a file.", path);
return null;
}
return osddFile;
}
protected boolean isOsddLinkEnabled() {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String osddLinkEnabled = fessConfig.getOsddLinkEnabled();
if (Constants.TRUE.equalsIgnoreCase(osddLinkEnabled)) {
return true;
}
if (!Constants.AUTO.equalsIgnoreCase(osddLinkEnabled)) {
return false;
}
final String ssoType = fessConfig.getSsoType();
return StringUtil.isBlank(ssoType) || Constants.NONE.equalsIgnoreCase(ssoType);
}
public boolean hasOpenSearchFile() {
@ -73,7 +98,7 @@ public class OsddHelper {
public StreamResponse asStream() {
if (osddFile == null) {
throw ComponentUtil.getResponseManager().new404("Unsupported OpenSearch response.");
throw ComponentUtil.getResponseManager().new404("Unsupported Open Search Description Document response.");
}
return new StreamResponse(osddFile.getName()).contentType(contentType + "; charset=" + encoding).stream(out -> {

View file

@ -1194,7 +1194,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. __TEMPLATE__ */
String FORM_ADMIN_DEFAULT_TEMPLATE_NAME = "form.admin.default.template.name";
/** The key of the configuration. e.g. true */
/** The key of the configuration. e.g. auto */
String OSDD_LINK_ENABLED = "osdd.link.enabled";
/** The key of the configuration. e.g. true */
@ -5569,18 +5569,11 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/**
* Get the value for the key 'osdd.link.enabled'. <br>
* The value is, e.g. true <br>
* The value is, e.g. auto <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getOsddLinkEnabled();
/**
* Is the property for the key 'osdd.link.enabled' true? <br>
* The value is, e.g. true <br>
* @return The determination, true or false. (if not found, exception but basically no way)
*/
boolean isOsddLinkEnabled();
/**
* Get the value for the key 'clipboard.copy.icon.enabled'. <br>
* The value is, e.g. true <br>
@ -9640,10 +9633,6 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
return get(FessConfig.OSDD_LINK_ENABLED);
}
public boolean isOsddLinkEnabled() {
return is(FessConfig.OSDD_LINK_ENABLED);
}
public String getClipboardCopyIconEnabled() {
return get(FessConfig.CLIPBOARD_COPY_ICON_ENABLED);
}
@ -11147,7 +11136,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
defaultMap.put(FessConfig.FORM_ADMIN_MAX_INPUT_SIZE, "10000");
defaultMap.put(FessConfig.FORM_ADMIN_LABEL_IN_CONFIG_ENABLED, "false");
defaultMap.put(FessConfig.FORM_ADMIN_DEFAULT_TEMPLATE_NAME, "__TEMPLATE__");
defaultMap.put(FessConfig.OSDD_LINK_ENABLED, "true");
defaultMap.put(FessConfig.OSDD_LINK_ENABLED, "auto");
defaultMap.put(FessConfig.CLIPBOARD_COPY_ICON_ENABLED, "true");
defaultMap.put(FessConfig.AUTHENTICATION_ADMIN_USERS, "admin");
defaultMap.put(FessConfig.AUTHENTICATION_ADMIN_ROLES, "admin");

View file

@ -723,6 +723,10 @@ public interface FessProp {
return Constants.TRUE.equalsIgnoreCase(getSystemProperty("aad.use.ds", "true"));
}
default String getSsoType() {
return getSystemProperty(Constants.SSO_TYPE_PROPERTY, Constants.NONE);
}
//
// fess_*.properties
//

View file

@ -20,6 +20,7 @@ import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.fess.Constants;
import org.codelibs.fess.mylasta.action.FessUserBean;
import org.codelibs.fess.util.ComponentUtil;
import org.lastaflute.web.login.credential.LoginCredential;
@ -28,10 +29,6 @@ import org.lastaflute.web.response.ActionResponse;
public class SsoManager {
private static final Logger logger = LogManager.getLogger(SsoManager.class);
protected static final String SSO_TYPE = "sso.type";
protected static final String NONE = "none";
protected final List<SsoAuthenticator> authenticatorList = new ArrayList<>();
public boolean available() {
@ -39,7 +36,7 @@ public class SsoManager {
if (logger.isDebugEnabled()) {
logger.debug("sso.type: {}", ssoType);
}
return !NONE.equals(ssoType);
return !Constants.NONE.equals(ssoType);
}
public LoginCredential getLoginCredential() {
@ -81,7 +78,7 @@ public class SsoManager {
}
protected String getSsoType() {
return ComponentUtil.getFessConfig().getSystemProperty(SSO_TYPE, NONE);
return ComponentUtil.getFessConfig().getSsoType();
}
public SsoAuthenticator[] getAuthenticators() {

View file

@ -633,7 +633,7 @@ logging.app.packages=org.codelibs,org.dbflute,org.lastaflute
form.admin.max.input.size=10000
form.admin.label.in.config.enabled=false
form.admin.default.template.name=__TEMPLATE__
osdd.link.enabled=true
osdd.link.enabled=auto
clipboard.copy.icon.enabled=true
# ----------------------------------------------------------

View file

@ -0,0 +1,169 @@
/*
* Copyright 2012-2023 CodeLibs Project and the Others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package org.codelibs.fess.helper;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.codelibs.core.io.InputStreamUtil;
import org.codelibs.fess.Constants;
import org.codelibs.fess.mylasta.direction.FessConfig;
import org.codelibs.fess.unit.UnitFessTestCase;
import org.codelibs.fess.util.ComponentUtil;
import org.lastaflute.web.response.StreamResponse;
import org.lastaflute.web.servlet.request.stream.WrittenStreamOut;
public class OsddHelperTest extends UnitFessTestCase {
public void test_init_nofile() {
ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() {
@Override
public String getOsddLinkEnabled() {
return "auto";
}
@Override
public String getSsoType() {
return "none";
}
});
final OsddHelper osddHelper = new OsddHelper();
osddHelper.setContentType("application/opensearchdescription+xml");
osddHelper.init();
assertFalse(osddHelper.hasOpenSearchFile());
try {
osddHelper.asStream();
fail();
} catch (final Exception e) {
assertEquals("Unsupported Open Search Description Document response.", e.getMessage());
}
}
public void test_init_osddpath() throws IOException {
ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() {
@Override
public String getOsddLinkEnabled() {
return "auto";
}
@Override
public String getSsoType() {
return "none";
}
});
final OsddHelper osddHelper = new OsddHelper();
osddHelper.setOsddPath("osdd/osdd.xml");
osddHelper.setEncoding(Constants.UTF_8);
osddHelper.init();
assertTrue(osddHelper.hasOpenSearchFile());
final StreamResponse streamResponse = osddHelper.asStream();
assertEquals("text/xml; charset=UTF-8", streamResponse.getContentType());
streamResponse.getStreamCall().callback(new WrittenStreamOut() {
@Override
public void write(final InputStream ins) throws IOException {
assertEquals("""
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>Fess</ShortName>
<Description>Full Text Search for Your Documents.</Description>
<Tags>Full Text Search</Tags>
<Contact>fess-user@lists.sourceforge.jp</Contact>
<SearchForm>http://localhost:8080/fess/</SearchForm>
<Url type="text/html" template="http://localhost:8080/fess/search?q={searchTerms}"/>
<InputEncoding>UTF-8</InputEncoding>
<OutputEncoding>UTF-8</OutputEncoding>
</OpenSearchDescription>
""", new String(InputStreamUtil.getBytes(ins)));
}
@Override
public OutputStream stream() {
return null;
}
});
}
public void test_init_osddpath_null() {
ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() {
@Override
public String getOsddLinkEnabled() {
return "auto";
}
@Override
public String getSsoType() {
return "none";
}
});
final OsddHelper osddHelper = new OsddHelper();
osddHelper.setOsddPath("osdd/none.xml");
osddHelper.init();
assertFalse(osddHelper.hasOpenSearchFile());
}
public void test_init_disabled() {
ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() {
@Override
public String getOsddLinkEnabled() {
return "false";
}
});
final OsddHelper osddHelper = new OsddHelper();
osddHelper.setOsddPath("osdd/osdd.xml");
osddHelper.init();
assertFalse(osddHelper.hasOpenSearchFile());
}
public void test_init_saml() {
ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() {
@Override
public String getOsddLinkEnabled() {
return "auto";
}
@Override
public String getSsoType() {
return "saml";
}
});
final OsddHelper osddHelper = new OsddHelper();
osddHelper.setOsddPath("osdd/osdd.xml");
osddHelper.init();
assertFalse(osddHelper.hasOpenSearchFile());
}
public void test_init_force() throws IOException {
ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() {
@Override
public String getOsddLinkEnabled() {
return "true";
}
@Override
public String getSsoType() {
return "saml";
}
});
final OsddHelper osddHelper = new OsddHelper();
osddHelper.setOsddPath("osdd/osdd.xml");
osddHelper.init();
assertTrue(osddHelper.hasOpenSearchFile());
}
}