fix #378 : replace with ActivityHelper
This commit is contained in:
parent
9cad6637d9
commit
6a2e5b32d3
6 changed files with 37 additions and 17 deletions
|
@ -24,7 +24,6 @@ import org.codelibs.core.beans.util.BeanUtil;
|
|||
import org.codelibs.core.beans.util.CopyOptions;
|
||||
import org.codelibs.fess.exception.UserRoleLoginException;
|
||||
import org.codelibs.fess.helper.SystemHelper;
|
||||
import org.codelibs.fess.util.ActivityUtil;
|
||||
import org.dbflute.optional.OptionalThing;
|
||||
import org.lastaflute.di.util.LdiFileUtil;
|
||||
import org.lastaflute.web.login.LoginManager;
|
||||
|
@ -111,7 +110,7 @@ public abstract class FessAdminAction extends FessBaseAction {
|
|||
final String username = getUserBean().map(u -> u.getUserId()).orElse("-");
|
||||
final String requestPath = runtime.getRequestPath();
|
||||
final String executeName = runtime.getExecuteMethod().getName();
|
||||
ActivityUtil.access(username, requestPath, executeName);
|
||||
activityHelper.access(getUserBean(), requestPath, executeName);
|
||||
return super.hookBefore(runtime);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.codelibs.fess.app.web.base;
|
|||
import javax.annotation.Resource;
|
||||
|
||||
import org.codelibs.fess.app.web.base.login.FessLoginAssist;
|
||||
import org.codelibs.fess.helper.ActivityHelper;
|
||||
import org.codelibs.fess.mylasta.action.FessHtmlPath;
|
||||
import org.codelibs.fess.mylasta.action.FessMessages;
|
||||
import org.codelibs.fess.mylasta.action.FessUserBean;
|
||||
|
@ -60,6 +61,9 @@ public abstract class FessBaseAction extends TypicalAction // has several interf
|
|||
@Resource
|
||||
protected FessConfig fessConfig;
|
||||
|
||||
@Resource
|
||||
protected ActivityHelper activityHelper;
|
||||
|
||||
// ===================================================================================
|
||||
// Hook
|
||||
// ======
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.codelibs.fess.Constants;
|
|||
import org.codelibs.fess.app.web.admin.dashboard.AdminDashboardAction;
|
||||
import org.codelibs.fess.app.web.base.FessSearchAction;
|
||||
import org.codelibs.fess.mylasta.action.FessUserBean;
|
||||
import org.codelibs.fess.util.ActivityUtil;
|
||||
import org.codelibs.fess.util.RenderDataUtil;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.login.exception.LoginFailureException;
|
||||
|
@ -60,9 +59,11 @@ public class LoginAction extends FessSearchAction {
|
|||
final String username = form.username;
|
||||
final String password = form.password;
|
||||
form.clearSecurityInfo();
|
||||
ActivityUtil.login(username);
|
||||
try {
|
||||
return fessLoginAssist.loginRedirect(username, password, op -> {}, () -> getHtmlResponse());
|
||||
return fessLoginAssist.loginRedirect(username, password, op -> {}, () -> {
|
||||
activityHelper.login(getUserBean());
|
||||
return getHtmlResponse();
|
||||
});
|
||||
} catch (final LoginFailureException lfe) {
|
||||
throwValidationError(messages -> messages.addErrorsLoginError(GLOBAL), () -> {
|
||||
return asHtml(path_Login_IndexJsp);
|
||||
|
|
|
@ -17,7 +17,6 @@ package org.codelibs.fess.app.web.logout;
|
|||
|
||||
import org.codelibs.fess.app.web.base.FessSearchAction;
|
||||
import org.codelibs.fess.app.web.login.LoginAction;
|
||||
import org.codelibs.fess.util.ActivityUtil;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.response.HtmlResponse;
|
||||
|
||||
|
@ -42,7 +41,7 @@ public class LogoutAction extends FessSearchAction {
|
|||
@Execute
|
||||
public HtmlResponse index() {
|
||||
final String username = getUserBean().map(u -> u.getUserId()).orElse("-");
|
||||
ActivityUtil.logout(username);
|
||||
activityHelper.logout(getUserBean());
|
||||
fessLoginAssist.logout();
|
||||
return redirect(LoginAction.class);
|
||||
}
|
||||
|
|
|
@ -13,12 +13,16 @@
|
|||
* either express or implied. See the License for the specific language
|
||||
* governing permissions and limitations under the License.
|
||||
*/
|
||||
package org.codelibs.fess.util;
|
||||
package org.codelibs.fess.helper;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.mylasta.action.FessUserBean;
|
||||
import org.dbflute.optional.OptionalThing;
|
||||
import org.lastaflute.web.util.LaRequestUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -27,36 +31,43 @@ import org.slf4j.LoggerFactory;
|
|||
* @author shinsuke
|
||||
*
|
||||
*/
|
||||
public class ActivityUtil {
|
||||
private static Logger logger = LoggerFactory.getLogger("fess.log.audit");
|
||||
public class ActivityHelper {
|
||||
private Logger logger = null;
|
||||
|
||||
public static void login(final String username) {
|
||||
protected String loggerName = "fess.log.audit";
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
logger = LoggerFactory.getLogger(loggerName);
|
||||
}
|
||||
|
||||
public void login(final OptionalThing<FessUserBean> user) {
|
||||
final StringBuilder buf = new StringBuilder(100);
|
||||
buf.append("action:");
|
||||
buf.append(Action.LOGIN);
|
||||
buf.append('\t');
|
||||
buf.append("user:");
|
||||
buf.append(username);
|
||||
buf.append(user.map(u -> u.getUserId()).orElse("-"));
|
||||
log(buf);
|
||||
}
|
||||
|
||||
public static void logout(final String username) {
|
||||
public void logout(final OptionalThing<FessUserBean> user) {
|
||||
final StringBuilder buf = new StringBuilder(100);
|
||||
buf.append("action:");
|
||||
buf.append(Action.LOGOUT);
|
||||
buf.append('\t');
|
||||
buf.append("user:");
|
||||
buf.append(username);
|
||||
buf.append(user.map(u -> u.getUserId()).orElse("-"));
|
||||
log(buf);
|
||||
}
|
||||
|
||||
public static void access(final String username, final String path, final String execute) {
|
||||
public void access(final OptionalThing<FessUserBean> user, final String path, final String execute) {
|
||||
final StringBuilder buf = new StringBuilder(100);
|
||||
buf.append("action:");
|
||||
buf.append(Action.ACCESS);
|
||||
buf.append('\t');
|
||||
buf.append("user:");
|
||||
buf.append(username);
|
||||
buf.append(user.map(u -> u.getUserId()).orElse("-"));
|
||||
buf.append('\t');
|
||||
buf.append("path:");
|
||||
buf.append(path);
|
||||
|
@ -66,7 +77,7 @@ public class ActivityUtil {
|
|||
log(buf);
|
||||
}
|
||||
|
||||
private static void log(final StringBuilder buf) {
|
||||
private void log(final StringBuilder buf) {
|
||||
buf.append('\t');
|
||||
buf.append("ip:");
|
||||
buf.append(getClientIp());
|
||||
|
@ -90,4 +101,8 @@ public class ActivityUtil {
|
|||
protected enum Action {
|
||||
LOGIN, LOGOUT, ACCESS;
|
||||
}
|
||||
|
||||
public void setLoggerName(String loggerName) {
|
||||
this.loggerName = loggerName;
|
||||
}
|
||||
}
|
|
@ -8,6 +8,8 @@
|
|||
<include path="esflute_user.xml"/>
|
||||
<include path="esflute_log.xml"/>
|
||||
|
||||
<component name="activityHelper" class="org.codelibs.fess.helper.ActivityHelper">
|
||||
</component>
|
||||
<component name="searchLogHelper" class="org.codelibs.fess.helper.SearchLogHelper">
|
||||
<!--
|
||||
<property name="userCheckInterval">5 * 60 * 1000</property>
|
||||
|
|
Loading…
Add table
Reference in a new issue