Authored by fangyeqing

ADD log and FIX some bug

.idea
*.iml
target/
\ No newline at end of file
target/
log/
\ No newline at end of file
... ...
package com.xkl.authorization.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created by win7 on 2017/1/14.
* 方法入参日志注解
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface LogAnnotation {
}
... ...
package com.xkl.authorization.aspect;
import lombok.extern.apachecommons.CommonsLog;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
/**
* Created by win7 on 2017/1/14.
*/
@Aspect
@Component
@CommonsLog
public class LogAspect {
/**
* 切面,定位到@ExecuteTimeAnnotation注解
*/
@Pointcut("@annotation(com.xkl.authorization.annotation.LogAnnotation)")
public void logPointCut() {
}
@Before("logPointCut()")
public void doBefore(JoinPoint joinPoint){
StringBuilder sb=new StringBuilder();
Signature signature=joinPoint.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Method method = methodSignature.getMethod();
Object[] args = joinPoint.getArgs();
sb.append("\n方法:\n").append(method.getDeclaringClass().getSimpleName())
.append("-").append(signature.getName()).append("\n").append("参数:\n");
boolean flag=true;
if(args!=null){
for(Object obj:args){
if(flag){
flag=false;
}else{
sb.append(",");
}
sb.append(obj.toString());
}
}
log.info(sb.toString());
}
}
... ...
... ... @@ -3,6 +3,7 @@ package com.xkl.controller;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xkl.authorization.annotation.Authorization;
import com.xkl.authorization.annotation.CurrentUser;
import com.xkl.authorization.annotation.LogAnnotation;
import com.xkl.authorization.annotation.Sign;
import com.xkl.authorization.manager.ITokenManager;
import com.xkl.authorization.model.TokenModel;
... ... @@ -43,6 +44,7 @@ public class OpenIdController {
@Autowired
private XklMemberOpenidRespository xklMemberOpenidRespository;
@LogAnnotation
@AntiXSS
@Sign
@RequestMapping(method = RequestMethod.POST)
... ... @@ -75,7 +77,7 @@ public class OpenIdController {
return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_BIND_SUCCESS), HttpStatus.OK);
}
@LogAnnotation
@AntiXSS
@Sign
@RequestMapping(method = RequestMethod.DELETE)
... ... @@ -103,6 +105,7 @@ public class OpenIdController {
return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_UNBIND_SUCESS), HttpStatus.OK);
}
@LogAnnotation
@AntiXSS
@Sign
@RequestMapping(value="/login",method = RequestMethod.POST)
... ...
... ... @@ -5,6 +5,7 @@ import com.wordnik.swagger.annotations.ApiImplicitParams;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xkl.authorization.annotation.Authorization;
import com.xkl.authorization.annotation.CurrentUser;
import com.xkl.authorization.annotation.LogAnnotation;
import com.xkl.authorization.annotation.Sign;
import com.xkl.config.Constants;
import com.xkl.config.ResultStatus;
... ... @@ -44,6 +45,7 @@ public class ReportController {
@Autowired
private IScoreService scoreService;
@LogAnnotation
@AntiXSS
@Authorization
@Sign
... ... @@ -62,6 +64,7 @@ public class ReportController {
return new ResponseEntity<>(ResultModel.ok(xklAmpReportEntity), HttpStatus.OK);
}
@LogAnnotation
@AntiXSS
@Authorization
@Sign
... ... @@ -111,6 +114,7 @@ public class ReportController {
return new ResponseEntity<>(ResultModel.ok(reportModel), HttpStatus.OK);
}
@LogAnnotation
@AntiXSS
@Sign
@RequestMapping(value="/score",method = RequestMethod.GET)
... ... @@ -133,6 +137,7 @@ public class ReportController {
return new ResponseEntity<>(ResultModel.ok(score), HttpStatus.OK);
}
@LogAnnotation
@AntiXSS
@Authorization
@Sign
... ... @@ -168,6 +173,7 @@ public class ReportController {
return new ResponseEntity<>(ResultModel.ok(result), HttpStatus.OK);
}
@LogAnnotation
@AntiXSS
@Authorization
@Sign
... ... @@ -203,7 +209,7 @@ public class ReportController {
return new ResponseEntity<>(ResultModel.ok(reportItemGraphModelList), HttpStatus.OK);
}
@LogAnnotation
@AntiXSS
@Authorization
@Sign
... ...
... ... @@ -5,6 +5,7 @@ import com.wordnik.swagger.annotations.ApiImplicitParams;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xkl.authorization.annotation.Authorization;
import com.xkl.authorization.annotation.CurrentUser;
import com.xkl.authorization.annotation.LogAnnotation;
import com.xkl.authorization.annotation.Sign;
import com.xkl.authorization.manager.ITokenManager;
import com.xkl.authorization.model.TokenModel;
... ... @@ -35,6 +36,7 @@ public class TokenController {
@Autowired
private ITokenManager tokenManager;
@LogAnnotation
@AntiXSS
@Sign
@RequestMapping(method = RequestMethod.POST)
... ... @@ -56,6 +58,7 @@ public class TokenController {
return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK);
}
@LogAnnotation
@AntiXSS
@Authorization
@Sign
... ...
... ... @@ -2,6 +2,7 @@ package com.xkl.controller;
import com.xkl.authorization.annotation.Authorization;
import com.xkl.authorization.annotation.CurrentUser;
import com.xkl.authorization.annotation.LogAnnotation;
import com.xkl.authorization.annotation.Sign;
import com.xkl.authorization.manager.ITokenManager;
import com.xkl.config.Constants;
... ... @@ -41,7 +42,7 @@ public class UserInfoController {
@Autowired
private XklMemberRespository xklMemberRespository;
@LogAnnotation
@AntiXSS
@Sign
@RequestMapping(method = RequestMethod.POST)
... ... @@ -77,6 +78,7 @@ public class UserInfoController {
return new ResponseEntity<>(ResultModel.ok(ResultStatus.USER_REGISTER), HttpStatus.OK);
}
@LogAnnotation
@AntiXSS
@Authorization
@Sign
... ... @@ -100,6 +102,7 @@ public class UserInfoController {
return new ResponseEntity<>(new ResultModel(ResultStatus.USER_MODPASS_LOGOUT), HttpStatus.OK);
}
@LogAnnotation
@AntiXSS
@Authorization
@Sign
... ...
... ... @@ -19,8 +19,7 @@ public class SecurityTool {
"v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
"V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8",
"9", "0", ".", "-", "*", "/", "'", ":", ";", ">", "<", "~", "!",
"@", "#", "$", "%", "^", "&", "(", ")", "{", "}", "[", "]", "|" };
"9", "0"};
/**
* SALT长度
... ...
... ... @@ -54,7 +54,7 @@ public class UtilTools {
}
/**
* 由String转为long型时间,10
* 由String转为long型时间,13
* @param timestamp
* @return
*/
... ... @@ -62,7 +62,7 @@ public class UtilTools {
long time = 0;
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
time = format.parse(timestamp).getTime()/1000;
time = format.parse(timestamp).getTime();
} catch (ParseException e) {
e.printStackTrace();
}
... ...
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- console中定义带颜色的日志 -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
<conversionRule conversionWord="wex"
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
<conversionRule conversionWord="wEx"
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="log"/>
<property name="APP_NAME" value="xklweb"/>
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- 日志输出编码 -->
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr([%thread]){magenta} %clr(---){faint} %clr(%logger{50}){cyan} -%msg%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}
</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/${APP_NAME}.log.%d{yyyy-MM-dd}</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} [%thread] --- %logger{50} -%msg%n
</pattern>
<charset>UTF-8</charset>
</encoder>
<!--日志文件最大的大小-->
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
</appender>
<!-- 日志输出级别 -->
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
</configuration>
\ No newline at end of file
... ...