Skip to content

Commit

Permalink
清除无用代码
Browse files Browse the repository at this point in the history
  • Loading branch information
dolyw committed Dec 4, 2018
1 parent 6f8d632 commit e35e599
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 48 deletions.
9 changes: 6 additions & 3 deletions src/main/java/com/wang/config/redis/JedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
@ConfigurationProperties(prefix = "redis")
public class JedisConfig {

private static Logger logger = LoggerFactory.getLogger(JedisConfig.class);
/**
* LOGGER
*/
private static final Logger LOGGER = LoggerFactory.getLogger(JedisConfig.class);

private String host;

Expand Down Expand Up @@ -55,10 +58,10 @@ public JedisPool redisPoolFactory(){
jedisPoolConfig.setMinIdle(minIdle);
// JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password);
JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, null);
logger.info("初始化Redis连接池JedisPool成功!" + " Redis地址: " + host + ":" + port);
LOGGER.info("初始化Redis连接池JedisPool成功!地址: " + host + ":" + port);
return jedisPool;
} catch (Exception e) {
logger.error("初始化Redis连接池JedisPool异常:" + e.getMessage());
LOGGER.error("初始化Redis连接池JedisPool异常:" + e.getMessage());
}
return null;
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/wang/config/shiro/UserRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand All @@ -34,8 +32,6 @@
@Service
public class UserRealm extends AuthorizingRealm {

private static final Logger LOGGER = LoggerFactory.getLogger(UserRealm.class);

private final UserMapper userMapper;
private final RoleMapper roleMapper;
private final PermissionMapper permissionMapper;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/wang/config/shiro/jwt/JwtFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
*/
public class JwtFilter extends BasicHttpAuthenticationFilter {
/**
* Logger
* LOGGER
*/
private Logger logger = LoggerFactory.getLogger(this.getClass());
private static final Logger LOGGER = LoggerFactory.getLogger(JwtFilter.class);

/**
* 这里我们详细说明下为什么最终返回的都是true,即允许访问
Expand Down Expand Up @@ -170,8 +170,8 @@ private void response401(ServletRequest req, ServletResponse resp, String msg) {
String data = JsonConvertUtil.objectToJson(new ResponseBean(HttpStatus.UNAUTHORIZED.value(), "无权访问(Unauthorized):" + msg, null));
out.append(data);
} catch (IOException e) {
logger.error(e.getMessage());
throw new CustomException("直接返回Response信息出现IOException异常");
LOGGER.error("直接返回Response信息出现IOException异常:" + e.getMessage());
throw new CustomException("直接返回Response信息出现IOException异常:" + e.getMessage());
} finally {
if (out != null) {
out.close();
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/com/wang/util/AesCipherUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public void setEncryptAESKey(String encryptAESKey) {
}

/**
* logger
* LOGGER
*/
private static final Logger logger = LoggerFactory.getLogger(AesCipherUtil.class);
private static final Logger LOGGER = LoggerFactory.getLogger(AesCipherUtil.class);

/**
* 加密
Expand Down Expand Up @@ -68,22 +68,22 @@ public static String enCrypto(String str) {
// 先将二进制转换成16进制,再返回Bsae64加密后的String
return Base64ConvertUtil.encode(HexConvertUtil.parseByte2HexStr(cipherByte));
} catch (NoSuchAlgorithmException e){
logger.error(e.getMessage());
LOGGER.error("getInstance()方法异常:" + e.getMessage());
throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage());
} catch (UnsupportedEncodingException e){
logger.error(e.getMessage());
LOGGER.error("Bsae64加密异常:" + e.getMessage());
throw new CustomUnauthorizedException("Bsae64加密异常:" + e.getMessage());
} catch (NoSuchPaddingException e){
logger.error(e.getMessage());
LOGGER.error("getInstance()方法异常:" + e.getMessage());
throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage());
} catch (InvalidKeyException e){
logger.error(e.getMessage());
LOGGER.error("初始化Cipher对象异常:" + e.getMessage());
throw new CustomUnauthorizedException("初始化Cipher对象异常:" + e.getMessage());
} catch (IllegalBlockSizeException e){
logger.error(e.getMessage());
LOGGER.error("加密异常,密钥有误:" + e.getMessage());
throw new CustomUnauthorizedException("加密异常,密钥有误:" + e.getMessage());
} catch (BadPaddingException e){
logger.error(e.getMessage());
LOGGER.error("加密异常,密钥有误:" + e.getMessage());
throw new CustomUnauthorizedException("加密异常,密钥有误:" + e.getMessage());
}
}
Expand Down Expand Up @@ -115,22 +115,22 @@ public static String deCrypto(String str) {
byte[] cipherByte = c.doFinal(HexConvertUtil.parseHexStr2Byte(Base64ConvertUtil.decode(str)));
return new String(cipherByte);
} catch (NoSuchAlgorithmException e){
logger.error(e.getMessage());
LOGGER.error("getInstance()方法异常:" + e.getMessage());
throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage());
} catch (UnsupportedEncodingException e){
logger.error(e.getMessage());
LOGGER.error("Bsae64加密异常:" + e.getMessage());
throw new CustomUnauthorizedException("Bsae64加密异常:" + e.getMessage());
} catch (NoSuchPaddingException e){
logger.error(e.getMessage());
LOGGER.error("getInstance()方法异常:" + e.getMessage());
throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage());
} catch (InvalidKeyException e){
logger.error(e.getMessage());
LOGGER.error("初始化Cipher对象异常:" + e.getMessage());
throw new CustomUnauthorizedException("初始化Cipher对象异常:" + e.getMessage());
} catch (IllegalBlockSizeException e){
logger.error(e.getMessage());
LOGGER.error("解密异常,密钥有误:" + e.getMessage());
throw new CustomUnauthorizedException("解密异常,密钥有误:" + e.getMessage());
} catch (BadPaddingException e){
logger.error(e.getMessage());
LOGGER.error("解密异常,密钥有误:" + e.getMessage());
throw new CustomUnauthorizedException("解密异常,密钥有误:" + e.getMessage());
}
}
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/com/wang/util/JedisUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.wang.model.common.Constant;
import com.wang.util.common.StringUtil;
import com.wang.util.common.SerializableUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
Expand All @@ -21,11 +19,6 @@
@Component
public class JedisUtil {

/**
* Logger
*/
private static Logger logger = LoggerFactory.getLogger(JedisUtil.class);

/**
* 静态注入JedisPool连接池
* 本来是正常注入JedisUtil,可以在Controller和Service层使用,但是重写Shiro的CustomCache无法注入JedisUtil
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/wang/util/JwtUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.wang.exception.CustomException;
import com.wang.model.common.Constant;
import com.wang.util.common.Base64ConvertUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

Expand All @@ -22,6 +24,11 @@
@Component
public class JwtUtil {

/**
* LOGGER
*/
private static final Logger LOGGER = LoggerFactory.getLogger(JwtUtil.class);

/**
* 过期时间改为从配置文件获取
*/
Expand Down Expand Up @@ -59,8 +66,8 @@ public static boolean verify(String token) {
DecodedJWT jwt = verifier.verify(token);
return true;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new CustomException("JWTToken认证解密出现UnsupportedEncodingException异常");
LOGGER.error("JWTToken认证解密出现UnsupportedEncodingException异常:" + e.getMessage());
throw new CustomException("JWTToken认证解密出现UnsupportedEncodingException异常:" + e.getMessage());
}
}

Expand All @@ -78,8 +85,8 @@ public static String getClaim(String token, String claim) {
// 只能输出String类型,如果是其他类型返回null
return jwt.getClaim(claim).asString();
} catch (JWTDecodeException e) {
e.printStackTrace();
throw new CustomException("解密Token中的公共信息出现JWTDecodeException异常");
LOGGER.error("解密Token中的公共信息出现JWTDecodeException异常:" + e.getMessage());
throw new CustomException("解密Token中的公共信息出现JWTDecodeException异常:" + e.getMessage());
}
}

