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
c8b9c054
Commit
c8b9c054
authored
Oct 23, 2024
by
杨翌文
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feature: 支持单点登录
parent
08403e1a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
11 deletions
+21
-11
UserMobileController.java
.../breeze/elleai/controller/front/UserMobileController.java
+21
-11
No files found.
src/main/java/cn/breeze/elleai/controller/front/UserMobileController.java
View file @
c8b9c054
...
@@ -2,6 +2,7 @@ package cn.breeze.elleai.controller.front;
...
@@ -2,6 +2,7 @@ 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.exceptions.ExceptionUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
...
@@ -11,39 +12,48 @@ import jakarta.servlet.http.Cookie;
...
@@ -11,39 +12,48 @@ import jakarta.servlet.http.Cookie;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
jakarta.servlet.http.HttpServletResponse
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.SneakyThrows
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.hadoop.yarn.webapp.hamlet2.Hamlet
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Controller
;
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.RequestParam
;
import
org.springframework.web.bind.annotation.Res
tController
;
import
org.springframework.web.bind.annotation.Res
ponseBody
;
@RestController
import
java.io.IOException
;
@Controller
@RequestMapping
(
value
=
"/front/user"
)
@RequestMapping
(
value
=
"/front/user"
)
@Tag
(
name
=
"移动端-用户&授权"
)
@Tag
(
name
=
"移动端-用户&授权"
)
@RequiredArgsConstructor
@RequiredArgsConstructor
@Slf4j
public
class
UserMobileController
{
public
class
UserMobileController
{
@Value
(
"${sso.user.mock:true}"
)
@Value
(
"${sso.user.mock:true}"
)
private
String
enableMock
;
private
String
enableMock
;
@SneakyThrows
@Operation
(
summary
=
"单点登录"
)
@Operation
(
summary
=
"单点登录"
)
@GetMapping
(
"/sso"
)
@GetMapping
(
"/sso"
)
public
void
userSSOLogin
(
@RequestParam
(
"jwt"
)
String
token
,
HttpServletResponse
response
)
{
public
void
userSSOLogin
(
@RequestParam
(
"jwt"
)
String
token
,
HttpServletResponse
response
)
{
if
(
StrUtil
.
isNotBlank
(
token
))
{
if
(
StrUtil
.
isNotBlank
(
token
))
{
Cookie
jwt
=
new
Cookie
(
"jwt"
,
token
);
log
.
info
(
"单点登录:{}"
,
token
);
jwt
.
setPath
(
"/"
);
try
{
response
.
addCookie
(
jwt
);
Cookie
jwt
=
new
Cookie
(
"jwt"
,
token
);
response
.
sendRedirect
(
"/elle-coaching/1.0.0/index.html"
);
jwt
.
setPath
(
"/"
);
jwt
.
setHttpOnly
(
true
);
response
.
addCookie
(
jwt
);
response
.
sendRedirect
(
"/elle-coaching/1.0.0/index.html"
);
}
catch
(
IOException
e
)
{
log
.
error
(
"单点登录异常{}"
,
ExceptionUtil
.
getMessage
(
e
));
}
}
}
}
}
@Operation
(
summary
=
"获取token"
)
@Operation
(
summary
=
"获取token"
)
@GetMapping
(
"/get_token"
)
@GetMapping
(
"/get_token"
)
public
ApiResponse
<
String
>
getToken
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
@ResponseBody
ApiResponse
<
String
>
getToken
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
Cookie
[]
cookies
=
request
.
getCookies
();
Cookie
[]
cookies
=
request
.
getCookies
();
if
(
ArrayUtil
.
isNotEmpty
(
cookies
))
{
if
(
ArrayUtil
.
isNotEmpty
(
cookies
))
{
Cookie
cookie
=
ArrayUtil
.
firstMatch
(
c
->
StrUtil
.
equals
(
c
.
getName
(),
"jwt"
),
cookies
);
Cookie
cookie
=
ArrayUtil
.
firstMatch
(
c
->
StrUtil
.
equals
(
c
.
getName
(),
"jwt"
),
cookies
);
...
@@ -62,7 +72,7 @@ public class UserMobileController {
...
@@ -62,7 +72,7 @@ public class UserMobileController {
@Operation
(
summary
=
"获取用户信息"
)
@Operation
(
summary
=
"获取用户信息"
)
@GetMapping
(
"/info"
)
@GetMapping
(
"/info"
)
public
ApiResponse
<
UserPrincipal
>
getUserInfo
(
UserPrincipal
userPrincipal
)
{
public
@ResponseBody
ApiResponse
<
UserPrincipal
>
getUserInfo
(
UserPrincipal
userPrincipal
)
{
return
ApiResponse
.
ok
(
userPrincipal
);
return
ApiResponse
.
ok
(
userPrincipal
);
}
}
...
...
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