ADD log and FIX some bug
Showing
10 changed files
with
138 additions
and
8 deletions
| 1 | +package com.xkl.authorization.annotation; | ||
| 2 | + | ||
| 3 | +import java.lang.annotation.ElementType; | ||
| 4 | +import java.lang.annotation.Retention; | ||
| 5 | +import java.lang.annotation.RetentionPolicy; | ||
| 6 | +import java.lang.annotation.Target; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Created by win7 on 2017/1/14. | ||
| 10 | + * 方法入参日志注解 | ||
| 11 | + */ | ||
| 12 | +@Retention(RetentionPolicy.RUNTIME) | ||
| 13 | +@Target(ElementType.METHOD) | ||
| 14 | +public @interface LogAnnotation { | ||
| 15 | +} |
| 1 | +package com.xkl.authorization.aspect; | ||
| 2 | + | ||
| 3 | +import lombok.extern.apachecommons.CommonsLog; | ||
| 4 | +import org.aspectj.lang.JoinPoint; | ||
| 5 | +import org.aspectj.lang.Signature; | ||
| 6 | +import org.aspectj.lang.annotation.Aspect; | ||
| 7 | +import org.aspectj.lang.annotation.Before; | ||
| 8 | +import org.aspectj.lang.annotation.Pointcut; | ||
| 9 | +import org.aspectj.lang.reflect.MethodSignature; | ||
| 10 | +import org.springframework.stereotype.Component; | ||
| 11 | + | ||
| 12 | +import java.lang.reflect.Method; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * Created by win7 on 2017/1/14. | ||
| 16 | + */ | ||
| 17 | +@Aspect | ||
| 18 | +@Component | ||
| 19 | +@CommonsLog | ||
| 20 | +public class LogAspect { | ||
| 21 | + /** | ||
| 22 | + * 切面,定位到@ExecuteTimeAnnotation注解 | ||
| 23 | + */ | ||
| 24 | + @Pointcut("@annotation(com.xkl.authorization.annotation.LogAnnotation)") | ||
| 25 | + public void logPointCut() { | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + @Before("logPointCut()") | ||
| 29 | + public void doBefore(JoinPoint joinPoint){ | ||
| 30 | + StringBuilder sb=new StringBuilder(); | ||
| 31 | + Signature signature=joinPoint.getSignature(); | ||
| 32 | + MethodSignature methodSignature = (MethodSignature) signature; | ||
| 33 | + Method method = methodSignature.getMethod(); | ||
| 34 | + Object[] args = joinPoint.getArgs(); | ||
| 35 | + sb.append("\n方法:\n").append(method.getDeclaringClass().getSimpleName()) | ||
| 36 | + .append("-").append(signature.getName()).append("\n").append("参数:\n"); | ||
| 37 | + boolean flag=true; | ||
| 38 | + if(args!=null){ | ||
| 39 | + for(Object obj:args){ | ||
| 40 | + if(flag){ | ||
| 41 | + flag=false; | ||
| 42 | + }else{ | ||
| 43 | + sb.append(","); | ||
| 44 | + } | ||
| 45 | + sb.append(obj.toString()); | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + log.info(sb.toString()); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | +} |
| @@ -3,6 +3,7 @@ package com.xkl.controller; | @@ -3,6 +3,7 @@ package com.xkl.controller; | ||
| 3 | import com.wordnik.swagger.annotations.ApiOperation; | 3 | import com.wordnik.swagger.annotations.ApiOperation; |
| 4 | import com.xkl.authorization.annotation.Authorization; | 4 | import com.xkl.authorization.annotation.Authorization; |
| 5 | import com.xkl.authorization.annotation.CurrentUser; | 5 | import com.xkl.authorization.annotation.CurrentUser; |
| 6 | +import com.xkl.authorization.annotation.LogAnnotation; | ||
| 6 | import com.xkl.authorization.annotation.Sign; | 7 | import com.xkl.authorization.annotation.Sign; |
| 7 | import com.xkl.authorization.manager.ITokenManager; | 8 | import com.xkl.authorization.manager.ITokenManager; |
| 8 | import com.xkl.authorization.model.TokenModel; | 9 | import com.xkl.authorization.model.TokenModel; |
| @@ -43,6 +44,7 @@ public class OpenIdController { | @@ -43,6 +44,7 @@ public class OpenIdController { | ||
| 43 | @Autowired | 44 | @Autowired |
| 44 | private XklMemberOpenidRespository xklMemberOpenidRespository; | 45 | private XklMemberOpenidRespository xklMemberOpenidRespository; |
| 45 | 46 | ||
| 47 | + @LogAnnotation | ||
| 46 | @AntiXSS | 48 | @AntiXSS |
| 47 | @Sign | 49 | @Sign |
| 48 | @RequestMapping(method = RequestMethod.POST) | 50 | @RequestMapping(method = RequestMethod.POST) |
| @@ -75,7 +77,7 @@ public class OpenIdController { | @@ -75,7 +77,7 @@ public class OpenIdController { | ||
| 75 | return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_BIND_SUCCESS), HttpStatus.OK); | 77 | return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_BIND_SUCCESS), HttpStatus.OK); |
| 76 | } | 78 | } |
| 77 | 79 | ||
| 78 | - | 80 | + @LogAnnotation |
| 79 | @AntiXSS | 81 | @AntiXSS |
| 80 | @Sign | 82 | @Sign |
| 81 | @RequestMapping(method = RequestMethod.DELETE) | 83 | @RequestMapping(method = RequestMethod.DELETE) |
| @@ -103,6 +105,7 @@ public class OpenIdController { | @@ -103,6 +105,7 @@ public class OpenIdController { | ||
| 103 | return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_UNBIND_SUCESS), HttpStatus.OK); | 105 | return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_UNBIND_SUCESS), HttpStatus.OK); |
| 104 | } | 106 | } |
| 105 | 107 | ||
| 108 | + @LogAnnotation | ||
| 106 | @AntiXSS | 109 | @AntiXSS |
| 107 | @Sign | 110 | @Sign |
| 108 | @RequestMapping(value="/login",method = RequestMethod.POST) | 111 | @RequestMapping(value="/login",method = RequestMethod.POST) |
| @@ -5,6 +5,7 @@ import com.wordnik.swagger.annotations.ApiImplicitParams; | @@ -5,6 +5,7 @@ import com.wordnik.swagger.annotations.ApiImplicitParams; | ||
| 5 | import com.wordnik.swagger.annotations.ApiOperation; | 5 | import com.wordnik.swagger.annotations.ApiOperation; |
| 6 | import com.xkl.authorization.annotation.Authorization; | 6 | import com.xkl.authorization.annotation.Authorization; |
| 7 | import com.xkl.authorization.annotation.CurrentUser; | 7 | import com.xkl.authorization.annotation.CurrentUser; |
| 8 | +import com.xkl.authorization.annotation.LogAnnotation; | ||
| 8 | import com.xkl.authorization.annotation.Sign; | 9 | import com.xkl.authorization.annotation.Sign; |
| 9 | import com.xkl.config.Constants; | 10 | import com.xkl.config.Constants; |
| 10 | import com.xkl.config.ResultStatus; | 11 | import com.xkl.config.ResultStatus; |
| @@ -44,6 +45,7 @@ public class ReportController { | @@ -44,6 +45,7 @@ public class ReportController { | ||
| 44 | @Autowired | 45 | @Autowired |
| 45 | private IScoreService scoreService; | 46 | private IScoreService scoreService; |
| 46 | 47 | ||
| 48 | + @LogAnnotation | ||
| 47 | @AntiXSS | 49 | @AntiXSS |
| 48 | @Authorization | 50 | @Authorization |
| 49 | @Sign | 51 | @Sign |
| @@ -62,6 +64,7 @@ public class ReportController { | @@ -62,6 +64,7 @@ public class ReportController { | ||
| 62 | return new ResponseEntity<>(ResultModel.ok(xklAmpReportEntity), HttpStatus.OK); | 64 | return new ResponseEntity<>(ResultModel.ok(xklAmpReportEntity), HttpStatus.OK); |
| 63 | } | 65 | } |
| 64 | 66 | ||
| 67 | + @LogAnnotation | ||
| 65 | @AntiXSS | 68 | @AntiXSS |
| 66 | @Authorization | 69 | @Authorization |
| 67 | @Sign | 70 | @Sign |
| @@ -111,6 +114,7 @@ public class ReportController { | @@ -111,6 +114,7 @@ public class ReportController { | ||
| 111 | return new ResponseEntity<>(ResultModel.ok(reportModel), HttpStatus.OK); | 114 | return new ResponseEntity<>(ResultModel.ok(reportModel), HttpStatus.OK); |
| 112 | } | 115 | } |
| 113 | 116 | ||
| 117 | + @LogAnnotation | ||
| 114 | @AntiXSS | 118 | @AntiXSS |
| 115 | @Sign | 119 | @Sign |
| 116 | @RequestMapping(value="/score",method = RequestMethod.GET) | 120 | @RequestMapping(value="/score",method = RequestMethod.GET) |
| @@ -133,6 +137,7 @@ public class ReportController { | @@ -133,6 +137,7 @@ public class ReportController { | ||
| 133 | return new ResponseEntity<>(ResultModel.ok(score), HttpStatus.OK); | 137 | return new ResponseEntity<>(ResultModel.ok(score), HttpStatus.OK); |
| 134 | } | 138 | } |
| 135 | 139 | ||
| 140 | + @LogAnnotation | ||
| 136 | @AntiXSS | 141 | @AntiXSS |
| 137 | @Authorization | 142 | @Authorization |
| 138 | @Sign | 143 | @Sign |
| @@ -168,6 +173,7 @@ public class ReportController { | @@ -168,6 +173,7 @@ public class ReportController { | ||
| 168 | return new ResponseEntity<>(ResultModel.ok(result), HttpStatus.OK); | 173 | return new ResponseEntity<>(ResultModel.ok(result), HttpStatus.OK); |
| 169 | } | 174 | } |
| 170 | 175 | ||
| 176 | + @LogAnnotation | ||
| 171 | @AntiXSS | 177 | @AntiXSS |
| 172 | @Authorization | 178 | @Authorization |
| 173 | @Sign | 179 | @Sign |
| @@ -203,7 +209,7 @@ public class ReportController { | @@ -203,7 +209,7 @@ public class ReportController { | ||
| 203 | return new ResponseEntity<>(ResultModel.ok(reportItemGraphModelList), HttpStatus.OK); | 209 | return new ResponseEntity<>(ResultModel.ok(reportItemGraphModelList), HttpStatus.OK); |
| 204 | } | 210 | } |
| 205 | 211 | ||
| 206 | - | 212 | + @LogAnnotation |
| 207 | @AntiXSS | 213 | @AntiXSS |
| 208 | @Authorization | 214 | @Authorization |
| 209 | @Sign | 215 | @Sign |
| @@ -5,6 +5,7 @@ import com.wordnik.swagger.annotations.ApiImplicitParams; | @@ -5,6 +5,7 @@ import com.wordnik.swagger.annotations.ApiImplicitParams; | ||
| 5 | import com.wordnik.swagger.annotations.ApiOperation; | 5 | import com.wordnik.swagger.annotations.ApiOperation; |
| 6 | import com.xkl.authorization.annotation.Authorization; | 6 | import com.xkl.authorization.annotation.Authorization; |
| 7 | import com.xkl.authorization.annotation.CurrentUser; | 7 | import com.xkl.authorization.annotation.CurrentUser; |
| 8 | +import com.xkl.authorization.annotation.LogAnnotation; | ||
| 8 | import com.xkl.authorization.annotation.Sign; | 9 | import com.xkl.authorization.annotation.Sign; |
| 9 | import com.xkl.authorization.manager.ITokenManager; | 10 | import com.xkl.authorization.manager.ITokenManager; |
| 10 | import com.xkl.authorization.model.TokenModel; | 11 | import com.xkl.authorization.model.TokenModel; |
| @@ -35,6 +36,7 @@ public class TokenController { | @@ -35,6 +36,7 @@ public class TokenController { | ||
| 35 | @Autowired | 36 | @Autowired |
| 36 | private ITokenManager tokenManager; | 37 | private ITokenManager tokenManager; |
| 37 | 38 | ||
| 39 | + @LogAnnotation | ||
| 38 | @AntiXSS | 40 | @AntiXSS |
| 39 | @Sign | 41 | @Sign |
| 40 | @RequestMapping(method = RequestMethod.POST) | 42 | @RequestMapping(method = RequestMethod.POST) |
| @@ -56,6 +58,7 @@ public class TokenController { | @@ -56,6 +58,7 @@ public class TokenController { | ||
| 56 | return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK); | 58 | return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK); |
| 57 | } | 59 | } |
| 58 | 60 | ||
| 61 | + @LogAnnotation | ||
| 59 | @AntiXSS | 62 | @AntiXSS |
| 60 | @Authorization | 63 | @Authorization |
| 61 | @Sign | 64 | @Sign |
| @@ -2,6 +2,7 @@ package com.xkl.controller; | @@ -2,6 +2,7 @@ package com.xkl.controller; | ||
| 2 | 2 | ||
| 3 | import com.xkl.authorization.annotation.Authorization; | 3 | import com.xkl.authorization.annotation.Authorization; |
| 4 | import com.xkl.authorization.annotation.CurrentUser; | 4 | import com.xkl.authorization.annotation.CurrentUser; |
| 5 | +import com.xkl.authorization.annotation.LogAnnotation; | ||
| 5 | import com.xkl.authorization.annotation.Sign; | 6 | import com.xkl.authorization.annotation.Sign; |
| 6 | import com.xkl.authorization.manager.ITokenManager; | 7 | import com.xkl.authorization.manager.ITokenManager; |
| 7 | import com.xkl.config.Constants; | 8 | import com.xkl.config.Constants; |
| @@ -41,7 +42,7 @@ public class UserInfoController { | @@ -41,7 +42,7 @@ public class UserInfoController { | ||
| 41 | @Autowired | 42 | @Autowired |
| 42 | private XklMemberRespository xklMemberRespository; | 43 | private XklMemberRespository xklMemberRespository; |
| 43 | 44 | ||
| 44 | - | 45 | + @LogAnnotation |
| 45 | @AntiXSS | 46 | @AntiXSS |
| 46 | @Sign | 47 | @Sign |
| 47 | @RequestMapping(method = RequestMethod.POST) | 48 | @RequestMapping(method = RequestMethod.POST) |
| @@ -77,6 +78,7 @@ public class UserInfoController { | @@ -77,6 +78,7 @@ public class UserInfoController { | ||
| 77 | return new ResponseEntity<>(ResultModel.ok(ResultStatus.USER_REGISTER), HttpStatus.OK); | 78 | return new ResponseEntity<>(ResultModel.ok(ResultStatus.USER_REGISTER), HttpStatus.OK); |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 81 | + @LogAnnotation | ||
| 80 | @AntiXSS | 82 | @AntiXSS |
| 81 | @Authorization | 83 | @Authorization |
| 82 | @Sign | 84 | @Sign |
| @@ -100,6 +102,7 @@ public class UserInfoController { | @@ -100,6 +102,7 @@ public class UserInfoController { | ||
| 100 | return new ResponseEntity<>(new ResultModel(ResultStatus.USER_MODPASS_LOGOUT), HttpStatus.OK); | 102 | return new ResponseEntity<>(new ResultModel(ResultStatus.USER_MODPASS_LOGOUT), HttpStatus.OK); |
| 101 | } | 103 | } |
| 102 | 104 | ||
| 105 | + @LogAnnotation | ||
| 103 | @AntiXSS | 106 | @AntiXSS |
| 104 | @Authorization | 107 | @Authorization |
| 105 | @Sign | 108 | @Sign |
| @@ -19,8 +19,7 @@ public class SecurityTool { | @@ -19,8 +19,7 @@ public class SecurityTool { | ||
| 19 | "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", | 19 | "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", |
| 20 | "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", | 20 | "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", |
| 21 | "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", | 21 | "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", |
| 22 | - "9", "0", ".", "-", "*", "/", "'", ":", ";", ">", "<", "~", "!", | ||
| 23 | - "@", "#", "$", "%", "^", "&", "(", ")", "{", "}", "[", "]", "|" }; | 22 | + "9", "0"}; |
| 24 | 23 | ||
| 25 | /** | 24 | /** |
| 26 | * SALT长度 | 25 | * SALT长度 |
| @@ -54,7 +54,7 @@ public class UtilTools { | @@ -54,7 +54,7 @@ public class UtilTools { | ||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | /** | 56 | /** |
| 57 | - * 由String转为long型时间,10位 | 57 | + * 由String转为long型时间,13位 |
| 58 | * @param timestamp | 58 | * @param timestamp |
| 59 | * @return | 59 | * @return |
| 60 | */ | 60 | */ |
| @@ -62,7 +62,7 @@ public class UtilTools { | @@ -62,7 +62,7 @@ public class UtilTools { | ||
| 62 | long time = 0; | 62 | long time = 0; |
| 63 | try { | 63 | try { |
| 64 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); | 64 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); |
| 65 | - time = format.parse(timestamp).getTime()/1000; | 65 | + time = format.parse(timestamp).getTime(); |
| 66 | } catch (ParseException e) { | 66 | } catch (ParseException e) { |
| 67 | e.printStackTrace(); | 67 | e.printStackTrace(); |
| 68 | } | 68 | } |
src/main/resources/logback-spring.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<configuration> | ||
| 3 | + | ||
| 4 | + <!-- console中定义带颜色的日志 --> | ||
| 5 | + <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/> | ||
| 6 | + <conversionRule conversionWord="wex" | ||
| 7 | + converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/> | ||
| 8 | + <conversionRule conversionWord="wEx" | ||
| 9 | + converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/> | ||
| 10 | + | ||
| 11 | + <!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径--> | ||
| 12 | + <property name="LOG_HOME" value="log"/> | ||
| 13 | + <property name="APP_NAME" value="xklweb"/> | ||
| 14 | + | ||
| 15 | + <!-- 控制台输出 --> | ||
| 16 | + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
| 17 | + <!-- 日志输出编码 --> | ||
| 18 | + <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> | ||
| 19 | + <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} | ||
| 20 | + </pattern> | ||
| 21 | + <charset>UTF-8</charset> | ||
| 22 | + </encoder> | ||
| 23 | + </appender> | ||
| 24 | + | ||
| 25 | + <!-- 按照每天生成日志文件 --> | ||
| 26 | + <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
| 27 | + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
| 28 | + <!--日志文件输出的文件名--> | ||
| 29 | + <FileNamePattern>${LOG_HOME}/${APP_NAME}.log.%d{yyyy-MM-dd}</FileNamePattern> | ||
| 30 | + <MaxHistory>30</MaxHistory> | ||
| 31 | + </rollingPolicy> | ||
| 32 | + <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> | ||
| 33 | + <!--格式化输出:%d表示日期,%thread表示线程名,%msg:日志消息,%n是换行符--> | ||
| 34 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} [%thread] --- %logger{50} -%msg%n | ||
| 35 | + </pattern> | ||
| 36 | + <charset>UTF-8</charset> | ||
| 37 | + </encoder> | ||
| 38 | + <!--日志文件最大的大小--> | ||
| 39 | + <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> | ||
| 40 | + <MaxFileSize>10MB</MaxFileSize> | ||
| 41 | + </triggeringPolicy> | ||
| 42 | + </appender> | ||
| 43 | + | ||
| 44 | + <!-- 日志输出级别 --> | ||
| 45 | + <root level="INFO"> | ||
| 46 | + <appender-ref ref="STDOUT"/> | ||
| 47 | + <appender-ref ref="FILE"/> | ||
| 48 | + </root> | ||
| 49 | +</configuration> |
-
Please register or login to post a comment