Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
e245296c
"vscode:/vscode.git/clone" did not exist on "3ad69e9a299ea4ffed86929b347eadacc464dca8"
Commit
e245296c
authored
Oct 26, 2019
by
dqjdda
Browse files
日志加入浏览器字段
parent
0c738b1e
Changes
14
Show whitespace changes
Inline
Side-by-side
eladmin-common/pom.xml
View file @
e245296c
...
@@ -11,5 +11,4 @@
...
@@ -11,5 +11,4 @@
<artifactId>
eladmin-common
</artifactId>
<artifactId>
eladmin-common
</artifactId>
<name>
公共模块
</name>
<name>
公共模块
</name>
</project>
</project>
\ No newline at end of file
eladmin-common/src/main/java/me/zhengjie/utils/StringUtils.java
View file @
e245296c
package
me.zhengjie.utils
;
package
me.zhengjie.utils
;
import
cn.hutool.core.io.resource.ClassPathResource
;
import
cn.hutool.core.io.resource.ClassPathResource
;
import
eu.bitwalker.useragentutils.Browser
;
import
eu.bitwalker.useragentutils.UserAgent
;
import
org.lionsoul.ip2region.DataBlock
;
import
org.lionsoul.ip2region.DataBlock
;
import
org.lionsoul.ip2region.DbConfig
;
import
org.lionsoul.ip2region.DbConfig
;
import
org.lionsoul.ip2region.DbSearcher
;
import
org.lionsoul.ip2region.DbSearcher
;
...
@@ -157,6 +159,12 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
...
@@ -157,6 +159,12 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
return
""
;
return
""
;
}
}
public
static
String
getBrowser
(
HttpServletRequest
request
){
UserAgent
userAgent
=
UserAgent
.
parseUserAgentString
(
request
.
getHeader
(
"User-Agent"
));
Browser
browser
=
userAgent
.
getBrowser
();
return
browser
.
getName
();
}
/**
/**
* 获得当天是周几
* 获得当天是周几
*/
*/
...
...
eladmin-logging/src/main/java/me/zhengjie/aspect/LogAspect.java
View file @
e245296c
...
@@ -15,6 +15,8 @@ import org.aspectj.lang.annotation.Aspect;
...
@@ -15,6 +15,8 @@ import org.aspectj.lang.annotation.Aspect;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.http.HttpServletRequest
;
/**
/**
* @author Zheng Jie
* @author Zheng Jie
* @date 2018-11-24
* @date 2018-11-24
...
@@ -51,7 +53,8 @@ public class LogAspect {
...
@@ -51,7 +53,8 @@ public class LogAspect {
currentTime
=
System
.
currentTimeMillis
();
currentTime
=
System
.
currentTimeMillis
();
result
=
joinPoint
.
proceed
();
result
=
joinPoint
.
proceed
();
Log
log
=
new
Log
(
"INFO"
,
System
.
currentTimeMillis
()
-
currentTime
);
Log
log
=
new
Log
(
"INFO"
,
System
.
currentTimeMillis
()
-
currentTime
);
logService
.
save
(
getUsername
(),
StringUtils
.
getIp
(
RequestHolder
.
getHttpServletRequest
()),
joinPoint
,
log
);
HttpServletRequest
request
=
RequestHolder
.
getHttpServletRequest
();
logService
.
save
(
getUsername
(),
StringUtils
.
getBrowser
(
request
),
StringUtils
.
getIp
(
request
),
joinPoint
,
log
);
return
result
;
return
result
;
}
}
...
@@ -65,7 +68,8 @@ public class LogAspect {
...
@@ -65,7 +68,8 @@ public class LogAspect {
public
void
logAfterThrowing
(
JoinPoint
joinPoint
,
Throwable
e
)
{
public
void
logAfterThrowing
(
JoinPoint
joinPoint
,
Throwable
e
)
{
Log
log
=
new
Log
(
"ERROR"
,
System
.
currentTimeMillis
()
-
currentTime
);
Log
log
=
new
Log
(
"ERROR"
,
System
.
currentTimeMillis
()
-
currentTime
);
log
.
setExceptionDetail
(
ThrowableUtil
.
getStackTrace
(
e
).
getBytes
());
log
.
setExceptionDetail
(
ThrowableUtil
.
getStackTrace
(
e
).
getBytes
());
logService
.
save
(
getUsername
(),
StringUtils
.
getIp
(
RequestHolder
.
getHttpServletRequest
()),
(
ProceedingJoinPoint
)
joinPoint
,
log
);
HttpServletRequest
request
=
RequestHolder
.
getHttpServletRequest
();
logService
.
save
(
getUsername
(),
StringUtils
.
getBrowser
(
request
),
StringUtils
.
getIp
(
request
),
(
ProceedingJoinPoint
)
joinPoint
,
log
);
}
}
public
String
getUsername
()
{
public
String
getUsername
()
{
...
...
eladmin-logging/src/main/java/me/zhengjie/domain/Log.java
View file @
e245296c
...
@@ -45,6 +45,8 @@ public class Log implements Serializable {
...
@@ -45,6 +45,8 @@ public class Log implements Serializable {
@Column
(
name
=
"address"
)
@Column
(
name
=
"address"
)
private
String
address
;
private
String
address
;
private
String
browser
;
// 请求耗时
// 请求耗时
private
Long
time
;
private
Long
time
;
...
...
eladmin-logging/src/main/java/me/zhengjie/service/LogService.java
View file @
e245296c
...
@@ -17,7 +17,7 @@ public interface LogService {
...
@@ -17,7 +17,7 @@ public interface LogService {
Object
queryAllByUser
(
LogQueryCriteria
criteria
,
Pageable
pageable
);
Object
queryAllByUser
(
LogQueryCriteria
criteria
,
Pageable
pageable
);
@Async
@Async
void
save
(
String
username
,
String
ip
,
ProceedingJoinPoint
joinPoint
,
Log
log
);
void
save
(
String
username
,
String
browser
,
String
ip
,
ProceedingJoinPoint
joinPoint
,
Log
log
);
/**
/**
* 查询异常详情
* 查询异常详情
...
...
eladmin-logging/src/main/java/me/zhengjie/service/dto/LogErrorDTO.java
View file @
e245296c
...
@@ -25,6 +25,8 @@ public class LogErrorDTO implements Serializable {
...
@@ -25,6 +25,8 @@ public class LogErrorDTO implements Serializable {
// 参数
// 参数
private
String
params
;
private
String
params
;
private
String
browser
;
// 请求ip
// 请求ip
private
String
requestIp
;
private
String
requestIp
;
...
...
eladmin-logging/src/main/java/me/zhengjie/service/dto/LogSmallDTO.java
View file @
e245296c
...
@@ -22,6 +22,8 @@ public class LogSmallDTO implements Serializable {
...
@@ -22,6 +22,8 @@ public class LogSmallDTO implements Serializable {
private
String
address
;
private
String
address
;
private
String
browser
;
// 创建日期
// 创建日期
private
Timestamp
createTime
;
private
Timestamp
createTime
;
}
}
eladmin-logging/src/main/java/me/zhengjie/service/impl/LogServiceImpl.java
View file @
e245296c
...
@@ -57,7 +57,7 @@ public class LogServiceImpl implements LogService {
...
@@ -57,7 +57,7 @@ public class LogServiceImpl implements LogService {
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
save
(
String
username
,
String
ip
,
ProceedingJoinPoint
joinPoint
,
Log
log
){
public
void
save
(
String
username
,
String
browser
,
String
ip
,
ProceedingJoinPoint
joinPoint
,
Log
log
){
MethodSignature
signature
=
(
MethodSignature
)
joinPoint
.
getSignature
();
MethodSignature
signature
=
(
MethodSignature
)
joinPoint
.
getSignature
();
Method
method
=
signature
.
getMethod
();
Method
method
=
signature
.
getMethod
();
...
@@ -96,6 +96,7 @@ public class LogServiceImpl implements LogService {
...
@@ -96,6 +96,7 @@ public class LogServiceImpl implements LogService {
log
.
setMethod
(
methodName
);
log
.
setMethod
(
methodName
);
log
.
setUsername
(
username
);
log
.
setUsername
(
username
);
log
.
setParams
(
params
.
toString
()
+
" }"
);
log
.
setParams
(
params
.
toString
()
+
" }"
);
log
.
setBrowser
(
browser
);
logRepository
.
save
(
log
);
logRepository
.
save
(
log
);
}
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/monitor/domain/vo/OnlineUser.java
0 → 100644
View file @
e245296c
package
me.zhengjie.modules.monitor.domain.vo
;
import
lombok.Data
;
import
java.sql.Timestamp
;
import
java.util.Date
;
/**
* @author Zheng Jie
*/
@Data
public
class
OnlineUser
{
private
String
userName
;
private
String
browser
;
private
String
ip
;
private
String
address
;
private
Date
createTime
;
private
Date
lastAccessTime
;
}
eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthenticationController.java
View file @
e245296c
...
@@ -8,8 +8,8 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -8,8 +8,8 @@ import lombok.extern.slf4j.Slf4j;
import
me.zhengjie.aop.log.Log
;
import
me.zhengjie.aop.log.Log
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.modules.monitor.service.RedisService
;
import
me.zhengjie.modules.monitor.service.RedisService
;
import
me.zhengjie.modules.security.security.Auth
entication
Info
;
import
me.zhengjie.modules.security.security.AuthInfo
;
import
me.zhengjie.modules.security.security.Auth
orization
User
;
import
me.zhengjie.modules.security.security.AuthUser
;
import
me.zhengjie.modules.security.security.ImgResult
;
import
me.zhengjie.modules.security.security.ImgResult
;
import
me.zhengjie.modules.security.security.JwtUser
;
import
me.zhengjie.modules.security.security.JwtUser
;
import
me.zhengjie.utils.EncryptUtils
;
import
me.zhengjie.utils.EncryptUtils
;
...
@@ -53,7 +53,7 @@ public class AuthenticationController {
...
@@ -53,7 +53,7 @@ public class AuthenticationController {
@Log
(
"用户登录"
)
@Log
(
"用户登录"
)
@ApiOperation
(
"登录授权"
)
@ApiOperation
(
"登录授权"
)
@PostMapping
(
value
=
"/login"
)
@PostMapping
(
value
=
"/login"
)
public
ResponseEntity
login
(
@Validated
@RequestBody
Auth
orization
User
authorizationUser
){
public
ResponseEntity
login
(
@Validated
@RequestBody
AuthUser
authorizationUser
){
// 查询验证码
// 查询验证码
String
code
=
redisService
.
getCodeVal
(
authorizationUser
.
getUuid
());
String
code
=
redisService
.
getCodeVal
(
authorizationUser
.
getUuid
());
...
@@ -79,7 +79,7 @@ public class AuthenticationController {
...
@@ -79,7 +79,7 @@ public class AuthenticationController {
final
String
token
=
jwtTokenUtil
.
generateToken
(
jwtUser
);
final
String
token
=
jwtTokenUtil
.
generateToken
(
jwtUser
);
// 返回 token
// 返回 token
return
ResponseEntity
.
ok
(
new
Auth
entication
Info
(
token
,
jwtUser
));
return
ResponseEntity
.
ok
(
new
AuthInfo
(
token
,
jwtUser
));
}
}
@ApiOperation
(
"获取用户信息"
)
@ApiOperation
(
"获取用户信息"
)
...
...
eladmin-system/src/main/java/me/zhengjie/modules/security/security/Auth
entication
Info.java
→
eladmin-system/src/main/java/me/zhengjie/modules/security/security/AuthInfo.java
View file @
e245296c
...
@@ -11,7 +11,7 @@ import java.io.Serializable;
...
@@ -11,7 +11,7 @@ import java.io.Serializable;
*/
*/
@Getter
@Getter
@AllArgsConstructor
@AllArgsConstructor
public
class
Auth
entication
Info
implements
Serializable
{
public
class
AuthInfo
implements
Serializable
{
private
final
String
token
;
private
final
String
token
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/security/security/Auth
orization
User.java
→
eladmin-system/src/main/java/me/zhengjie/modules/security/security/AuthUser.java
View file @
e245296c
...
@@ -11,7 +11,7 @@ import javax.validation.constraints.NotBlank;
...
@@ -11,7 +11,7 @@ import javax.validation.constraints.NotBlank;
*/
*/
@Getter
@Getter
@Setter
@Setter
public
class
Auth
orization
User
{
public
class
AuthUser
{
@NotBlank
@NotBlank
private
String
username
;
private
String
username
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/security/security/JwtAuthorizationTokenFilter.java
View file @
e245296c
...
@@ -7,7 +7,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
...
@@ -7,7 +7,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.web.authentication.WebAuthenticationDetailsSource
;
import
org.springframework.security.web.authentication.WebAuthenticationDetailsSource
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
...
pom.xml
View file @
e245296c
...
@@ -200,6 +200,11 @@
...
@@ -200,6 +200,11 @@
<artifactId>
easy-captcha
</artifactId>
<artifactId>
easy-captcha
</artifactId>
<version>
1.6.2
</version>
<version>
1.6.2
</version>
</dependency>
</dependency>
<dependency>
<groupId>
eu.bitwalker
</groupId>
<artifactId>
UserAgentUtils
</artifactId>
<version>
1.20
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment