提交 0be9214a 编写于 作者: Z zhourui

移动encryptType,从token配置移动到person配置

上级 b3755df0
......@@ -1078,6 +1078,20 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
return new ArrayList<>(os);
}
public <T extends JpaObject, W, X> List<String> idsInOrInOrIsMember(Class<T> cls, String firstAttribute,
Collection<W> firstCollection, String secondAttribute, Collection<X> secondCollection,
String isMemberAttribute, Object isMemberValue) throws Exception {
EntityManager em = this.get(cls);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<T> root = cq.from(cls);
Predicate p = cb.or(root.get(firstAttribute).in(firstCollection),
root.get(secondAttribute).in(secondCollection),
cb.isMember(isMemberValue, root.get(isMemberAttribute)));
List<String> os = em.createQuery(cq.select(root.get(JpaObject.id_FIELDNAME)).where(p)).getResultList();
return new ArrayList<>(os);
}
public void commit() throws Exception {
try {
for (EntityManager em : entityManagerMap.values()) {
......
......@@ -54,6 +54,8 @@ public class Person extends ConfigObject {
public static final Boolean DEFAULT_ENABLESAFELOGOUT = false;
public static final String DEFAULT_ENCRYPTTYPE = "";
public Person() {
this.captchaLogin = DEFAULT_CAPTCHALOGIN;
this.codeLogin = DEFAULT_CODELOGIN;
......@@ -70,6 +72,7 @@ public class Person extends ConfigObject {
this.language = DEFAULT_LANGUAGE;
this.tokenName = DEFAULT_TOKENNAME;
this.enableSafeLogout = DEFAULT_ENABLESAFELOGOUT;
this.encryptType = DEFAULT_ENCRYPTTYPE;
}
public static Person defaultInstance() {
......@@ -135,6 +138,13 @@ public class Person extends ConfigObject {
@FieldDescribe("是否启用安全注销.")
private Boolean enableSafeLogout;
@FieldDescribe("加密方式,支持国密sm4")
private String encryptType;
public String getEncryptType() {
return StringUtils.isEmpty(this.encryptType) ? DEFAULT_ENCRYPTTYPE : this.encryptType;
}
@FieldDescribe("扩展设置.")
private Map<String, Object> extension;
......
......@@ -35,8 +35,6 @@ public class Token extends ConfigObject {
public static final String defaultSslKeyStorePassword = "123456";
public static final String defaultSslKeyManagerPassword = "123456";
public static final String DEFAULT_ENCRYPTTYPE = "";
public static final Boolean DEFAULT_RSAENABLE = false;
// 此对象临时计算无需存储
......@@ -53,7 +51,7 @@ public class Token extends ConfigObject {
this.password = "";
this.sslKeyStorePassword = defaultSslKeyStorePassword;
this.sslKeyManagerPassword = defaultSslKeyManagerPassword;
this.encryptType = DEFAULT_ENCRYPTTYPE;
this.rsaEnable = DEFAULT_RSAENABLE;
}
......@@ -70,9 +68,6 @@ public class Token extends ConfigObject {
@FieldDescribe("ssl管理密码")
private String sslKeyManagerPassword;
@FieldDescribe("加密方式,支持国密sm4")
private String encryptType;
@FieldDescribe("LDAP认证配置")
private LdapAuth ldapAuth;
......@@ -92,14 +87,6 @@ public class Token extends ConfigObject {
return null == this.rsaEnable ? DEFAULT_RSAENABLE : this.rsaEnable;
}
public String getEncryptType() {
return StringUtils.isEmpty(this.encryptType) ? DEFAULT_ENCRYPTTYPE : this.encryptType;
}
public void setEncryptType(String encryptType) {
this.encryptType = encryptType;
}
// 前面的代码是 key+surfix 结果是nullo2platform
public String getKey() {
String val = Objects.toString(key, "") + surfix;
......
......@@ -313,7 +313,7 @@ public class CipherConnectionAction {
public static List<NameValuePair> cipher() throws Exception {
EffectivePerson effectivePerson = EffectivePerson.cipher(Config.token().getCipher(),
Config.token().getEncryptType());
Config.person().getEncryptType());
return ListTools.toList(new NameValuePair(Config.person().getTokenName(), effectivePerson.getToken()));
}
......
......@@ -75,7 +75,7 @@ public class EffectivePerson extends GsonPropertyObject {
}
public EffectivePerson(String distinguishedName, TokenType tokenType, String key) throws Exception {
this(distinguishedName, tokenType, key, Config.token().getEncryptType());
this(distinguishedName, tokenType, key, Config.person().getEncryptType());
}
public EffectivePerson(String distinguishedName, TokenType tokenType, String key, String encryptType)
......
......@@ -60,7 +60,7 @@ public class HttpToken {
try {
String plain = "";
try {
plain = Crypto.decrypt(token, key, Config.token().getEncryptType());
plain = Crypto.decrypt(token, key, Config.person().getEncryptType());
} catch (Exception e) {
logger.warn("can not decrypt token:{}, {}, remote address:{}.", token, e.getMessage(), address);
return EffectivePerson.anonymous();
......@@ -102,7 +102,7 @@ public class HttpToken {
return EffectivePerson.anonymous();
}
return new EffectivePerson(URLDecoder.decode(matcher.group(3), StandardCharsets.UTF_8.name()), tokenType,
key, Config.token().getEncryptType());
key, Config.person().getEncryptType());
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -55,7 +55,7 @@ public class Crypto {
private static final String TYPE_SM4 = "sm4";
public static String encrypt(String data, String key) throws Exception {
return encrypt(data, key, Config.token().getEncryptType());
return encrypt(data, key, Config.person().getEncryptType());
}
public static String encrypt(String data, String key, String type)
......@@ -100,9 +100,8 @@ public class Crypto {
return classSm4;
}
public static String decrypt(String data, String key)
throws Exception {
return decrypt(data, key, Config.token().getEncryptType());
public static String decrypt(String data, String key) throws Exception {
return decrypt(data, key, Config.person().getEncryptType());
}
public static String decrypt(String data, String key, String type)
......
......@@ -40,7 +40,7 @@ public class ActionConfig extends ActionBase {
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type", HttpMediaType.APPLICATION_JSON_UTF_8);
EffectivePerson effectivePerson = EffectivePerson.cipher(Config.token().getCipher(),
Config.token().getEncryptType());
Config.person().getEncryptType());
connection.setRequestProperty(Config.person().getTokenName(), effectivePerson.getToken());
connection.setRequestMethod("GET");
connection.setDoOutput(false);
......
......@@ -80,7 +80,7 @@ abstract class BaseAction extends StandardJaxrsAction {
tokenType = Config.ternaryManagement().getTokenType(credential);
}
EffectivePerson effectivePerson = new EffectivePerson(credential, tokenType, Config.token().getCipher(),
Config.token().getEncryptType());
Config.person().getEncryptType());
if ((null != request) && (null != response)) {
httpToken.setToken(request, response, effectivePerson);
}
......@@ -113,7 +113,7 @@ abstract class BaseAction extends StandardJaxrsAction {
tokenType = TokenType.auditManager;
}
EffectivePerson effectivePerson = new EffectivePerson(person.getDistinguishedName(), tokenType,
Config.token().getCipher(), Config.token().getEncryptType());
Config.token().getCipher(), Config.person().getEncryptType());
if ((null != request) && (null != response)) {
if (!isMoaTerminal(request)) {
String clientIp = HttpToken.remoteAddress(request);
......@@ -203,7 +203,7 @@ abstract class BaseAction extends StandardJaxrsAction {
&& LdapTools.auth(person.getUnique(), password)) {
return true;
}
return (StringUtils.equals(Crypto.encrypt(password, Config.token().getKey(), Config.token().getEncryptType()),
return (StringUtils.equals(Crypto.encrypt(password, Config.token().getKey(), Config.person().getEncryptType()),
person.getPassword()) || StringUtils.equals(MD5Tool.getMD5Str(password), person.getPassword()));
}
......
......@@ -65,7 +65,7 @@ class ActionLogin extends BaseAction {
List<String> roles = business.organization().role().listWithPerson(person.getDistinguishedName());
wo.setRoleList(roles);
EffectivePerson effective = new EffectivePerson(wo.getDistinguishedName(), TokenType.user,
Config.token().getCipher(), Config.token().getEncryptType());
Config.token().getCipher(), Config.person().getEncryptType());
wo.setToken(effective.getToken());
HttpToken httpToken = new HttpToken();
httpToken.setToken(request, response, effective);
......
......@@ -61,7 +61,7 @@ public class ActionLoginWithCode extends BaseAction {
List<String> roles = business.organization().role().listWithPerson(person.getDistinguishedName());
wo.setRoleList(roles);
EffectivePerson effective = new EffectivePerson(wo.getDistinguishedName(), TokenType.user,
Config.token().getCipher(), Config.token().getEncryptType());
Config.token().getCipher(), Config.person().getEncryptType());
wo.setToken(effective.getToken());
HttpToken httpToken = new HttpToken();
httpToken.setToken(request, response, effective);
......
......@@ -64,7 +64,7 @@ class ActionGetLogin extends BaseAction {
List<String> roles = business.organization().role().listWithPerson(person.getDistinguishedName());
wo.setRoleList(roles);
EffectivePerson effective = new EffectivePerson(wo.getDistinguishedName(), TokenType.user,
Config.token().getCipher(), Config.token().getEncryptType());
Config.token().getCipher(), Config.person().getEncryptType());
wo.setToken(effective.getToken());
HttpToken httpToken = new HttpToken();
httpToken.setToken(request, response, effective);
......
......@@ -38,7 +38,7 @@ class ActionGetEncrypt extends BaseAction {
throw new ExceptionClientNotExist(client);
}
String str = credential + TOKEN_SPLIT + new Date().getTime();
String token = Crypto.encrypt(str, key, Config.token().getEncryptType());
String token = Crypto.encrypt(str, key, Config.person().getEncryptType());
Wo wo = new Wo();
wo.setToken(token);
result.setData(wo);
......
......@@ -54,7 +54,7 @@ class ActionGetLogin extends BaseAction {
String content = null;
logger.debug("decrypt sso client:{}, token:{}, key:{}.", client, token, sso.getKey());
try {
content = Crypto.decrypt(token, sso.getKey(), Config.token().getEncryptType());
content = Crypto.decrypt(token, sso.getKey(), Config.person().getEncryptType());
logger.debug("decrypt sso client:{}, token:{}, key:{}, content:{}.", client, token, sso.getKey(),
content);
} catch (Exception e) {
......@@ -98,7 +98,7 @@ class ActionGetLogin extends BaseAction {
tokenType = TokenType.auditManager;
}
EffectivePerson effective = new EffectivePerson(wo.getDistinguishedName(), tokenType,
Config.token().getCipher(), Config.token().getEncryptType());
Config.token().getCipher(), Config.person().getEncryptType());
wo.setToken(effective.getToken());
HttpToken httpToken = new HttpToken();
httpToken.setToken(request, response, effective);
......
......@@ -41,7 +41,7 @@ class ActionPostEncrypt extends BaseAction {
throw new ExceptionClientNotExist(wi.getClient());
}
String str = wi.getCredential() + TOKEN_SPLIT + new Date().getTime();
String token = Crypto.encrypt(str, wi.getKey(), Config.token().getEncryptType());
String token = Crypto.encrypt(str, wi.getKey(), Config.person().getEncryptType());
Wo wo = new Wo();
wo.setToken(token);
result.setData(wo);
......
......@@ -57,7 +57,7 @@ class ActionPostLogin extends BaseAction {
String content = null;
logger.debug("decrypt sso client:{}, token:{}, key:{}.", wi.getClient(), wi.getToken(), sso.getKey());
try {
content = Crypto.decrypt(wi.getToken(), sso.getKey(), Config.token().getEncryptType());
content = Crypto.decrypt(wi.getToken(), sso.getKey(), Config.person().getEncryptType());
} catch (Exception e) {
throw new ExceptionReadToken(wi.getClient(), wi.getToken());
}
......@@ -99,7 +99,7 @@ class ActionPostLogin extends BaseAction {
tokenType = TokenType.auditManager;
}
EffectivePerson effective = new EffectivePerson(wo.getDistinguishedName(), tokenType,
Config.token().getCipher(), Config.token().getEncryptType());
Config.token().getCipher(), Config.person().getEncryptType());
wo.setToken(effective.getToken());
HttpToken httpToken = new HttpToken();
httpToken.setToken(request, response, effective);
......
......@@ -59,7 +59,7 @@ public class ActionLogin extends BaseAction {
List<String> roles = business.organization().role().listWithPerson(person.getDistinguishedName());
wo.setRoleList(roles);
EffectivePerson effective = new EffectivePerson(wo.getDistinguishedName(), TokenType.user,
Config.token().getCipher(), Config.token().getEncryptType());
Config.token().getCipher(), Config.person().getEncryptType());
wo.setToken(effective.getToken());
HttpToken httpToken = new HttpToken();
httpToken.setToken(request, response, effective);
......
......@@ -50,7 +50,7 @@ class ActionLogin extends BaseAction {
List<String> roles = business.organization().role().listWithPerson(person.getDistinguishedName());
wo.setRoleList(roles);
EffectivePerson effective = new EffectivePerson(wo.getDistinguishedName(), TokenType.user,
Config.token().getCipher(), Config.token().getEncryptType());
Config.token().getCipher(), Config.person().getEncryptType());
wo.setToken(effective.getToken());
HttpToken httpToken = new HttpToken();
httpToken.setToken(request, response, effective);
......
......@@ -192,7 +192,7 @@ public class PersonFactory extends AbstractFactory {
public void setPassword(Person person, String password, boolean isInitialization) throws Exception {
Calendar cal = Calendar.getInstance();
person.setChangePasswordTime(cal.getTime());
person.setPassword(Crypto.encrypt(password, Config.token().getKey(), Config.token().getEncryptType()));
person.setPassword(Crypto.encrypt(password, Config.token().getKey(), Config.person().getEncryptType()));
Integer passwordPeriod = Config.person().getPasswordPeriod();
if (passwordPeriod == null || passwordPeriod <= 0) {
person.setPasswordExpiredTime(null);
......
......@@ -109,7 +109,7 @@ class ActionInput extends BaseAction {
}
}
for (PersonItem o : people) {
o.setPassword(Crypto.encrypt(o.getPassword(), Config.token().getKey(), Config.token().getEncryptType()));
o.setPassword(Crypto.encrypt(o.getPassword(), Config.token().getKey(), Config.person().getEncryptType()));
}
}
......
......@@ -257,7 +257,7 @@ public class PersonFactory extends AbstractFactory {
public void setPassword(Person person, String password) throws Exception {
Calendar cal = Calendar.getInstance();
person.setChangePasswordTime(cal.getTime());
person.setPassword(Crypto.encrypt(password, Config.token().getKey(), Config.token().getEncryptType()));
person.setPassword(Crypto.encrypt(password, Config.token().getKey(), Config.person().getEncryptType()));
Integer passwordPeriod = Config.person().getPasswordPeriod();
if (passwordPeriod == null || passwordPeriod <= 0) {
person.setPasswordExpiredTime(null);
......
......@@ -57,7 +57,7 @@ class ActionChangePassword extends ActionBase {
logger.info("user{name:" + person.getName() + "} use superPermission.");
} else {
if (!StringUtils.equals(
Crypto.encrypt(wi.getOldPassword(), Config.token().getKey(), Config.token().getEncryptType()),
Crypto.encrypt(wi.getOldPassword(), Config.token().getKey(), Config.person().getEncryptType()),
person.getPassword())) {
throw new ExceptionOldPasswordNotMatch();
}
......
......@@ -79,7 +79,7 @@ class ActionSetPassword extends BaseAction {
logger.info("user{name:" + person.getName() + "} use superPermission.");
} else {
if (!StringUtils.equals(
Crypto.encrypt(oldPassword, Config.token().getKey(), Config.token().getEncryptType()),
Crypto.encrypt(oldPassword, Config.token().getKey(), Config.person().getEncryptType()),
person.getPassword())) {
throw new ExceptionOldPasswordNotMatch();
}
......
......@@ -61,7 +61,7 @@ class ActionReset extends BaseAction {
}
}
emc.beginTransaction(Person.class);
person.setPassword(Crypto.encrypt(password, Config.token().getKey(), Config.token().getEncryptType()));
person.setPassword(Crypto.encrypt(password, Config.token().getKey(), Config.person().getEncryptType()));
person.setChangePasswordTime(new Date());
emc.check(person, CheckPersistType.all);
emc.commit();
......
......@@ -86,7 +86,7 @@ public class ActionSetPasswordAnonymous extends BaseAction {
LOGGER.info("user{name:" + person.getName() + "} use superPermission.");
} else {
if (!StringUtils.equals(
Crypto.encrypt(oldPassword, Config.token().getKey(), Config.token().getEncryptType()),
Crypto.encrypt(oldPassword, Config.token().getKey(), Config.person().getEncryptType()),
person.getPassword())) {
throw new ExceptionOldPasswordNotMatch();
}
......
......@@ -83,7 +83,7 @@ public class PersonFactory extends AbstractFactory {
public void setPassword(Person person, String password) throws Exception {
Calendar cal = Calendar.getInstance();
person.setChangePasswordTime(cal.getTime());
person.setPassword(Crypto.encrypt(password, Config.token().getKey(), Config.token().getEncryptType()));
person.setPassword(Crypto.encrypt(password, Config.token().getKey(), Config.person().getEncryptType()));
Integer passwordPeriod = Config.person().getPasswordPeriod();
if (passwordPeriod == null || passwordPeriod <= 0) {
person.setPasswordExpiredTime(null);
......
......@@ -32,7 +32,7 @@ class ActionLogin extends BaseAction {
}
HttpToken httpToken = new HttpToken();
EffectivePerson ep = new EffectivePerson(Config.token().initialManagerInstance().getName(), TokenType.manager,
Config.token().getCipher(), Config.token().getEncryptType());
Config.token().getCipher(), Config.person().getEncryptType());
httpToken.setToken(request, response, ep);
Wo wo = new Wo();
Config.token().initialManagerInstance().copyTo(wo, JpaObject.FieldsInvisible);
......
......@@ -87,7 +87,7 @@ class ActionExecuteToken extends BaseAction {
private String decrypt(String client, String token, Sso sso) throws ExceptionReadToken {
String value = "";
try {
value = Crypto.decrypt(token, sso.getKey(), Config.token().getEncryptType());
value = Crypto.decrypt(token, sso.getKey(), Config.person().getEncryptType());
LOGGER.debug("decrypt sso client:{}, token:{}, key:{}, content:{}.", client::toString, token::toString,
sso::getKey, value::toString);
} catch (Exception e) {
......
......@@ -29,7 +29,7 @@ class ActionToken extends BaseAction {
}
wo.setValue(Crypto.encrypt(effectivePerson.getDistinguishedName() + SPLIT + (new Date().getTime()),
sso.getKey(), Config.token().getEncryptType()));
sso.getKey(), Config.person().getEncryptType()));
result.setData(wo);
return result;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册