Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elleai
Project
Project
Details
Activity
Releases
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
ai-tech
E
ellehuis-group
backend
elleai
Commits
08403e1a
Commit
08403e1a
authored
Oct 23, 2024
by
杨翌文
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feature: 支持单点登录
parent
9abdedb3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
3 deletions
+40
-3
UserMobileController.java
.../breeze/elleai/controller/front/UserMobileController.java
+40
-3
No files found.
src/main/java/cn/breeze/elleai/controller/front/UserMobileController.java
View file @
08403e1a
...
@@ -2,11 +2,22 @@ package cn.breeze.elleai.controller.front;
...
@@ -2,11 +2,22 @@ package cn.breeze.elleai.controller.front;
import
cn.breeze.elleai.application.dto.ApiResponse
;
import
cn.breeze.elleai.application.dto.ApiResponse
;
import
cn.breeze.elleai.util.UserPrincipal
;
import
cn.breeze.elleai.util.UserPrincipal
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.servlet.http.Cookie
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.SneakyThrows
;
import
org.apache.hadoop.yarn.webapp.hamlet2.Hamlet
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RestController
...
@@ -15,11 +26,37 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -15,11 +26,37 @@ import org.springframework.web.bind.annotation.RestController;
@RequiredArgsConstructor
@RequiredArgsConstructor
public
class
UserMobileController
{
public
class
UserMobileController
{
@Value
(
"${sso.user.mock:true}"
)
private
String
enableMock
;
@SneakyThrows
@Operation
(
summary
=
"单点登录"
)
@GetMapping
(
"/sso"
)
public
void
userSSOLogin
(
@RequestParam
(
"jwt"
)
String
token
,
HttpServletResponse
response
)
{
if
(
StrUtil
.
isNotBlank
(
token
))
{
Cookie
jwt
=
new
Cookie
(
"jwt"
,
token
);
jwt
.
setPath
(
"/"
);
response
.
addCookie
(
jwt
);
response
.
sendRedirect
(
"/elle-coaching/1.0.0/index.html"
);
}
}
@Operation
(
summary
=
"获取token"
)
@Operation
(
summary
=
"获取token"
)
@GetMapping
(
"/get_token"
)
@GetMapping
(
"/get_token"
)
public
ApiResponse
<
String
>
getToken
()
{
public
ApiResponse
<
String
>
getToken
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
//todo 移除mock数据,通过cookie获取返回
Cookie
[]
cookies
=
request
.
getCookies
();
return
ApiResponse
.
ok
(
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqb2JUaXRsZSI6IuengeS6uumhvumXriIsImlzcyI6Im9zcyIsInNob3BOYW1lIjoi5p2P5Z2b5a6P5rGH5Z-O5bqXIiwicG9zaXRpb24iOiLpob7pl64iLCJzaG9wSWQiOiIwMDAwMDAwMDZlODY2OTVlMDE2ZTg2ZDJiYTkyMDAwOCIsInVzZXJOYW1lIjoiTTAwODg3NyIsImV4cCI6MTgxMTY3NDQ5NCwidXNlcklkIjoiMDAwMDAwMDA2MmQ3NWRiNTAxNjJkNzc1YjYxOTAwMGEifQ.4XCYKRVuHTaP3TYob7O31bpPnhoBQ9XSq1inM93IqYE"
);
if
(
ArrayUtil
.
isNotEmpty
(
cookies
))
{
Cookie
cookie
=
ArrayUtil
.
firstMatch
(
c
->
StrUtil
.
equals
(
c
.
getName
(),
"jwt"
),
cookies
);
if
(
ObjectUtil
.
isNotNull
(
cookie
))
{
return
ApiResponse
.
ok
(
cookie
.
getValue
());
}
}
if
(
StrUtil
.
equals
(
enableMock
,
"true"
))
{
return
ApiResponse
.
ok
(
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqb2JUaXRsZSI6IuengeS6uumhvumXriIsImlzcyI6Im9zcyIsInNob3BOYW1lIjoi5p2P5Z2b5a6P5rGH5Z-O5bqXIiwicG9zaXRpb24iOiLpob7pl64iLCJzaG9wSWQiOiIwMDAwMDAwMDZlODY2OTVlMDE2ZTg2ZDJiYTkyMDAwOCIsInVzZXJOYW1lIjoiTTAwODg3NyIsImV4cCI6MTgxMTY3NDQ5NCwidXNlcklkIjoiMDAwMDAwMDA2MmQ3NWRiNTAxNjJkNzc1YjYxOTAwMGEifQ.4XCYKRVuHTaP3TYob7O31bpPnhoBQ9XSq1inM93IqYE"
);
}
response
.
setStatus
(
HttpStatus
.
UNAUTHORIZED
.
value
());
return
ApiResponse
.
fail
(
401
,
"登录失败"
);
}
}
...
...
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