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
2cd22759
Commit
2cd22759
authored
Jul 02, 2019
by
linxu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
处理sessionInfo异常
parent
2de960ef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
14 deletions
+23
-14
LoginManagement.java
src/main/java/com/keymobile/proxy/api/LoginManagement.java
+23
-14
No files found.
src/main/java/com/keymobile/proxy/api/LoginManagement.java
View file @
2cd22759
package
com
.
keymobile
.
proxy
.
api
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -17,22 +19,29 @@ import java.util.Map;
@RequestMapping
(
value
=
"/"
)
public
class
LoginManagement
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
LoginManagement
.
class
);
@RequestMapping
(
value
=
"/sessionInfo"
,
method
=
RequestMethod
.
POST
)
public
@ResponseBody
Map
<
String
,
Object
>
verifyLogin
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
UserDetails
userDetails
=
(
UserDetails
)
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
Map
<
String
,
Object
>
rs
=
new
HashMap
<>();
String
userNameWithIdAttached
=
userDetails
.
getUsername
();
rs
.
put
(
Constants
.
Session_UserName
,
userNameWithIdAttached
.
split
(
":"
)[
0
]);
rs
.
put
(
Constants
.
Session_UserId
,
userNameWithIdAttached
.
split
(
":"
)[
1
]);
rs
.
put
(
Constants
.
Session_UserDName
,
userNameWithIdAttached
.
split
(
":"
)[
2
]);
List
<
String
>
roles
=
new
ArrayList
<>();
userDetails
.
getAuthorities
().
forEach
(
auth
->
roles
.
add
(
auth
.
getAuthority
()));
rs
.
put
(
Constants
.
Session_Roles
,
roles
);
HttpSession
session
=
request
.
getSession
();
Object
lang
=
session
.
getAttribute
(
Constants
.
Session_Lang
);
rs
.
put
(
Constants
.
Session_Lang
,
lang
!=
null
?
lang
.
toString
()
:
"cn"
);
return
rs
;
try
{
UserDetails
userDetails
=
(
UserDetails
)
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
Map
<
String
,
Object
>
rs
=
new
HashMap
<>();
String
userNameWithIdAttached
=
userDetails
.
getUsername
();
rs
.
put
(
Constants
.
Session_UserName
,
userNameWithIdAttached
.
split
(
":"
)[
0
]);
rs
.
put
(
Constants
.
Session_UserId
,
userNameWithIdAttached
.
split
(
":"
)[
1
]);
rs
.
put
(
Constants
.
Session_UserDName
,
userNameWithIdAttached
.
split
(
":"
)[
2
]);
List
<
String
>
roles
=
new
ArrayList
<>();
userDetails
.
getAuthorities
().
forEach
(
auth
->
roles
.
add
(
auth
.
getAuthority
()));
rs
.
put
(
Constants
.
Session_Roles
,
roles
);
HttpSession
session
=
request
.
getSession
();
Object
lang
=
session
.
getAttribute
(
Constants
.
Session_Lang
);
rs
.
put
(
Constants
.
Session_Lang
,
lang
!=
null
?
lang
.
toString
()
:
"cn"
);
return
rs
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"Errors occur when getting session."
,
e
);
return
null
;
}
}
@RequestMapping
(
value
=
"/lang"
,
method
=
RequestMethod
.
POST
)
...
...
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