diff --git a/pom.xml b/pom.xml
index dc535422c..ae7dea6eb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -593,7 +593,7 @@
org.codelibs
corelib
- 0.1.2
+ 0.2.0-SNAPSHOT
org.codelibs.solr
@@ -603,7 +603,7 @@
org.codelibs.sastruts
sastruts-core
- 0.1.1
+ 0.2.0-SNAPSHOT
org.codelibs.sastruts
diff --git a/src/main/java/jp/sf/fess/Constants.java b/src/main/java/jp/sf/fess/Constants.java
index e49246a86..21ce6ad3c 100644
--- a/src/main/java/jp/sf/fess/Constants.java
+++ b/src/main/java/jp/sf/fess/Constants.java
@@ -35,8 +35,6 @@ public class Constants extends CoreLibConstants {
public static final String WEB_API_VERSION = "5";
- public static final String LOGIN_INFO = "jp.sf.fess.LoginInfo";
-
public static final String EMPTY_STRING = "";
public static final String[] EMPTY_STRINGS = new String[0];
@@ -168,7 +166,7 @@ public class Constants extends CoreLibConstants {
public static final String NOTIFICATION_TO_PROPERTY = "notification.to";
- public static final String AUTH_CIPHER = "jp.sf.fess.AuthCipher";
+ public static final String AUTH_CIPHER = "authenticationCipher";
public static final String RETURN_PATH = "jp.sf.fess.ReturnPath";
diff --git a/src/main/java/jp/sf/fess/action/LoginAction.java b/src/main/java/jp/sf/fess/action/LoginAction.java
index 8aeccc82b..d0345bcf5 100644
--- a/src/main/java/jp/sf/fess/action/LoginAction.java
+++ b/src/main/java/jp/sf/fess/action/LoginAction.java
@@ -20,8 +20,9 @@ import java.io.IOException;
import java.io.Serializable;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.List;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@@ -30,12 +31,14 @@ import javax.servlet.http.HttpSession;
import jp.sf.fess.Constants;
import jp.sf.fess.FessSystemException;
-import jp.sf.fess.crypto.FessCipher;
import jp.sf.fess.entity.LoginInfo;
import jp.sf.fess.form.LoginForm;
import jp.sf.fess.helper.SystemHelper;
+import jp.sf.fess.util.ComponentUtil;
import org.apache.struts.Globals;
+import org.codelibs.core.crypto.CachedCipher;
+import org.codelibs.sastruts.core.SSCConstants;
import org.seasar.framework.util.StringUtil;
import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;
@@ -62,7 +65,7 @@ public class LoginAction implements Serializable {
final HttpServletRequest request = RequestUtil.getRequest();
final HttpSession session = request.getSession();
// check login session
- final Object obj = session.getAttribute(Constants.LOGIN_INFO);
+ final Object obj = session.getAttribute(SSCConstants.USER_INFO);
if (obj instanceof LoginInfo) {
final LoginInfo loginInfo = (LoginInfo) obj;
if (loginInfo.isAdministrator()) {
@@ -83,13 +86,13 @@ public class LoginAction implements Serializable {
String returnPath;
if (StringUtil.isNotBlank(loginForm.returnPath)) {
- final FessCipher fessCipher = FessCipher.class.cast(RequestUtil
- .getRequest().getAttribute(Constants.AUTH_CIPHER));
- if (fessCipher == null) {
+ final CachedCipher cipher = ComponentUtil
+ .getCipher(Constants.AUTH_CIPHER);
+ if (cipher == null) {
throw new FessSystemException(
"A cipher for authentication is null. Please check a filter setting.");
}
- final String value = fessCipher.decryptoText(loginForm.returnPath);
+ final String value = cipher.decryptoText(loginForm.returnPath);
final int idx = value.indexOf('|');
if (idx >= 0) {
returnPath = value.substring(idx + 1);
@@ -131,25 +134,24 @@ public class LoginAction implements Serializable {
// create user info
final LoginInfo loginInfo = new LoginInfo();
loginInfo.setUsername(request.getRemoteUser());
- session.setAttribute(Constants.LOGIN_INFO, loginInfo);
+ session.setAttribute(SSCConstants.USER_INFO, loginInfo);
String returnPath;
- final List authenticatedRoleList = systemHelper
- .getAuthenticatedRoleList();
- if (request.isUserInRole(systemHelper.getAdminRole())) {
+ final Set authenticatedRoleList = systemHelper
+ .getAuthenticatedRoleSet();
+ final Set roleSet = new HashSet<>();
+ for (final String role : authenticatedRoleList) {
+ if (request.isUserInRole(role)) {
+ roleSet.add(role);
+ }
+ }
+ loginInfo.setRoleSet(roleSet);
+
+ if (loginInfo.isAdministrator()) {
if (logger.isInfoEnabled()) {
logger.info("[LOGIN] ADMIN: " + "The usename is "
+ request.getRemoteUser());
}
- loginInfo.setAdministrator(true);
-
- if (authenticatedRoleList != null) {
- for (final String role : authenticatedRoleList) {
- if (request.isUserInRole(role)) {
- loginInfo.addRole(role);
- }
- }
- }
returnPath = (String) session.getAttribute(Constants.RETURN_PATH);
if (returnPath != null) {
@@ -159,28 +161,18 @@ public class LoginAction implements Serializable {
returnPath = getAdminRootPath();
}
} else {
- if (authenticatedRoleList != null) {
- boolean authenticated = false;
- for (final String role : authenticatedRoleList) {
- if (request.isUserInRole(role)) {
- loginInfo.addRole(role);
- authenticated = true;
- }
+ if (!loginInfo.getRoleSet().isEmpty()) {
+ if (logger.isInfoEnabled()) {
+ logger.info("[LOGIN] USER: " + "The usename is "
+ + request.getRemoteUser());
}
- if (authenticated) {
- if (logger.isInfoEnabled()) {
- logger.info("[LOGIN] USER: " + "The usename is "
- + request.getRemoteUser());
- }
- loginInfo.setAdministrator(false);
- } else {
- if (logger.isWarnEnabled()) {
- logger.warn("Login Failure: " + request.getRemoteUser()
- + " does not have authenticated roles.");
- }
- // logout
- session.invalidate();
+ } else {
+ if (logger.isWarnEnabled()) {
+ logger.warn("Login Failure: " + request.getRemoteUser()
+ + " does not have authenticated roles.");
}
+ // logout
+ session.invalidate();
}
returnPath = RequestUtil.getRequest().getContextPath();
}
diff --git a/src/main/java/jp/sf/fess/crypto/FessCipher.java b/src/main/java/jp/sf/fess/crypto/FessCipher.java
deleted file mode 100644
index 61e574f97..000000000
--- a/src/main/java/jp/sf/fess/crypto/FessCipher.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright 2009-2014 the 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 jp.sf.fess.crypto;
-
-import java.nio.charset.Charset;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-import javax.crypto.Cipher;
-import javax.crypto.spec.SecretKeySpec;
-
-import jp.sf.fess.FessSystemException;
-
-import org.apache.commons.codec.binary.Base64;
-import org.seasar.framework.container.annotation.tiger.Binding;
-import org.seasar.framework.container.annotation.tiger.BindingType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class FessCipher {
- private static final Logger logger = LoggerFactory
- .getLogger(FessCipher.class);
-
- protected static final Charset UTF_8 = Charset.forName("UTF-8");
-
- public String algorithm = "Blowfish";
-
- @Binding(bindingType = BindingType.MUST)
- public String key;
-
- public Charset charset = UTF_8;
-
- protected Queue encryptoQueue = new ConcurrentLinkedQueue();
-
- protected Queue decryptoQueue = new ConcurrentLinkedQueue();
-
- public byte[] encrypto(final byte[] data) {
- final Cipher cipher = pollEncryptoCipher();
- byte[] encrypted;
- try {
- encrypted = cipher.doFinal(data);
- } catch (final Exception e) {
- throw new FessSystemException(
- "Could not create a new cipher for encrypto.", e);
- } finally {
- offerEncryptoCipher(cipher);
- }
- return encrypted;
- }
-
- public String encryptoText(final String text) {
- return new String(
- Base64.encodeBase64(encrypto(text.getBytes(charset))), UTF_8);
- }
-
- public byte[] decrypto(final byte[] data) {
- final Cipher cipher = pollDecryptoCipher();
- byte[] decrypted;
- try {
- decrypted = cipher.doFinal(data);
- } catch (final Exception e) {
- throw new FessSystemException(
- "Could not create a new cipher for decrypto.", e);
- } finally {
- offerDecryptoCipher(cipher);
- }
- return decrypted;
- }
-
- public String decryptoText(final String text) {
- return new String(decrypto(Base64.decodeBase64(text.getBytes(UTF_8))),
- charset);
- }
-
- protected Cipher pollEncryptoCipher() {
- Cipher cipher = encryptoQueue.poll();
- if (cipher == null) {
- if (logger.isInfoEnabled()) {
- logger.info("Initializing a cipher for an encryption.");
- }
- final SecretKeySpec sksSpec = new SecretKeySpec(
- key.getBytes(UTF_8), algorithm);
- try {
- cipher = Cipher.getInstance(algorithm);
- cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, sksSpec);
- } catch (final Exception e) {
- throw new FessSystemException(
- "Could not create a new cipher for encrypto.", e);
- }
- }
- return cipher;
- }
-
- protected void offerEncryptoCipher(final Cipher cipher) {
- encryptoQueue.offer(cipher);
- }
-
- protected Cipher pollDecryptoCipher() {
- Cipher cipher = decryptoQueue.poll();
- if (cipher == null) {
- if (logger.isInfoEnabled()) {
- logger.info("Initializing a cipher for an decryption.");
- }
- final SecretKeySpec sksSpec = new SecretKeySpec(
- key.getBytes(UTF_8), algorithm);
- try {
- cipher = Cipher.getInstance(algorithm);
- cipher.init(javax.crypto.Cipher.DECRYPT_MODE, sksSpec);
- } catch (final Exception e) {
- throw new FessSystemException(
- "Could not create a new cipher for decrypto.", e);
- }
- }
- return cipher;
- }
-
- protected void offerDecryptoCipher(final Cipher cipher) {
- decryptoQueue.offer(cipher);
- }
-}
diff --git a/src/main/java/jp/sf/fess/entity/LoginInfo.java b/src/main/java/jp/sf/fess/entity/LoginInfo.java
index ecff08040..132b23551 100644
--- a/src/main/java/jp/sf/fess/entity/LoginInfo.java
+++ b/src/main/java/jp/sf/fess/entity/LoginInfo.java
@@ -16,54 +16,14 @@
package jp.sf.fess.entity;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
+import jp.sf.fess.util.ComponentUtil;
-import org.seasar.framework.util.StringUtil;
+import org.codelibs.sastruts.core.entity.UserInfo;
-public class LoginInfo implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- protected String username;
-
- protected boolean administrator = false;
-
- protected List roleList = new ArrayList();
+public class LoginInfo extends UserInfo {
protected long updatedTime = System.currentTimeMillis();
- public String getUsername() {
- return username;
- }
-
- public void setUsername(final String username) {
- this.username = username;
- }
-
- public boolean isAdministrator() {
- return administrator;
- }
-
- public void setAdministrator(final boolean administrator) {
- this.administrator = administrator;
- }
-
- public void addRole(final String role) {
- if (StringUtil.isNotBlank(role)) {
- roleList.add(role);
- }
- }
-
- public void setRoleList(final List roleList) {
- this.roleList = roleList;
- }
-
- public List getRoleList() {
- return roleList;
- }
-
public void setUpdatedTime(final long updatedTime) {
this.updatedTime = updatedTime;
}
@@ -72,10 +32,14 @@ public class LoginInfo implements Serializable {
return updatedTime;
}
- @Override
- public String toString() {
- return "LoginInfo [username=" + username + ", administrator="
- + administrator + ", roleList=" + roleList + ", updatedTime="
- + updatedTime + "]";
+ public boolean isAdministrator() {
+ for (final String role : ComponentUtil.getSystemHelper()
+ .getAdminRoleSet()) {
+ if (isUserInRole(role)) {
+ return true;
+ }
+ }
+ return false;
}
+
}
diff --git a/src/main/java/jp/sf/fess/filter/AuthenticationFilter.java b/src/main/java/jp/sf/fess/filter/AuthenticationFilter.java
deleted file mode 100644
index 45e1f4ca3..000000000
--- a/src/main/java/jp/sf/fess/filter/AuthenticationFilter.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright 2009-2014 the 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 jp.sf.fess.filter;
-
-import java.io.IOException;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import jp.sf.fess.Constants;
-import jp.sf.fess.crypto.FessCipher;
-import jp.sf.fess.entity.LoginInfo;
-import jp.sf.fess.util.ComponentUtil;
-
-import org.seasar.framework.util.StringUtil;
-
-public class AuthenticationFilter implements Filter {
- private static final String DEFAULT_CIPHER_NAME = "authenticationCipher";
-
- public List urlPatternList = new ArrayList();
-
- protected String cipherName;
-
- protected String loginPath;
-
- protected String adminRole;
-
- protected boolean useSecureLogin;
-
- @Override
- public void destroy() {
- urlPatternList = null;
- cipherName = null;
- }
-
- @Override
- public void doFilter(final ServletRequest request,
- final ServletResponse response, final FilterChain chain)
- throws IOException, ServletException {
- final HttpServletRequest req = (HttpServletRequest) request;
- final HttpServletResponse res = (HttpServletResponse) response;
- final String uri = req.getRequestURI();
- final FessCipher fessCipher = ComponentUtil.getCipher(cipherName);
- for (final Pattern pattern : urlPatternList) {
- final Matcher matcher = pattern.matcher(uri);
- if (matcher.matches()) {
- if (useSecureLogin) {
- final String requestURL = req.getRequestURL().toString();
- if (requestURL.startsWith("http:")) {
- // redirect
- res.sendRedirect(requestURL.replaceFirst("^http:",
- "https:"));
- return;
- }
- }
-
- // require authentication
- boolean redirectLogin = false;
- final Object obj = req.getSession().getAttribute(
- Constants.LOGIN_INFO);
- if (!(obj instanceof LoginInfo)) {
- redirectLogin = true;
- } else {
- final LoginInfo loginInfo = (LoginInfo) obj;
- if (!loginInfo.isAdministrator()) {
- redirectLogin = true;
- }
- }
- if (redirectLogin) {
- final StringBuilder buf = new StringBuilder(256);
- buf.append(System.currentTimeMillis());
- buf.append('|');
- buf.append(req.getRequestURL());
-
- String encoding = request.getCharacterEncoding();
- if (encoding == null) {
- encoding = Constants.UTF_8;
- }
-
- final StringBuilder urlBuf = new StringBuilder(1000);
- urlBuf.append(res.encodeURL(loginPath));
- urlBuf.append("?returnPath=");
- urlBuf.append(URLEncoder.encode(
- fessCipher.encryptoText(buf.toString()), encoding));
-
- // redirect
- res.sendRedirect(urlBuf.toString());
- return;
- }
- }
- }
-
- request.setAttribute(Constants.AUTH_CIPHER, fessCipher);
-
- chain.doFilter(request, response);
- }
-
- @Override
- public void init(final FilterConfig filterConfig) throws ServletException {
- String value = filterConfig.getInitParameter("urlPatterns");
- if (value != null) {
- final String[] urlPatterns = value.split(",");
- for (final String urlPattern : urlPatterns) {
- // TODO context name
- urlPatternList.add(Pattern.compile(urlPattern.trim()));
- }
- }
-
- cipherName = filterConfig.getInitParameter("cipherName");
- if (StringUtil.isBlank(cipherName)) {
- cipherName = DEFAULT_CIPHER_NAME;
- }
-
- loginPath = filterConfig.getInitParameter("loginPath");
- if (StringUtil.isBlank(loginPath)) {
- loginPath = filterConfig.getServletContext().getContextPath()
- + "/login/";
- }
-
- value = filterConfig.getInitParameter("useSecureLogin");
- if (StringUtil.isNotBlank(value)) {
- useSecureLogin = Boolean.parseBoolean(value);
- } else {
- useSecureLogin = false;
- }
-
- }
-
-}
diff --git a/src/main/java/jp/sf/fess/filter/LoginInfoFilter.java b/src/main/java/jp/sf/fess/filter/LoginInfoFilter.java
index 56941e808..101e53c78 100644
--- a/src/main/java/jp/sf/fess/filter/LoginInfoFilter.java
+++ b/src/main/java/jp/sf/fess/filter/LoginInfoFilter.java
@@ -17,8 +17,8 @@
package jp.sf.fess.filter;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -29,11 +29,13 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
-import jp.sf.fess.Constants;
import jp.sf.fess.entity.LoginInfo;
import jp.sf.fess.helper.SystemHelper;
import jp.sf.fess.util.ComponentUtil;
+import org.codelibs.sastruts.core.SSCConstants;
+
+// TODO refactoring...
public class LoginInfoFilter implements Filter {
private long updateInterval = 60 * 60 * 1000L; // 1h
@@ -52,10 +54,10 @@ public class LoginInfoFilter implements Filter {
final HttpServletRequest hRequest = (HttpServletRequest) request;
final HttpSession session = hRequest.getSession();
LoginInfo loginInfo = (LoginInfo) session
- .getAttribute(Constants.LOGIN_INFO);
+ .getAttribute(SSCConstants.USER_INFO);
if (loginInfo == null) {
loginInfo = new LoginInfo();
- session.setAttribute(Constants.LOGIN_INFO, loginInfo);
+ session.setAttribute(SSCConstants.USER_INFO, loginInfo);
updateRoleList(hRequest, loginInfo);
} else {
@@ -72,15 +74,15 @@ public class LoginInfoFilter implements Filter {
private void updateRoleList(final HttpServletRequest hRequest,
final LoginInfo loginInfo) {
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
- final List authenticatedRoleList = systemHelper
- .getAuthenticatedRoleList();
- final List roleList = new ArrayList();
+ final Set authenticatedRoleList = systemHelper
+ .getAuthenticatedRoleSet();
+ final Set roleSet = new HashSet<>();
for (final String role : authenticatedRoleList) {
if (hRequest.isUserInRole(role)) {
- roleList.add(role);
+ roleSet.add(role);
}
}
- loginInfo.setRoleList(roleList);
+ loginInfo.setRoleSet(roleSet);
}
@Override
diff --git a/src/main/java/jp/sf/fess/helper/LabelTypeHelper.java b/src/main/java/jp/sf/fess/helper/LabelTypeHelper.java
index f8e54af3a..1e109f546 100644
--- a/src/main/java/jp/sf/fess/helper/LabelTypeHelper.java
+++ b/src/main/java/jp/sf/fess/helper/LabelTypeHelper.java
@@ -84,8 +84,8 @@ public class LabelTypeHelper implements Serializable {
}
final List