Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loginservice
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lanmw
loginservice
Commits
3dfd935e
Commit
3dfd935e
authored
Oct 23, 2026
by
xieshaohua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add loginout log
parent
2b274570
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
14 deletions
+27
-14
RESTLogoutSuccessHandler.java
...java/com/keymobile/sso/conf/RESTLogoutSuccessHandler.java
+9
-7
LogManager.java
src/main/java/com/keymobile/sso/logging/LogManager.java
+18
-7
No files found.
src/main/java/com/keymobile/sso/conf/RESTLogoutSuccessHandler.java
View file @
3dfd935e
package
com
.
keymobile
.
sso
.
conf
;
package
com
.
keymobile
.
sso
.
conf
;
import
com.keymobile.sso.logging.LogConstants
;
import
com.keymobile.sso.logging.LogManager
;
import
com.keymobile.sso.logging.LogManager
;
import
jakarta.servlet.ServletException
;
import
jakarta.servlet.ServletException
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
jakarta.servlet.http.HttpServletResponse
;
import
jakarta.servlet.http.HttpSession
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.web.authentication.logout.LogoutSuccessHandler
;
import
org.springframework.security.web.authentication.logout.LogoutSuccessHandler
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -17,13 +16,17 @@ import java.io.IOException;
...
@@ -17,13 +16,17 @@ import java.io.IOException;
public
class
RESTLogoutSuccessHandler
implements
LogoutSuccessHandler
{
public
class
RESTLogoutSuccessHandler
implements
LogoutSuccessHandler
{
@Override
@Override
public
void
onLogoutSuccess
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Authentication
authentication
)
throws
IOException
,
ServletException
{
public
void
onLogoutSuccess
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Authentication
authentication
)
throws
IOException
,
ServletException
{
HttpSession
session
=
request
.
getSession
(
false
);
if
(
authentication
!=
null
&&
authentication
.
getName
()
!=
null
)
{
if
(
authentication
!=
null
&&
authentication
.
getName
()
!=
null
)
{
LogManager
.
logInfo
(
LogConstants
.
CTX_AUDIT
,
"User logged out: "
+
authentication
.
getName
());
LogManager
.
logLogout
(
authentication
.
getName
(),
session
);
}
if
(
session
!=
null
)
{
session
.
invalidate
();
}
}
request
.
getSession
().
invalidate
();
response
.
setStatus
(
HttpStatus
.
OK
.
value
());
response
.
setStatus
(
HttpStatus
.
OK
.
value
());
response
.
getWriter
().
flush
();
response
.
getWriter
().
flush
();
}
}
}
}
\ No newline at end of file
src/main/java/com/keymobile/sso/logging/LogManager.java
View file @
3dfd935e
...
@@ -55,16 +55,15 @@ public class LogManager {
...
@@ -55,16 +55,15 @@ public class LogManager {
}
}
public
static
void
logLogin
(
String
userNameWithIdAttached
,
HttpSession
session
)
{
public
static
void
logLogin
(
String
userNameWithIdAttached
,
HttpSession
session
)
{
String
[]
parts
=
userNameWithIdAttached
.
split
(
":"
);
putUserSessionMdc
(
userNameWithIdAttached
,
session
);
String
userName
=
parts
[
0
];
String
userDName
=
parts
.
length
>
2
?
parts
[
2
]
:
""
;
if
(
session
!=
null
)
{
MDC
.
put
(
"user"
,
getLogUserInfo
(
userName
,
userDName
));
MDC
.
put
(
"session"
,
session
.
getId
());
}
logInfo
(
LogConstants
.
SSO_API
,
"登录"
);
logInfo
(
LogConstants
.
SSO_API
,
"登录"
);
}
}
public
static
void
logLogout
(
String
userNameWithIdAttached
,
HttpSession
session
)
{
putUserSessionMdc
(
userNameWithIdAttached
,
session
);
logInfo
(
LogConstants
.
SSO_API
,
"登出"
);
}
public
static
String
getLogUserInfo
(
String
userName
,
String
userDName
)
{
public
static
String
getLogUserInfo
(
String
userName
,
String
userDName
)
{
if
(
userDName
==
null
||
userDName
.
isEmpty
())
{
if
(
userDName
==
null
||
userDName
.
isEmpty
())
{
return
userName
;
return
userName
;
...
@@ -72,5 +71,17 @@ public class LogManager {
...
@@ -72,5 +71,17 @@ public class LogManager {
return
userName
+
"("
+
userDName
+
")"
;
return
userName
+
"("
+
userDName
+
")"
;
}
}
private
static
void
putUserSessionMdc
(
String
userNameWithIdAttached
,
HttpSession
session
)
{
if
(
userNameWithIdAttached
==
null
)
{
return
;
}
String
[]
parts
=
userNameWithIdAttached
.
split
(
":"
);
String
userName
=
parts
[
0
];
String
userDName
=
parts
.
length
>
2
?
parts
[
2
]
:
""
;
if
(
session
!=
null
)
{
MDC
.
put
(
"user"
,
getLogUserInfo
(
userName
,
userDName
));
MDC
.
put
(
"session"
,
session
.
getId
());
}
}
}
}
Write
Preview
Markdown
is supported
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