Commit 0131a50b by WeiCong

优化登陆密码校验

添加国密密码校验器
parent a8343c57
......@@ -5,10 +5,11 @@ import log.LogFactory;
import org.apache.commons.dbutils.DbUtils;
import org.sss.common.impl.AbstractLoginContext;
import org.sss.common.impl.MenuItemImpl;
import org.sss.common.impl.PasswordFilter;
import org.sss.common.model.IContext.DataType;
import org.sss.common.model.IFilter;
import org.sss.common.model.IMenuItem;
import org.sss.presentation.noui.api.response.ErrorCode;
import org.sss.presentation.noui.util.NoUiUtils;
import org.sss.util.ContainerUtils;
import java.sql.*;
......@@ -152,10 +153,14 @@ public class DatabaseLoginContextForELCS extends AbstractLoginContext {
}
public String checkPassword(String userName, String dbPassword, String password) {
PasswordFilter passwordFilter = new PasswordFilter();
if (dbPassword != null)
IFilter passwordFilter = NoUiUtils.passwordFilter;
if(NoUiUtils.passwordFilter == null){
log.info("请在eibs.xml为NoUiUtils配置passwordFilter项");
}
if (dbPassword != null){
dbPassword = dbPassword.trim();
String encodedPassword = passwordFilter.encode(password).trim();
}
String encodedPassword = ContainerUtils.encodeWithSalt ? passwordFilter.encode(password, userName).trim() : passwordFilter.encode(password).trim();
log.debug("password(input/db)" + dbPassword + "\t" + encodedPassword);
if (!encodedPassword.equals(dbPassword))
return "[Database: NOT Match.]";
......
/*
* Create on 2007-11-15
*/
package org.sss.presentation.noui.filter;
import log.Log;
import log.LogFactory;
import org.apache.commons.codec.binary.Base64;
import org.sss.common.model.IFilter;
import org.sss.util.ContainerUtils;
import cfca.sadk.util.HashUtil;
/**
* 密码过滤器实现(国密)
* @author Jason.Hoo (latest modification by $Author: hujianxin $)
* @version $Revision: 1014 $ $Date: 2019-01-03 18:23:23 +0800 (Thu, 03 Jan 2019) $
*/
public class PasswordSM2Filter
implements IFilter
{
static final Log log = LogFactory.getLog(PasswordSM2Filter.class);
public String decode(String encodedValue)
{
if (ContainerUtils.isEmpty(encodedValue))
return null;
return "**********";
}
public String encode(String value)
{
if (ContainerUtils.isEmpty(value))
return value;
byte[] result = null;
try
{
result = HashUtil.SM2HashMessageByBCWithoutZValue(value.getBytes());
}
catch (Exception e)
{
log.error("encode SM2 error.", e);
return null;
}
return new Base64().encodeToString(result).trim();
}
public String encode(String value, String salt)
{
if (ContainerUtils.isEmpty(value))
return value;
value = encode(value);
if (ContainerUtils.isEmpty(salt) || ContainerUtils.isEmpty(value))
return value;
else
return encode(value + salt);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment