forked from p85126437/datagear
移除已启用的部分类RoleUser、SmtpSetting
This commit is contained in:
parent
8ead74bf18
commit
56b050c0a7
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 datagear.tech
|
||||
*
|
||||
* Licensed under the LGPLv3 license:
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.html
|
||||
*/
|
||||
|
||||
package org.datagear.management.domain;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
/**
|
||||
* 角色-用户。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class RoleUser extends AbstractStringIdEntity implements CloneableEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 角色 */
|
||||
private Role role;
|
||||
|
||||
/** 用户 */
|
||||
private User user;
|
||||
|
||||
public RoleUser()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public RoleUser(String id, Role role, User user)
|
||||
{
|
||||
super(id);
|
||||
this.role = role;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Role getRole()
|
||||
{
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(Role role)
|
||||
{
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public User getUser()
|
||||
{
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user)
|
||||
{
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleUser clone()
|
||||
{
|
||||
RoleUser entity = new RoleUser();
|
||||
BeanUtils.copyProperties(this, entity);
|
||||
|
||||
return entity;
|
||||
}
|
||||
}
|
|
@ -1,183 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 datagear.tech
|
||||
*
|
||||
* Licensed under the LGPLv3 license:
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.html
|
||||
*/
|
||||
|
||||
package org.datagear.management.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* SMTP设置。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class SmtpSetting implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 服务器主机 */
|
||||
private String host;
|
||||
|
||||
/** 服务器端口 */
|
||||
private int port;
|
||||
|
||||
/** 用户名 */
|
||||
private String username;
|
||||
|
||||
/** 密码 */
|
||||
private String password;
|
||||
|
||||
/** 连接类型 */
|
||||
private ConnectionType connectionType;
|
||||
|
||||
/** 系统邮箱 */
|
||||
private String systemEmail;
|
||||
|
||||
public SmtpSetting()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public String getHost()
|
||||
{
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host)
|
||||
{
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public int getPort()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port)
|
||||
{
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getUsername()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username)
|
||||
{
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password)
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public ConnectionType getConnectionType()
|
||||
{
|
||||
return connectionType;
|
||||
}
|
||||
|
||||
public void setConnectionType(ConnectionType connectionType)
|
||||
{
|
||||
this.connectionType = connectionType;
|
||||
}
|
||||
|
||||
public String getSystemEmail()
|
||||
{
|
||||
return systemEmail;
|
||||
}
|
||||
|
||||
public void setSystemEmail(String systemEmail)
|
||||
{
|
||||
this.systemEmail = systemEmail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((connectionType == null) ? 0 : connectionType.hashCode());
|
||||
result = prime * result + ((host == null) ? 0 : host.hashCode());
|
||||
result = prime * result + ((password == null) ? 0 : password.hashCode());
|
||||
result = prime * result + port;
|
||||
result = prime * result + ((systemEmail == null) ? 0 : systemEmail.hashCode());
|
||||
result = prime * result + ((username == null) ? 0 : username.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
SmtpSetting other = (SmtpSetting) obj;
|
||||
if (connectionType != other.connectionType)
|
||||
return false;
|
||||
if (host == null)
|
||||
{
|
||||
if (other.host != null)
|
||||
return false;
|
||||
}
|
||||
else if (!host.equals(other.host))
|
||||
return false;
|
||||
if (password == null)
|
||||
{
|
||||
if (other.password != null)
|
||||
return false;
|
||||
}
|
||||
else if (!password.equals(other.password))
|
||||
return false;
|
||||
if (port != other.port)
|
||||
return false;
|
||||
if (systemEmail == null)
|
||||
{
|
||||
if (other.systemEmail != null)
|
||||
return false;
|
||||
}
|
||||
else if (!systemEmail.equals(other.systemEmail))
|
||||
return false;
|
||||
if (username == null)
|
||||
{
|
||||
if (other.username != null)
|
||||
return false;
|
||||
}
|
||||
else if (!username.equals(other.username))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getClass().getSimpleName() + " [host=" + host + ", port=" + port + ", username=" + username
|
||||
+ ", password=" + password + ", connectionType=" + connectionType + ", systemEmail=" + systemEmail
|
||||
+ "]";
|
||||
}
|
||||
|
||||
public static enum ConnectionType
|
||||
{
|
||||
/** 简单SMPT连接 */
|
||||
PLAIN,
|
||||
|
||||
/** SSL安全连接 */
|
||||
SSL,
|
||||
|
||||
/** TLS安全连接 */
|
||||
TLS
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 datagear.tech
|
||||
*
|
||||
* Licensed under the LGPLv3 license:
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.html
|
||||
*/
|
||||
|
||||
package org.datagear.management.service.impl;
|
||||
|
||||
import org.datagear.management.domain.SmtpSetting;
|
||||
|
||||
/**
|
||||
* {@linkplain SmtpSetting#getPassword()}加密、解密类。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public interface SmtpSettingPasswordEncryptor
|
||||
{
|
||||
/**
|
||||
* 加密。
|
||||
*
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
String encrypt(String password);
|
||||
|
||||
/**
|
||||
* 解密。
|
||||
*
|
||||
* @param encryptedPassword
|
||||
* @return
|
||||
*/
|
||||
String decrypt(String encryptedPassword);
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 datagear.tech
|
||||
*
|
||||
* Licensed under the LGPLv3 license:
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.html
|
||||
*/
|
||||
|
||||
package org.datagear.web.security;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.DESKeySpec;
|
||||
|
||||
import org.datagear.management.service.impl.SmtpSettingPasswordEncryptor;
|
||||
import org.springframework.security.crypto.codec.Hex;
|
||||
import org.springframework.security.crypto.codec.Utf8;
|
||||
|
||||
/**
|
||||
* {@linkplain SmtpSettingPasswordEncryptor}实现类。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class SmtpSettingPasswordEncryptorImpl implements SmtpSettingPasswordEncryptor
|
||||
{
|
||||
private static final String ALGORITHM_DES = "DES";
|
||||
private static final String ENCRYPT_PASSWORD = "ZY150401";
|
||||
|
||||
public SmtpSettingPasswordEncryptorImpl()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encrypt(String password)
|
||||
{
|
||||
SecureRandom random = new SecureRandom();
|
||||
|
||||
try
|
||||
{
|
||||
DESKeySpec desKey = new DESKeySpec(ENCRYPT_PASSWORD.getBytes("iso-8859-1"));
|
||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM_DES);
|
||||
SecretKey securekey = keyFactory.generateSecret(desKey);
|
||||
Cipher cipher = Cipher.getInstance(ALGORITHM_DES);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, securekey, random);
|
||||
|
||||
byte[] passwordBytes = Utf8.encode(password);
|
||||
byte[] result = cipher.doFinal(passwordBytes);
|
||||
|
||||
return new String(Hex.encode(result));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e instanceof RuntimeException)
|
||||
throw (RuntimeException) e;
|
||||
else
|
||||
throw new EncryptorException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String encryptedPassword)
|
||||
{
|
||||
SecureRandom random = new SecureRandom();
|
||||
|
||||
try
|
||||
{
|
||||
DESKeySpec desKey = new DESKeySpec(ENCRYPT_PASSWORD.getBytes("iso-8859-1"));
|
||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM_DES);
|
||||
SecretKey securekey = keyFactory.generateSecret(desKey);
|
||||
Cipher cipher = Cipher.getInstance(ALGORITHM_DES);
|
||||
cipher.init(Cipher.DECRYPT_MODE, securekey, random);
|
||||
|
||||
byte[] passwordBytes = Hex.decode(encryptedPassword);
|
||||
byte[] result = cipher.doFinal(passwordBytes);
|
||||
|
||||
return new String(Utf8.decode(result));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e instanceof RuntimeException)
|
||||
throw (RuntimeException) e;
|
||||
else
|
||||
throw new EncryptorException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 datagear.tech
|
||||
*
|
||||
* Licensed under the LGPLv3 license:
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.html
|
||||
*/
|
||||
|
||||
package org.datagear.web.security;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* {@linkplain SmtpSettingPasswordEncryptorImpl}单元测试类。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class SmtpSettingPasswordEncryptorImplTest
|
||||
{
|
||||
private SmtpSettingPasswordEncryptorImpl smtpSettingPasswordEncryptorImpl = new SmtpSettingPasswordEncryptorImpl();
|
||||
|
||||
@Test
|
||||
public void test()
|
||||
{
|
||||
String password = "i am a password";
|
||||
|
||||
String encryptedPassword = smtpSettingPasswordEncryptorImpl.encrypt(password);
|
||||
|
||||
String decryptedPassword = smtpSettingPasswordEncryptorImpl.decrypt(encryptedPassword);
|
||||
|
||||
Assert.assertEquals(password, decryptedPassword);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue