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
26852d39
Commit
26852d39
authored
Jun 07, 2022
by
zengtianlai3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改鉴权
parent
e2312047
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
34 deletions
+71
-34
AuthManager.java
...e/src/main/java/iot/sixiang/license/auth/AuthManager.java
+47
-24
DeviceServerHandler.java
.../java/iot/sixiang/license/device/DeviceServerHandler.java
+21
-7
CreateForwarClientEventHandler.java
...sixiang/license/event/CreateForwarClientEventHandler.java
+3
-3
No files found.
license/src/main/java/iot/sixiang/license/auth/AuthManager.java
View file @
26852d39
package
iot
.
sixiang
.
license
.
auth
;
package
iot
.
sixiang
.
license
.
auth
;
import
iot.sixiang.license.entity.Server
;
import
iot.sixiang.license.entity.License
;
import
iot.sixiang.license.service.ServerService
;
import
iot.sixiang.license.entity.User
;
import
iot.sixiang.license.service.LicenseService
;
import
iot.sixiang.license.service.UserService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PostConstruct
;
import
java.util.*
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Component
@Component
@Slf4j
@Slf4j
public
class
AuthManager
{
public
class
AuthManager
{
@Autowired
@Autowired
private
ServerService
serverService
;
private
UserService
userService
;
@Autowired
private
LicenseService
licenseService
;
private
Map
<
String
,
Server
>
allServers
=
null
;
private
Map
<
String
,
User
>
allUsers
=
null
;
private
Map
<
String
,
License
>
allLicense
=
null
;
public
AuthManager
()
{
public
AuthManager
()
{
allServers
=
new
HashMap
<
String
,
Server
>();
allUsers
=
new
HashMap
<
String
,
User
>();
allLicense
=
new
HashMap
<
String
,
License
>();
}
}
@PostConstruct
@PostConstruct
public
void
init
()
{
public
void
init
()
{
List
<
Server
>
servers
=
serverService
.
getServerList
(
0
,
20
);
initUsers
();
for
(
Server
server
:
servers
)
{
initLicense
();
String
serverIp
=
server
.
getServerIp
();
allServers
.
put
(
serverIp
,
server
);
}
}
}
public
Server
getBalanceServer
(){
private
void
initUsers
()
{
int
count
=
allServers
.
size
();
List
<
User
>
users
=
userService
.
getUserList
(
0
,
20
);
if
(
count
==
0
){
for
(
User
user
:
users
)
{
return
null
;
String
userId
=
user
.
getUserId
();
}
else
{
allUsers
.
put
(
userId
,
user
);
Random
random
=
new
Random
();
int
index
=
random
.
nextInt
(
count
);
List
<
Server
>
servers
=
new
ArrayList
<>(
allServers
.
values
());
return
servers
.
get
(
index
);
}
}
}
}
private
void
initLicense
()
{
List
<
License
>
licenses
=
licenseService
.
getLicenseList
(
0
,
20
);
for
(
License
license
:
licenses
)
{
String
appId
=
license
.
getAppId
();
allLicense
.
put
(
appId
,
license
);
}
}
public
boolean
auth
(
String
userId
,
String
password
,
String
appId
,
String
appKey
)
{
if
(!
allUsers
.
containsKey
(
userId
))
{
return
false
;
}
else
{
User
user
=
allUsers
.
get
(
userId
);
if
(
user
.
getPassword
()
!=
password
)
{
return
false
;
}
}
if
(!
allLicense
.
containsKey
(
appId
))
{
return
false
;
}
else
{
License
license
=
allLicense
.
get
(
appId
);
if
(
license
.
getAppKey
()
!=
appKey
)
{
return
false
;
}
}
return
true
;
}
}
}
license/src/main/java/iot/sixiang/license/device/DeviceServerHandler.java
View file @
26852d39
package
iot
.
sixiang
.
license
.
device
;
package
iot
.
sixiang
.
license
.
device
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
io.netty.channel.ChannelHandler
;
import
io.netty.channel.ChannelHandler
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.SimpleChannelInboundHandler
;
import
io.netty.channel.SimpleChannelInboundHandler
;
import
io.netty.channel.socket.SocketChannel
;
import
io.netty.channel.socket.SocketChannel
;
import
iot.sixiang.license.auth.AuthManager
;
import
iot.sixiang.license.consts.Consts
;
import
iot.sixiang.license.consts.Consts
;
import
iot.sixiang.license.event.CreateForwarClientEvent
;
import
iot.sixiang.license.event.CreateForwarClientEvent
;
import
iot.sixiang.license.event.DeviceClientInactiveEvent
;
import
iot.sixiang.license.event.DeviceClientInactiveEvent
;
...
@@ -51,8 +54,8 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
...
@@ -51,8 +54,8 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
*/
*/
byte
cmd
=
protocol
.
getCmd
();
byte
cmd
=
protocol
.
getCmd
();
int
cmdInt
=
cmd
&
0xFF
;
int
cmdInt
=
cmd
&
0xFF
;
log
.
info
(
"real cmd:"
+
cmdInt
);
log
.
info
(
"real cmd:"
+
cmdInt
);
log
.
info
(
"收到的消息:"
+
HexUtil
.
bytes2hex
(
protocol
.
getContent
()));
log
.
info
(
"收到的消息:"
+
HexUtil
.
bytes2hex
(
protocol
.
getContent
()));
boolean
license
=
false
;
boolean
license
=
false
;
// cmdInt = Consts.CMD_LICENSE;
// cmdInt = Consts.CMD_LICENSE;
...
@@ -153,13 +156,24 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
...
@@ -153,13 +156,24 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
private
boolean
handlerLicense
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
private
boolean
handlerLicense
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
String
jsonLicense
=
new
String
(
protocol
.
getContent
(),
0
,
protocol
.
getContent
().
length
);
String
jsonLicense
=
new
String
(
protocol
.
getContent
(),
0
,
protocol
.
getContent
().
length
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
jsonLicense
);
String
appId
=
"123456"
;
String
userId
=
jsonObject
.
getString
(
"userId"
);
String
appKey
=
"123456"
;
String
password
=
jsonObject
.
getString
(
"password"
);
String
appId
=
jsonObject
.
getString
(
"appId"
);
String
appKey
=
jsonObject
.
getString
(
"appKey"
);
// String userId = "12345";
// String password = "1234";
// String appId = "12222";
// String appKey = "1234455";
String
token
=
"123456"
;
String
token
=
"123456"
;
String
channelId
=
channel
.
id
().
asLongText
();
boolean
license
=
true
;
AuthManager
authManager
=
SpringUtil
.
getBean
(
AuthManager
.
class
);
boolean
license
=
authManager
.
auth
(
userId
,
password
,
appId
,
appKey
);
String
channelId
=
channel
.
id
().
asLongText
();
if
(
license
)
{
if
(
license
)
{
SessionContext
session
=
new
SessionContext
();
SessionContext
session
=
new
SessionContext
();
session
.
setRemoteIp
(
remoteIp
);
session
.
setRemoteIp
(
remoteIp
);
...
...
license/src/main/java/iot/sixiang/license/event/CreateForwarClientEventHandler.java
View file @
26852d39
package
iot
.
sixiang
.
license
.
event
;
package
iot
.
sixiang
.
license
.
event
;
import
iot.sixiang.license.
auth.Auth
Manager
;
import
iot.sixiang.license.
balance.Balance
Manager
;
import
iot.sixiang.license.entity.Server
;
import
iot.sixiang.license.entity.Server
;
import
iot.sixiang.license.forward.ForwardManager
;
import
iot.sixiang.license.forward.ForwardManager
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -18,7 +18,7 @@ public class CreateForwarClientEventHandler {
...
@@ -18,7 +18,7 @@ public class CreateForwarClientEventHandler {
@Autowired
@Autowired
EventPublisher
eventPublisher
;
EventPublisher
eventPublisher
;
@Autowired
@Autowired
AuthManager
auth
Manager
;
BalanceManager
balance
Manager
;
public
CreateForwarClientEventHandler
()
{
public
CreateForwarClientEventHandler
()
{
...
@@ -30,7 +30,7 @@ public class CreateForwarClientEventHandler {
...
@@ -30,7 +30,7 @@ public class CreateForwarClientEventHandler {
String
appId
=
event
.
getAppId
();
String
appId
=
event
.
getAppId
();
Server
balanceServer
=
auth
Manager
.
getBalanceServer
();
Server
balanceServer
=
balance
Manager
.
getBalanceServer
();
if
(
balanceServer
!=
null
)
{
if
(
balanceServer
!=
null
)
{
String
serverIp
=
balanceServer
.
getServerIp
();
String
serverIp
=
balanceServer
.
getServerIp
();
Integer
port
=
balanceServer
.
getPort
();
Integer
port
=
balanceServer
.
getPort
();
...
...
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