Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
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
zengtianlai3
ioc_sixiang_license
Commits
74c76e21
Commit
74c76e21
authored
Nov 25, 2022
by
马33
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增设备获取TOKEN【接口】
parent
9d8be15d
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
130 additions
and
2 deletions
+130
-2
AuthManager.java
...e/src/main/java/iot/sixiang/license/auth/AuthManager.java
+27
-0
TerminalDeviceController.java
.../sixiang/license/controller/TerminalDeviceController.java
+25
-0
JwtFilter.java
license/src/main/java/iot/sixiang/license/jwt/JwtFilter.java
+2
-1
ResResult.java
...se/src/main/java/iot/sixiang/license/model/ResResult.java
+1
-1
GetTerminalDeviceTokenDTO.java
.../sixiang/license/model/dto/GetTerminalDeviceTokenDTO.java
+17
-0
TerminalDeviceService.java
...va/iot/sixiang/license/service/TerminalDeviceService.java
+9
-0
TerminalDeviceServiceImpl.java
...xiang/license/service/impl/TerminalDeviceServiceImpl.java
+49
-0
No files found.
license/src/main/java/iot/sixiang/license/auth/AuthManager.java
View file @
74c76e21
...
...
@@ -64,6 +64,33 @@ public class AuthManager {
}
}
// 终端设备鉴权
public
boolean
authTerminalDevice
(
String
appId
,
String
sn
,
String
sign
)
{
if
(!
allApply
.
containsKey
(
appId
))
{
log
.
info
(
"no valid appId..."
);
return
false
;
}
if
(!
deviceManager
.
getContainSn
(
sn
))
{
log
.
info
(
"no this sn..."
);
return
false
;
}
DeviceVo
device
=
deviceManager
.
getDevice
(
sn
);
int
deviceId
=
device
.
getDeviceId
();
if
(
deviceBlackMap
.
containsKey
(
deviceId
))
{
log
.
info
(
"in black..."
);
return
false
;
}
Apply
apply
=
allApply
.
get
(
appId
);
String
appKey
=
apply
.
getAppKey
();
String
input
=
"app_id="
+
appId
+
"&sn="
+
sn
;
String
valSHA1
=
HmacUtil
.
encrypt
(
input
,
appKey
,
HmacUtil
.
HMAC_SHA1
).
toUpperCase
();
if
(
CommonUtil
.
toUpperCaseByEnglish
(
sign
).
equals
(
CommonUtil
.
toUpperCaseByEnglish
(
valSHA1
)))
{
return
true
;
}
else
{
log
.
info
(
"sign no valid:"
+
input
);
return
false
;
}
}
public
boolean
auth
(
String
appId
,
String
sn
,
String
sign
)
{
if
(!
allApply
.
containsKey
(
appId
))
{
...
...
license/src/main/java/iot/sixiang/license/controller/TerminalDeviceController.java
0 → 100644
View file @
74c76e21
package
iot
.
sixiang
.
license
.
controller
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
iot.sixiang.license.model.ResResult
;
import
iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO
;
import
iot.sixiang.license.service.TerminalDeviceService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
"/iot_license/terminal_device"
)
@Api
(
value
=
"终端设备模块"
,
tags
=
{
"终端设备模块"
})
public
class
TerminalDeviceController
{
@Autowired
TerminalDeviceService
terminalDeviceService
;
@GetMapping
(
"/get_token"
)
@ApiOperation
(
value
=
"终端设备获取token"
,
notes
=
"终端设备获取token"
)
public
ResResult
getToken
(
GetTerminalDeviceTokenDTO
getTerminalDeviceTokenDTO
)
{
return
terminalDeviceService
.
getToken
(
getTerminalDeviceTokenDTO
);
}
}
license/src/main/java/iot/sixiang/license/jwt/JwtFilter.java
View file @
74c76e21
...
...
@@ -27,6 +27,7 @@ public class JwtFilter implements Filter {
private
static
final
String
url7
=
"/swagger-resources"
;
private
static
final
String
url8
=
"/webjars/"
;
private
static
final
String
url9
=
"/log/get"
;
private
static
final
String
url10
=
"/terminal_device/get_token"
;
@Override
public
void
init
(
FilterConfig
filterConfig
)
{
...
...
@@ -48,7 +49,7 @@ public class JwtFilter implements Filter {
boolean
check
=
true
;
String
uri
=
request
.
getRequestURI
();
if
(
uri
.
contains
(
url1
)
||
uri
.
contains
(
url2
)
||
uri
.
contains
(
url3
)
||
uri
.
contains
(
url4
)
||
uri
.
contains
(
url7
)
||
uri
.
contains
(
url8
)
||
uri
.
contains
(
url9
))
{
if
(
uri
.
contains
(
url1
)
||
uri
.
contains
(
url2
)
||
uri
.
contains
(
url3
)
||
uri
.
contains
(
url4
)
||
uri
.
contains
(
url7
)
||
uri
.
contains
(
url8
)
||
uri
.
contains
(
url9
)
||
uri
.
contains
(
url10
)
)
{
if
(
uri
.
contains
(
url1
)
||
uri
.
contains
(
url2
))
{
UserUtils
.
setUri
(
uri
);
}
...
...
license/src/main/java/iot/sixiang/license/model/ResResult.java
View file @
74c76e21
...
...
@@ -69,7 +69,7 @@ public class ResResult<T> {
* @return
*/
public
static
ResResult
failed
()
{
return
new
ResResult
(
ResultCode
.
SUCCESS
.
getCode
(),
ResultCode
.
SUCCESS
.
getMsg
());
return
new
ResResult
(
ResultCode
.
FAILED
.
getCode
(),
ResultCode
.
FAILED
.
getMsg
());
}
...
...
license/src/main/java/iot/sixiang/license/model/dto/GetTerminalDeviceTokenDTO.java
0 → 100644
View file @
74c76e21
package
iot
.
sixiang
.
license
.
model
.
dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
@Data
public
class
GetTerminalDeviceTokenDTO
{
@ApiModelProperty
(
"应用id"
)
private
String
appId
;
@ApiModelProperty
(
"设备编号"
)
private
String
sn
;
@ApiModelProperty
(
"签名"
)
private
String
sign
;
}
license/src/main/java/iot/sixiang/license/service/TerminalDeviceService.java
0 → 100644
View file @
74c76e21
package
iot
.
sixiang
.
license
.
service
;
import
iot.sixiang.license.model.ResResult
;
import
iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO
;
import
iot.sixiang.license.model.vo.GetTerminalDeviceTokenVO
;
public
interface
TerminalDeviceService
{
ResResult
getToken
(
GetTerminalDeviceTokenDTO
getTerminalDeviceTokenDTO
);
}
license/src/main/java/iot/sixiang/license/service/impl/TerminalDeviceServiceImpl.java
0 → 100644
View file @
74c76e21
package
iot
.
sixiang
.
license
.
service
.
impl
;
import
iot.sixiang.license.auth.AuthManager
;
import
iot.sixiang.license.device.DeviceManager
;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.jwt.JwtUtil
;
import
iot.sixiang.license.jwt.LoginUser
;
import
iot.sixiang.license.model.ResResult
;
import
iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO
;
import
iot.sixiang.license.service.TerminalDeviceService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
@Slf4j
@Service
public
class
TerminalDeviceServiceImpl
implements
TerminalDeviceService
{
@Autowired
private
AuthManager
authManager
;
@Autowired
private
DeviceManager
deviceManager
;
@Override
public
ResResult
getToken
(
GetTerminalDeviceTokenDTO
getTerminalDeviceTokenDTO
)
{
String
appId
=
getTerminalDeviceTokenDTO
.
getAppId
();
String
sn
=
getTerminalDeviceTokenDTO
.
getSn
();
String
sign
=
getTerminalDeviceTokenDTO
.
getSign
();
if
(
StringUtils
.
isEmpty
(
appId
))
{
throw
new
IotLicenseException
(
403
,
"应用id不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
sn
))
{
throw
new
IotLicenseException
(
403
,
"终端编号不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
sign
))
{
throw
new
IotLicenseException
(
403
,
"签名不能为空"
);
}
boolean
authResult
=
authManager
.
authTerminalDevice
(
appId
,
sn
,
sign
);
if
(
authResult
)
{
LoginUser
user
=
new
LoginUser
();
user
.
setUserId
(
appId
);
user
.
setUserName
(
sn
);
String
token
=
JwtUtil
.
createToken
(
user
);
return
ResResult
.
success
().
record
(
token
);
}
else
{
return
ResResult
.
validate_failed
();
}
}
}
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