Expand All @@ -104,7 +111,8 @@ public static String sign(String account, String currentTimeMillis) {
.withExpiresAt(date)
.sign(algorithm);
} catch (UnsupportedEncodingException e) {
throw new CustomException("JWTToken加密出现UnsupportedEncodingException异常");
LOGGER.error("JWTToken加密出现UnsupportedEncodingException异常:" + e.getMessage());
throw new CustomException("JWTToken加密出现UnsupportedEncodingException异常:" + e.getMessage());
}
}
}
14 changes: 11 additions & 3 deletions src/main/java/com/wang/util/common/PropertiesUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.wang.util.common;

import com.wang.exception.CustomException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -15,6 +17,11 @@
*/
public class PropertiesUtil {

/**
* LOGGER
*/
private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesUtil.class);

/**
* PROP
*/
Expand All @@ -34,15 +41,16 @@ public static void readProperties(String fileName){
BufferedReader bf = new BufferedReader(new InputStreamReader(in));
PROP.load(bf);
} catch (IOException e){
e.printStackTrace();
LOGGER.error("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage());
throw new CustomException("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage());
} finally {
try{
if(in != null){
in.close();
}
}catch (IOException e){
e.printStackTrace();
throw new CustomException("PropertiesUtil工具类读取配置文件出现IOException异常");
LOGGER.error("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage());
throw new CustomException("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage());
}
}
}
Expand Down
25 changes: 17 additions & 8 deletions src/main/java/com/wang/util/common/SerializableUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.wang.util.common;

import com.wang.exception.CustomException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;

Expand All @@ -11,6 +13,11 @@
*/
public class SerializableUtil {

/**
* LOGGER
*/
private static final Logger LOGGER = LoggerFactory.getLogger(SerializableUtil.class);

/**
* 序列化
* @param object
Expand All @@ -28,8 +35,8 @@ public static byte[] serializable(Object object) {
byte[] bytes = baos.toByteArray();
return bytes;
} catch (IOException e) {
e.printStackTrace();
throw new CustomException("SerializableUtil工具类序列化出现IOException异常");
LOGGER.error("SerializableUtil工具类序列化出现IOException异常:" + e.getMessage());
throw new CustomException("SerializableUtil工具类序列化出现IOException异常:" + e.getMessage());
} finally {
try {
if(oos != null) {
Expand All @@ -39,7 +46,8 @@ public static byte[] serializable(Object object) {
baos.close();
}
} catch (IOException e) {
e.printStackTrace();
LOGGER.error("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage());
throw new CustomException("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage());
}
}
}
Expand All @@ -59,11 +67,11 @@ public static Object unserializable(byte[] bytes) {
ois = new ObjectInputStream(bais);
return ois.readObject();
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw new CustomException("SerializableUtil工具类反序列化出现ClassNotFoundException异常");
LOGGER.error("SerializableUtil工具类反序列化出现ClassNotFoundException异常:" + e.getMessage());
throw new CustomException("SerializableUtil工具类反序列化出现ClassNotFoundException异常:" + e.getMessage());
} catch (IOException e) {
e.printStackTrace();
throw new CustomException("SerializableUtil工具类反序列化出现IOException异常");
LOGGER.error("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage());
throw new CustomException("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage());
} finally {
try {
if(ois != null) {
Expand All @@ -73,7 +81,8 @@ public static Object unserializable(byte[] bytes) {
bais.close();
}
} catch (IOException e) {
e.printStackTrace();
LOGGER.error("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage());
throw new CustomException("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage());
}
}
}
Expand Down

0 comments on commit e35e599

Please sign in to comment.