commit
94edd95824
|
@ -78,6 +78,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
// 构建UsernamePasswordAuthenticationToken,这里密码为null,是因为提供了正确的JWT,实现自动登录
|
// 构建UsernamePasswordAuthenticationToken,这里密码为null,是因为提供了正确的JWT,实现自动登录
|
||||||
User user = new User();
|
User user = new User();
|
||||||
|
user.setId(jwtUser.getUserId());
|
||||||
user.setUsername(jwtUser.getUserName());
|
user.setUsername(jwtUser.getUserName());
|
||||||
user.setPassword(jwtUser.getPassword());
|
user.setPassword(jwtUser.getPassword());
|
||||||
Role role = new Role();
|
Role role = new Role();
|
||||||
|
|
|
@ -144,6 +144,7 @@ public class JwtUtils implements InitializingBean {
|
||||||
jwtUser.setUserName(username);
|
jwtUser.setUserName(username);
|
||||||
jwtUser.setPassword(user.getPassword());
|
jwtUser.setPassword(user.getPassword());
|
||||||
jwtUser.setRoleId(user.getRole().getId());
|
jwtUser.setRoleId(user.getRole().getId());
|
||||||
|
jwtUser.setUserId(user.getId());
|
||||||
|
|
||||||
return jwtUser;
|
return jwtUser;
|
||||||
} catch (InvalidJwtException e) {
|
} catch (InvalidJwtException e) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class JwtUser {
|
||||||
EXCEPTION
|
EXCEPTION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int userId;
|
||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
private String password;
|
private String password;
|
||||||
|
@ -29,6 +30,14 @@ public class JwtUser {
|
||||||
|
|
||||||
private TokenStatus status;
|
private TokenStatus status;
|
||||||
|
|
||||||
|
public int getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(int userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUserName() {
|
public String getUserName() {
|
||||||
return userName;
|
return userName;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.genersoft.iot.vmp.gb28181.conf;
|
package com.genersoft.iot.vmp.gb28181.conf;
|
||||||
|
|
||||||
import gov.nist.core.StackLogger;
|
import gov.nist.core.StackLogger;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.slf4j.spi.LocationAwareLogger;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -10,7 +10,39 @@ import java.util.Properties;
|
||||||
@Component
|
@Component
|
||||||
public class StackLoggerImpl implements StackLogger {
|
public class StackLoggerImpl implements StackLogger {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(StackLoggerImpl.class);
|
/**
|
||||||
|
* 完全限定类名(Fully Qualified Class Name),用于定位日志位置
|
||||||
|
*/
|
||||||
|
private static final String FQCN = StackLoggerImpl.class.getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取栈中类信息(以便底层日志记录系统能够提取正确的位置信息(方法名、行号))
|
||||||
|
* @return LocationAwareLogger
|
||||||
|
*/
|
||||||
|
private static LocationAwareLogger getLocationAwareLogger() {
|
||||||
|
return (LocationAwareLogger) LoggerFactory.getLogger(new Throwable().getStackTrace()[4].getClassName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 封装打印日志的位置信息
|
||||||
|
* @param level 日志级别
|
||||||
|
* @param message 日志事件的消息
|
||||||
|
*/
|
||||||
|
private static void log(int level, String message) {
|
||||||
|
LocationAwareLogger locationAwareLogger = getLocationAwareLogger();
|
||||||
|
locationAwareLogger.log(null, FQCN, level, message, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 封装打印日志的位置信息
|
||||||
|
* @param level 日志级别
|
||||||
|
* @param message 日志事件的消息
|
||||||
|
*/
|
||||||
|
private static void log(int level, String message, Throwable throwable) {
|
||||||
|
LocationAwareLogger locationAwareLogger = getLocationAwareLogger();
|
||||||
|
locationAwareLogger.log(null, FQCN, level, message, null, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logStackTrace() {
|
public void logStackTrace() {
|
||||||
|
@ -34,27 +66,27 @@ public class StackLoggerImpl implements StackLogger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logDebug(String message) {
|
public void logDebug(String message) {
|
||||||
// logger.debug(message);
|
log(LocationAwareLogger.INFO_INT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logDebug(String message, Exception ex) {
|
public void logDebug(String message, Exception ex) {
|
||||||
// logger.debug(message);
|
log(LocationAwareLogger.INFO_INT, message, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logTrace(String message) {
|
public void logTrace(String message) {
|
||||||
logger.trace(message);
|
log(LocationAwareLogger.INFO_INT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logFatalError(String message) {
|
public void logFatalError(String message) {
|
||||||
// logger.error(message);
|
log(LocationAwareLogger.INFO_INT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logError(String message) {
|
public void logError(String message) {
|
||||||
// logger.error(message);
|
log(LocationAwareLogger.INFO_INT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,17 +101,17 @@ public class StackLoggerImpl implements StackLogger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logError(String message, Exception ex) {
|
public void logError(String message, Exception ex) {
|
||||||
// logger.error(message);
|
log(LocationAwareLogger.INFO_INT, message, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logWarning(String message) {
|
public void logWarning(String message) {
|
||||||
logger.warn(message);
|
log(LocationAwareLogger.INFO_INT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logInfo(String message) {
|
public void logInfo(String message) {
|
||||||
logger.info(message);
|
log(LocationAwareLogger.INFO_INT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
|
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
|
||||||
<property name="LOG_HOME" value="logs" />
|
<property name="LOG_HOME" value="logs" />
|
||||||
|
|
||||||
<substitutionProperty name="log.pattern" value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(---){faint} %clr(%-1.30logger{0}){cyan} %clr(:){faint} %m%n%wEx"/>
|
<substitutionProperty name="log.pattern"
|
||||||
|
value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr([%thread]) %clr(%5p) %clr(---){faint} %clr(%logger{50}){cyan} %clr(:) %clr(%L){faint} %m%n%wEx"/>
|
||||||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
|
<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.WhitespaceThrowableProxyConverter"/>
|
||||||
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
|
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
|
||||||
|
|
Loading…
Reference in New Issue