Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
周海宝
/
auth-server-parent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3e4e8b4c
authored
Apr 19, 2023
by
刘宇峰
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
授权服务
1 parent
31448eae
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
101 additions
and
10 deletions
platform-auth-api/src/main/java/cn/com/glsx/auth/config/ApiGatewayServiceConfig.java
platform-auth/src/main/java/cn/com/glsx/auth/modules/controller/AuthController.java
platform-auth/src/main/java/cn/com/glsx/auth/modules/controller/LoginController.java
platform-auth/src/main/java/cn/com/glsx/auth/modules/request/LoginRequest.java
platform-auth/src/main/java/cn/com/glsx/auth/modules/request/CraneQueryAccessTokenRequest.java → platform-auth/src/main/java/cn/com/glsx/auth/modules/request/QueryAccessTokenRequest.java
platform-auth-api/src/main/java/cn/com/glsx/auth/config/ApiGatewayServiceConfig.java
View file @
3e4e8b4
...
...
@@ -5,6 +5,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
...
...
@@ -29,7 +30,7 @@ public class ApiGatewayServiceConfig {
public
void
setServices
(
Map
<
String
,
GatewayService
>
services
)
{
Map
<
String
,
GatewayService
>
newMap
=
new
ConcurrentHashMap
<>();
for
(
Map
.
Entry
<
String
,
GatewayService
>
entry
:
services
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
GatewayService
>
entry
:
services
.
entrySet
())
{
GatewayService
gatewayService
=
entry
.
getValue
();
gatewayService
.
setName
(
entry
.
getKey
());
newMap
.
put
(
gatewayService
.
getAppKey
(),
gatewayService
);
...
...
@@ -37,7 +38,17 @@ public class ApiGatewayServiceConfig {
this
.
services
=
newMap
;
}
public
GatewayService
getServiceByAppKey
(
String
appKey
){
return
this
.
services
.
get
(
appKey
);
public
GatewayService
getServiceByAppKey
(
String
appKey
)
{
return
this
.
services
.
get
(
appKey
);
}
public
GatewayService
getServiceByName
(
String
serName
)
{
for
(
GatewayService
v
:
services
.
values
())
{
if
(
Objects
.
equals
(
v
.
getName
(),
serName
))
{
return
v
;
}
}
return
null
;
}
}
platform-auth/src/main/java/cn/com/glsx/auth/modules/controller/AuthController.java
View file @
3e4e8b4
...
...
@@ -3,13 +3,17 @@ package cn.com.glsx.auth.modules.controller;
import
cn.com.glsx.auth.config.ApiGatewayServiceConfig
;
import
cn.com.glsx.auth.model.GatewayService
;
import
cn.com.glsx.auth.model.OpenApiResult
;
import
cn.com.glsx.auth.modules.request.
Crane
QueryAccessTokenRequest
;
import
cn.com.glsx.auth.modules.request.QueryAccessTokenRequest
;
import
cn.com.glsx.auth.modules.utils.SM3Utils
;
import
cn.com.glsx.auth.utils.GatewayJwtUtils
;
import
com.glsx.plat.common.annotation.SysLog
;
import
com.glsx.plat.common.enums.OperateType
;
import
com.glsx.plat.common.utils.DateUtils
;
import
com.glsx.plat.common.utils.MD5Util
;
import
com.glsx.plat.exception.OpenApiResultException
;
import
com.glsx.plat.exception.ResultException
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -31,6 +35,7 @@ import java.util.Map;
* @Date 2023/4/6 18:08
*/
@Slf4j
@Tag
(
name
=
"授权Api接口"
)
@RestController
@RequestMapping
(
value
=
"/open/api"
)
public
class
AuthController
{
...
...
@@ -41,10 +46,12 @@ public class AuthController {
@Autowired
private
GatewayJwtUtils
gatewayJwtUtils
;
@SysLog
(
module
=
"授权"
,
action
=
OperateType
.
API
,
value
=
"授权"
,
saveLog
=
false
)
@Operation
(
summary
=
"获取AccessToken接口"
,
description
=
"提供给客户方的业务接口的认证令牌,在调用其他接口时,作为调用接口的凭证参数"
)
@PostMapping
(
"/access/queryAccessToken"
)
public
OpenApiResult
<
Map
<
String
,
Object
>>
queryAccessToken
(
@Valid
@RequestBody
Crane
QueryAccessTokenRequest
request
)
{
public
OpenApiResult
<
Map
<
String
,
Object
>>
queryAccessToken
(
@Valid
@RequestBody
QueryAccessTokenRequest
request
)
{
try
{
GatewayService
gatewayService
=
ver
r
fyRequestParam
(
request
);
GatewayService
gatewayService
=
ver
i
fyRequestParam
(
request
);
//生成token返回
Map
<
String
,
Object
>
userMap
=
new
HashMap
<>();
userMap
.
put
(
"name"
,
gatewayService
.
getName
());
...
...
@@ -55,11 +62,11 @@ public class AuthController {
resultMap
.
put
(
"expiresAt"
,
DateUtils
.
format
(
DateUtils
.
addDateDays
(
new
Date
(),
1
),
DateUtils
.
NORMAL_DATE_TIME_PATTERN
));
return
OpenApiResult
.
success
(
resultMap
);
}
catch
(
Exception
e
)
{
throw
OpenApiResultException
.
create
(
"授权失败
"
);
throw
OpenApiResultException
.
create
(
"授权失败
"
+
e
.
getMessage
()
);
}
}
private
GatewayService
ver
rfyRequestParam
(
Crane
QueryAccessTokenRequest
request
)
{
private
GatewayService
ver
ifyRequestParam
(
QueryAccessTokenRequest
request
)
{
GatewayService
gatewayService
=
apiGatewayServiceConfig
.
getServiceByAppKey
(
request
.
getAppKey
());
if
(
gatewayService
==
null
)
{
throw
ResultException
.
create
(
"请求参数校验不通过"
);
...
...
platform-auth/src/main/java/cn/com/glsx/auth/modules/controller/LoginController.java
0 → 100644
View file @
3e4e8b4
package
cn
.
com
.
glsx
.
auth
.
modules
.
controller
;
import
cn.com.glsx.auth.modules.request.LoginRequest
;
import
com.glsx.plat.common.annotation.SysLog
;
import
com.glsx.plat.common.enums.OperateType
;
import
com.glsx.plat.core.web.R
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.HashMap
;
import
java.util.Map
;
@Slf4j
@Tag
(
name
=
"登录接口"
)
@RestController
@RequestMapping
(
value
=
"/login"
)
public
class
LoginController
{
@Operation
(
summary
=
"系统登录"
,
description
=
"通过账号密码或手机验证码方式登录系统"
)
@SysLog
(
module
=
"系统登录"
,
action
=
OperateType
.
LOGIN
,
value
=
"登录"
,
saveLog
=
false
)
@PostMapping
(
value
=
"/login"
)
public
R
login
(
@RequestBody
@Validated
LoginRequest
request
)
{
//1、用户中心登录
//User user = userService.localAuth(request);
//2、创建授权令牌
String
token
=
"123456"
;
Map
<
String
,
Object
>
rtnMap
=
new
HashMap
<>();
//rtnMap.put("user", user);
rtnMap
.
put
(
"token"
,
token
);
return
R
.
ok
().
data
(
rtnMap
);
}
@Operation
(
summary
=
"登出系统"
)
@SysLog
(
module
=
"系统登出"
,
action
=
OperateType
.
LOGOUT
,
value
=
"登出"
,
saveLog
=
false
)
@GetMapping
(
value
=
"/logout"
)
public
R
logout
()
{
return
R
.
ok
();
}
}
platform-auth/src/main/java/cn/com/glsx/auth/modules/request/LoginRequest.java
0 → 100644
View file @
3e4e8b4
package
cn
.
com
.
glsx
.
auth
.
modules
.
request
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
@Data
public
class
LoginRequest
{
@Schema
(
description
=
"登录平台"
)
private
String
platform
;
@Schema
(
description
=
"登录类型(1xxx,2xxx)"
)
@NotNull
(
message
=
"登录类型不能为空"
)
private
Integer
loginType
;
@Schema
(
description
=
"账号"
)
@NotBlank
(
message
=
"账号不能为空"
)
private
String
account
;
@Schema
(
description
=
"验证码/密码"
)
@NotBlank
(
message
=
"验证码/密码不能为空"
)
private
String
code
;
}
platform-auth/src/main/java/cn/com/glsx/auth/modules/request/
Crane
QueryAccessTokenRequest.java
→
platform-auth/src/main/java/cn/com/glsx/auth/modules/request/QueryAccessTokenRequest.java
View file @
3e4e8b4
...
...
@@ -7,13 +7,13 @@ import javax.validation.constraints.NotBlank;
/**
* @author huangch
* @version V1.0
* @Title:
Crane
QueryAccessTokenRequest
* @Title: QueryAccessTokenRequest
* @Description:
* @Company: Didihu.com.cn
* @Date 2023/4/13 15:31
*/
@Data
public
class
Crane
QueryAccessTokenRequest
{
public
class
QueryAccessTokenRequest
{
@NotBlank
(
message
=
"appKey不能为空"
)
private
String
appKey
;
...
...
@@ -28,4 +28,5 @@ public class CraneQueryAccessTokenRequest {
private
String
timestamp
;
private
String
grantType
;
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment